Diana Software
QBaseModule.cc
Go to the documentation of this file.
1 /* Diana Reconstruction program
2  *
3  * Author: MP 11/11/05
4  * $Id: QBaseModule.cc 93 2006-05-23 13:50:24Z pallas $
5  *
6  * Class QBaseModule
7  *
8 */
9 
10 #include "QBaseModule.hh"
11 #include "QOptions.hh"
12 #include "QDemangle.hh"
13 #include "QEventAssembler.hh"
14 #include "QEventList.hh"
15 
17 // ctor
19 {
20  fOccurrence = 0;
21  fEnabled = false;
23  fNeedNeighbours = false;
24  fMessageName = "";
25  fName = "";
26  fType = type;
27 }
28 
29 // dtor
31 }
32 
33 
34 void QBaseModule::Update(QSequence* s, unsigned int occurrence)
35 {
36  my_sequence = s;
37  fOccurrence = occurrence;
38  fName = Demangle(*this,1);
39  std::stringstream name;
40  name<<fName;
41  if(GetOccurrence() > 0) {
42  name<<"."<<GetOccurrence();
43  }
44  fMessageName = name.str();
45 
46  QOptions::GetInstance().SetParameter(GetSequence().GetName(),GetName(),GetOccurrence(),"enable",std::string("false"));
47 
50  fConfig.fVersionTag = QOptions::GetInstance().GetParameter("General.DIANA_VERSIONTAG").GetString();
51  fConfig.fSoftwareRevision = QOptions::GetInstance().GetParameter("General.DIANA_SWREVISION").GetString();
52  switch(fType) {
53  case Module:
54  fConfig.fType = "module";
55  break;
56  case Filter:
57  fConfig.fType = "filter";
58  break;
59  case Reader:
60  fConfig.fType = "reader";
61  break;
62  case Writer:
63  fConfig.fType = "writer";
64  break;
65  case Driver:
66  fConfig.fType = "driver";
67  break;
68  }
70  fConfig.fLabel = "";
71 
72 }
73 
75 {
76 
77  fLabel = fName;
78  std::string extraLabel = GetString("ExtraLabel","",false);
79  if(extraLabel != "") fLabel += std::string("_") + extraLabel;
81 
82  fProcessTime = 0.;
83  fProcessCalls = 0ULL;
84 
85  std::string strVerb = GetString("verbosity","info");
86  if ( strVerb == "debug")
88  else if ( strVerb == "info")
90  else if ( strVerb == "warning")
92  else if ( strVerb == "error")
94  else if ( strVerb == "panic")
96  else
97  Warn("Invalid value for parameter \"verbosity\"");
98 
99  SetTimeProfilingOn(GetBool("TimeProfilingOn",false,false));
100  if(QOptions::GetInstance().GetBool("General.TimeProfilingOn")) SetTimeProfilingOn(true);
101 
102  bool overWriteEvent = GetBool("OverWriteEvent",false,false);
103  overWriteEvent = overWriteEvent || (GetIteration() > 1);
104  if(QOptions::GetInstance().GetBool("General.OverWrite")) overWriteEvent = true;
106  eva.SetOverWrite(overWriteEvent);
107  eva.SetOwner(&fLabel);
108 
109  fNeedNeighbours = true;
110 
111  // erase required labels in the QEvent to keep track which are selected by this module
112  std::vector<QEventLabel> prevRequired = eva.GetRequiredLabels();
113  std::vector<QEventLabel> empty;
114  eva.SetRequiredLabels(empty,false);
115  // execute the Begin (Init)
116  Begin(eva);
117  // Get required labels and restore full list of required lables in the event
119  eva.SetRequiredLabels(prevRequired);
121 
122  eva.SetOwner(0);
123  eva.SetOverWrite(false);
124 
126 }
127 
128 bool QBaseModule::ProcessBase(QEventAssembler& eva, QEventList& evl, const bool exec, QEventList& oevl)
129 {
130  bool ret;
131  if(GetTimeProfilingOn()) {
133  eva.SetOwner(&fLabel);
134  for(size_t i = 0; i < evl.Size(); i++) { evl[i].SetOwner(&fLabel); }
135  ResetTimer();
136  fExecuted = false;
137  ret = Process(eva,evl,exec,oevl);
138  double process_time = GetTimer();
139  eva.SetOwner(0);
140  for(size_t i = 0; i < evl.Size(); i++) { evl[i].SetOwner(0); }
142  if(fExecuted) {
143  fProcessCalls++;
144  fProcessTime += process_time;
145  }
146  } else {
148  eva.SetOwner(&fLabel);
149  for(size_t i = 0; i < evl.Size(); i++) { evl[i].SetOwner(&fLabel); }
150  fExecuted = false;
151  ret = Process(eva,evl,exec,oevl);
152  eva.SetOwner(0);
153  for(size_t i = 0; i < evl.Size(); i++) { evl[i].SetOwner(0); }
155  if(fExecuted) {
156  fProcessCalls++;
157  }
158  }
159  return ret;
160 }
161 
163 {
164  if(fProcessCalls == 0) fNeedNeighbours = false;
165 
167  if(GetTimeProfilingOn()) {
168  Info("%s",GetTimeProfileReport().c_str());
169  }
170 
171  End();
172 
174 }
175 
176 
177 std::string QBaseModule::GetFullPath() const
178 {
179  char occBuf[8];
180  snprintf(occBuf,8,"%d",GetOccurrence());
181  return GetName() + "." + occBuf;
182 }
183 
184 double QBaseModule::GetDouble(const std::string& s, double defVal, bool warnCfg) const
185 {
186  double param;
187  try {
189  }
190  catch(std::exception &ex) {
191  if(warnCfg) Warn("%s; using default: %f", ex.what(), defVal);
194  }
196  return param;
197 }
198 
199 std::vector<double> QBaseModule::GetVectorDouble(const std::string& s, std::vector<double> defVal, bool warnCfg) const
200 {
201  std::vector<double> param;
202  try {
204  }
205  catch(std::exception &ex) {
206  std::stringstream defMsg;
207  defMsg<<"{";
208  for(size_t i =0; i < defVal.size(); i++) defMsg<<defVal[i]<<",";
209  defMsg<<"}";
210  if(warnCfg) Warn("%s; using default: %s", ex.what(), defMsg.str().c_str());
213  }
215  return param;
216 }
217 
218 // get a parameter of integer type
219 int QBaseModule::GetInt(const std::string& s, int defVal, bool warnCfg) const
220 {
221  int param;
222  try {
224  }
225  catch(std::exception &ex) {
226  if(warnCfg) Warn("%s; using default: %d", ex.what(), defVal);
229  }
231  return param;
232 }
233 
234 std::vector<int> QBaseModule::GetVectorInt(const std::string& s, std::vector<int> defVal, bool warnCfg) const
235 {
236  std::vector<int> param;
237  try {
239  }
240  catch(std::exception &ex) {
241  std::stringstream defMsg;
242  defMsg<<"{";
243  for(size_t i =0; i < defVal.size(); i++) defMsg<<defVal[i]<<",";
244  defMsg<<"}";
245 
246  if(warnCfg) Warn("%s; using default: %s", ex.what(), defMsg.str().c_str());
249  }
251  return param;
252 }
253 
254 
255 
256 bool QBaseModule::GetBool(const std::string& s, bool defVal, bool warnCfg) const
257 {
258  bool param;
259  try{
261  }
262  catch(std::exception &ex) {
263  if(warnCfg) Warn("%s; using default: %s", ex.what(), (defVal ? "true" : "false") );
266  }
268  return param;
269 }
270 std::vector<bool> QBaseModule::GetVectorBool(const std::string& s, std::vector<bool> defVal, bool warnCfg) const
271 {
272  std::vector<bool> param;
273  try {
275  }
276  catch(std::exception &ex) {
277  std::stringstream defMsg;
278  std::vector<int> boolToInt;
279  defMsg<<"{";
280  for(size_t i =0; i < defVal.size(); i++) {
281  defMsg<<defVal[i]<<",";
282  boolToInt.push_back(defVal[i]);
283  }
284  defMsg<<"}";
285 
286  if(warnCfg) Warn("%s; using default: %s", ex.what(), defMsg.str().c_str());
289  }
291  return param;
292 }
293 
294 
295 
296 
297 const std::string& QBaseModule::GetString(const std::string& s, const std::string& defVal, bool warnCfg) const
298 {
299  const std::string* param;
300  try {
302 
303  }
304  catch(std::exception &ex) {
305  if(warnCfg) Warn("%s; using default: %s", ex.what(), defVal.c_str() );
308  }
310  return *param;
311 }
312 
313 std::vector<std::string> QBaseModule::GetVectorString(const std::string& s, std::vector<std::string> defVal, bool warnCfg) const
314 {
315  std::vector<std::string> param;
316  try {
318  }
319  catch(std::exception &ex) {
320  std::stringstream defMsg;
321  defMsg<<"{";
322  for(size_t i =0; i < defVal.size(); i++) defMsg<<defVal[i]<<",";
323  defMsg<<"}";
324 
325  if(warnCfg) Warn("%s; using default: %s", ex.what(), defMsg.str().c_str());
328  }
330  return param;
331 }
332 
333 void QBaseModule::UpdateConfigParameters(const std::string& p) const
334 {
336 }
337 
338 
std::string Demangle(const C &obj, int firstChar=0)
Definition: QDemangle.hh:12
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
@ ErrorMsg
Definition: QMessageDefs.hh:9
@ DebugMsg
Definition: QMessageDefs.hh:6
@ WarnMsg
Definition: QMessageDefs.hh:8
@ PanicMsg
Definition: QMessageDefs.hh:10
@ InfoMsg
Definition: QMessageDefs.hh:7
std::string GetFullPath() const
Get Full Path of module "GetName() + "." + GetOccurrence".
Definition: QBaseModule.cc:177
const std::string & GetString(const std::string &parname, const std::string &defVal, bool warnCfg=true) const
Get a string parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:297
std::string fMessageName
Definition: QBaseModule.hh:187
bool ProcessBase(QEventAssembler &ev, QEventList &evl, const bool exec, QEventList &ovl)
ProcessBase method is called for each event, getting the event and as argument.
Definition: QBaseModule.cc:128
MsgLevel verbosity
Definition: QBaseModule.hh:182
std::string fName
Definition: QBaseModule.hh:186
void Warn(const char *descr,...) const
Send a warning message (an error that the framework can recover) with printf syntax.
Definition: QBaseModule.hh:228
virtual ~QBaseModule()
constructor
Definition: QBaseModule.cc:30
void EndBase()
EndBase method is called after event loop.
Definition: QBaseModule.cc:162
unsigned int GetIteration() const
Get Current sequence iteration.
Definition: QBaseModule.hh:122
virtual bool Process(QEventAssembler &ev, QEventList &evl, const bool exec, QEventList &ovl)=0
Process method is called for each event, getting the event and as argument and must be implemented by...
unsigned int fOccurrence
Definition: QBaseModule.hh:183
QSequence * my_sequence
Definition: QBaseModule.hh:190
std::vector< QEventLabel > fRequiredLabels
Definition: QBaseModule.hh:193
void Info(const char *descr,...) const
Send an info message (information) with printf syntax.
Definition: QBaseModule.hh:218
bool fNeedNeighbours
Definition: QBaseModule.hh:189
void UpdateConfigParameters(const std::string &p) const
update module config
Definition: QBaseModule.cc:333
double GetDouble(const std::string &parname, double defVal, bool warnCfg=true) const
Get a double parameter from config file.
Definition: QBaseModule.cc:184
QModuleConfig fConfig
Definition: QBaseModule.hh:191
const QSequence & GetSequence() const
get reference to this sequence
Definition: QBaseModule.hh:137
virtual void End()=0
End method is called after event loop and must be implemented by inheriting classes.
std::string fLabel
Definition: QBaseModule.hh:185
int GetInt(const std::string &parname, int defVal, bool warnCfg=true) const
Get an int parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:219
std::vector< std::string > GetVectorString(const std::string &parname, std::vector< std::string > defVal, bool warnCfg=true) const
Get a vector<string> parameter from config file ( see GetVectorDouble() )
Definition: QBaseModule.cc:313
bool GetBool(const std::string &parname, bool defVal, bool warnCfg=true) const
Get a bool parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:256
std::vector< bool > GetVectorBool(const std::string &parname, std::vector< bool > defVal, bool warnCfg=true) const
Get a vector<bool> parameter from config file ( see GetVectorDouble() )
Definition: QBaseModule.cc:270
std::vector< int > GetVectorInt(const std::string &parname, std::vector< int > defVal, bool warnCfg=true) const
Get an vector<int> parameter from config file ( see GetVectorDouble() )
Definition: QBaseModule.cc:234
void Update(QSequence *s, unsigned int occurrence)
set the occurrence in the same sequence. MV FIXME: should not be public
Definition: QBaseModule.cc:34
virtual void Begin(QEventAssembler &ev)=0
Begin method is called before event loop and must be implemented by inheriting classes.
void BeginBase(QEventAssembler &ev)
Begin Base method is called before event loop.
Definition: QBaseModule.cc:74
unsigned int GetOccurrence() const
get the number of times the same module is loaded inside a QSequence
Definition: QBaseModule.hh:125
std::vector< double > GetVectorDouble(const std::string &parname, std::vector< double > defVal, bool warnCfg=true) const
Get a std::vector<double> parameter from config file with syntax "{x,y,z}".
Definition: QBaseModule.cc:199
QBaseModule(Type type)
constructor
Definition: QBaseModule.cc:18
const std::string & GetName() const
Get Module name.
Definition: QBaseModule.hh:131
Visitor class of QEvent that provides full handling of QEvent.
void SetOverWrite(const bool ow=true)
set that all the QEvent QObject (s) can be overwritten (calls QEvent::SetOverWrite())
void SetOwner(const std::string *owner)
set the module that is currently acting on the QEvent calls (QEvent::SetOwner())
void SetRequiredLabels(const std::vector< QEventLabel > &labels, bool incremental=true)
set which QObjects are required. If incremental = false, labels not in the vector are set to not requ...
std::vector< QEventLabel > GetRequiredLabels(const std::string &owner="all") const
Get the list of all required QObject labels.
list of references to const QEvent (s)
Definition: QEventList.hh:21
size_t Size() const
number of QEvent (s)
Definition: QEventList.hh:36
void SetOwner(const std::string &owner)
set the module that is accessing this object
int fOccurrence
occurrence in sequence
std::map< std::string, std::string > fParameters
config and optional parameters
std::string fName
module name
std::string fLabel
label of the module = fName + "_" + ExtraLabel
std::string fSoftwareRevision
GIT revision SHA-1
std::string fVersionTag
Version release tag.
std::string fSequenceName
sequence name
std::string fType
module type (reader,module,driver...)
void ResetTimer()
Reset the timer to now.
void SetTimeProfilingOn(bool val)
Set the time profiling on/off.
unsigned long long int fProcessCalls
NUmber of calls to the process.
double fProcessTime
Total time spent running the process.
bool GetTimeProfilingOn() const
Check if the time profiling is on.
double GetTimer() const
return the time since the last reset
std::string GetTimeProfileReport(const std::string &prefix="") const
Report the time profiling.
const std::string & GetName() const
Definition: QNamed.hh:19
const std::string & GetString(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:556
double GetDouble(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:489
std::vector< double > GetVectorDouble(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:498
void SetParameter(const std::string &n, const QVdt &value, const bool isDefault=false)
std::vector< bool > GetVectorBool(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:534
const QVdt & GetParameter(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:472
std::vector< std::string > GetVectorString(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:544
int GetInt(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:508
static QOptions & GetInstance()
Definition: QOptions.cc:23
std::vector< int > GetVectorInt(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:516
bool GetBool(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
Definition: QOptions.cc:526
Diana Reconstruction program.
Definition: QSequence.hh:40
const QGlobalDataManager & GlobalData() const
Access to the global data manager for the sequence.
Definition: QSequence.hh:65
const std::string & GetString() const
Definition: QVdt.cc:225