Added methods for finding a given module in the DDL map (F. Prino)
[u/mrichter/AliRoot.git] / STEER / AliTriggerRunScalers.cxx
CommitLineData
d7dd8a54 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: AliTriggerRunScalers.cxx 22322 2007-11-22 11:43:14Z cvetan $ */
17
18///////////////////////////////////////////////////////////////////////////////
19//
20// Class to define the ALICE Trigger Scalers Record per Run.
21//
22//
23//////////////////////////////////////////////////////////////////////////////
24
25#include <Riostream.h>
26#include <TObject.h>
27#include <TClass.h>
28#include <TArrayC.h>
29#include <TSystem.h>
30#include <TObjString.h>
31#include <TObjArray.h>
32#include <TSystem.h>
33#include <TFile.h>
34
35#include "AliLog.h"
36#include "AliTimeStamp.h"
37#include "AliTriggerScalers.h"
38#include "AliTriggerScalersRecord.h"
39#include "AliTriggerRunScalers.h"
40
41ClassImp( AliTriggerRunScalers )
42
43//_____________________________________________________________________________
44AliTriggerRunScalers::AliTriggerRunScalers():
45 TObject(),
46 fVersion(0),
47 fRunNumber(0),
48 fnClasses(0),
49 fClassIndex(),
50 fScalersRecord()
51{
52 // Default constructor
53}
54
55//_____________________________________________________________________________
56void AliTriggerRunScalers::AddTriggerScalers( AliTriggerScalersRecord* scaler )
57{
58 //
59 fScalersRecord.AddLast( scaler );
60 fScalersRecord.Sort();
61}
62
63//_____________________________________________________________________________
64AliTriggerRunScalers* AliTriggerRunScalers::ReadScalers( TString & filename )
65{
66
67 if( gSystem->AccessPathName( filename.Data() ) ) {
68 AliErrorClass( Form( "file (%s) not found", filename.Data() ) );
69 return NULL;
70 }
71
72 ifstream *file = new ifstream ( filename.Data() );
73 if (!*file) {
74 AliErrorClass(Form("Error opening file (%s) !\n",filename.Data()));
75 file->close();
76 delete file;
77 return NULL;
78 }
79
80 AliTriggerRunScalers* rScaler = new AliTriggerRunScalers();
81
82 TString strLine;
83 Bool_t verflag = kFALSE;
84 Bool_t classflag = kFALSE;
85 UChar_t nclass = 0;
86 while (strLine.ReadLine(*file)) {
87 if (strLine.BeginsWith("#")) continue;
88
89 TObjArray *tokens = strLine.Tokenize(" \t");
90 Int_t ntokens = tokens->GetEntriesFast();
91 // 1st line, version, it is one number,
92 if (!verflag) {
93 if (ntokens != 1) {
94 AliErrorClass( Form( "Error reading version number from (%s), line :%s\n",
95 filename.Data() , strLine.Data() ) );
96 return NULL;
97 }
98 // cout << "Version "<< ((TObjString*)tokens->At(0))->String().Atoi() << endl;
99 rScaler->SetVersion( ((TObjString*)tokens->At(0))->String().Atoi() );
100 verflag = kTRUE;
101 delete tokens;
102 continue;
103 }
104
105 // 2nd line, run number , number of classes, list of classes used in this partition
106
107 if (!classflag) {
108 if ( !((TObjString*)tokens->At(1))->String().IsDigit() ) {
109 AliErrorClass( Form( "Error reading Run number from (%s)\n", filename.Data() ));
110 }
111 // cout << "Run Number " << ((TObjString*)tokens->At(0))->String().Atoi() << endl;
112 rScaler->SetRunNumber( ((TObjString*)tokens->At(0))->String().Atoi() );
113 nclass = (UChar_t)((TObjString*)tokens->At(1))->String().Atoi();
114 // cout << "Number of classes " << nclass << endl;
115 rScaler->SetNumClasses( nclass );
116 if ( nclass != ntokens - 2 ) {
117 AliErrorClass( Form( "Error reading number of classes from (%s)\n", filename.Data() ));
118 }
119 for (UChar_t i=0; i<nclass; ++i) {
120 rScaler->SetClass( i, (Char_t)((TObjString*)tokens->At(2+i))->String().Atoi() );
121 }
122 classflag = kTRUE;
123 delete tokens;
124 continue;
125 }
126
127 // Records
128 // Each record consists of 1+(number of classes in partition) lines
129 // 1st line of record = time stamp (4 words)
130 // 1st word = ORBIT(24 bits)
131 // 2nd word = Period Counter (28 bit)
132 // 3rd word = seconds (32 bits) from epoch
133 // 4th word = microsecs (32 bits)
134 // other lines = 6 words of counters (L0 before,L0 after, ....)
135 if (ntokens != 4) {
136 AliErrorClass( Form( "Error reading timestamp from (%s): line (%s)",
137 filename.Data(), strLine.Data() ));
138 return NULL;
139 }
140 UInt_t orbit = ((TObjString*)tokens->At(0))->String().Atoi();
141 UInt_t period = ((TObjString*)tokens->At(1))->String().Atoi();
142 UInt_t seconds = ((TObjString*)tokens->At(2))->String().Atoi();
143 UInt_t microSecs = ((TObjString*)tokens->At(3))->String().Atoi();
144 AliTriggerScalersRecord * rec = new AliTriggerScalersRecord();
145 rec->SetTimeStamp( orbit, period, seconds, microSecs );
146
147 TString strLine1;
148 for (Int_t i=0; i<nclass; ++i) {
149 strLine1.ReadLine(*file);
150 if (strLine1.BeginsWith("#")) continue;
151 TObjArray *tokens1 = strLine1.Tokenize(" \t");
152 Int_t ntokens1 = tokens1->GetEntriesFast();
153 if( ntokens1 != 6 ) {
154 AliErrorClass( Form( "Error reading scalers from (%s): line (%s)\n",
155 filename.Data(), strLine1.Data() ));
156 }
157 UInt_t LOCB = ((TObjString*)tokens1->At(0))->String().Atoi();
158 UInt_t LOCA = ((TObjString*)tokens1->At(1))->String().Atoi();
159 UInt_t L1CB = ((TObjString*)tokens1->At(2))->String().Atoi();
160 UInt_t L1CA = ((TObjString*)tokens1->At(3))->String().Atoi();
161 UInt_t L2CB = ((TObjString*)tokens1->At(4))->String().Atoi();
162 UInt_t L2CA = ((TObjString*)tokens1->At(5))->String().Atoi();
163 rScaler->GetClass(i);
164 rec->AddTriggerScalers( rScaler->GetClass(i),
165 LOCB, LOCA, L1CB,
166 L1CA, L2CB, L2CA );
167 delete tokens1;
168 }
169 rScaler->AddTriggerScalers( rec );
170
171 delete tokens;
172 }
173 file->close();
174 delete file;
175
176 return rScaler;
177}
178
179//_____________________________________________________________________________
180Int_t AliTriggerRunScalers::FindNearestScalersRecord( AliTimeStamp * stamp )
181{
182 // Find Trigger scaler record with the closest timestamp <= "stamp"
183 // using a binary search.
184 // return the index in the array of records, if the timestamp
185 // is out of range return -1
186
187 Int_t base, position=-1, last, result = 0;
188 AliTimeStamp *op2 = NULL;
189
190 fScalersRecord.Sort();
191
192 base = 0;
193 last = fScalersRecord.GetEntriesFast();
194
195 while (last >= base) {
196 position = (base+last) / 2;
197 cout << "pos " << position<< " base " << base << "last " << last << endl;
198 AliTriggerScalersRecord* rec = (AliTriggerScalersRecord*)fScalersRecord.At(position);
199 if( rec ) op2 = rec->GetTimeStamp();
200 if( op2 && (result = stamp->Compare(op2)) == 0 )
201 return position; // exact match
202 cout << "result " << result << " op2 " << op2 << " rec "<< rec << endl;
203 if (!op2 || result < 0)
204 last = position-1;
205 else
206 base = position+1;
207 op2 = NULL;
208 }
209 if( (position == 0 && result < 0) || position >= fScalersRecord.GetEntriesFast() )
210 return -1; // out of range
211 else
212 return (result < 0 ) ? position-1 : position; // nearst < stamp
213}
214
215//_____________________________________________________________________________
216void AliTriggerRunScalers::Print( const Option_t* ) const
217{
218 // Print
219 cout << "Trigger Scalers Record per Run: " << endl;
220 cout << " File version :" << fVersion << endl;
221 cout << " Run Number :" << fRunNumber << endl;
222 cout << " Number of Classes :" << (Int_t)fnClasses << endl;
223 cout << " Classes ID:";
224 for( Int_t i=0; i<fnClasses; ++i )
225 cout << " " << (Int_t)fClassIndex[i];
226 cout << endl;
227
228 for( Int_t i=0; i<fScalersRecord.GetEntriesFast(); ++i )
229 ((AliTriggerScalersRecord*)fScalersRecord.At(i))->Print();
230}
231