19#include "BDSAcceleratorModel.hh"
20#include "BDSBeamline.hh"
21#include "BDSBeamlineElement.hh"
22#include "BDSMessenger.hh"
23#include "BDSParser.hh"
24#include "BDSSamplerRegistry.hh"
25#include "BDSUIcmdStringInt.hh"
26#include "BDSUtilities.hh"
28#include "parser/query.h"
31#include "G4UImanager.hh"
32#include "G4UIdirectory.hh"
33#include "G4UIcmdWithoutParameter.hh"
34#include "G4UIcmdWithAString.hh"
42BDSMessenger::BDSMessenger()
44 bdsDirectory =
new G4UIdirectory(
"/bds/");
45 bdsDirectory->SetGuidance(
"BDSIM commands");
47 bdsBeamlineDirectory =
new G4UIdirectory(
"/bds/beamline/");
49 beamlineListCmd =
new G4UIcmdWithoutParameter(
"/bds/beamline/list",
this);
50 beamlineListCmd->SetGuidance(
"List beamline components");
52 elementNameSearchCmd =
new G4UIcmdWithAString(
"/bds/beamline/namesearch",
this);
53 elementNameSearchCmd->SetGuidance(
"Search beamline components for element");
56 G4String elementGoToCmdGuidance =
"Move the viewpoint to a particular element's location. ";
57 elementGoToCmdGuidance +=
"Arguments are the name of an element in the beam line and optionally,";
58 elementGoToCmdGuidance +=
" the instance number (zero-counting).";
59 elementGoToCmd->SetGuidance(elementGoToCmdGuidance);
61 bdsSamplersDirectory =
new G4UIdirectory(
"/bds/samplers/");
62 samplerListCmd =
new G4UIcmdWithoutParameter(
"/bds/samplers/list",
this);
63 samplerListCmd->SetGuidance(
"List samplers");
65 samplerViewCmd =
new G4UIcmdWithoutParameter(
"/bds/samplers/view",
this);
66 samplerViewCmd->SetGuidance(
"View sampler paralle world");
68 queryListCmd =
new G4UIcmdWithoutParameter(
"/bds/field/listQueries",
this);
69 queryListCmd->SetGuidance(
"List all queries defined in input");
75BDSMessenger::~BDSMessenger()
78 delete bdsBeamlineDirectory;
79 delete beamlineListCmd;
80 delete elementNameSearchCmd;
81 delete elementGoToCmd;
82 delete bdsSamplersDirectory;
83 delete samplerListCmd;
84 delete samplerViewCmd;
87void BDSMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
89 if(command == beamlineListCmd)
91 else if(command == elementNameSearchCmd)
92 {ElementNameSearch(newValue);}
93 else if(command == elementGoToCmd)
94 {GoToElement(newValue);}
95 else if(command == samplerListCmd)
97 else if (command == samplerViewCmd)
99 else if (command == queryListCmd)
103void BDSMessenger::BeamLineList()
108 auto flagsCache(G4cout.flags());
110 << std::setw(4) <<
"index" << std::setfill(
' ')
111 << std::setw(25) <<
"name"
112 << std::setw(25) <<
"placement name"
113 << std::setw(20) <<
"type"
114 << std::setw(20) <<
"S-middle[m]" << G4endl;
115 for (
auto i = beamline->
begin(); i != beamline->
end(); ++i, ++j)
116 {G4cout << BDSBeamlineElementToString(j) << G4endl;}
117 G4cout.flags(flagsCache);
120std::string BDSMessenger::BDSBeamlineElementToString(G4int iElement)
122 std::stringstream ss;
127 ss << std::setfill(
'0') << std::right << std::setw(4) << iElement <<
" " << std::setfill(
' ')
128 << std::setw(25) << e->
GetName()
130 << std::setw(20) << e->
GetType()
131 << std::setw(20) << std::setprecision(4) << std::fixed << e->
GetSPositionMiddle()/CLHEP::m;
136void BDSMessenger::ElementNameSearch(std::string name)
140 for (
auto i = beamline->
begin(); i != beamline->
end(); ++i, ++j)
143 {G4cout << (*i)->GetName() << G4endl;}
147void BDSMessenger::GoToElement(
const std::string& value)
150 {G4cerr <<
"empty string given - can't search" << G4endl;
return;}
152 G4String name = words[0];
154 if (words.size() > 1)
155 {instance = std::stoi(words[1]);}
160 {G4cout <<
"No beam line in this model so not possible to search it.";
return;}
168 for (
const auto& el : *beamline)
173 if (count == instance)
182 G4cout <<
"No component found by that name" << G4endl;
184 {G4cout <<
"only " << count <<
" instances found." << G4endl;}
190 G4cout <<
"goto> " << name <<
" at global position> " << pos/CLHEP::m <<
" m" << G4endl;
191 G4UImanager* UIManager = G4UImanager::GetUIpointer();
192 G4String posStr = std::to_string(pos.x()) +
" " + std::to_string(pos.y()) +
" " + std::to_string(pos.z());
193 UIManager->ApplyCommand(
"/vis/viewer/set/targetPoint " + posStr +
" mm");
196void BDSMessenger::ElementTypeSearch(std::string )
199void BDSMessenger::SamplerList()
202 {G4cout << name << G4endl;}
205void BDSMessenger::ViewSamplers()
210 G4UImanager* UIManager = G4UImanager::GetUIpointer();
211 UIManager->ApplyCommand(
"/vis/scene/add/volume SamplerWorld_main");
212 UIManager->ApplyCommand(
"/vis/sceneHandler/attach");
213 UIManager->ApplyCommand(
"/vis/scene/endOfEventAction accumulate");
214 UIManager->ApplyCommand(
"/vis/scene/add/trajectories");
215 UIManager->ApplyCommand(
"/vis/ogl/flushAt endOfEvent");
218std::string BDSMessenger::BDSSamplerToString(std::string )
220 return std::string();
223std::string BDSMessenger::BDSSamplerToString(
int iSampler)
225 std::stringstream ss;
229 ss << std::setfill(
'0') << std::right << std::setw(4) << iSampler <<
" " << std::setfill(
' ')
230 << std::right << std::setw(20) << sInfo.
Name() <<
" "
231 << std::right << std::setw(20) << sInfo.
SPosition();
235void BDSMessenger::ListQueries()
238 for (
const auto& qu : queries)
239 {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 > GetQuery() const
Return the parser list of that object.
Information about a registered sampler.
G4String Name() const
Accessor.
G4double SPosition() const
Accessor.
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'.