KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVParticleCondition.h
Go to the documentation of this file.
1 /*
2 $Id: KVParticleCondition.h,v 1.3 2007/03/26 10:14:56 franklan Exp $
3 $Revision: 1.3 $
4 $Date: 2007/03/26 10:14:56 $
5 */
6 
9 
10 #ifndef __KVPARTICLECONDITION_H
11 #define __KVPARTICLECONDITION_H
12 
13 #include "KVBase.h"
14 #include "KVString.h"
15 #include "KVHashList.h"
16 #include "KVNucleus.h"
17 
18 #ifdef USING_ROOT6
22 #include <vector>
23 #include <functional>
24 #endif
25 
26 class KVClassFactory;
27 
64 class KVParticleCondition : public KVBase {
66  mutable Int_t fNUsing;
67 #ifdef USING_ROOT6
68  using LambdaFunc = std::function<bool(const KVNucleus*)>;
71  enum class LogOp { AND, OR } fOpType;
72 
74  {
76  if (IsLambda() && !IsSet()) {
77  switch (fOpType) {
78  case LogOp::AND:
79  fLambdaCondition = [this](const KVNucleus * nuc) {
80  return (fSavedLambda1(nuc) && fSavedLambda2(nuc));
81  };
82  break;
83  case LogOp::OR:
84  fLambdaCondition = [this](const KVNucleus * nuc) {
85  return (fSavedLambda1(nuc) || fSavedLambda2(nuc));
86  };
87  break;
88  }
89  }
90  }
91 #endif
92 
93 protected:
94 
98 
99  mutable const KVParticleCondition* fOptimal;
101  mutable KVClassFactory* cf;
103  mutable Bool_t fOptOK;
104 
105  void Optimize() const;
106  virtual bool optimized_test(const KVNucleus*) const
107  {
108  return kFALSE;
109  }
110  void CreateClassFactory() const;
112 
113 public:
114 
116  KVParticleCondition(const KVString& cond);
117  KVParticleCondition(const Char_t* cond);
119 #ifdef USING_ROOT6
120  KVParticleCondition(const KVString& name, const LambdaFunc& F)
121  : KVBase(name, "KVParticleCondition"), fLambdaCondition(F)
122  {
146  fOptimal = nullptr;
147  cf = nullptr;
148  fOptOK = kFALSE;
149  fNUsing = 0;
150  }
151  bool IsLambda() const
152  {
154  return (bool)fLambdaCondition || ((bool)fSavedLambda1 && (bool)fSavedLambda2);
155  }
158 #endif
159  virtual ~KVParticleCondition();
160 #ifdef USING_ROOT6
161  void Set(const KVString& name, const LambdaFunc& F)
162  {
174  SetName(name);
175  }
176 #endif
177  void Set(const KVString&);
178 
179  Bool_t Test(const KVNucleus* nuc) const
180  {
188 
189 #ifdef USING_ROOT6
191 #endif
192  if (!IsSet()) return kTRUE;
193 #ifdef USING_ROOT6
194  if (IsLambda()) return fLambdaCondition(nuc);
195 #endif
196  if (!fOptimal) Optimize();
197 
198  return (fOptOK ? fOptimal->optimized_test(nuc) : kFALSE);
199  }
200 
201  Bool_t Test(const KVNucleus& nuc) const
202  {
210 
211  return Test(&nuc);
212  }
213 
215  {
216  fClassName = cl;
217  }
218  void AddExtraInclude(const Char_t* inc_file);
219 
220  void Copy(TObject&) const;
221 
224 #ifdef USING_ROOT6
226 #endif
231 
232  void Print(Option_t* opt = "") const;
233  static void PrintOptimizedList()
234  {
235  fgOptimized.Print();
236  }
237  Bool_t IsSet() const
238  {
242 #ifdef USING_ROOT6
243  return (fLambdaCondition || fCondition != "");
244 #else
245  return fCondition != "";
246 #endif
247  }
248 
249  ClassDef(KVParticleCondition, 2) //Implements parser of particle selection criteria
250 };
251 
252 #endif
int Int_t
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
const char Option_t
#define ClassDef(name, id)
Base class for KaliVeda framework.
Definition: KVBase.h:135
Factory class for generating skeleton files for new classes.
Extended version of ROOT THashList.
Definition: KVHashList.h:28
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:125
Handles particle selection criteria for data analysis classes ,.
friend KVParticleCondition operator&&(const KVParticleCondition &, const KVParticleCondition &)
LambdaFunc fSavedLambda2
used by || and &&
virtual ~KVParticleCondition()
default dtor
static KVHashList fgOptimized
list of optimized particle conditions
Bool_t fOptOK
false if optimisation failed (can't load generated code)
void logical_operator_lambda_condition_test() const
void CreateClassFactory() const
Initialises KVClassFactory object used for optimization if it doesn't exist.
Bool_t Test(const KVNucleus *nuc) const
KVClassFactory * cf
used to generate code for optimisation
Int_t fNUsing
number of classes using this as an optimized condition
void AddExtraInclude(const Char_t *inc_file)
KVParticleCondition & operator|=(const KVParticleCondition &)
KVParticleCondition(const KVString &name, const LambdaFunc &F)
enum KVParticleCondition::LogOp fOpType
KVParticleCondition()
default ctor
KVString fOptimizedClassName
name of generated class used for optimisation
virtual bool optimized_test(const KVNucleus *) const
KVParticleCondition & operator&=(const KVParticleCondition &)
Bool_t Test(const KVNucleus &nuc) const
KVString fCondition
string containing selection criteria with ";" at end
void Copy(TObject &) const
Copy this to obj.
KVString fCondition_raw
'raw' condition, i.e. no ';'
void SetClassFactory(KVClassFactory *CF)
void SetParticleClassName(const Char_t *cl)
KVParticleCondition & operator=(const KVParticleCondition &)
Set condition to be same as for existing KVParticleCondition object.
std::function< bool(const KVNucleus *)> LambdaFunc
KVString fCondition_brackets
condition with '(' and ')' around it
static void PrintOptimizedList()
void Set(const KVString &name, const LambdaFunc &F)
const KVParticleCondition * fOptimal
friend KVParticleCondition operator||(const KVParticleCondition &, const KVParticleCondition &)
void Print(Option_t *opt="") const
Print informations on object.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
virtual void Print(Option_t *option, const char *wildcard, Int_t recurse=1) const
virtual void SetName(const char *name)
#define F(x, y, z)
const long double cl
Definition: KVUnits.h:85