1 #include "AliOADBPhysicsSelection.h"
4 #include "TObjString.h"
13 ClassImp(AliOADBPhysicsSelection)
16 AliOADBPhysicsSelection::AliOADBPhysicsSelection() :
17 TNamed("AliOADBPhysicsSelection", "OADB object for the physics selection"), fNtriggerBits(NTRIGGERBITS), fNtriggerLogics(NTRIGGERLOGICS),fCollTrigClasses(0),fBGTrigClasses(0),fHardwareTrigger(0),fOfflineTrigger(0),fBeamSide(0)
22 AliOADBPhysicsSelection::AliOADBPhysicsSelection(const 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)
25 // ctor, better use this one
29 void AliOADBPhysicsSelection::Init() {
30 //Initialization of pointers
32 if(fCollTrigClasses) {
33 AliInfo("Already initialized");
37 fNtriggerBits = NTRIGGERBITS;
38 fCollTrigClasses = new TList*[fNtriggerBits];
39 fBGTrigClasses = new TList*[fNtriggerBits];
40 fHardwareTrigger = new TObjString[fNtriggerLogics];
41 fOfflineTrigger = new TObjString[fNtriggerLogics];
43 for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
44 fCollTrigClasses[ibit] = new TList;
45 fBGTrigClasses [ibit] = new TList;
47 for(UInt_t ilogic = 0; ilogic < fNtriggerLogics; ilogic++){
48 fHardwareTrigger[ilogic] = "";
49 fOfflineTrigger [ilogic] = "";
55 AliOADBPhysicsSelection::~AliOADBPhysicsSelection(){
58 if(fHardwareTrigger) delete [] fHardwareTrigger;
59 if(fOfflineTrigger) delete [] fOfflineTrigger ;
61 for(Int_t ibit = 0; ibit < NTRIGGERBITS; ibit++){
64 if(fCollTrigClasses[ibit]) delete fCollTrigClasses[ibit];
66 if(fBGTrigClasses [ibit]) delete fBGTrigClasses [ibit];
71 AliOADBPhysicsSelection::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) {
73 fCollTrigClasses = cont.fCollTrigClasses;
74 fBGTrigClasses = cont.fBGTrigClasses;
75 fHardwareTrigger = cont.fHardwareTrigger;
76 fOfflineTrigger = cont.fOfflineTrigger;
77 fBeamSide = cont.fBeamSide;
81 AliOADBPhysicsSelection& AliOADBPhysicsSelection::operator=(const AliOADBPhysicsSelection& other) {
83 if(&other == this) return *this;
84 TNamed::operator=(other);
86 fCollTrigClasses = other.fCollTrigClasses;
87 fBGTrigClasses = other.fBGTrigClasses;
88 fHardwareTrigger = other.fHardwareTrigger;
89 fOfflineTrigger = other.fOfflineTrigger;
90 fBeamSide = other.fBeamSide;
96 void AliOADBPhysicsSelection::AddCollisionTriggerClass(AliVEvent::EOfflineTriggerTypes triggerMask, const char* className,const char * beamSide, UInt_t triggerLogic) {
97 // add collision trigger class
98 TObjString * tclass = new TObjString(Form("%s &%u *%u",ExpandTriggerString(className),triggerMask, triggerLogic));
99 fCollTrigClasses[GetActiveBit(triggerMask)]->Add(tclass);
100 SetBeamSide(tclass->String().Data(),beamSide);
102 void AliOADBPhysicsSelection::AddBGTriggerClass (AliVEvent::EOfflineTriggerTypes triggerMask, const char* className,const char * beamSide, UInt_t triggerLogic)
104 // add bg trigger class
105 TObjString * tclass = new TObjString(Form("%s &%u *%u",ExpandTriggerString(className),triggerMask, triggerLogic));
106 fBGTrigClasses [GetActiveBit(triggerMask)]->Add(tclass);
107 SetBeamSide(tclass->String().Data(),beamSide);
110 const TString AliOADBPhysicsSelection::GetBeamSide (const char * trigger) {
111 // Associate beam side to trigger class name
112 TObjString * cname = new TObjString(trigger);
113 CleanKey(cname->String());
114 static TString retValue="";
115 retValue = ((TObjString*)fBeamSide->GetValue(cname->String().Data())) ?
116 ((TObjString*)fBeamSide->GetValue(cname->String().Data()))->String() : "" ;
120 void AliOADBPhysicsSelection::SetBeamSide (const char * className, const char * side)
123 TObjString * cname = new TObjString(className);
124 CleanKey(cname->String());
125 fBeamSide->Add(new TObjString(cname->String().Data()), new TObjString(side));
129 void AliOADBPhysicsSelection::CleanKey(TString & str) {
131 // Remove all wite spaces and "goodies" of the trigger class string (bx ids, trigger logic...)
133 str.Remove(str.Index("*")); // keep only the class name (no bx, offline trigger...)
135 str.Remove(str.Index("#")); // keep only the class name (no bx, offline trigger...)
137 str.Remove(str.Index("&")); // keep only the class name (no bx, offline trigger...)
138 str.ReplaceAll(" ","");
144 // FIXME: decide about these getters
145 // TList * AliOADBPhysicsSelection::GetCollTrigClass(AliVEvent::EOfflineTriggerTypes trig) const {
146 // // Returns list of collision trigger classes for the requested bits
147 // return GetTrigClass(trig,fCollTrigClasses);
150 // TList * AliOADBPhysicsSelection::GetBGTrigClass(AliVEvent::EOfflineTriggerTypes trig) const {
151 // // Returns list of background trigger classes for the requested bits
152 // return GetTrigClass(trig,fBGTrigClasses);
155 // TList * AliOADBPhysicsSelection::GetTrigClass(AliVEvent::EOfflineTriggerTypes trig, TList ** listClasses) const {
156 // // Returns list of trigger classes for the requested bits
158 // TList * list= new TList;
159 // // Check which bits are on and build the final list
160 // for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
161 // if ((trig&(0x1<<ibit))) {
162 // if(listClasses[ibit]) list->AddAll(listClasses[ibit]);
163 // else AliError(Form("List %d not initialized?",ibit));
170 void AliOADBPhysicsSelection::Print(Option_t* option) const {
172 for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
173 cout << "Bit " << ibit << endl;
175 fCollTrigClasses[ibit]->Print(option);
176 fBGTrigClasses[ibit]->Print(option);
177 cout << "HW trig " << fHardwareTrigger[ibit].String().Data() << endl;
178 cout << "Offline trig " << fHardwareTrigger[ibit].String().Data() << endl;
181 cout << "Beams: " << endl;
187 void AliOADBPhysicsSelection::Browse(TBrowser *b)
189 // Browse this object.
190 // If b=0, there is no Browse call TObject::Browse(0) instead.
191 // This means TObject::Inspect() will be invoked indirectly
192 static TFolder ** bitFolders = 0;
194 bitFolders = new TFolder*[fNtriggerBits];
195 for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
196 bitFolders[ibit] = 0;
202 for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
203 if(bitFolders[ibit]) delete bitFolders[ibit];
204 bitFolders[ibit] = new TFolder (Form("Bit %2.2d", ibit), "Trigger bit folder");
205 bitFolders[ibit]->SetOwner(); // Delete also the TObjString when deleting the folder
206 for(UInt_t ilogic = 0; ilogic < fNtriggerLogics; ilogic++){
207 if(GetHardwareTrigger(ilogic) != "" || GetOfflineTrigger(ilogic) != "") {
208 bitFolders[ibit]->Add(new TObjString(Form("Hardware Trig [*%d][%s]",ilogic,GetHardwareTrigger(ilogic).Data())));
209 bitFolders[ibit]->Add(new TObjString(Form("Offline Trig [*%d][%s]",ilogic,GetOfflineTrigger(ilogic).Data())));
213 TIterator *itColl = fCollTrigClasses[ibit]->MakeIterator();
214 TObjString * coll = 0;
216 while ((coll = (TObjString*)itColl->Next())) {
217 bitFolders[ibit]->Add(new TObjString(Form("Collision Class [%s] [%s]", coll->String().Data(),
218 GetBeamSide(coll->String().Data()).Data())));
222 TIterator *itBG = fBGTrigClasses[ibit]->MakeIterator();
224 while ((bg = (TObjString*)itBG->Next())) {
225 bitFolders[ibit]->Add(new TObjString(Form("Background Class [%s] [%s]", bg->String().Data(),
226 GetBeamSide(bg->String().Data()).Data())));
230 b->Add(bitFolders[ibit]);
238 UInt_t AliOADBPhysicsSelection::GetActiveBit(UInt_t mask) {
239 // Returns the active bit index in the mask
240 // Assumes only one bit is on.
241 // If more than one bit is lit, prints an error and returns the first.
242 // If no bit is on, prints an error and returns 0
244 const Int_t kNBitsToCheck = 29;
246 // Int_t nbit = sizeof(mask)*8;
247 Int_t nbit = kNBitsToCheck;
248 Int_t activeBit = -1;
249 for(Int_t ibit = 0; ibit < nbit; ibit++){
250 if ( mask & (0x1 << ibit) ) {
251 if (activeBit == -1) activeBit = ibit;
252 else Printf("ERROR (AliTriggerAnalysis::GetActiveBit): More than one bit is on in this mask 0x%x", mask);
255 if (activeBit == -1) {
256 Printf("ERROR (AliTriggerAnalysis::GetActiveBit): No bit is on");
264 const char* AliOADBPhysicsSelection::ExpandTriggerString(const char* className)
267 // E.g. +CVHN-B-[NOPF|PF]-[ALL|CENT]NOTRD goes to +CVHN-B-NOPF-ALLNOTRD,CVHN-B-NOPF-CENTNOTRD,CVHN-B-PF-ALLNOTRD,CVHN-B-PF-CENTNOTRD
271 TObjArray* triggers = str.Tokenize(" ");
272 for (Int_t j=0; j<triggers->GetEntries(); j++)
274 str = triggers->At(j)->GetName();
275 str = str(1, str.Length());
280 TObjArray* triggers2 = str.Tokenize(",");
281 for (Int_t k=0; k<triggers2->GetEntries(); k++)
282 list.Add(new TObjString(triggers2->At(k)->GetName()));
290 for (i=0; i<list.GetEntries(); i++)
292 str = list.At(i)->GetName();
294 Int_t begin = str.Index("[");
295 Int_t end = str.Index("]");
296 if (begin >= 0 && end >= 0)
298 TString before = str(0, begin);
299 TString after = str(end+1, str.Length());
300 TString tokens = str(begin+1, end-begin-1);
301 // Printf("%s %s %s", before.Data(), tokens.Data(), after.Data());
303 while (tokens.Index("|", pos) >= 0)
305 list.Add(new TObjString(before + tokens(pos, tokens.Index("|", pos) - pos) + after));
306 pos = tokens.Index("|", pos) + 1;
308 list.Add(new TObjString(before + tokens(pos, tokens.Length()) + after));
309 delete list.RemoveAt(i);
317 for (i=0; i<list.GetEntries(); i++)
319 str += list.At(i)->GetName();
322 str = str(0, str.Length() - 1);
326 TString& target = ((TObjString*) triggers->At(j))->String();
327 target.Form("%c%s", target[0], str.Data());
331 for (Int_t j=0; j<triggers->GetEntries(); j++)
333 str += triggers->At(j)->GetName();
336 str = str(0, str.Length() - 1);
339 if (strcmp(className, str.Data()))
340 Printf("AliOADBPhysicsSelection::ExpandTriggerString: In: <%s> Out: <%s>", className, str.Data());