18#include "BDSAcceleratorModel.hh"
19#include "BDSBeamline.hh"
20#include "BDSBeamlineElement.hh"
21#include "BDSMessenger.hh"
22#include "BDSParser.hh"
23#include "BDSSamplerRegistry.hh"
24#include "BDSUIcmdStringInt.hh"
25#include "BDSUtilities.hh"
27#include "parser/query.h"
30#include "G4UImanager.hh"
31#include "G4UIdirectory.hh"
32#include "G4UIcmdWithoutParameter.hh"
33#include "G4UIcmdWithAString.hh"
41BDSMessenger::BDSMessenger()
43 bdsDirectory =
new G4UIdirectory(
"/bds/");
44 bdsDirectory->SetGuidance(
"BDSIM commands");
46 bdsBeamlineDirectory =
new G4UIdirectory(
"/bds/beamline/");
48 beamlineListCmd =
new G4UIcmdWithoutParameter(
"/bds/beamline/list",
this);
49 beamlineListCmd->SetGuidance(
"List beamline components");
51 elementNameSearchCmd =
new G4UIcmdWithAString(
"/bds/beamline/namesearch",
this);
52 elementNameSearchCmd->SetGuidance(
"Search beamline components for element");
55 G4String elementGoToCmdGuidance =
"Move the viewpoint to a particular element's location. ";
56 elementGoToCmdGuidance +=
"Arguments are the name of an element in the beam line and optionally,";
57 elementGoToCmdGuidance +=
" the instance number (zero-counting).";
58 elementGoToCmd->SetGuidance(elementGoToCmdGuidance);
60 bdsSamplersDirectory =
new G4UIdirectory(
"/bds/samplers/");
61 samplerListCmd =
new G4UIcmdWithoutParameter(
"/bds/samplers/list",
this);
62 samplerListCmd->SetGuidance(
"List samplers");
64 samplerViewCmd =
new G4UIcmdWithoutParameter(
"/bds/samplers/view",
this);
65 samplerViewCmd->SetGuidance(
"View sampler paralle world");
67 queryListCmd =
new G4UIcmdWithoutParameter(
"/bds/field/listQueries",
this);
68 queryListCmd->SetGuidance(
"List all queries defined in input");
74BDSMessenger::~BDSMessenger()
77 delete bdsBeamlineDirectory;
78 delete beamlineListCmd;
79 delete elementNameSearchCmd;
80 delete elementGoToCmd;
81 delete bdsSamplersDirectory;
82 delete samplerListCmd;
83 delete samplerViewCmd;
86void BDSMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
88 if(command == beamlineListCmd)
90 else if(command == elementNameSearchCmd)
91 {ElementNameSearch(newValue);}
92 else if(command == elementGoToCmd)
93 {GoToElement(newValue);}
94 else if(command == samplerListCmd)
96 else if (command == samplerViewCmd)
98 else if (command == queryListCmd)
102void BDSMessenger::BeamLineList()
107 auto flagsCache(G4cout.flags());
109 << std::setw(4) <<
"index" << std::setfill(
' ')
110 << std::setw(25) <<
"name"
111 << std::setw(25) <<
"placement name"
112 << std::setw(20) <<
"type"
113 << std::setw(20) <<
"S-middle[m]" << G4endl;
114 for (
auto i = beamline->
begin(); i != beamline->
end(); ++i, ++j)
115 {G4cout << BDSBeamlineElementToString(j) << G4endl;}
116 G4cout.flags(flagsCache);
119std::string BDSMessenger::BDSBeamlineElementToString(G4int iElement)
121 std::stringstream ss;
126 ss << std::setfill(
'0') << std::right << std::setw(4) << iElement <<
" " << std::setfill(
' ')
127 << std::setw(25) << e->
GetName()
129 << std::setw(20) << e->
GetType()
130 << std::setw(20) << std::setprecision(4) << std::fixed << e->
GetSPositionMiddle()/CLHEP::m;
135void BDSMessenger::ElementNameSearch(std::string name)
138 for (
auto i = beamline->
begin(); i != beamline->
end(); ++i)
141 {G4cout << (*i)->GetName() << G4endl;}
145void BDSMessenger::GoToElement(
const std::string& value)
148 {G4cerr <<
"empty string given - can't search" << G4endl;
return;}
150 G4String name = words[0];
152 if (words.size() > 1)
153 {instance = std::stoi(words[1]);}
158 {G4cout <<
"No beam line in this model so not possible to search it.";
return;}
166 for (
const auto& el : *beamline)
171 if (count == instance)
180 G4cout <<
"No component found by that name" << G4endl;
182 {G4cout <<
"only " << count <<
" instances found." << G4endl;}
188 G4cout <<
"goto> " << name <<
" at global position> " << pos/CLHEP::m <<
" m" << G4endl;
189 G4UImanager* UIManager = G4UImanager::GetUIpointer();
190 G4String posStr = std::to_string(pos.x()) +
" " + std::to_string(pos.y()) +
" " + std::to_string(pos.z());
191 UIManager->ApplyCommand(
"/vis/viewer/set/targetPoint " + posStr +
" mm");
194void BDSMessenger::ElementTypeSearch(std::string )
197void BDSMessenger::SamplerList()
201 G4cout <<
"No samplers defined" << G4endl;
205 {G4cout << name << G4endl;}
208void BDSMessenger::ViewSamplers()
213 G4UImanager* UIManager = G4UImanager::GetUIpointer();
214 UIManager->ApplyCommand(
"/vis/scene/add/volume SamplerWorld_main");
215 UIManager->ApplyCommand(
"/vis/sceneHandler/attach");
216 UIManager->ApplyCommand(
"/vis/scene/endOfEventAction accumulate");
217 UIManager->ApplyCommand(
"/vis/scene/add/trajectories");
218 UIManager->ApplyCommand(
"/vis/ogl/flushAt endOfEvent");
221std::string BDSMessenger::BDSSamplerToString(std::string )
223 return std::string();
226std::string BDSMessenger::BDSSamplerToString(
int iSampler)
228 std::stringstream ss;
232 ss << std::setfill(
'0') << std::right << std::setw(4) << iSampler <<
" " << std::setfill(
' ')
233 << std::right << std::setw(20) << sInfo.
Name() <<
" "
234 << std::right << std::setw(20) << sInfo.
SPosition();
238void BDSMessenger::ListQueries()
241 for (
const auto& qu : queries)
242 {G4cout << qu.name << G4endl;}
const BDSBeamline * BeamlineMain() const
Accessor.
A class that holds a fully constructed BDSAcceleratorComponent as well as any information relevant to...
G4String GetPlacementName() const
Accessor.
G4String GetName() const
Accessor.
G4ThreeVector GetReferencePositionMiddle() const
Accessor.
G4double GetSPositionMiddle() const
Accessor.
G4String GetType() const
Accessor.
A vector of BDSBeamlineElement instances - a beamline.
const BDSBeamlineElement * GetElement(G4String acceleratorComponentName, G4int i=0) const
Get the ith placement of an element in the beam line. Returns null pointer if not found.
const BDSBeamlineElement * at(int iElement) const
Return a reference to the element at i.
iterator begin()
Iterator mechanics.
iterator end()
Iterator mechanics.
static BDSParser * Instance()
Access method.
std::vector< GMAD::Query > GetQueries() const
Return the parser list of that object.
Information about a registered sampler.
G4String Name() const
Accessor.
G4double SPosition() const
Accessor.
Associated information for the placement of a sampler.
static BDSSamplerRegistry * Instance()
Accessor for registry.
const BDSSamplerPlacementRecord & GetInfo(G4int index) const
Accessor.
UI command with string, then optional integer argument.
G4bool StrContains(const G4String &str, const G4String &test)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
std::vector< G4String > SplitOnWhiteSpace(const G4String &input)
Split a string on whitespace and return a vector of these 'words'.