Diana Software
QFilter.cc
Go to the documentation of this file.
1 #include "QFilter.hh"
2 #include "QEventAssembler.hh"
3 #include "QEventList.hh"
4 #include "QBool.hh"
5 
7 
8 
10 {
11 }
12 
13 
15 {
16  fTotEvents = 0LL;
17  fSelEvents = 0LL;
18  fSelNeighEvents = 0LL;
19  fTotNeighEvents = 0LL;
20 
21 
22  QEvent& ev = eva.GetEvent();
23  GetCuts(ev);
24 
25  std::string logicFlag = GetString("Logic","CASE");
26  if(logicFlag == "AND") {
27  fLogicFlag = AND;
28  } else if(logicFlag == "OR") {
29  fLogicFlag = OR;
30  } else if(logicFlag == "CASE") {
31  fLogicFlag = CASE;
32  } else {
33  Error("Unknown logic flag, resetting Logic to \"AND\"");
34  fLogicFlag = AND;
35  }
36 
37  fFilterMainEvent = GetBool("FilterMainEvent",true,false);
38  fFilterNeighbours = GetBool("FilterNeighbours",false,false);
39  fNegate = GetBool("Negate",false,false);
40 
41  fSave = false;
42  fWrite = false;
43  if(fFilterMainEvent) {
44  fSave = GetBool("Save",true,false);
45  }
46  if(fSave) {
47  fWrite = GetBool("WriteResult",true,false);
48  ev.Add<QBool>("Passed").SetWrite(fWrite);
49  std::string alias = GetString("Alias","",false);
50  if(alias != "") {
51  Debug("Setting alias: Filter_%s",alias.c_str());
52  alias = std::string("Filter_") + alias;
53  ev.SetAlias("Passed","fValue",alias);
54  }
55  }
56 
57  fFirstCall = true;
58  SetNeedNeighbours(true);
59  fSkipRequiredNotValid = GetBool("SkipRequiredNotValid",false,false);
61  Info("Skipping events with non valid but required objects");
62  }
63 
64 }
65 
66 bool QFilter::Process(QEventAssembler& eva, QEventList& neigh, const bool exec, QEventList& oneigh)
67 {
68  // MV FIXME: se si filtrano i neighbours non possono essere recuperati, forse ho fixato
69  QEvent& ev = eva.GetEvent();
70  QBool thisPassed = false;
71  if(!fFilterMainEvent) {
72  // we return the result of previous filters
73  thisPassed = exec;
74  if(!thisPassed) return thisPassed;
75  } else {
76  fTotEvents++;
77  // the neighbours are those filtered by previous filters
78  thisPassed = FilterAlgorithm(ev,oneigh,exec);
79  if(thisPassed) fSelEvents++;
80  if(fSave) {
81  WriteHandle<QBool> passedHandle("Passed");
82  ev.Get(passedHandle);
83  passedHandle.Get() = thisPassed;
84  }
85  }
86  if(thisPassed && fFilterNeighbours) {
87  // remove filtered events from the oneigh list
88 
89  QEventList nneigh,emptyneigh;
90  for(int i = 0; i < (int)neigh.Size(); i++) {
91  bool oexec = false;
92  for(int j = 0; j < (int)oneigh.Size(); j++)
93  if(&oneigh[j] == &neigh[i]) oexec = true;
94  if(FilterAlgorithm(neigh[i],emptyneigh,oexec))
95  nneigh.Push(&neigh[i]);
96  }
97  oneigh = nneigh;
98  fSelNeighEvents += oneigh.Size();
99  fTotNeighEvents += neigh.Size();
100  }
101 
102  return thisPassed;
103 
104 }
105 
106 bool QFilter::FilterAlgorithm(const QEvent& ev, QEventList& neigh, const bool exec)
107 {
108  bool thisPassed = false;
109 
110  bool globalPassed = exec;
111  if(fLogicFlag != AND || globalPassed) {
112  bool requiredAreValid = true;
114  const std::vector<QEventLabel>& labels = GetRequiredLabels();
115  for(size_t l = 0; l < labels.size(); l++) {
116  const char* owner = labels[l].owner.c_str();
117  const char* name = labels[l].name.c_str();
119  ev.Get(owner,rHandle);
120  if(!rHandle.IsValid()&& labels[l].owner != fLabel){
121  requiredAreValid = false;
122  l = labels.size();
123  }
124  }
125  }
126  if(requiredAreValid) {
127  thisPassed = fNegate^Filter(ev,neigh); // xor the filter result with negation
128  fExecuted = true;
129  }
130  }
131  // the result of this filter is the combingation of previous filters
132  if(fLogicFlag == AND) thisPassed = globalPassed && thisPassed;
133  else if(fLogicFlag == OR) thisPassed = globalPassed || thisPassed;
134 
135  return thisPassed;
136 }
137 
139 {
140 
141  Done();
142  if(fFilterMainEvent) {
143  if(fSelEvents == 0LL) Error("Selected %llu events over %llu", fSelEvents, fTotEvents);
144  else Info("Selected %llu events over %llu", fSelEvents, fTotEvents);
145  }
146  if(fFilterNeighbours) {
147  if(fSelNeighEvents == 0LL) Error("Selected %llu neighbours over %llu", fSelNeighEvents, fTotNeighEvents);
148  else Info("Selected %llu neighbours over %llu", fSelNeighEvents, fTotNeighEvents);
149  }
150 }
151 
152 bool QFilter::Filter(const QEvent& ev)
153 {
154  Panic("Missing method: \"bool Filter(const QEvent& ev)\" or \"bool Filter(const QEvent& ev, const QEventList& neigh)\" not implemented");
155  return false;
156 }
157 
158 bool QFilter::Filter(const QEvent& ev, const QEventList& neigh)
159 {
160  // this filter probably implements the method without neighbours
161  if(fFirstCall) {
162  SetNeedNeighbours(false);
163  fFirstCall = false;
164  }
165  return Filter(ev);
166 }
167 
168 
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
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
void Debug(const char *descr,...) const
Send a debug message (used to debug the module) with printf syntax.
Definition: QBaseModule.hh:208
void Info(const char *descr,...) const
Send an info message (information) with printf syntax.
Definition: QBaseModule.hh:218
void Error(const char *descr,...) const
Send an error message (an error that the framework cannot recover) with printf syntax.
Definition: QBaseModule.hh:238
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
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 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
void Push(const QEvent *obj)
add a QEvent
Definition: QEventList.cc:17
size_t Size() const
number of QEvent (s)
Definition: QEventList.hh:36
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
void SetAlias(const std::string &name, const std::string &pathInObject, const std::string &alias)
set alias for objects or variables in objects owned by currentmodule.
Definition: QEvent.hh:261
virtual void GetCuts(const QEvent &ev)=0
Initialize all cuts, possibly from config file.
bool Process(QEventAssembler &ev, QEventList &neigh, const bool exec, QEventList &oneigh)
Process method is called for each event, and calls FilterAlgorithm()
Definition: QFilter.cc:66
bool fWrite
save QBool into files
Definition: QFilter.hh:104
unsigned long long fSelNeighEvents
Definition: QFilter.hh:92
@ CASE
Definition: QFilter.hh:79
@ OR
Definition: QFilter.hh:80
@ AND
Definition: QFilter.hh:78
QFilter()
constructor
Definition: QFilter.cc:9
bool fFilterMainEvent
Definition: QFilter.hh:93
bool fSkipRequiredNotValid
Definition: QFilter.hh:96
LogicFlag fLogicFlag
Definition: QFilter.hh:98
void End()
End method is called after event loop, and calls no method of inheriting classes.
Definition: QFilter.cc:138
virtual void Done()
optionally one can also implement actions after the event loop
Definition: QFilter.hh:75
unsigned long long fSelEvents
Definition: QFilter.hh:91
bool FilterAlgorithm(const QEvent &ev, QEventList &neigh, const bool exec)
called for each event, and calls Filter() of inheriting classes
Definition: QFilter.cc:106
bool fNegate
Definition: QFilter.hh:97
unsigned long long fTotEvents
Definition: QFilter.hh:89
void Begin(QEventAssembler &ev)
Begin method is called before event loop, and calls GetCuts()
Definition: QFilter.cc:14
bool fSave
store QBool result into event
Definition: QFilter.hh:101
bool fFilterNeighbours
Definition: QFilter.hh:94
unsigned long long fTotNeighEvents
Definition: QFilter.hh:90
bool fFirstCall
Definition: QFilter.hh:95
read handle to access QEvent QObject's.
Definition: QHandle.hh:126
write handle to access and add QEvent QObject's.
Definition: QHandle.hh:155
T & Get()
get object
Definition: QHandle.hh:161