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"
40 //--------------------------------------------------------------------------
41 AliLHCReader::AliLHCReader():
49 //--------------------------------------------------------------------------
50 AliLHCReader::~AliLHCReader()
57 //--------------------------------------------------------------------------
58 TMap* AliLHCReader::ReadLHCDP(TString filename)
61 // reading the file with the inputs
64 if( gSystem->AccessPathName( filename.Data() ) ) {
65 AliError(Form( "file (%s) not found", filename.Data() ) );
69 ifstream *file = new ifstream ( filename.Data() );
71 AliError(Form("Error opening file (%s) !",filename.Data()));
76 TMap* mapLHC = new TMap();
77 mapLHC->SetOwnerKeyValue();
82 while(strLine.ReadLine(*file)){
84 AliDebug(3,Form("line n. = %d",nline));
85 // tokenize the line with tabs
86 //if (strLine.BeginsWith("=")) continue;
87 //if (!strLine.CompareTo("END_OF_BLOCK")) {
88 if (strLine.Contains("END_OF_BLOCK")) {
89 AliDebug(2,"END_OF_BLOCK");
93 TObjArray* tokens = strLine.Tokenize("\t");
94 Int_t ntokens = tokens->GetEntriesFast();
95 AliDebug(3,Form("Number of tokens = %d",ntokens));
96 if (ntokens == 2 && !(((TObjString*)tokens->At(0))->String()).CompareTo("LHC_ENTRIES")){
97 lhcEntries = (((TObjString*)tokens->At(1))->String()).Atoi();
98 AliInfo(Form("LHC entries = %d",lhcEntries));
99 AliDebug(3,Form("LHC entries = %d",lhcEntries));
102 if (ntokens == 1 && !(((TObjString*)tokens->At(0))->String()).CompareTo("END_OF_DATA")){
103 AliDebug(2,"End of file reached");
108 AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
109 // requiring at least the index of the DP, the DP name, the format, and the number of entries
113 Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
114 AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
115 TObjString* lhcDPname = (TObjString*)tokens->At(1);
116 TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
117 AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
118 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
119 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
120 if (typeTokens->GetEntriesFast() < 2 ){
121 // requiring the the type and the number of elements for each measurement
122 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
127 TString type = ((TObjString*)typeTokens->At(0))->String();
128 AliDebug(2,Form("type = %s",type.Data()));
129 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
130 AliDebug(2,Form("nelements = %i",nelements));
131 Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi();
132 AliDebug(2,Form("nentries = %i",nentries));
133 Int_t nValuesPerEntry = nelements+1;
134 Int_t nfixed = 4; // n. of fixed entries
136 if (mapLHC->GetValue(lhcDPname)==0x0){
137 array = new TObjArray();
139 mapLHC->Add(new TObjString(lhcDPname->String()),array);
142 array = (TObjArray*)mapLHC->GetValue(lhcDPname);
143 AliDebug(2,Form("entry found! --> %p",array));
146 for (Int_t ientry=0; ientry< nentries; ientry ++){
147 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
148 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
149 Double_t timestamp = strTimestamp.Atof();
150 AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
151 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
152 // error in case the measurement is not within the data taking time interval
153 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
157 Int_t* value = new Int_t[nelements];
158 for (Int_t ielement=0; ielement<nelements; ielement++){
159 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
160 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
162 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
166 else if (type == "b"){
167 Bool_t* value = new Bool_t[nelements];
168 for (Int_t ielement=0; ielement<nelements; ielement++){
169 value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
170 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
172 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
176 else if (type == "f"){ // the floats should be considered as doubles
177 Double_t* value = new Double_t[nelements];
178 for (Int_t ielement=0; ielement<nelements; ielement++){
179 TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
180 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
181 AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
183 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
187 else if (type == "s"){
188 TObjArray* value = new TObjArray();
190 for (Int_t ielement=0; ielement<nelements; ielement++){
191 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
192 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
195 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
200 AliError(Form("Non-expected type %s",type.Data()));