]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEERBase/AliTriggerScalersRecord.cxx
New MFT analysis tools
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliTriggerScalersRecord.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 /* $Id: AliTriggerScalersRecord.cxx 22322 2007-11-22 11:43:14Z cvetan $ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //
20 // Class to define the ALICE Trigger Scalers Record 
21 //
22 // Each record consists of 1 time stamp (4 words)  (AliTimeStamp)
23 // and an array with the scalers (AliTriggerScalers) for each trigger class 
24 // in partition  
25 //
26 //////////////////////////////////////////////////////////////////////////////
27
28 #include <Riostream.h>
29 #include <TObjArray.h>
30 #include "AliLog.h"  
31 #include "AliTimeStamp.h"
32 #include "AliTriggerScalers.h"
33 #include "AliTriggerScalersRecord.h"
34
35 using std::endl;
36 using std::cout;
37 ClassImp( AliTriggerScalersRecord )
38 //_____________________________________________________________________________
39 AliTriggerScalersRecord::AliTriggerScalersRecord():
40   fTimestamp(),
41   fScalers(),
42   fTimeGroup(0)
43 {
44  //Default constructor
45 }
46
47 //_____________________________________________________________________________
48 void AliTriggerScalersRecord::SetTimeStamp( UInt_t orbit, UInt_t period, 
49                                             UInt_t seconds, UInt_t microsecs )
50 {
51    fTimestamp.SetTimeStamp( orbit, period, seconds, microsecs );
52 }
53
54 //_____________________________________________________________________________
55 void AliTriggerScalersRecord::AddTriggerScalers( AliTriggerScalers* scaler ) 
56
57   fScalers.AddLast( scaler ); 
58   fScalers.Sort(); 
59 }
60
61 //_____________________________________________________________________________
62 void AliTriggerScalersRecord::AddTriggerScalers( UChar_t classIndex, UInt_t LOCB, UInt_t LOCA,        
63                                          UInt_t L1CB, UInt_t L1CA, UInt_t L2CB, UInt_t L2CA )
64 {
65     AddTriggerScalers( new AliTriggerScalers( classIndex, LOCB, LOCA, L1CB, L1CA, L2CB, L2CA ) );
66     fScalers.Sort();
67
68
69 //_____________________________________________________________________________
70 Int_t AliTriggerScalersRecord::Compare( const TObject* obj ) const
71 {
72   // Compare  timestamps
73   
74   return fTimestamp.Compare( &(((AliTriggerScalersRecord*)obj)->fTimestamp) );
75 }
76 //_____________________________________________________________________________
77 const AliTriggerScalers* AliTriggerScalersRecord::GetTriggerScalersForClass( const Int_t classindex ) const
78 {
79    // Find Trigger scaler with class ID = classindex using a brutal force 
80
81    Int_t   position, last;
82    AliTriggerScalers *op2 = 0;
83    position = 0;
84    last = fScalers.GetEntriesFast();
85    while (position < last) {
86       op2 = (AliTriggerScalers *)fScalers.At(position);
87       if( op2 && (op2->GetClassIndex() == classindex )) break;
88       op2=0;
89       position++;
90    }
91    return op2;   
92 }
93
94 //_____________________________________________________________________________
95 AliTriggerScalers* AliTriggerScalersRecord::GetTriggerScalersForClassBinary( const Int_t classindex )
96 {
97    // Find Trigger scaler with class ID = classindex using a binary search. 
98
99    Int_t   base, position, last, result = 0;
100    AliTriggerScalers *op2 = NULL;
101    
102    fScalers.Sort(); 
103    
104    base = 0;
105    last = fScalers.GetEntriesFast();
106
107    while (last >= base) {
108       result = 0;
109       position = (base+last) / 2;
110       op2 = (AliTriggerScalers *)fScalers.At(position);
111       if( op2 && op2->GetClassIndex() > classindex ) result = -1;
112       if( op2 && op2->GetClassIndex() < classindex ) result = 1;
113   
114       if (op2 && result == 0)
115          return op2;
116       if (!op2 || result < 0)
117          last = position-1;
118       else
119          base = position+1;
120       op2 = NULL;   
121    }
122    return op2;   
123 }
124                                       
125 //_____________________________________________________________________________
126 void AliTriggerScalersRecord::Print( const Option_t* ) const
127 {
128    // Print
129   cout << "Trigger Scalers Record, time group: "<< fTimeGroup << endl;
130   fTimestamp.Print();
131   for( Int_t i=0; i<fScalers.GetEntriesFast(); ++i ) 
132      ((AliTriggerScalers*)fScalers.At(i))->Print();
133 }