HighLAND
StepBase.cxx
1 #include "StepBase.hxx"
2 
3 ClassImp(StepBase)
4 
5 //****************************************************
7 //****************************************************
8 
9  _title="";
10  _type=kUnknown;
11  _break=false;
12  _nextSteps.clear();
13  _branchUniqueIDs.clear();
14  _disabledInBranch.clear();
15 }
16 
17 //****************************************************
19 //****************************************************
20 
21  if (GetBranchUniqueIDs().size()==0){
22  std::cout << "\nERROR. StepBase::ValidateStepRecursive(). Step '" << _title
23  << "' does not belong to any branch. You must use SetBranchAlias after adding the steps in your selection" << std::endl;
24  exit(1);
25  }
26 
27  for (UInt_t i = 0; i < GetNextSteps().size(); ++i){
28  StepBase* step2=GetNextSteps()[i];
29  if (step2) step2->ValidateStepRecursive();
30  }
31 
32 }
33 
34 //****************************************************
35 void StepBase::AddBranchUniqueID(UInt_t branch){
36 //****************************************************
37 
38  _branchUniqueIDs.push_back(branch);
39  if (_disabledInBranch.size() < branch+1){
40  _disabledInBranch.resize(branch+1);
41  for (UInt_t i=0;i<_disabledInBranch.size();i++)
42  _disabledInBranch[i]=false;
43  }
44 }
45 
46 //****************************************************
47 void StepBase::RemoveBranchUniqueID(UInt_t branch){
48 //****************************************************
49 
50  for (std::vector<UInt_t>::iterator it =_branchUniqueIDs.begin(); it!=_branchUniqueIDs.end();it++){
51  if (*it == branch){
52  _branchUniqueIDs.erase(it);
53  break;
54  }
55  }
56 }
57 
58 //***********************************************************
59 std::string StepBase::ConvertType() const{
60 //***********************************************************
61 
62  if (_type == kCut)
63  return "cut";
64  else if (_type == kAction)
65  return "action";
66  else
67  return "unknown";
68 }
69 
70 //********************************************************************
71 void StepBase::AddNextStep(StepBase* step, Int_t branch){
72 //********************************************************************
73 
74  if (branch==-1 || _nextSteps.size()==0)
75  _nextSteps.push_back(step);
76  else{
77  if (branch>=0 && branch < (Int_t)_nextSteps.size()){
78  _nextSteps[branch] = step;
79  }
80  else
81  std::cout << "StepBase::AddNextStep(). branch " << branch << " not defined for step '" << _title << "'" << std::endl;
82  }
83 }
84 
85 //********************************************************************
86 void StepBase::RemoveNextStep(const std::string& title, Int_t branch){
87 //********************************************************************
88 
89  if (branch<0 || branch >= (Int_t)_nextSteps.size()){
90  std::cout << "ERROR. StepBase::AddNextStep(). branch " << branch << " not defined for step '" << _title << "'" << std::endl;
91  exit(1);
92  }
93 
94  // This method removes a step with a given title (and branch ID) from the vector of next steps
95  if (_nextSteps[branch]->Title() != title){
96  std::cout << "ERROR. StepBase::AddNextStep(). Step '" << _title << "' does not have a child step '" << title << "' in branch " << branch << std::endl;
97  exit(1);
98  }
99 
100  // if there is only one next step, the vector is emptied, otherwise the corresponding entry in the vector is set to NULL
101  // in order to keep the number of branches in the split
102  if (_nextSteps.size()==1)
103  _nextSteps.clear();
104  else
105  _nextSteps[branch]=NULL;
106 }
107 
108 //********************************************************************
109 void StepBase::GetNextSteps(std::vector<StepBase*>& steps, bool withSplits){
110 //********************************************************************
111 
112  // Get all Steps with or without splits
113  if (!withSplits && _nextSteps.size() != 1) return;
114 
115  for (std::vector<StepBase*>::iterator it=_nextSteps.begin();it!=_nextSteps.end();it++){
116  // Add The next step
117  steps.push_back(*it);
118 
119  // Go recursively to add the childs of the next step
120  (*it)->GetNextSteps(steps,withSplits);
121  }
122 }
123 
124 //********************************************************************
125 StepBase::BranchStatus StepBase::GetNextStepsInBranch(std::vector<StepBase*>& steps, int branch){
126 //********************************************************************
127 
128  // This function adds all subsequent steps to the steps vector at a given split, for the specific branch at this split.
129 
130  // Make sure the requested branch is OK
131  if ((branch<0 || branch>=(Int_t)_nextSteps.size()) && branch!=0 && _nextSteps.size() !=0){
132  std::cout << "StepBase::GetNextSteps(branch): Branch index " << branch << " does not exist in Step '" << _title << "'" << std::endl;
133  return BranchOutOfRange;
134  }
135 
136  // No more steps to add when nextSteps has 0 elements
137  if (_nextSteps.size()==0) return NoBranches;
138 
139  // TODO: not sure it is needed. Just a protection
140  if (!_nextSteps[branch]) return BranchEmpty;
141 
142  // Add The next step
143  steps.push_back(_nextSteps[branch]);
144 
145  // Go recursively to add the doughters of the next step
146  _nextSteps[branch]->GetNextSteps(steps);
147 
148  return BranchOK;
149 }
150 
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
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 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 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
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