SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
LcioFileNamer.cc
Go to the documentation of this file.
1 // SLIC
2 #include "LcioFileNamer.hh"
3 #include "EventSourceManager.hh"
4 #include "FileUtil.hh"
5 #include "SlicApplication.hh"
6 #include "PackageInfo.hh"
7 #include "RunManager.hh"
8 #include "TimeUtil.hh"
9 #include "PhysicsListManager.hh"
10 
11 // LCDD
12 #include "lcdd/core/LCDDProcessor.hh"
13 #include "lcdd/util/StringUtil.hh"
14 
15 // Geant4
16 #include "G4Run.hh"
17 #include "G4RunManager.hh"
18 #include "G4SystemOfUnits.hh"
19 
20 // stl
21 #include <sstream>
22 
23 using namespace std;
24 
25 namespace slic {
26 
27 std::string LcioFileNamer::m_sep = "_";
28 
29 LcioFileNamer::LcioFileNamer() :
30  Module("LcioFileNamer") {
31  m_defaultFields.push_back("event");
32  m_defaultFields.push_back("application");
33  m_defaultFields.push_back("physics");
34  m_defaultFields.push_back("geometry");
35 }
36 
38 }
39 
40 std::string LcioFileNamer::getFieldValue(std::string field) {
41  std::string value;
42 
43  static std::string sep("-");
44 
45  if (field == "application") {
46  value = PackageInfo::getShortName() + "-v" + PackageInfo::getVersion(sep);
47  } else if (field == "geometry") {
48  value = LCDDProcessor::instance()->getDetectorName();
49  } else if (field == "date") {
50  value = TimeUtil::getDate();
51  } else if (field == "event" || field == "evt") {
53  } else if (field == "eventNumber") {
55  } else if (field == "run") {
57  } else if (field == "binary") {
58  value = SlicApplication::instance()->getBinaryBasename();
59  } else if (field == "physics") {
60  value = PhysicsListManager::instance()->getCurrentListName();
61  } else {
62 #ifdef SLIC_LOG
63  log() << LOG::error << "Ignoring unknown autoname field <" << field << ">." << LOG::done;
64 #endif
65  value = "";
66  }
67  return value;
68 }
69 
70 std::string LcioFileNamer::makeFileName(std::vector<std::string> fieldList) {
71  std::string filename = "";
72  if (fieldList.size() != 0) {
73  for (std::vector<std::string>::const_iterator it = fieldList.begin(); it != fieldList.end(); it++) {
74  std::string value = getFieldValue(*it);
75  if (value != "") {
76  filename = filename + value + m_sep;
77  }
78  }
79  if (filename != "") {
80  filename.erase(filename.end() - 1, filename.end());
81  }
82  } else {
83  filename = makeDefaultFileName();
84  }
85  return filename;
86 }
87 
90 }
91 
93  std::string evt;
94 
95  EventSourceManager::ESourceType est = EventSourceManager::instance()->getCurrentSourceType();
96 
97  if (EventSourceManager::instance()->isFileSource()) {
98  evt = makeFileBasedName();
99  } else if (est == EventSourceManager::eGPS) {
100  evt = makeGPSName();
101  } else if (est == EventSourceManager::eParticleGun) {
102  evt = makeGunName();
103  } else {
104  evt = "events";
105  }
106  return evt;
107 }
108 
110  std::string fname = EventSourceManager::instance()->getFilename();
111 
112  // basename and remove file extension
114 
115  return fname;
116 }
117 
119  G4GeneralParticleSource* gps = EventSourceManager::instance()->getGPS();
120 
121  // particle name
122  std::string pname = gps->GetParticleDefinition()->GetParticleName();
123 
124  // energy
125  double ene = gps->GetCurrentSource()->GetEneDist()->GenerateOne(gps->GetParticleDefinition());
126  std::string eneStr = StringUtil::toString(ene / GeV) + "GeV";
127 
128  // full string
129  std::string evtname = pname + m_sep + eneStr;
130 
131  return evtname;
132 }
133 
135  G4ParticleGun* gun = EventSourceManager::instance()->getParticleGun();
136 
137  // particle name
138  std::string pname = gun->GetParticleDefinition()->GetParticleName();
139 
140  // energy
141  std::string pE = StringUtil::toString(gun->GetParticleEnergy() / GeV) + "GeV";
142 
143  // full string
144  std::string evtname = pname + m_sep + pE;
145 
146  return evtname;
147 }
148 
150  return StringUtil::toString(G4RunManager::GetRunManager()->GetCurrentRun()->GetRunID());
151 }
152 
154  return StringUtil::toString(SlicApplication::instance()->getRunManager()->getNumberOfEventsToRun());
155 }
156 }
static SlicApplication * instance()
static std::string removeExtension(std::string filename)
Definition: FileUtil.cc:76
static std::string basename(std::string filename)
Definition: FileUtil.cc:40
static std::string m_sep
static std::string makeGunName()
std::string getFieldValue(std::string field)
static std::string makeGPSName()
static std::string makeFileBasedName()
virtual ~LcioFileNamer()
std::vector< std::string > m_defaultFields
static std::string makeEventName()
static std::string makeEventNumberString()
std::string makeFileName(std::vector< std::string > fields)
std::string makeDefaultFileName()
static std::string makeRunNumberString()
Base class for slic code modules that provides common functionality, such as logging to an output str...
Definition: Module.hh:25
LogStream & log()
Definition: Module.hh:99
static std::string getDate()
Definition: TimeUtil.hh:37
@ error
Definition: LogStream.hh:33
@ done
Definition: LogStream.hh:26
@ sep
Definition: LogStream.hh:26