1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
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 //
23 ///////////////////////////////////////////////////////////////////////////////
25 #include <Riostream.h>
28 #include <TObjArray.h>
29 #include <TObjString.h>
36 #include "AliDCSArray.h"
37 #include "AliLHCReader.h"
41 ClassImp(AliLHCReader)
43 //--------------------------------------------------------------------------
44 AliLHCReader::AliLHCReader():
52 //--------------------------------------------------------------------------
53 AliLHCReader::~AliLHCReader()
60 //--------------------------------------------------------------------------
61 TMap* AliLHCReader::ReadLHCDP(TString filename)
64 // reading the file with the inputs
66 gSystem->ExpandPathName(filename);
67 if( gSystem->AccessPathName( filename.Data() ) ) {
68 AliError(Form( "file (%s) not found", filename.Data() ) );
72 ifstream *file = new ifstream ( filename.Data() );
74 AliError(Form("Error opening file (%s) !",filename.Data()));
79 TMap* mapLHC = new TMap();
80 mapLHC->SetOwnerKeyValue();
85 while(strLine.ReadLine(*file)){
87 AliDebug(3,Form("line n. = %d",nline));
88 // tokenize the line with tabs
89 //if (strLine.BeginsWith("=")) continue;
90 //if (!strLine.CompareTo("END_OF_BLOCK")) {
91 if (strLine.Contains("END_OF_BLOCK")) {
92 AliDebug(2,"END_OF_BLOCK");
96 TObjArray* tokens = strLine.Tokenize("\t");
97 Int_t ntokens = tokens->GetEntriesFast();
99 if ( strLine.Contains("LHC_ENTRIES ") ) {
100 // RS: special treatment for "LHC_ENTRIES N" record, which is space (and not tab) separated)
102 tokens = strLine.Tokenize(" ");
103 ntokens = tokens->GetEntriesFast();
106 AliDebug(3,Form("Number of tokens = %d",ntokens));
107 if (ntokens == 2 && !(((TObjString*)tokens->At(0))->String()).CompareTo("LHC_ENTRIES")){
108 lhcEntries = (((TObjString*)tokens->At(1))->String()).Atoi();
109 AliInfo(Form("LHC entries = %d",lhcEntries));
110 AliDebug(3,Form("LHC entries = %d",lhcEntries));
113 if (ntokens == 1 && !(((TObjString*)tokens->At(0))->String()).CompareTo("END_OF_DATA")){
114 AliDebug(2,"End of file reached");
119 AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
120 // requiring at least the index of the DP, the DP name, the format, and the number of entries
124 Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
125 AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
126 TObjString* lhcDPname = (TObjString*)tokens->At(1);
127 TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
128 AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
129 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
130 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
131 if (typeTokens->GetEntriesFast() < 2 ){
132 // requiring the the type and the number of elements for each measurement
133 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
138 TString type = ((TObjString*)typeTokens->At(0))->String();
139 AliDebug(2,Form("type = %s",type.Data()));
140 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
141 AliDebug(2,Form("nelements = %i",nelements));
142 Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi();
143 AliDebug(2,Form("nentries = %i",nentries));
144 Int_t nValuesPerEntry = nelements+1;
145 Int_t nfixed = 4; // n. of fixed entries
147 if (mapLHC->GetValue(lhcDPname)==0x0){
148 array = new TObjArray();
150 mapLHC->Add(new TObjString(lhcDPname->String()),array);
153 array = (TObjArray*)mapLHC->GetValue(lhcDPname);
154 AliDebug(2,Form("entry found! --> %p",array));
157 for (Int_t ientry=0; ientry< nentries; ientry ++){
158 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
159 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
160 Double_t timestamp = strTimestamp.Atof();
161 AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
162 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
163 // error in case the measurement is not within the data taking time interval
164 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
168 Int_t* value = new Int_t[nelements];
169 for (Int_t ielement=0; ielement<nelements; ielement++){
170 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
171 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
173 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
177 else if (type == "b"){
178 Bool_t* value = new Bool_t[nelements];
179 for (Int_t ielement=0; ielement<nelements; ielement++){
180 value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
181 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
183 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
187 else if (type == "f"){ // the floats should be considered as doubles
188 Double_t* value = new Double_t[nelements];
189 for (Int_t ielement=0; ielement<nelements; ielement++){
190 TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
191 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
192 AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
194 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
198 else if (type == "s"){
199 TObjArray* value = new TObjArray();
201 for (Int_t ielement=0; ielement<nelements; ielement++){
202 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
203 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
206 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
211 AliError(Form("Non-expected type %s",type.Data()));
227 //--------------------------------------------------------------------------
228 TObjArray* AliLHCReader::ReadSingleLHCDP(TString filename, TString alias)
231 // reading the file with the inputs for the selected alias
232 // returning the TObjArray containing the information only for the current alias
234 gSystem->ExpandPathName(filename);
235 if( gSystem->AccessPathName( filename.Data() ) ) {
236 AliError(Form( "file (%s) not found", filename.Data() ) );
240 TString selection = gSystem->GetFromPipe(Form("grep -P '^\\d+\\s+%s+\\s' %s",alias.Data(), filename.Data()));
242 if (selection.Length() == 0) {
243 AliError(Form("Alias %s not fouond in LHC Data file, returning a null pointer",alias.Data()));
249 TObjArray* tokenslines = selection.Tokenize("\n");
250 Int_t ntokenslines = tokenslines->GetEntriesFast();
251 AliDebug(3,Form("Number of tokenslines = %d",ntokenslines));
253 TObjArray* array = new TObjArray(); // array to be returned
256 for (Int_t iline=0; iline<ntokenslines; iline++){
257 TString strLine = ((TObjString*)tokenslines->At(iline))->String();
258 AliDebug(4,Form("***************** line = %s\n",strLine.Data()));
259 TObjArray* tokens = strLine.Tokenize("\t");
260 Int_t ntokens = tokens->GetEntriesFast();
261 AliDebug(3,Form("Number of tokens = %d",ntokens));
263 AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
264 // requiring at least the index of the DP, the DP name, the format, and the number of entries
268 Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
269 AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
270 TObjString* lhcDPname = (TObjString*)tokens->At(1);
271 TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
272 AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
273 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
274 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
275 if (typeTokens->GetEntriesFast() < 2 ){
276 // requiring the the type and the number of elements for each measurement
277 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
282 TString type = ((TObjString*)typeTokens->At(0))->String();
283 AliDebug(2,Form("type = %s",type.Data()));
284 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
285 AliDebug(2,Form("nelements = %i",nelements));
286 Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi();
287 AliDebug(2,Form("nentries = %i",nentries));
288 Int_t nValuesPerEntry = nelements+1;
289 Int_t nfixed = 4; // n. of fixed entries
290 for (Int_t ientry=0; ientry< nentries; ientry ++){
291 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
292 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
293 Double_t timestamp = strTimestamp.Atof();
294 AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
295 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
296 // error in case the measurement is not within the data taking time interval
297 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
301 Int_t* value = new Int_t[nelements];
302 for (Int_t ielement=0; ielement<nelements; ielement++){
303 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
304 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
306 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
310 else if (type == "b"){
311 Bool_t* value = new Bool_t[nelements];
312 for (Int_t ielement=0; ielement<nelements; ielement++){
313 value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
314 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
316 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
320 else if (type == "f"){ // the floats should be considered as doubles
321 Double_t* value = new Double_t[nelements];
322 for (Int_t ielement=0; ielement<nelements; ielement++){
323 TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
324 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
325 AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
327 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
331 else if (type == "s"){
332 TObjArray* value = new TObjArray();
334 for (Int_t ielement=0; ielement<nelements; ielement++){
335 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
336 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
339 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
344 AliError(Form("Non-expected type %s",type.Data()));