]>
Commit | Line | Data |
---|---|---|
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 | //-------------------------------------------------------------------------- | |
41 | AliLHCReader::AliLHCReader(): | |
42 | TObject(), | |
43 | fStartTime(0), | |
44 | fEndTime(0) | |
45 | { | |
46 | // default ctor | |
47 | } | |
48 | ||
49 | //-------------------------------------------------------------------------- | |
50 | AliLHCReader::~AliLHCReader() | |
51 | { | |
52 | // | |
53 | // dtor | |
54 | // | |
55 | } | |
56 | ||
57 | //-------------------------------------------------------------------------- | |
58 | TMap* AliLHCReader::ReadLHCDP(TString filename) | |
59 | { | |
60 | // | |
61 | // reading the file with the inputs | |
62 | // | |
63 | ||
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(); | |
30ec5bf7 | 77 | // mapLHC->SetOwner(1); |
d96c6484 | 78 | TString strLine; |
30ec5bf7 | 79 | Int_t lhcEntries; |
80 | Int_t nBlocks = 0; | |
81 | // TObjArray** array; | |
82 | Int_t nline =0; | |
d96c6484 | 83 | while(strLine.ReadLine(*file)){ |
30ec5bf7 | 84 | nline++; |
85 | AliDebug(3,Form("line n. = %d",nline)); | |
d96c6484 | 86 | // tokenize the line with tabs |
30ec5bf7 | 87 | //if (strLine.BeginsWith("=")) continue; |
88 | //if (!strLine.CompareTo("END_OF_BLOCK")) { | |
89 | if (strLine.Contains("END_OF_BLOCK")) { | |
90 | AliInfo("END_OF_BLOCK"); | |
91 | nBlocks++; | |
92 | continue; | |
93 | } | |
94 | TObjArray* tokens = strLine.Tokenize("\t"); | |
d96c6484 | 95 | Int_t ntokens = tokens->GetEntriesFast(); |
30ec5bf7 | 96 | AliDebug(3,Form("Number of tokens = %d",ntokens)); |
97 | if (ntokens == 2 && !(((TObjString*)tokens->At(0))->String()).CompareTo("LHC_ENTRIES")){ | |
98 | lhcEntries = (((TObjString*)tokens->At(1))->String()).Atoi(); | |
99 | AliInfo(Form("LHC entries = %d",lhcEntries)); | |
100 | AliDebug(3,Form("LHC entries = %d",lhcEntries)); | |
101 | continue; | |
102 | } | |
103 | if (ntokens == 1 && !(((TObjString*)tokens->At(0))->String()).CompareTo("END_OF_DATA")){ | |
104 | AliInfo("End of file reached"); | |
105 | break; | |
106 | } | |
107 | if (ntokens < 4){ | |
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 | |
d96c6484 | 110 | delete tokens; |
111 | continue; | |
112 | } | |
30ec5bf7 | 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 | AliInfo(Form("lhcDPname = %s",(lhcDPname->String()).Data())); | |
d96c6484 | 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())); | |
123 | delete typeTokens; | |
124 | continue; | |
125 | } | |
126 | TString type = ((TObjString*)typeTokens->At(0))->String(); | |
127 | AliDebug(2,Form("type = %s",type.Data())); | |
128 | Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi(); | |
129 | AliDebug(2,Form("nelements = %i",nelements)); | |
30ec5bf7 | 130 | Int_t nentries = (((TObjString*)tokens->At(3))->String()).Atoi(); |
d96c6484 | 131 | AliDebug(2,Form("nentries = %i",nentries)); |
132 | Int_t nValuesPerEntry = nelements+1; | |
30ec5bf7 | 133 | Int_t nfixed = 4; // n. of fixed entries |
134 | TObjArray* array; | |
135 | if (mapLHC->GetValue(lhcDPname)==0x0){ | |
136 | array = new TObjArray(); | |
137 | array->SetOwner(1); | |
138 | } | |
139 | else{ | |
140 | TPair* p = mapLHC->RemoveEntry(lhcDPname); | |
141 | array = (TObjArray*)p->Value(); | |
142 | AliDebug(2,Form("entry found! --> %p",array)); | |
143 | } | |
144 | ||
d96c6484 | 145 | for (Int_t ientry=0; ientry< nentries; ientry ++){ |
146 | Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements; | |
147 | TString strTimestamp = ((TObjString*)tokens->At(indextime))->String(); | |
30ec5bf7 | 148 | // TObjArray* timeTokens = strTimestamp.Tokenize("."); |
149 | //if (timeTokens->GetEntriesFast() < 2 ){ | |
150 | // // requiring both the seconds and the nseconds for the timestamp | |
151 | // AliError(Form("The timestamp format does not match the expected one, skipping entry %d for DP = %s", ientry, lhcDPtype.Data())); | |
152 | // continue; | |
153 | //} | |
154 | //time_t seconds = time_t((((TObjString*)timeTokens->At(0))->String()).Atoi()); | |
155 | //Int_t nseconds = Int_t((((TObjString*)timeTokens->At(1))->String()).Atoi()); | |
156 | //TTimeStamp* timestamp = new TTimeStamp(seconds, (Int_t)(nseconds*1E8)); | |
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); | |
172 | } | |
30ec5bf7 | 173 | else if (type == "b"){ |
174 | Bool_t* value = new Bool_t[nelements]; | |
175 | for (Int_t ielement=0; ielement<nelements; ielement++){ | |
176 | value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi()); | |
177 | AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement]))); | |
178 | } | |
179 | AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp); | |
180 | array->Add(dcs); | |
181 | } | |
182 | else if (type == "f"){ // the floats should be considered as doubles | |
183 | Double_t* value = new Double_t[nelements]; | |
d96c6484 | 184 | for (Int_t ielement=0; ielement<nelements; ielement++){ |
30ec5bf7 | 185 | TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()); |
d96c6484 | 186 | value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof(); |
30ec5bf7 | 187 | AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data())); |
d96c6484 | 188 | } |
189 | AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp); | |
190 | array->Add(dcs); | |
191 | } | |
192 | else if (type == "s"){ | |
30ec5bf7 | 193 | TObjArray* value = new TObjArray(); |
d96c6484 | 194 | for (Int_t ielement=0; ielement<nelements; ielement++){ |
30ec5bf7 | 195 | TObjString* strobj = ((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry)); |
196 | AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data())); | |
197 | value->Add(strobj); | |
d96c6484 | 198 | } |
199 | AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp); | |
200 | array->Add(dcs); | |
201 | } | |
202 | else{ | |
30ec5bf7 | 203 | AliError(Form("Non-expected type %s",type.Data())); |
d96c6484 | 204 | return NULL; |
205 | } | |
206 | } | |
207 | mapLHC->Add(lhcDPname,array); | |
208 | } | |
30ec5bf7 | 209 | //mapLHC->Print(); |
d96c6484 | 210 | return mapLHC; |
211 | } | |
212 | ||
213 | ||
214 | ||
215 | ||
216 | ||
217 | ||
218 | ||
219 |