SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
LcioMessenger.cc
Go to the documentation of this file.
1 // SLIC
2 #include "LcioMessenger.hh"
3 #include "LcioManager.hh"
4 #include "LcioFileNamer.hh"
5 
6 // LCDD
7 #include "lcdd/util/StringUtil.hh"
8 
9 // Geant4
10 #include "G4UIcommand.hh"
11 #include "G4UIcmdWithAnInteger.hh"
12 #include "G4UIcmdWithABool.hh"
13 #include "G4UIdirectory.hh"
14 #include "G4UImanager.hh"
15 
16 // STL
17 #include <sstream>
18 
19 namespace slic {
20 
22  m_mgr(mgr) {
24 }
25 
27  delete m_lcioDir;
28  delete m_pathCmd;
29  delete m_filenameCmd;
30 }
31 
32 void LcioMessenger::SetNewValue(G4UIcommand* cmd, G4String newVals) {
33  std::istringstream is((const char*) newVals);
34 
35  std::string s;
36  is >> s;
37 
38  // set output path
39  if (cmd == m_pathCmd) {
40  m_mgr->setPath(s);
41  }
42  // set filename
43  else if (cmd == m_filenameCmd) {
44  m_mgr->setFilename(s);
45  }
46  // fileExistsAction
47  else if (cmd == m_fileExistsActionCmd) {
49  }
50  // setRunNumber
51  else if (cmd == m_setRunNumberCmd) {
52  m_mgr->setRunNumber(StringUtil::toInt(s));
53  }
54  // autoname
55  else if (cmd == m_autonameCmd) {
56  std::vector<std::string> fields;
57  StringUtil::split(newVals, " ", fields);
58  m_mgr->setAutonameFields(fields);
59  }
60  /* dump event */
61  else if (cmd == m_printEventCmd) {
62  m_mgr->enableDumpEvent(m_printEventCmd->GetNewBoolValue(newVals.c_str()));
63  }
64  // flags
65  else if (cmd == m_setLongFlagCmd || cmd == m_setPDGFlagCmd) {
66 
67  // no args then true
68  bool flag_set = true;
69 
70  // get arg val if exists
71  if (s != std::string("")) {
72  flag_set = StringUtil::toBool(s);
73  }
74 
76 
77  if (hcb) {
78 
79  // CHBIT_LONG for positions in hits
80  if (cmd == m_setLongFlagCmd) {
81  hcb->setLongFlag(flag_set);
82  }
83  // CHBIT_PDG for every PDG contribution in hits
84  else if (cmd == m_setPDGFlagCmd) {
85  hcb->setPDGFlag(flag_set);
86  }
87  } else {
88  G4Exception("", "", FatalException, "LcioHitsCollectionBuilder is null.");
89  }
90  } else if (cmd == _writeCompleteEventCmd) {
91  G4bool writeCompleteEvent = StringUtil::toBool(s);
92  LcioManager::instance()->setWriteCompleteEvent(writeCompleteEvent);
93  }
94  // bad command; shouldn't happen
95  else {
96  G4Exception("LcioMessenger::setNewValue()", "", JustWarning, "Unknown command.");
97  }
98  return;
99 }
100 
102  G4UIparameter* p;
103 
104  // Lcio dir
105  m_lcioDir = new G4UIdirectory("/lcio/");
106  m_lcioDir->SetGuidance("LCIO output commands. [SLIC]");
107 
108  // path
109  m_pathCmd = new G4UIcommand("/lcio/path", this);
110  m_pathCmd->SetGuidance("Set Lcio output path.");
111  p = new G4UIparameter("path", 's', false);
112  m_pathCmd->SetParameter(p);
113 
114  // filename
115  m_filenameCmd = new G4UIcommand("/lcio/filename", this);
116  m_filenameCmd->SetGuidance("Set Lcio output filename.");
117  p = new G4UIparameter("filename", 's', false);
118  m_filenameCmd->SetParameter(p);
119 
120  // CHBIT_LONG
121  m_setLongFlagCmd = new G4UIcommand("/lcio/longFlag", this);
122  m_setLongFlagCmd->SetGuidance("Set CHBIT_LONG flag for hit positions in output (default = on).");
123  p = new G4UIparameter("Value", 'b', true);
124  m_setLongFlagCmd->SetParameter(p);
125  m_setLongFlagCmd->AvailableForStates(G4State_PreInit);
126 
127  // CHBIT_PDG
128  m_setPDGFlagCmd = new G4UIcommand("/lcio/PDGFlag", this);
129  m_setPDGFlagCmd->SetGuidance("Set CHBIT_PDG flag for super-long output with all Mcp contribs (default is aggregated).");
130  p = new G4UIparameter("Value", 'b', true);
131  m_setPDGFlagCmd->SetParameter(p);
132  m_setLongFlagCmd->AvailableForStates(G4State_PreInit);
133 
134  // fileExistsAction
135  m_fileExistsActionCmd = new G4UIcommand("/lcio/fileExists", this);
136  m_fileExistsActionCmd->SetGuidance("Set action when an Lcio output file exists: fail, overwrite/delete or append.");
137  p = new G4UIparameter("mode", 's', false);
138  m_fileExistsActionCmd->SetParameter(p);
139 
140  // set the starting run number
141  m_setRunNumberCmd = new G4UIcmdWithAnInteger("/lcio/runNumber", this);
142  m_setRunNumberCmd->SetGuidance("Set starting run number for LCIO event.");
143  m_setRunNumberCmd->SetParameterName("RunNumber", false);
144 
145  // enable autonaming
146  m_autonameCmd = new G4UIcommand("/lcio/autoname", this);
147  m_autonameCmd->SetGuidance("Set autonaming parameters.");
148  m_autonameCmd->SetGuidance("Valid autoname fields: application geometry event eventNumber run binary physics date geant4");
149  p = new G4UIparameter("autoname", 's', true);
150  m_autonameCmd->SetParameter(p);
151 
152  /* dumping of event data */
153  m_printEventCmd = new G4UIcmdWithABool("/lcio/printEvent", this);
154  m_printEventCmd->SetGuidance("Dump information about collections in the event");
155  m_printEventCmd->SetParameterName("enable", true);
156  m_printEventCmd->SetDefaultValue(true);
157 
158  _writeCompleteEventCmd = new G4UIcmdWithABool("/lcio/writeCompleteEvent", this);
159  _writeCompleteEventCmd->SetGuidance("Write complete event to MCParticle output.");
160  _writeCompleteEventCmd->SetParameterName("enable", true);
161  _writeCompleteEventCmd->SetDefaultValue(true);
162 }
163 }
static LcioManager * instance()
Builds Lcio hits collections from G4/SLIC event data.
Singleton manager class of LCIO configuration and output file operations.
Definition: LcioManager.hh:45
LcioHitsCollectionBuilder * getHitsCollectionBuilder()
Definition: LcioManager.hh:206
void setFileExistsAction(EFileExistsAction fea)
Definition: LcioManager.hh:183
void enableDumpEvent(bool p=true)
Definition: LcioManager.hh:222
void setRunNumber(int runNumber)
Definition: LcioManager.cc:144
static EFileExistsAction getFileExistsActionFromString(const std::string &fileExists)
Definition: LcioManager.cc:130
void setFilename(const std::string &filename)
Definition: LcioManager.cc:285
void setAutonameFields(const std::vector< std::string > &fields)
Definition: LcioManager.cc:298
void setPath(const std::string &path)
Definition: LcioManager.cc:279
G4UIcommand * m_pathCmd
G4UIcommand * m_setPDGFlagCmd
G4UIcmdWithABool * _writeCompleteEventCmd
G4UIdirectory * m_lcioDir
LcioManager * m_mgr
G4UIcommand * m_filenameCmd
G4UIcmdWithABool * m_printEventCmd
LcioMessenger(LcioManager *mgr)
G4UIcommand * m_fileExistsActionCmd
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
G4UIcmdWithAnInteger * m_setRunNumberCmd
G4UIcommand * m_autonameCmd
virtual ~LcioMessenger()
G4UIcommand * m_setLongFlagCmd