]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliLHCReader.cxx
ITS cluster multiplicity and TPC standalone multiplicity in AODHeader
[u/mrichter/AliRoot.git] / STEER / AliLHCReader.cxx
CommitLineData
d96c6484 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// //
18// Class to read the file coming from DCS containing the information //
19// from LHC. Everything is stored in a TMap, where: //
20// Key --> DP name, as passed by LHC //
21// value --> TObjArray of AliDCSArray objects //
22// //
23///////////////////////////////////////////////////////////////////////////////
24
25#include <Riostream.h>
26#include <time.h>
27
28#include <TObjArray.h>
29#include <TObjString.h>
30#include <TObject.h>
31#include <TString.h>
32#include <TMap.h>
33#include <TSystem.h>
30ec5bf7 34#include <TError.h>
d96c6484 35
36#include "AliDCSArray.h"
37#include "AliLHCReader.h"
38#include "AliLog.h"
39
40//--------------------------------------------------------------------------
41AliLHCReader::AliLHCReader():
42 TObject(),
43 fStartTime(0),
44 fEndTime(0)
45{
46 // default ctor
47}
48
49//--------------------------------------------------------------------------
50AliLHCReader::~AliLHCReader()
51{
52 //
53 // dtor
54 //
55}
56
57//--------------------------------------------------------------------------
58TMap* AliLHCReader::ReadLHCDP(TString filename)
59{
60 //
61 // reading the file with the inputs
62 //
63bd40f4 63 gSystem->ExpandPathName(filename);
d96c6484 64 if( gSystem->AccessPathName( filename.Data() ) ) {
65 AliError(Form( "file (%s) not found", filename.Data() ) );
66 return NULL;
67 }
68
69 ifstream *file = new ifstream ( filename.Data() );
70 if (!*file) {
71 AliError(Form("Error opening file (%s) !",filename.Data()));
72 file->close();
73 delete file;
74 return NULL;
75 }
76 TMap* mapLHC = new TMap();
e541e2aa 77 mapLHC->SetOwnerKeyValue();
d96c6484 78 TString strLine;
30ec5bf7 79 Int_t lhcEntries;
80 Int_t nBlocks = 0;
30ec5bf7 81 Int_t nline =0;
d96c6484 82 while(strLine.ReadLine(*file)){
30ec5bf7 83 nline++;
84 AliDebug(3,Form("line n. = %d",nline));
d96c6484 85 // tokenize the line with tabs
30ec5bf7 86 //if (strLine.BeginsWith("=")) continue;
87 //if (!strLine.CompareTo("END_OF_BLOCK")) {
88 if (strLine.Contains("END_OF_BLOCK")) {
571b4b9f 89 AliDebug(2,"END_OF_BLOCK");
30ec5bf7 90 nBlocks++;
91 continue;
92 }
93 TObjArray* tokens = strLine.Tokenize("\t");
d96c6484 94 Int_t ntokens = tokens->GetEntriesFast();
63bd40f4 95 //
96 if ( strLine.Contains("LHC_ENTRIES ") ) {
97 // RS: special treatment for "LHC_ENTRIES N" record, which is space (and not tab) separated)
98 delete tokens;
99 tokens = strLine.Tokenize(" ");
100 ntokens = tokens->GetEntriesFast();
101 }
102 //
30ec5bf7 103 AliDebug(3,Form("Number of tokens = %d",ntokens));
104 if (ntokens == 2 && !(((TObjString*)tokens->At(0))->String()).CompareTo("LHC_ENTRIES")){
105 lhcEntries = (((TObjString*)tokens->At(1))->String()).Atoi();
106 AliInfo(Form("LHC entries = %d",lhcEntries));
107 AliDebug(3,Form("LHC entries = %d",lhcEntries));
108 continue;
109 }
110 if (ntokens == 1 && !(((TObjString*)tokens->At(0))->String()).CompareTo("END_OF_DATA")){
571b4b9f 111 AliDebug(2,"End of file reached");
e541e2aa 112 delete tokens;
30ec5bf7 113 break;
114 }
115 if (ntokens < 4){
116 AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
117 // requiring at least the index of the DP, the DP name, the format, and the number of entries
d96c6484 118 delete tokens;
119 continue;
120 }
30ec5bf7 121 Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
122 AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
123 TObjString* lhcDPname = (TObjString*)tokens->At(1);
124 TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
571b4b9f 125 AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
d96c6484 126 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
127 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
128 if (typeTokens->GetEntriesFast() < 2 ){
129 // requiring the the type and the number of elements for each measurement
130 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
131 delete typeTokens;
e541e2aa 132 delete tokens;
d96c6484 133 continue;
134 }
135 TString type = ((TObjString*)typeTokens->At(0))->String();
136 AliDebug(2,Form("type = %s",type.Data()));
137 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
138 AliDebug(2,Form("nelements = %i",nelements));
30ec5bf7 139 Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi();
d96c6484 140 AliDebug(2,Form("nentries = %i",nentries));
141 Int_t nValuesPerEntry = nelements+1;
30ec5bf7 142 Int_t nfixed = 4; // n. of fixed entries
143 TObjArray* array;
144 if (mapLHC->GetValue(lhcDPname)==0x0){
145 array = new TObjArray();
146 array->SetOwner(1);
e541e2aa 147 mapLHC->Add(new TObjString(lhcDPname->String()),array);
30ec5bf7 148 }
149 else{
e541e2aa 150 array = (TObjArray*)mapLHC->GetValue(lhcDPname);
30ec5bf7 151 AliDebug(2,Form("entry found! --> %p",array));
152 }
153
d96c6484 154 for (Int_t ientry=0; ientry< nentries; ientry ++){
155 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
156 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
30ec5bf7 157 Double_t timestamp = strTimestamp.Atof();
158 AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
159 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
d96c6484 160 // error in case the measurement is not within the data taking time interval
161 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
162 continue;
163 }
164 if (type == "i"){
165 Int_t* value = new Int_t[nelements];
166 for (Int_t ielement=0; ielement<nelements; ielement++){
167 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
168 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
169 }
170 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
171 array->Add(dcs);
e541e2aa 172 delete[] value;
d96c6484 173 }
30ec5bf7 174 else if (type == "b"){
175 Bool_t* value = new Bool_t[nelements];
176 for (Int_t ielement=0; ielement<nelements; ielement++){
177 value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
178 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
179 }
180 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
181 array->Add(dcs);
e541e2aa 182 delete[] value;
30ec5bf7 183 }
184 else if (type == "f"){ // the floats should be considered as doubles
185 Double_t* value = new Double_t[nelements];
d96c6484 186 for (Int_t ielement=0; ielement<nelements; ielement++){
30ec5bf7 187 TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
d96c6484 188 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
30ec5bf7 189 AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
d96c6484 190 }
191 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
192 array->Add(dcs);
e541e2aa 193 delete[] value;
d96c6484 194 }
195 else if (type == "s"){
30ec5bf7 196 TObjArray* value = new TObjArray();
e541e2aa 197 value->SetOwner(1);
d96c6484 198 for (Int_t ielement=0; ielement<nelements; ielement++){
e541e2aa 199 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
30ec5bf7 200 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
201 value->Add(strobj);
d96c6484 202 }
203 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
204 array->Add(dcs);
e541e2aa 205 delete value;
d96c6484 206 }
207 else{
30ec5bf7 208 AliError(Form("Non-expected type %s",type.Data()));
e541e2aa 209 delete typeTokens;
210 delete tokens;
211 file->close();
212 delete file;
d96c6484 213 return NULL;
214 }
215 }
e541e2aa 216 delete typeTokens;
217 delete tokens;
d96c6484 218 }
e541e2aa 219 file->close();
220 delete file;
d96c6484 221 return mapLHC;
222}
223
49822138 224//--------------------------------------------------------------------------
225TObjArray* AliLHCReader::ReadSingleLHCDP(TString filename, TString alias)
226{
227 //
228 // reading the file with the inputs for the selected alias
229 // returning the TObjArray containing the information only for the current alias
230 //
63bd40f4 231 gSystem->ExpandPathName(filename);
49822138 232 if( gSystem->AccessPathName( filename.Data() ) ) {
233 AliError(Form( "file (%s) not found", filename.Data() ) );
234 return NULL;
235 }
236
237 TString selection = gSystem->GetFromPipe(Form("grep -P '^\\d+\\s+%s+\\s' %s",alias.Data(), filename.Data()));
238
239 if (selection.Length() == 0) {
240 AliError(Form("Alias %s not fouond in LHC Data file, returning a null pointer",alias.Data()));
241 return NULL;
242 }
243
244 Int_t nline =0;
245
246 TObjArray* tokenslines = selection.Tokenize("\n");
247 Int_t ntokenslines = tokenslines->GetEntriesFast();
248 AliDebug(3,Form("Number of tokenslines = %d",ntokenslines));
249
250 TObjArray* array = new TObjArray(); // array to be returned
251 array->SetOwner(1);
252
253 for (Int_t iline=0; iline<ntokenslines; iline++){
254 TString strLine = ((TObjString*)tokenslines->At(iline))->String();
255 AliDebug(4,Form("***************** line = %s\n",strLine.Data()));
256 TObjArray* tokens = strLine.Tokenize("\t");
257 Int_t ntokens = tokens->GetEntriesFast();
258 AliDebug(3,Form("Number of tokens = %d",ntokens));
259 if (ntokens < 4){
260 AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
261 // requiring at least the index of the DP, the DP name, the format, and the number of entries
262 delete tokens;
263 continue;
264 }
265 Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
266 AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
267 TObjString* lhcDPname = (TObjString*)tokens->At(1);
268 TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
269 AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
270 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
271 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
272 if (typeTokens->GetEntriesFast() < 2 ){
273 // requiring the the type and the number of elements for each measurement
274 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
275 delete typeTokens;
276 delete tokens;
277 continue;
278 }
279 TString type = ((TObjString*)typeTokens->At(0))->String();
280 AliDebug(2,Form("type = %s",type.Data()));
281 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
282 AliDebug(2,Form("nelements = %i",nelements));
283 Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi();
284 AliDebug(2,Form("nentries = %i",nentries));
285 Int_t nValuesPerEntry = nelements+1;
286 Int_t nfixed = 4; // n. of fixed entries
287 for (Int_t ientry=0; ientry< nentries; ientry ++){
288 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
289 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
290 Double_t timestamp = strTimestamp.Atof();
291 AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
292 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
293 // error in case the measurement is not within the data taking time interval
294 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
295 continue;
296 }
297 if (type == "i"){
298 Int_t* value = new Int_t[nelements];
299 for (Int_t ielement=0; ielement<nelements; ielement++){
300 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
301 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
302 }
303 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
304 array->Add(dcs);
305 delete[] value;
306 }
307 else if (type == "b"){
308 Bool_t* value = new Bool_t[nelements];
309 for (Int_t ielement=0; ielement<nelements; ielement++){
310 value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
311 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
312 }
313 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
314 array->Add(dcs);
315 delete[] value;
316 }
317 else if (type == "f"){ // the floats should be considered as doubles
318 Double_t* value = new Double_t[nelements];
319 for (Int_t ielement=0; ielement<nelements; ielement++){
320 TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
321 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
322 AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
323 }
324 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
325 array->Add(dcs);
326 delete[] value;
327 }
328 else if (type == "s"){
329 TObjArray* value = new TObjArray();
330 value->SetOwner(1);
331 for (Int_t ielement=0; ielement<nelements; ielement++){
332 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
333 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
334 value->Add(strobj);
335 }
336 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
337 array->Add(dcs);
338 delete value;
339 }
340 else{
341 AliError(Form("Non-expected type %s",type.Data()));
342 delete typeTokens;
343 delete tokens;
344 delete tokenslines;
345 return NULL;
346 }
347 }
348 delete typeTokens;
349 delete tokens;
350 }
351 delete tokenslines;
352 return array;
353}
354
d96c6484 355
356
357
358
359
360