]> git.uio.no Git - u/mrichter/AliRoot.git/blob - OADB/AliOADBPhysicsSelection.cxx
Removing useless flag.
[u/mrichter/AliRoot.git] / OADB / AliOADBPhysicsSelection.cxx
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
11 using namespace std;
12
13 ClassImp(AliOADBPhysicsSelection)
14
15
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)
18 {
19   // default ctor
20   
21 }
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)
24 {
25   // ctor, better use this one
26   Init();
27 }
28
29 void 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
55 AliOADBPhysicsSelection::~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
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) {
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
81 AliOADBPhysicsSelection& AliOADBPhysicsSelection::operator=(const AliOADBPhysicsSelection& other)  {
82   //Assignment operator
83   if(&other == this) return *this;
84   TNamed::operator=(other);
85
86   fCollTrigClasses = other.fCollTrigClasses;
87   fBGTrigClasses = other.fBGTrigClasses;
88   fHardwareTrigger = other.fHardwareTrigger;
89   fOfflineTrigger = other.fOfflineTrigger;
90   fBeamSide = other.fBeamSide;
91   
92
93   return *this;
94 }
95  
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);
101 }
102 void AliOADBPhysicsSelection::AddBGTriggerClass       (AliVEvent::EOfflineTriggerTypes triggerMask, const char* className,const char * beamSide, UInt_t triggerLogic) 
103
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);
108 }
109
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() : "" ;
117   delete cname;
118   return retValue;
119 }
120 void AliOADBPhysicsSelection::SetBeamSide (const char * className, const char * side)
121
122   // return beam side
123   TObjString * cname = new TObjString(className);
124   CleanKey(cname->String());
125   fBeamSide->Add(new TObjString(cname->String().Data()), new TObjString(side));
126   delete cname;
127 }
128
129 void AliOADBPhysicsSelection::CleanKey(TString & str) {
130
131   //  Remove all wite spaces and "goodies" of the trigger class string (bx ids, trigger logic...)
132   if(str.Index("*")>0)
133     str.Remove(str.Index("*")); // keep only the class name (no bx, offline trigger...)   
134   if(str.Index("#")>0)
135     str.Remove(str.Index("#")); // keep only the class name (no bx, offline trigger...)   
136   if(str.Index("&")>0)
137     str.Remove(str.Index("&")); // keep only the class name (no bx, offline trigger...)   
138   str.ReplaceAll(" ","");
139
140 }
141  
142 // Getters
143
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);
148 // }
149
150 // TList * AliOADBPhysicsSelection::GetBGTrigClass(AliVEvent::EOfflineTriggerTypes trig) const { 
151 //   // Returns list of background trigger classes for the requested bits
152 //   return GetTrigClass(trig,fBGTrigClasses);
153 // }
154
155 // TList * AliOADBPhysicsSelection::GetTrigClass(AliVEvent::EOfflineTriggerTypes trig, TList ** listClasses) const { 
156 //   // Returns list of trigger classes for the requested bits
157
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));
164 //     }
165 //   }
166   
167 //   return list;
168 // }
169
170 void AliOADBPhysicsSelection::Print(Option_t* option) const {
171
172   for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
173     cout << "Bit " << ibit << endl;
174     
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;
179     
180   }
181   cout << "Beams: " << endl;
182   fBeamSide->Print();
183
184 }
185
186
187 void AliOADBPhysicsSelection::Browse(TBrowser *b)
188 {
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;
193   if(!bitFolders) {
194     bitFolders = new TFolder*[fNtriggerBits];
195     for(UInt_t ibit = 0; ibit < fNtriggerBits; ibit++){
196       bitFolders[ibit] = 0;
197     }
198     
199   }
200
201   if (b) {
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())));      
210         }
211       }
212       
213       TIterator *itColl = fCollTrigClasses[ibit]->MakeIterator();
214       TObjString * coll = 0;
215
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())));
219       }
220       delete itColl;
221
222       TIterator *itBG = fBGTrigClasses[ibit]->MakeIterator();
223       TObjString * bg = 0;
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())));
227       }
228       delete itBG;
229
230       b->Add(bitFolders[ibit]);
231
232     }    
233   }     
234    else
235       TObject::Browse(b);
236 }
237
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
243
244   const Int_t kNBitsToCheck = 29;
245
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);
253     }
254   }
255   if (activeBit == -1) {
256     Printf("ERROR (AliTriggerAnalysis::GetActiveBit): No bit is on");
257     activeBit=0;
258   }
259
260   return activeBit;
261
262 }
263
264 const char* AliOADBPhysicsSelection::ExpandTriggerString(const char* className)
265 {
266   // expands [] syntax
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
268   
269   static TString str;
270   str = className;
271   TObjArray* triggers = str.Tokenize(" ");
272   for (Int_t j=0; j<triggers->GetEntries(); j++)
273   {
274     str = triggers->At(j)->GetName();
275     str = str(1, str.Length());
276     
277     TList list;
278     list.SetOwner();
279
280     TObjArray* triggers2 = str.Tokenize(",");
281     for (Int_t k=0; k<triggers2->GetEntries(); k++)
282       list.Add(new TObjString(triggers2->At(k)->GetName()));
283     delete triggers2;
284     
285 //     list.Print();
286     
287     while (1)
288     {
289       Int_t i=0;
290       for (i=0; i<list.GetEntries(); i++)
291       {
292         str = list.At(i)->GetName();
293       
294         Int_t begin = str.Index("[");
295         Int_t end = str.Index("]");
296         if (begin >= 0 && end >= 0)
297         {
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());
302           Int_t pos = 0;
303           while (tokens.Index("|", pos) >= 0)
304           {
305             list.Add(new TObjString(before + tokens(pos, tokens.Index("|", pos) - pos) + after));
306             pos = tokens.Index("|", pos) + 1;
307           }
308           list.Add(new TObjString(before + tokens(pos, tokens.Length()) + after));
309           delete list.RemoveAt(i);
310           
311   //    list.Print();
312           i=-1;
313         }
314       }
315
316       str = "";
317       for (i=0; i<list.GetEntries(); i++)
318       {
319         str += list.At(i)->GetName();
320         str += ",";
321       }
322       str = str(0, str.Length() - 1);
323       break;
324     }
325       
326     TString& target = ((TObjString*) triggers->At(j))->String();
327     target.Form("%c%s", target[0], str.Data());
328   }
329   
330   str = "";
331   for (Int_t j=0; j<triggers->GetEntries(); j++)
332   {
333     str += triggers->At(j)->GetName();
334     str += " ";
335   }
336   str = str(0, str.Length() - 1);
337
338   delete triggers;
339   if (strcmp(className, str.Data()))
340     Printf("AliOADBPhysicsSelection::ExpandTriggerString: In: <%s> Out: <%s>", className, str.Data());
341   return str;
342 }