Diana Software
QModule.cc
Go to the documentation of this file.
1 #include "QModule.hh"
2 #include "QBool.hh"
3 #include "QEventAssembler.hh"
4 
6 
8 {
9 }
10 
12 {
13 }
14 
16 {
17  fRunOnIteration = GetInt("RunOnIteration",0,false);
18  if(fRunOnIteration > 2) Panic("Controlling sequence iterations > 2 is not implemented!");
19  if(fRunOnIteration > 0 && fRunOnIteration != GetIteration()) return;
20  Init(eva.GetEvent());
21  fSkipEvents = GetBool("SkipEvents",true,false);
22  if(!fSkipEvents) {
23  Info("Skip events set to false");
24  eva.GetEvent().Add<QBool>("SkipEvent").SetWrite(false);
25  }
26  fFirstCall = true;
27  SetNeedNeighbours(true);
28  fSkipRequiredNotValid = GetBool("SkipRequiredNotValid",false,false);
29 
31  Info("Skipping events with non valid but required objects");
32  eva.GetEvent().Add<QBool>("RequiredAreValid").SetWrite(false);
33  } else {
34  Debug("NOT skipping events with non valid but required objects");
35  }
36 
37 }
38 
39 bool QModule::Process( QEventAssembler& eva, QEventList& neigh, const bool exec, QEventList& oneigh)
40 {
41 
42  if(fRunOnIteration > 0 && fRunOnIteration != GetIteration()) return exec;
43 
44  if(!fSkipEvents) eva.GetEvent().Get<QBool>("SkipEvent") = !exec;
45  if(!fSkipEvents || exec) {
46  bool requiredAreValid = true;
48  const std::vector<QEventLabel>& labels = GetRequiredLabels();
49  for(size_t l = 0; l < labels.size(); l++) {
50  const char* owner = labels[l].owner.c_str();
51  const char* name = labels[l].name.c_str();
53  eva.GetEvent().Get(owner,rHandle);
54  if(!rHandle.IsValid() && labels[l].owner != fLabel){
55  requiredAreValid = false;
56  l = labels.size();
57  }
58  }
59 
60  eva.GetEvent().Get<QBool>("RequiredAreValid") = requiredAreValid;
61  }
62  if(requiredAreValid) {
63  Do(eva.GetEvent(),oneigh);
64  fExecuted = true;
65  }
66  }
67  // modules do not control wheter skip or not other modules
68  return exec;
69 }
70 
72 {
73  Panic("Missing method: \"void Do(QEvent& ev)\" or \"void Do(QEvent& ev, const QEventList& neigh)\" not implemented");
74 }
75 
76 
77 void QModule::Do( QEvent& ev, const QEventList& neighbours)
78 {
79  if(fFirstCall) {
80  SetNeedNeighbours(false);
81  fFirstCall = false;
82  }
83  Do(ev);
84 }
85 
86 
87 void QModule::End()
88 {
91  SetRunAgain(true);
92  }
93  return;
94  }
95  Done();
96 }
QRunDataHandle rHandle(753)
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
Base class for modules.
Definition: QBaseModule.hh:57
void Debug(const char *descr,...) const
Send a debug message (used to debug the module) with printf syntax.
Definition: QBaseModule.hh:208
unsigned int GetIteration() const
Get Current sequence iteration.
Definition: QBaseModule.hh:122
void Info(const char *descr,...) const
Send an info message (information) with printf syntax.
Definition: QBaseModule.hh:218
void Panic(const char *descr,...) const
Send a panic message (stops the framework) with printf syntax.
Definition: QBaseModule.hh:248
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
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
const std::vector< QEventLabel > & GetRequiredLabels() const
Get labels of objects required by this module.
Definition: QBaseModule.hh:159
void SetRunAgain(bool b)
Set that the sequence will be reiterated.
Definition: QBaseModule.hh:120
void SetNeedNeighbours(bool need)
set wheter this module needs neighbours
Definition: QBaseModule.hh:169
bool wrapped into a QObject
Definition: QBool.hh:17
Visitor class of QEvent that provides full handling of QEvent.
QEvent & GetEvent()
Get the QEvent.
list of references to const QEvent (s)
Definition: QEventList.hh:21
diana event
Definition: QEvent.hh:46
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
Definition: QEvent.hh:193
virtual void Done()=0
Done method is called after event loop.
void End()
End method is called after event loop, and calls Done()
Definition: QModule.cc:87
bool Process(QEventAssembler &eva, QEventList &neigh, const bool exec, QEventList &oneigh)
Process method is called for each event, and calls Do()
Definition: QModule.cc:39
bool fSkipRequiredNotValid
Skip events containing non-valid required objects.
Definition: QModule.hh:89
QModule()
constuctor
Definition: QModule.cc:7
virtual void Init(QEvent &ev)=0
Init method is called before event loop.
bool fSkipEvents
flag to skip the Do() execution on filtered events
Definition: QModule.hh:86
size_t fRunOnIteration
Specify on which iteration the module runs.
Definition: QModule.hh:95
virtual void Do(QEvent &ev)
Do method is called on each event, getting the event as argument.
Definition: QModule.cc:71
bool fFirstCall
flag to check first Do() call
Definition: QModule.hh:92
void Begin(QEventAssembler &eva)
Begin method is called before event loop, and calls Init()
Definition: QModule.cc:15
virtual ~QModule()
destructor
Definition: QModule.cc:11
read handle to access QEvent QObject's.
Definition: QHandle.hh:126