OADB Classes for the physics selection and filling scheme
[u/mrichter/AliRoot.git] / OADB / AliOADBPhysicsSelection.cxx
CommitLineData
eeb4307b 1#include "AliOADBPhysicsSelection.h"
2#include "TList.h"
3#include "TString.h"
4#include "TObjString.h"
5#include "AliLog.h"
6#include "TBrowser.h"
7#include "TFolder.h"
8#include "TIterator.h"
9#include <iostream>
10
11using namespace std;
12
13ClassImp(AliOADBPhysicsSelection)
14
15
16AliOADBPhysicsSelection::AliOADBPhysicsSelection() :
17TNamed("AliOADBPhysicsSelection", "OADB object for the physics selection"), fNtriggerBits(NTRIGGERBITS), fNtriggerLogics(NTRIGGERLOGICS),fCollTrigClasses(0),fBGTrigClasses(0),fHardwareTrigger(0),fOfflineTrigger(0),fBeamSide(0)
18{
19 // default ctor
20
21}
22AliOADBPhysicsSelection::AliOADBPhysicsSelection(char* name) :
23 TNamed(name, "OADB object for the physics selection"), fNtriggerBits(NTRIGGERBITS), fNtriggerLogics(NTRIGGERLOGICS),fCollTrigClasses(0),fBGTrigClasses(0),fHardwareTrigger(0),fOfflineTrigger(0),fBeamSide(0)
24{
25 // ctor, better use this one
26 Init();
27}
28
29void AliOADBPhysicsSelection::Init() {
30 //Initialization of pointers
31
32 if(fCollTrigClasses) {
33 AliInfo("Already initialized");
34 return;
35 }
36
37 fNtriggerBits = NTRIGGERBITS;
38 fCollTrigClasses = new TList*[fNtriggerBits];
39 fBGTrigClasses = new TList*[fNtriggerBits];
40 fHardwareTrigger = new TObjString[fNtriggerLogics];
41 fOfflineTrigger = new TObjString[fNtriggerLogics];
42 fBeamSide = new TMap;
43 for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
44 fCollTrigClasses[ibit] = new TList;
45 fBGTrigClasses [ibit] = new TList;
46 }
47 for(UInt_t ilogic = 0; ilogic < fNtriggerLogics; ilogic++){
48 fHardwareTrigger[ilogic] = "";
49 fOfflineTrigger [ilogic] = "";
50 }
51
52
53}
54
55AliOADBPhysicsSelection::~AliOADBPhysicsSelection(){
56 // dtor
57
58 if(fHardwareTrigger) delete [] fHardwareTrigger;
59 if(fOfflineTrigger) delete [] fOfflineTrigger ;
60
61 for(Int_t ibit = 0; ibit < NTRIGGERBITS; ibit++){
62
63 if(fCollTrigClasses)
64 if(fCollTrigClasses[ibit]) delete fCollTrigClasses[ibit];
65 if(fBGTrigClasses)
66 if(fBGTrigClasses [ibit]) delete fBGTrigClasses [ibit];
67 }
68
69}
70
71AliOADBPhysicsSelection::AliOADBPhysicsSelection(const AliOADBPhysicsSelection& cont) :TNamed("AliOADBPhysicsSelection", "OADB object for the physics selection"), fNtriggerBits(NTRIGGERBITS), fNtriggerLogics(NTRIGGERLOGICS),fCollTrigClasses(0),fBGTrigClasses(0),fHardwareTrigger(0),fOfflineTrigger(0),fBeamSide(0) {
72 // Copy ctor
73 fCollTrigClasses = cont.fCollTrigClasses;
74 fBGTrigClasses = cont.fBGTrigClasses;
75 fHardwareTrigger = cont.fHardwareTrigger;
76 fOfflineTrigger = cont.fOfflineTrigger;
77 fBeamSide = cont.fBeamSide;
78
79}
80
81AliOADBPhysicsSelection& AliOADBPhysicsSelection::operator=(const AliOADBPhysicsSelection& other) {
82 //Assignment operator
83 TNamed::operator=(other);
84
85 fCollTrigClasses = other.fCollTrigClasses;
86 fBGTrigClasses = other.fBGTrigClasses;
87 fHardwareTrigger = other.fHardwareTrigger;
88 fOfflineTrigger = other.fOfflineTrigger;
89 fBeamSide = other.fBeamSide;
90
91
92 return *this;
93}
94
95void AliOADBPhysicsSelection::AddCollisionTriggerClass(AliVEvent::EOfflineTriggerTypes triggerMask, const char* className,const char * beamSide, UInt_t triggerLogic) {
96 // add collision trigger class
97 TObjString * tclass = new TObjString(Form("%s &%u *%u",className,triggerMask, triggerLogic));
98 fCollTrigClasses[GetActiveBit(triggerMask)]->Add(tclass);
99 SetBeamSide(tclass->String().Data(),beamSide);
100}
101void AliOADBPhysicsSelection::AddBGTriggerClass (AliVEvent::EOfflineTriggerTypes triggerMask, const char* className,const char * beamSide, UInt_t triggerLogic)
102{
103 // add bg gtrigger class
104 TObjString * tclass = new TObjString(Form("%s &%u *%u",className,triggerMask, triggerLogic));
105 fBGTrigClasses [GetActiveBit(triggerMask)]->Add(tclass);
106 SetBeamSide(tclass->String().Data(),beamSide);
107}
108
109const TString AliOADBPhysicsSelection::GetBeamSide (const char * trigger) {
110 // Associate beam site to trigger class name
111 TObjString * cname = new TObjString(trigger);
112 CleanKey(cname->String());
113 static TString retValue="";
114 retValue = ((TObjString*)fBeamSide->GetValue(cname->String().Data())) ?
115 ((TObjString*)fBeamSide->GetValue(cname->String().Data()))->String() : "" ;
116 delete cname;
117 return retValue;
118}
119void AliOADBPhysicsSelection::SetBeamSide (const char * className, const char * side)
120{
121 // return beam side
122 TObjString * cname = new TObjString(className);
123 CleanKey(cname->String());
124 fBeamSide->Add(new TObjString(cname->String().Data()), new TObjString(side));
125 delete cname;
126}
127
128void AliOADBPhysicsSelection::CleanKey(TString & str) {
129
130 // Remove all wite spacese and "goodies" of the trigger class string (bx ids, trigger logic...)
131 if(str.Index("*")>0)
132 str.Remove(str.Index("*")); // keep only the class name (no bx, offline trigger...)
133 if(str.Index("#")>0)
134 str.Remove(str.Index("#")); // keep only the class name (no bx, offline trigger...)
135 if(str.Index("&")>0)
136 str.Remove(str.Index("&")); // keep only the class name (no bx, offline trigger...)
137 str.ReplaceAll(" ","");
138
139}
140
141// Getters
142
143// FIXME: decide about these getters
144// TList * AliOADBPhysicsSelection::GetCollTrigClass(AliVEvent::EOfflineTriggerTypes trig) const {
145// // Returns list of collision trigger classes for the requested bits
146// return GetTrigClass(trig,fCollTrigClasses);
147// }
148
149// TList * AliOADBPhysicsSelection::GetBGTrigClass(AliVEvent::EOfflineTriggerTypes trig) const {
150// // Returns list of background trigger classes for the requested bits
151// return GetTrigClass(trig,fBGTrigClasses);
152// }
153
154// TList * AliOADBPhysicsSelection::GetTrigClass(AliVEvent::EOfflineTriggerTypes trig, TList ** listClasses) const {
155// // Returns list of trigger classes for the requested bits
156
157// TList * list= new TList;
158// // Check which bits are on and build the final list
159// for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
160// if ((trig&(0x1<<ibit))) {
161// if(listClasses[ibit]) list->AddAll(listClasses[ibit]);
162// else AliError(Form("List %d not initialized?",ibit));
163// }
164// }
165
166// return list;
167// }
168
169void AliOADBPhysicsSelection::Print(Option_t* option) const {
170
171 for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
172 cout << "Bit " << ibit << endl;
173
174 fCollTrigClasses[ibit]->Print(option);
175 fBGTrigClasses[ibit]->Print(option);
176 cout << "HW trig " << fHardwareTrigger[ibit].String().Data() << endl;
177 cout << "Offline trig " << fHardwareTrigger[ibit].String().Data() << endl;
178
179 }
180 cout << "Beams: " << endl;
181 fBeamSide->Print();
182
183}
184
185
186void AliOADBPhysicsSelection::Browse(TBrowser *b)
187{
188 // Browse this object.
189 // If b=0, there is no Browse call TObject::Browse(0) instead.
190 // This means TObject::Inspect() will be invoked indirectly
191
192 TFolder ** bitFolders = new TFolder*[fNtriggerBits];
193
194 if (b) {
195 for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
196 // if(bitFolders[ibit]) delete bitFolders[ibit];
197 bitFolders[ibit] = new TFolder (Form("Bit %2.2d", ibit), "Trigger bit folder");
198 for(UInt_t ilogic = 0; ilogic < fNtriggerLogics; ilogic++){
199 if(GetHardwareTrigger(ilogic) != "" || GetOfflineTrigger(ilogic) != "") {
200 bitFolders[ibit]->Add(new TObjString(Form("Hardware Trig [*%d][%s]",ilogic,GetHardwareTrigger(ilogic).Data())));
201 bitFolders[ibit]->Add(new TObjString(Form("Offline Trig [*%d][%s]",ilogic,GetOfflineTrigger(ilogic).Data())));
202 }
203 }
204
205 TIterator *itColl = fCollTrigClasses[ibit]->MakeIterator();
206 TObjString * coll = 0;
207
208 while ((coll = (TObjString*)itColl->Next())) {
209 bitFolders[ibit]->Add(new TObjString(Form("Collision Class [%s] [%s]", coll->String().Data(),
210 GetBeamSide(coll->String().Data()).Data())));
211 }
212
213 TIterator *itBG = fBGTrigClasses[ibit]->MakeIterator();
214 TObjString * bg = 0;
215 while ((bg = (TObjString*)itBG->Next())) {
216 bitFolders[ibit]->Add(new TObjString(Form("Background Class [%s] [%s]", bg->String().Data(),
217 GetBeamSide(bg->String().Data()).Data())));
218 }
219
220
221 b->Add(bitFolders[ibit]);
222
223 }
224 }
225 else
226 TObject::Browse(b);
227}
228
229const UInt_t AliOADBPhysicsSelection::GetActiveBit(UInt_t mask) {
230 // Returns the active bit index in the mask
231 // Assumes only one bit is on.
232 // If more than one bit is lit, prints an error and returns the first.
233 // If no bit is on, prints an error and returns 0
234
235 Int_t nbit = sizeof(mask)*8;
236 Int_t activeBit = -1;
237 for(Int_t ibit = 0; ibit < nbit; ibit++){
238 if ( mask & (0x1 << ibit) ) {
239 if (activeBit == -1) activeBit = ibit;
240 else Printf("ERROR (AliTriggerAnalysis::GetActiveBit): More than one bit is on in this mask 0x%x", mask);
241 }
242 }
243 if (activeBit == -1) {
244 Printf("ERROR (AliTriggerAnalysis::GetActiveBit): No bit is on");
245 activeBit=0;
246 }
247
248 return activeBit;
249
250}