]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliESDHeader.cxx
23c48c33bbb772902b6689e56de78fc5c4ed4d11
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDHeader.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //-------------------------------------------------------------------------
17 //                      Implementation of   Class AliESDHeader
18 //   Header data
19 //   for the ESD   
20 //   Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch 
21 //-------------------------------------------------------------------------
22
23 #include "AliESDHeader.h"
24 #include "AliTriggerScalersESD.h"
25 #include "AliTriggerScalersRecordESD.h"
26 #include "AliTriggerIR.h"
27 #include "AliTriggerConfiguration.h"
28 #include "AliLog.h" 
29
30 ClassImp(AliESDHeader)
31
32 //______________________________________________________________________________
33 AliESDHeader::AliESDHeader() :
34   AliVHeader(),
35   fTriggerMask(0),
36   fOrbitNumber(0),
37   fTimeStamp(0),
38   fEventType(0),
39   fEventSpecie(0),
40   fPeriodNumber(0),
41   fEventNumberInFile(0),
42   fBunchCrossNumber(0),
43   fTriggerCluster(0),
44   fL0TriggerInputs(0),
45   fL1TriggerInputs(0),
46   fL2TriggerInputs(0),
47   fTriggerScalers(),
48   fTriggerScalersDeltaEvent(),
49   fTriggerScalersDeltaRun(),
50   fTriggerInputsNames(kNTriggerInputs),
51   fCTPConfig(NULL),
52   fIRBufferArray()
53 {
54   // default constructor
55
56   SetName("AliESDHeader");
57   for(Int_t i = 0; i<kNMaxIR ; i++) fIRArray[i] = 0;
58   fTriggerInputsNames.SetOwner(kTRUE);
59 }
60
61 AliESDHeader::~AliESDHeader() 
62 {
63   // destructor
64   for(Int_t i=0;i<kNMaxIR;i++)if(fIRArray[i])delete fIRArray[i];
65   delete fCTPConfig;
66
67   fIRBufferArray.Delete();
68 }
69
70
71 AliESDHeader::AliESDHeader(const AliESDHeader &header) :
72   AliVHeader(header),
73   fTriggerMask(header.fTriggerMask),
74   fOrbitNumber(header.fOrbitNumber),
75   fTimeStamp(header.fTimeStamp),
76   fEventType(header.fEventType),
77   fEventSpecie(header.fEventSpecie),
78   fPeriodNumber(header.fPeriodNumber),
79   fEventNumberInFile(header.fEventNumberInFile),
80   fBunchCrossNumber(header.fBunchCrossNumber),
81   fTriggerCluster(header.fTriggerCluster),
82   fL0TriggerInputs(header.fL0TriggerInputs),
83   fL1TriggerInputs(header.fL1TriggerInputs),
84   fL2TriggerInputs(header.fL2TriggerInputs),
85   fTriggerScalers(header.fTriggerScalers),
86   fTriggerScalersDeltaEvent(header.fTriggerScalersDeltaEvent),
87   fTriggerScalersDeltaRun(header.fTriggerScalersDeltaRun),
88   fTriggerInputsNames(TObjArray(kNTriggerInputs)),
89   fCTPConfig(header.fCTPConfig),
90   fIRBufferArray()
91 {
92   // copy constructor
93   for(Int_t i = 0; i<kNMaxIR ; i++) {
94     if(header.fIRArray[i])fIRArray[i] = new AliTriggerIR(*header.fIRArray[i]);
95     else fIRArray[i]=0;
96   }
97   for(Int_t i = 0; i < kNTriggerInputs; i++) {
98     TNamed *str = (TNamed *)((header.fTriggerInputsNames).At(i));
99     if (str) fTriggerInputsNames.AddAt(new TNamed(*str),i);
100   }
101
102   for(Int_t i = 0; i < (header.fIRBufferArray).GetEntries(); ++i) {
103     AliTriggerIR *ir = (AliTriggerIR*)((header.fIRBufferArray).At(i));
104     if (ir) fIRBufferArray.Add(new AliTriggerIR(*ir));
105   }
106 }
107
108 AliESDHeader& AliESDHeader::operator=(const AliESDHeader &header)
109
110   // assigment operator
111   if(this!=&header) {
112     AliVHeader::operator=(header);
113     fTriggerMask = header.fTriggerMask;
114     fOrbitNumber = header.fOrbitNumber;
115     fTimeStamp = header.fTimeStamp;
116     fEventType = header.fEventType;
117     fEventSpecie = header.fEventSpecie;
118     fPeriodNumber = header.fPeriodNumber;
119     fEventNumberInFile = header.fEventNumberInFile;
120     fBunchCrossNumber = header.fBunchCrossNumber;
121     fTriggerCluster = header.fTriggerCluster;
122     fL0TriggerInputs = header.fL0TriggerInputs;
123     fL1TriggerInputs = header.fL1TriggerInputs;
124     fL2TriggerInputs = header.fL2TriggerInputs;
125     fTriggerScalers = header.fTriggerScalers;
126     fTriggerScalersDeltaEvent = header.fTriggerScalersDeltaEvent;
127     fTriggerScalersDeltaRun = header.fTriggerScalersDeltaRun;
128     delete fCTPConfig;
129     fCTPConfig = header.fCTPConfig;
130
131     fTriggerInputsNames.Clear();
132     for(Int_t i = 0; i < kNTriggerInputs; i++) {
133       TNamed *str = (TNamed *)((header.fTriggerInputsNames).At(i));
134       if (str) fTriggerInputsNames.AddAt(new TNamed(*str),i);
135     }
136     for(Int_t i = 0; i<kNMaxIR ; i++) {
137       delete fIRArray[i];
138        if(header.fIRArray[i])fIRArray[i] = new AliTriggerIR(*header.fIRArray[i]);
139        else fIRArray[i]=0;
140     }
141
142     fIRBufferArray.Delete();
143     for(Int_t i = 0; i < (header.fIRBufferArray).GetEntries(); ++i) {
144       AliTriggerIR *ir = (AliTriggerIR*)((header.fIRBufferArray).At(i));
145       if (ir) fIRBufferArray.Add(new AliTriggerIR(*ir));
146     }
147   }
148   return *this;
149 }
150
151 void AliESDHeader::Copy(TObject &obj) const 
152 {  
153   // this overwrites the virtual TOBject::Copy()
154   // to allow run time copying without casting
155   // in AliESDEvent
156
157   if(this==&obj)return;
158   AliESDHeader *robj = dynamic_cast<AliESDHeader*>(&obj);
159   if(!robj)return; // not an AliESDHeader
160   *robj = *this;
161
162 }
163 //______________________________________________________________________________
164 void AliESDHeader::Reset()
165 {
166   // reset all data members
167   fTriggerMask       = 0;
168   fOrbitNumber       = 0;
169   fTimeStamp         = 0;
170   fEventType         = 0;
171   fEventSpecie       = 0;
172   fPeriodNumber      = 0;
173   fEventNumberInFile = 0;
174   fBunchCrossNumber  = 0;
175   fTriggerCluster    = 0;
176   fL0TriggerInputs   = 0;
177   fL1TriggerInputs   = 0;
178   fL2TriggerInputs   = 0;
179   fTriggerScalers.Reset();
180   fTriggerScalersDeltaEvent.Reset();
181   fTriggerScalersDeltaRun.Reset();
182   fTriggerInputsNames.Clear();
183   delete fCTPConfig;
184   fCTPConfig = 0;
185   for(Int_t i=0;i<kNMaxIR;i++)if(fIRArray[i]){
186    delete fIRArray[i];
187    fIRArray[i]=0;
188   }
189
190   fIRBufferArray.Delete();
191 }
192 //______________________________________________________________________________
193 Bool_t AliESDHeader::AddTriggerIR(const AliTriggerIR* ir)
194 {
195   // Add an IR object into the array
196   // of IRs in the ESD header
197
198  fIRBufferArray.Add(new AliTriggerIR(*ir));
199
200  return kTRUE;
201 }
202 //______________________________________________________________________________
203 void AliESDHeader::Print(const Option_t *) const
204 {
205   // Print some data members
206   printf("Event # %d in file Bunch crossing # %d Orbit # %d Trigger %lld \n",
207          GetEventNumberInFile(),
208          GetBunchCrossNumber(),
209          GetOrbitNumber(),
210          GetTriggerMask());
211          printf("List of the active trigger inputs: ");
212          for(Int_t i = 0; i < kNTriggerInputs; i++) {
213            TNamed *str = (TNamed *)((fTriggerInputsNames).At(i));
214            if (str) printf("%s ",str->GetName());
215          }
216          printf("\n");
217 }
218
219 //______________________________________________________________________________
220 void AliESDHeader::SetActiveTriggerInputs(const char*name, Int_t index)
221 {
222   // Fill the active trigger inputs names
223   // into the corresponding fTriggerInputsNames (TObjArray of TNamed)
224   if (index >= kNTriggerInputs || index < 0) {
225     AliError(Form("Index (%d) is outside the allowed range (0,59)!",index));
226     return;
227   }
228
229   fTriggerInputsNames.AddAt(new TNamed(name,NULL),index);
230 }
231 //______________________________________________________________________________
232 const char* AliESDHeader::GetTriggerInputName(Int_t index, Int_t trglevel) const
233 {
234   // Get the trigger input name
235   // at the specified position in the trigger mask and trigger level (0,1,2)
236   TNamed *trginput = 0;
237   if (trglevel == 0) trginput = (TNamed *)fTriggerInputsNames.At(index);
238   if (trglevel == 1) trginput = (TNamed *)fTriggerInputsNames.At(index+24);  
239   if (trglevel == 2) trginput = (TNamed *)fTriggerInputsNames.At(index+48); 
240   if (trginput) return trginput->GetName();
241   else return "";
242 }
243 //______________________________________________________________________________
244 TString AliESDHeader::GetActiveTriggerInputs() const
245 {
246   // Returns the list with the names of the active trigger inputs
247   TString trginputs;
248   for(Int_t i = 0; i < kNTriggerInputs; i++) {
249     TNamed *str = (TNamed *)((fTriggerInputsNames).At(i));
250     if (str) {
251       trginputs += " ";
252       trginputs += str->GetName();
253       trginputs += " ";
254     }
255   }
256
257   return trginputs;
258 }
259 //______________________________________________________________________________
260 TString AliESDHeader::GetFiredTriggerInputs() const
261 {
262   // Returns the list with the names of the fired trigger inputs
263   TString trginputs;
264   for(Int_t i = 0; i < kNTriggerInputs; i++) {
265       TNamed *str = (TNamed *)((fTriggerInputsNames.At(i)));
266       if (i < 24 && (fL0TriggerInputs & (1 << i))) {
267         if (str) {
268           trginputs += " ";
269           trginputs += str->GetName();
270           trginputs += " ";
271         }
272       }
273       if (i >= 24 && i < 48 && (fL1TriggerInputs & (1 << (i-24)))) {
274         if (str) {
275           trginputs += " ";
276           trginputs += str->GetName();
277           trginputs += " ";
278         }
279       }
280       if (i >= 48 && (fL2TriggerInputs & (1 << (i-48)))) {
281         if (str) {
282           trginputs += " ";
283           trginputs += str->GetName();
284           trginputs += " ";
285         }
286       }
287
288   }
289   return trginputs;
290 }
291 //______________________________________________________________________________
292 Bool_t AliESDHeader::IsTriggerInputFired(const char *name) const
293 {
294   // Checks if the trigger input is fired 
295  
296   TNamed *trginput = (TNamed *)fTriggerInputsNames.FindObject(name);
297   if (!trginput) return kFALSE;
298
299   Int_t inputIndex = fTriggerInputsNames.IndexOf(trginput);
300   if (inputIndex < 0) return kFALSE;
301   
302   if (fL0TriggerInputs & (1 << inputIndex)) return kTRUE;
303   else if (fL1TriggerInputs & (1 << (inputIndex-24))) return kTRUE;
304   else if (fL2TriggerInputs & (1 << (inputIndex-48))) return kTRUE;
305   else return kFALSE;
306 }
307 //________________________________________________________________________________
308 Int_t  AliESDHeader::GetTriggerIREntries(Int_t int1, Int_t int2, Float_t deltaTime) const
309 {
310   // returns number of IR-s within time window deltaTime
311   // all possible combinations of int1 and int2 int1 - zdc bit, int2 v0 bit
312   //
313   const AliTriggerIR *IR;
314   // triggered event 
315   Int_t nIR = GetTriggerIREntries();
316   UInt_t orbit1 = GetOrbitNumber();
317   const Double_t ot=0.0889218; //orbit time msec
318   Float_t timediff; // time difference between orbits (msec)
319   //
320   Int_t nofIR;
321   nofIR=0;
322   // loop over IR-s
323     for(Int_t i=0;i<nIR;i++){//1
324       IR=GetTriggerIR(i);
325       //
326       UInt_t orbit2 = IR->GetOrbit();
327       timediff = (orbit2<=orbit1) ? (Float_t)((orbit1-orbit2))*ot : 
328         (Float_t)((16777215-orbit1+orbit2))*ot;
329       if (timediff>deltaTime) continue; //timediff outside time window
330       if((int1&int2) == -1){ //ignore both bits, just count IR-s within time window
331         nofIR++;
332         continue;
333       }
334       // now check if int1, int2 bits are set
335       UInt_t nw = IR->GetNWord();
336       Bool_t *bint1 = IR->GetInt1s();
337       Bool_t *bint2 = IR->GetInt2s();
338       //
339       Int_t flag1,flag2;
340       flag1=0;
341       flag2=0;
342       for(UInt_t j=0;j<nw;j++){//2
343         if(bint1[j]) flag1=1; // at least one int1 set
344         if(bint2[j]) flag2=1; //  at least one int2 set
345         //printf("IR %d, bint1 %d, bint2 %d\n",i,bint1[j],bint2[j]);
346       }//2
347       // checking combinations
348       //
349       
350       if((flag1*int1*flag2*int2)==1){// int1=1 & int2=1  
351           nofIR++;
352           continue;       
353       }
354       if(int1 == -1){// ignore int1
355         if(flag2&int2){// int2=1
356           nofIR++;
357           continue;
358         }
359         else if (!flag2&!int2){ //int2=0 
360           nofIR++;
361           continue;          
362         }
363       }
364       
365       if(int2 ==-1){//ignore int2
366         if(flag1&int1){//int1=1
367           nofIR++;
368           continue;  
369         }
370         else if(!flag1&!int1){ //int1=0
371           nofIR++;
372           continue;  
373         }
374       }
375       
376       if((flag1*int1)&!flag2&!int2){// int1=1, int2=0
377           nofIR++;
378           continue;  
379       }
380       
381       if((int2*flag2)&!int1&!flag1){// int1=0, int2=1
382           nofIR++;
383           continue;  
384       } 
385          
386       
387
388     }//1
389   
390     return nofIR;
391 }
392 //__________________________________________________________________________
393 TObjArray AliESDHeader::GetIRArray(Int_t int1, Int_t int2, Float_t deltaTime) const
394 {
395   //
396   // returns an array of IR-s within time window deltaTime
397   // all possible combinations of int1 and int2 int1 - zdc bit, int2 v0 bit
398   //
399   const AliTriggerIR *IR;
400   TObjArray arr;
401   // triggered event 
402   Int_t nIR = GetTriggerIREntries();
403   UInt_t orbit1 = GetOrbitNumber();
404   const Double_t ot=0.0889218; //orbit time msec
405   Float_t timediff; // time difference between orbits (msec)
406   //
407   // loop over IR-s
408     for(Int_t i=0;i<nIR;i++){//1
409       IR=GetTriggerIR(i);
410       //
411       UInt_t orbit2 = IR->GetOrbit();
412       timediff = (orbit2<=orbit1) ? (Float_t)((orbit1-orbit2))*ot : 
413         (Float_t)((16777215-orbit1+orbit2))*ot;
414       if (timediff>deltaTime) continue; //timediff outside time window
415       if((int1&int2) == -1){ //ignore both bits, just count IR-s within time window
416         arr.Add((AliTriggerIR*)IR); //add this IR
417         continue;
418       }
419       // now check if int1, int2 bits are set
420       UInt_t nw = IR->GetNWord();
421       Bool_t *bint1 = IR->GetInt1s();
422       Bool_t *bint2 = IR->GetInt2s();
423       //
424       Int_t flag1,flag2;
425       flag1=0;
426       flag2=0;
427       for(UInt_t j=0;j<nw;j++){//2
428         if(bint1[j]) flag1=1; // at least one int1 set
429         if(bint2[j]) flag2=1; //  at least one int2 set
430       }//2
431       // checking combinations
432       //
433       if((flag1*int1*flag2*int2)==1){// int1=1 & int2=1
434           arr.Add((AliTriggerIR*)IR); //add this IR
435           continue;       
436       }
437       if(int1 == -1){// ignore int1
438         if(flag2&int2){// int2=1
439           arr.Add((AliTriggerIR*)IR); //add this IR
440           continue;
441         }
442         else if (!flag2&!int2){ //int2=0 
443           arr.Add((AliTriggerIR*)IR); //add this IR
444           continue;          
445         }
446       }
447       if(int2 ==-1){//ignore int2
448         if(flag1&int1){//int1=1
449           arr.Add((AliTriggerIR*)IR); //add this IR
450           continue;  
451         }
452         else if(!flag1&!int1){ //int1=0
453           arr.Add((AliTriggerIR*)IR); //add this IR
454           continue;  
455         }
456       }
457       if ((flag1*int1)&!flag2&!int2){// int1=1, int2=0
458           arr.Add((AliTriggerIR*)IR); //add this IR
459           continue;  
460       }
461       if ((int2*flag2)&!int1&!flag1){// int1=0, int2=1
462           arr.Add((AliTriggerIR*)IR); //add this IR
463           continue;  
464       }      
465
466     }//1
467   
468   return arr;
469 }