]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTriggerRunScalers.cxx
Correction of the Z position of Q2 quadrupole from Chiara Oppedisano
[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 ) {
29bdda4f 154 AliErrorClass( Form( "Error reading scalers from (%s): line (%s)",
155 filename.Data(), strLine1.Data() ));
156 delete rec;
157 return rScaler;
d7dd8a54 158 }
159 UInt_t LOCB = ((TObjString*)tokens1->At(0))->String().Atoi();
160 UInt_t LOCA = ((TObjString*)tokens1->At(1))->String().Atoi();
161 UInt_t L1CB = ((TObjString*)tokens1->At(2))->String().Atoi();
162 UInt_t L1CA = ((TObjString*)tokens1->At(3))->String().Atoi();
163 UInt_t L2CB = ((TObjString*)tokens1->At(4))->String().Atoi();
164 UInt_t L2CA = ((TObjString*)tokens1->At(5))->String().Atoi();
165 rScaler->GetClass(i);
166 rec->AddTriggerScalers( rScaler->GetClass(i),
167 LOCB, LOCA, L1CB,
168 L1CA, L2CB, L2CA );
169 delete tokens1;
170 }
171 rScaler->AddTriggerScalers( rec );
172
173 delete tokens;
174 }
175 file->close();
176 delete file;
177
178 return rScaler;
179}
180
181//_____________________________________________________________________________
182Int_t AliTriggerRunScalers::FindNearestScalersRecord( AliTimeStamp * stamp )
183{
184 // Find Trigger scaler record with the closest timestamp <= "stamp"
185 // using a binary search.
186 // return the index in the array of records, if the timestamp
187 // is out of range return -1
188
189 Int_t base, position=-1, last, result = 0;
190 AliTimeStamp *op2 = NULL;
191
192 fScalersRecord.Sort();
193
194 base = 0;
195 last = fScalersRecord.GetEntriesFast();
196
197 while (last >= base) {
198 position = (base+last) / 2;
199 cout << "pos " << position<< " base " << base << "last " << last << endl;
200 AliTriggerScalersRecord* rec = (AliTriggerScalersRecord*)fScalersRecord.At(position);
201 if( rec ) op2 = rec->GetTimeStamp();
202 if( op2 && (result = stamp->Compare(op2)) == 0 )
203 return position; // exact match
204 cout << "result " << result << " op2 " << op2 << " rec "<< rec << endl;
205 if (!op2 || result < 0)
206 last = position-1;
207 else
208 base = position+1;
209 op2 = NULL;
210 }
211 if( (position == 0 && result < 0) || position >= fScalersRecord.GetEntriesFast() )
212 return -1; // out of range
213 else
214 return (result < 0 ) ? position-1 : position; // nearst < stamp
215}
216
217//_____________________________________________________________________________
218void AliTriggerRunScalers::Print( const Option_t* ) const
219{
220 // Print
221 cout << "Trigger Scalers Record per Run: " << endl;
222 cout << " File version :" << fVersion << endl;
223 cout << " Run Number :" << fRunNumber << endl;
224 cout << " Number of Classes :" << (Int_t)fnClasses << endl;
225 cout << " Classes ID:";
226 for( Int_t i=0; i<fnClasses; ++i )
227 cout << " " << (Int_t)fClassIndex[i];
228 cout << endl;
229
230 for( Int_t i=0; i<fScalersRecord.GetEntriesFast(); ++i )
231 ((AliTriggerScalersRecord*)fScalersRecord.At(i))->Print();
232}
233