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));
114 if (ntokens == 1 && !(((TObjString*)tokens->At(0))->String()).CompareTo("END_OF_DATA")){
115 AliDebug(2,"End of file reached");
120 AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
121 // requiring at least the index of the DP, the DP name, the format, and the number of entries
125 Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
126 AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
127 TObjString* lhcDPname = (TObjString*)tokens->At(1);
128 TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
129 AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
130 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
131 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
132 if (typeTokens->GetEntriesFast() < 2 ){
133 // requiring the the type and the number of elements for each measurement
134 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
139 TString type = ((TObjString*)typeTokens->At(0))->String();
140 AliDebug(2,Form("type = %s",type.Data()));
141 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
142 AliDebug(2,Form("nelements = %i",nelements));
143 Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi();
144 AliDebug(2,Form("nentries = %i",nentries));
145 Int_t nValuesPerEntry = nelements+1;
146 Int_t nfixed = 4; // n. of fixed entries
148 if (mapLHC->GetValue(lhcDPname)==0x0){
149 array = new TObjArray();
151 mapLHC->Add(new TObjString(lhcDPname->String()),array);
154 array = (TObjArray*)mapLHC->GetValue(lhcDPname);
155 AliDebug(2,Form("entry found! --> %p",array));
158 for (Int_t ientry=0; ientry< nentries; ientry ++){
159 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
160 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
161 Double_t timestamp = strTimestamp.Atof();
162 AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
163 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
164 // error in case the measurement is not within the data taking time interval
165 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
169 Int_t* value = new Int_t[nelements];
170 for (Int_t ielement=0; ielement<nelements; ielement++){
171 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
172 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
174 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
178 else if (type == "b"){
179 Bool_t* value = new Bool_t[nelements];
180 for (Int_t ielement=0; ielement<nelements; ielement++){
181 value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
182 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
184 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
188 else if (type == "f"){ // the floats should be considered as doubles
189 Double_t* value = new Double_t[nelements];
190 for (Int_t ielement=0; ielement<nelements; ielement++){
191 TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
192 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
193 AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
195 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
199 else if (type == "s"){
200 TObjArray* value = new TObjArray();
202 for (Int_t ielement=0; ielement<nelements; ielement++){
203 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
204 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
207 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
212 AliError(Form("Non-expected type %s",type.Data()));
228 //--------------------------------------------------------------------------
229 TObjArray* AliLHCReader::ReadSingleLHCDP(TString filename, TString alias)
232 // reading the file with the inputs for the selected alias
233 // returning the TObjArray containing the information only for the current alias
235 gSystem->ExpandPathName(filename);
236 if( gSystem->AccessPathName( filename.Data() ) ) {
237 AliError(Form( "file (%s) not found", filename.Data() ) );
241 TString selection = gSystem->GetFromPipe(Form("grep -P '^\\d+\\s+%s+\\s' %s",alias.Data(), filename.Data()));
243 if (selection.Length() == 0) {
244 AliError(Form("Alias %s not fouond in LHC Data file, returning a null pointer",alias.Data()));
250 TObjArray* tokenslines = selection.Tokenize("\n");
251 Int_t ntokenslines = tokenslines->GetEntriesFast();
252 AliDebug(3,Form("Number of tokenslines = %d",ntokenslines));
254 TObjArray* array = new TObjArray(); // array to be returned
257 for (Int_t iline=0; iline<ntokenslines; iline++){
258 TString strLine = ((TObjString*)tokenslines->At(iline))->String();
259 AliDebug(4,Form("***************** line = %s\n",strLine.Data()));
260 TObjArray* tokens = strLine.Tokenize("\t");
261 Int_t ntokens = tokens->GetEntriesFast();
262 AliDebug(3,Form("Number of tokens = %d",ntokens));
264 AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
265 // requiring at least the index of the DP, the DP name, the format, and the number of entries
269 Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
270 AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
271 TObjString* lhcDPname = (TObjString*)tokens->At(1);
272 TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
273 AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
274 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
275 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
276 if (typeTokens->GetEntriesFast() < 2 ){
277 // requiring the the type and the number of elements for each measurement
278 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
283 TString type = ((TObjString*)typeTokens->At(0))->String();
284 AliDebug(2,Form("type = %s",type.Data()));
285 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
286 AliDebug(2,Form("nelements = %i",nelements));
287 Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi();
288 AliDebug(2,Form("nentries = %i",nentries));
289 Int_t nValuesPerEntry = nelements+1;
290 Int_t nfixed = 4; // n. of fixed entries
291 for (Int_t ientry=0; ientry< nentries; ientry ++){
292 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
293 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
294 Double_t timestamp = strTimestamp.Atof();
295 AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
296 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
297 // error in case the measurement is not within the data taking time interval
298 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
302 Int_t* value = new Int_t[nelements];
303 for (Int_t ielement=0; ielement<nelements; ielement++){
304 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
305 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
307 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
311 else if (type == "b"){
312 Bool_t* value = new Bool_t[nelements];
313 for (Int_t ielement=0; ielement<nelements; ielement++){
314 value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
315 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
317 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
321 else if (type == "f"){ // the floats should be considered as doubles
322 Double_t* value = new Double_t[nelements];
323 for (Int_t ielement=0; ielement<nelements; ielement++){
324 TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
325 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
326 AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
328 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
332 else if (type == "s"){
333 TObjArray* value = new TObjArray();
335 for (Int_t ielement=0; ielement<nelements; ielement++){
336 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
337 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
340 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
345 AliError(Form("Non-expected type %s",type.Data()));