HighLAND
StepBase.hxx
1 #ifndef StepBase_h
2 #define StepBase_h
3 
4 #include <TObject.h>
5 #include <stdio.h>
6 #include <iostream>
7 #include <map>
8 
9 #include "ToyBoxB.hxx"
10 #include "CoreDataClasses.hxx"
11 
12 /// Base class for an event selection step. All user steps should inherit from
13 /// this class, and implement the Apply() function. The type and title are
14 /// set when the step is added to the step manager using StepManager::AddStep().
15 /// Steps can be of type Cut or Action.
16 /// Cuts would have to return a meaninful boolean while for actions the boolean will be ignored
17 
18 class StepBase: public TObject{
19  public :
20 
21  /// Enumerator describing the values that _type member can take.
22  enum TypeEnum {
23  kCut=0,
24  kAction,
25  kUnknown
26  }; //!
27 
28  enum BranchStatus{
29  BranchOK=0,
30  BranchEmpty,
31  NoBranches,
32  BranchOutOfRange
33  }; //!
34 
35  StepBase();
36  virtual ~StepBase(){}
37 
38  //-----------------------------------------------------
39  /// MANDATORY FUNCTIONS !!!
40 
41  // Clones this step. Keeps only Type, Title and Break
42  virtual StepBase* MakeClone(){std::cout << "ERROR: StepBase::MakeClone() must be implemented in your Cut!!!" << std::endl;exit(1);return NULL;}
43 
44  /// The return value should specify whether the step was passed.
45  /// For actions the return value is ignored
46  virtual bool Apply(AnaEventC& event, ToyBoxB& box) const {(void)event;(void)box;return true;std::cout << "ERROR: StepBase::Apply() must be implemented in your Cut!!!" << std::endl;exit(1);}
47  //------------------------------------------------------
48 
49  /// Set the title of this step, which is the "nice" version of the step name,
50  /// used when plotting the step.
51  void SetTitle(const std::string& title){_title=title;}
52 
53  /// Set the type of this step.
54  void SetType(TypeEnum type) {_type = type;}
55 
56  /// Set whether the cut sequence should be stopped when this cut fails
57  void SetBreak(bool b){_break=b;}
58 
59  /// Set the index of this step.
60  void SetIndex(Int_t index) {_index = index;}
61 
62  /// Return the title of this step.
63  const std::string& Title() const{return _title;}
64 
65  /// Return the type of this step.
66  TypeEnum Type() const{return _type;}
67 
68  /// Return true if the cut sequence should be stopped when a cut fails
69  bool Break() const{return _break;}
70 
71  /// Return the index of this step
72  Int_t Index() const{return _index;}
73 
74  /// Convert into a string the type of this step
75  std::string ConvertType() const;
76 
77  /// Disable step in a given branch
78  void DisableInBranch(Int_t branch) {_disabledInBranch[branch] = true;}
79 
80  /// Enable step in a given branch
81  void EnableInBranch(Int_t branch) {_disabledInBranch[branch] = false;}
82 
83  /// Returns true if the step is disabled in the specified branch
84  bool IsDisabledInBranch(Int_t branch) const {return _disabledInBranch[branch];}
85 
86  /// Returns the vector of next steps
87  const std::vector<StepBase*>& GetNextSteps() const{return _nextSteps;}
88 
89  /// Remove step with a given title (and branch ID) from next steps
90  void RemoveNextStep(const std::string& title, Int_t ID=0);
91 
92  /// Add a branch unique ID to this step
93  /// Although steps are unique and can be shared by different branches we need to store
94  /// the branches in which this step is used
95  void AddBranchUniqueID(UInt_t ibranch);
96 
97  /// Remove a branch unique ID from this step
98  void RemoveBranchUniqueID(UInt_t branch);
99 
100  /// Returns the vector of branche unique IDs associated to this step
101  const std::vector<UInt_t>& GetBranchUniqueIDs() const {return _branchUniqueIDs;}
102 
103  /// Add a next step
104  /// If now second argument is specified this step will have a unique next step (no split)
105  /// If this step contains a split we need to specify the branch to which the next step is added
106  void AddNextStep(StepBase* step, Int_t branch=-1);
107 
108  /// Get the vector of next steps
109  void GetNextSteps(std::vector<StepBase*>& steps, bool withSplits=false);
110 
111  /// Get the vector of next steps in a given branch, returns a status code
112  BranchStatus GetNextStepsInBranch(std::vector<StepBase*>& steps, Int_t branch);
113 
114  /// check that the step and all its suns are correct (it was branch unique IDs defined)
115  void ValidateStepRecursive() const;
116 
117  ClassDef(StepBase, 1);
118 
119 protected:
120 
121  /// The type of this step: cut or action
123 
124  /// true if the cut sequence should be stopped when a cut fails
125  bool _break;
126 
127  /// The title of this step, which is used by the DrawingTools.
128  std::string _title;
129 
130  /// Is the step disabled in a given branch
131  std::vector<bool> _disabledInBranch;
132 
133  /// The vector of next steps
134  std::vector<StepBase*> _nextSteps;
135 
136  /// Branch unique IDs associated to this step
137  std::vector<UInt_t> _branchUniqueIDs;
138 
139  /// Index of the step in the selection
140  Int_t _index; //!
141 };
142 
143 #endif
BranchStatus GetNextStepsInBranch(std::vector< StepBase *> &steps, Int_t branch)
Get the vector of next steps in a given branch, returns a status code.
Definition: StepBase.cxx:125
Int_t Index() const
Return the index of this step.
Definition: StepBase.hxx:72
void AddBranchUniqueID(UInt_t ibranch)
Definition: StepBase.cxx:35
std::string ConvertType() const
Convert into a string the type of this step.
Definition: StepBase.cxx:59
const std::vector< StepBase * > & GetNextSteps() const
Returns the vector of next steps.
Definition: StepBase.hxx:87
const std::vector< UInt_t > & GetBranchUniqueIDs() const
Returns the vector of branche unique IDs associated to this step.
Definition: StepBase.hxx:101
void ValidateStepRecursive() const
check that the step and all its suns are correct (it was branch unique IDs defined) ...
Definition: StepBase.cxx:18
const std::string & Title() const
Return the title of this step.
Definition: StepBase.hxx:63
TypeEnum _type
The type of this step: cut or action.
Definition: StepBase.hxx:122
void SetType(TypeEnum type)
Set the type of this step.
Definition: StepBase.hxx:54
bool _break
true if the cut sequence should be stopped when a cut fails
Definition: StepBase.hxx:125
Int_t _index
Index of the step in the selection.
Definition: StepBase.hxx:140
virtual bool Apply(AnaEventC &event, ToyBoxB &box) const
Definition: StepBase.hxx:46
bool Break() const
Return true if the cut sequence should be stopped when a cut fails.
Definition: StepBase.hxx:69
void AddNextStep(StepBase *step, Int_t branch=-1)
Definition: StepBase.cxx:71
std::vector< UInt_t > _branchUniqueIDs
Branch unique IDs associated to this step.
Definition: StepBase.hxx:137
void SetBreak(bool b)
Set whether the cut sequence should be stopped when this cut fails.
Definition: StepBase.hxx:57
void RemoveBranchUniqueID(UInt_t branch)
Remove a branch unique ID from this step.
Definition: StepBase.cxx:47
std::string _title
The title of this step, which is used by the DrawingTools.
Definition: StepBase.hxx:128
void SetIndex(Int_t index)
Set the index of this step.
Definition: StepBase.hxx:60
void SetTitle(const std::string &title)
Definition: StepBase.hxx:51
std::vector< StepBase * > _nextSteps
The vector of next steps.
Definition: StepBase.hxx:134
void RemoveNextStep(const std::string &title, Int_t ID=0)
Remove step with a given title (and branch ID) from next steps.
Definition: StepBase.cxx:86
std::vector< bool > _disabledInBranch
Is the step disabled in a given branch.
Definition: StepBase.hxx:131
virtual StepBase * MakeClone()
MANDATORY FUNCTIONS !!!
Definition: StepBase.hxx:42
void EnableInBranch(Int_t branch)
Enable step in a given branch.
Definition: StepBase.hxx:81
TypeEnum Type() const
Return the type of this step.
Definition: StepBase.hxx:66
bool IsDisabledInBranch(Int_t branch) const
Returns true if the step is disabled in the specified branch.
Definition: StepBase.hxx:84
void DisableInBranch(Int_t branch)
Disable step in a given branch.
Definition: StepBase.hxx:78
TypeEnum
Enumerator describing the values that _type member can take.
Definition: StepBase.hxx:22