]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////// | |
2 | // Author: Henrik Tydesjo // | |
3 | // Preprocessor Class for the SPD // | |
4 | // // | |
5 | /////////////////////////////////////////////// | |
6 | ||
7 | #include "AliITSPreprocessorSPD.h" | |
8 | #include "AliITSCalibrationSPD.h" | |
9 | #include "AliITSOnlineCalibrationSPDhandler.h" | |
10 | #include "AliCDBEntry.h" | |
11 | #include "AliCDBMetaData.h" | |
12 | #include "AliShuttleInterface.h" | |
13 | #include "AliLog.h" | |
14 | #include <TTimeStamp.h> | |
15 | #include <TObjString.h> | |
16 | #include <TSystem.h> | |
17 | #include <fstream> | |
18 | ||
19 | /* $Id$ */ | |
20 | ||
21 | ClassImp(AliITSPreprocessorSPD) | |
22 | ||
23 | //______________________________________________________________________________________________ | |
24 | AliITSPreprocessorSPD::AliITSPreprocessorSPD(AliShuttleInterface* shuttle) : | |
25 | AliPreprocessor("SPD", shuttle), fIdList() | |
26 | { | |
27 | // constructor | |
28 | AddRunType("DAQ_MIN_TH_SCAN"); | |
29 | AddRunType("DAQ_MEAN_TH_SCAN"); | |
30 | AddRunType("DAQ_GEN_DAC_SCAN"); | |
31 | AddRunType("DAQ_UNIFORMITY_SCAN"); | |
32 | AddRunType("DAQ_NOISY_PIX_SCAN"); | |
33 | AddRunType("DAQ_PIX_DELAY_SCAN"); | |
34 | AddRunType("DAQ_FO_UNIF_SCAN"); | |
35 | AddRunType("PHYSICS"); | |
36 | ||
37 | fIdList.SetOwner(kTRUE); | |
38 | } | |
39 | ||
40 | //______________________________________________________________________________________________ | |
41 | AliITSPreprocessorSPD::~AliITSPreprocessorSPD() | |
42 | { | |
43 | // destructor | |
44 | } | |
45 | ||
46 | //______________________________________________________________________________________________ | |
47 | void AliITSPreprocessorSPD::Initialize(Int_t run, UInt_t startTime, | |
48 | UInt_t endTime) | |
49 | { | |
50 | // initialize | |
51 | AliPreprocessor::Initialize(run, startTime, endTime); | |
52 | ||
53 | AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, | |
54 | TTimeStamp(startTime).AsString(), | |
55 | TTimeStamp(endTime).AsString())); | |
56 | } | |
57 | ||
58 | //______________________________________________________________________________________________ | |
59 | UInt_t AliITSPreprocessorSPD::Process(TMap* /*dcsAliasMap*/) | |
60 | { | |
61 | // Do the actual preprocessing | |
62 | ||
63 | ||
64 | // *** GET RUN TYPE *** | |
65 | ||
66 | TString runType = GetRunType(); | |
67 | ||
68 | ||
69 | fIdList.Clear(); | |
70 | ||
71 | ||
72 | // ******************************************************************************************** // | |
73 | // *** GET THE FILE IDs FOR DEBUGGING *** // | |
74 | if (runType == "DAQ_MIN_TH_SCAN" || | |
75 | runType == "DAQ_MEAN_TH_SCAN" || | |
76 | runType == "DAQ_GEN_DAC_SCAN" || | |
77 | runType == "DAQ_UNIFORMITY_SCAN" || | |
78 | runType == "DAQ_NOISY_PIX_SCAN" || | |
79 | runType == "DAQ_PIX_DELAY_SCAN" || | |
80 | runType == "DAQ_FO_UNIF_SCAN" || | |
81 | runType == "PHYSICS") { | |
82 | TString idListId = "SPD_id_list"; | |
83 | TList* list = GetFileSources(kDAQ,idListId.Data()); | |
84 | UInt_t nrIdFiles = 0; | |
85 | if (list) { | |
86 | TListIter *iter = new TListIter(list); | |
87 | while (TObjString* fileNameEntry = (TObjString*) iter->Next()) { | |
88 | TString fileName = GetFile(kDAQ, idListId.Data(), fileNameEntry->GetString().Data()); | |
89 | if (fileName.IsNull()) { | |
90 | Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data())); | |
91 | return 1; | |
92 | } | |
93 | nrIdFiles++; | |
94 | ifstream idFile; | |
95 | idFile.open(fileName.Data(), ifstream::in); | |
96 | if (idFile.fail()) { | |
97 | Log(Form("Could not open file (%s) for reading.",fileName.Data())); | |
98 | return 1; | |
99 | } | |
100 | else { | |
101 | while(1) { | |
102 | Char_t id[50]; | |
103 | idFile >> id; | |
104 | if (idFile.eof()) break; | |
105 | // Add id to the list; | |
106 | fIdList.AddLast(new TObjString(id)); | |
107 | } | |
108 | } | |
109 | idFile.close(); | |
110 | } | |
111 | delete iter; | |
112 | } | |
113 | if (nrIdFiles==0) { | |
114 | Log("Failed to retrieve any id list file."); | |
115 | return 1; | |
116 | } | |
117 | } | |
118 | ||
119 | ||
120 | // ******************************************************************************************** // | |
121 | // *** REFERENCE DATA *** // | |
122 | ||
123 | // SCAN runs: | |
124 | if (runType == "DAQ_MIN_TH_SCAN" || | |
125 | runType == "DAQ_MEAN_TH_SCAN" || | |
126 | runType == "DAQ_GEN_DAC_SCAN" || | |
127 | runType == "DAQ_UNIFORMITY_SCAN" || | |
128 | runType == "DAQ_NOISY_PIX_SCAN" || | |
129 | runType == "DAQ_PIX_DELAY_SCAN") { | |
130 | // Store scan container files for all equipments used - as reference data | |
131 | // ids from FXS follow ("SPD_ref_scan_%d",eq), while Alien follow ("SPD_ref_scan_eq_%d",eq) | |
132 | // the first part of the id is passed as argument here: | |
133 | if (!StoreRefForIdStartingWith("SPD_ref_scan")) return 1; | |
134 | } | |
135 | ||
136 | // FO runs: | |
137 | else if (runType == "DAQ_FO_UNIF_SCAN") { | |
138 | // Store fo container files for all equipments used - as reference data | |
139 | // ids from FXS follow ("SPD_ref_fo_%d",eq), while Alien follow ("SPD_ref_fo_eq_%d",eq) | |
140 | // the first part of the id is passed as argument here: | |
141 | if (!StoreRefForIdStartingWith("SPD_ref_fo")) return 1; | |
142 | } | |
143 | ||
144 | // Physics runs (online monitoring): | |
145 | else if (runType == "PHYSICS") { | |
146 | // Store the phys "per run" container files - as reference data | |
147 | if (!StoreRefFromTarForId("SPD_ref_phys")) return 1; | |
148 | // Store the phys "dead" container files - as reference data | |
149 | if (!StoreRefFromTarForId("SPD_ref_phys_dead")) return 1; | |
150 | } | |
151 | ||
152 | ||
153 | ||
154 | // ******************************************************************************************** // | |
155 | // *** NOISY AND DEAD DATA *** // | |
156 | ||
157 | // Standalone runs: | |
158 | if (runType == "DAQ_NOISY_PIX_SCAN") { | |
159 | // Retrieve and unpack tared calibration files from FXS | |
160 | TString id = "SPD_scan_noisy"; | |
161 | TList* list = GetFileSources(kDAQ,id.Data()); | |
162 | if (list) { | |
163 | UInt_t index = 0; | |
164 | while (list->At(index)!=NULL) { | |
165 | TObjString* fileNameEntry = (TObjString*) list->At(index); | |
166 | TString fileName = GetFile(kDAQ, id.Data(), fileNameEntry->GetString().Data()); | |
167 | if (fileName.IsNull()) { | |
168 | Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data())); | |
169 | return 1; | |
170 | } | |
171 | if (!RemoveIdFromList("SPD_scan_noisy")) { | |
172 | Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data())); | |
173 | } | |
174 | TString command = Form("tar -xf %s",fileName.Data()); | |
175 | gSystem->Exec(command.Data()); | |
176 | index++; | |
177 | } | |
178 | } | |
179 | // Create new database entries | |
180 | TObjArray* spdEntryNoisy = new TObjArray(240); | |
181 | spdEntryNoisy->SetOwner(kTRUE); | |
182 | for(UInt_t module=0; module<240; module++){ | |
183 | AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD(); | |
184 | spdEntryNoisy->Add(calObj); | |
185 | } | |
186 | // Add noisy from the copied FXS files | |
187 | AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler(); | |
188 | TString fileLoc = "."; | |
189 | handler->SetFileLocation(fileLoc.Data()); | |
190 | handler->ReadNoisyFromFiles(); | |
191 | for (Int_t module=0; module<240; module++) { | |
192 | ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBadSingle( handler->GetNrNoisySingle(module) ); | |
193 | ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handler->GetNoisyArray(module) ); | |
194 | } | |
195 | delete handler; | |
196 | // Store the new calibration objects in OCDB | |
197 | Log("Noisy lists (scan) will be stored..."); | |
198 | AliCDBMetaData metaData; | |
199 | metaData.SetBeamPeriod(0); | |
200 | metaData.SetResponsible("Henrik Tydesjo"); | |
201 | metaData.SetComment("Created by SPD PreProcessor"); | |
202 | // validity for this run until infinity | |
203 | if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kTRUE)) { | |
204 | Log("Failed to store calibration data."); | |
205 | return 1; | |
206 | } | |
207 | Log("Database updated."); | |
208 | delete spdEntryNoisy; | |
209 | } | |
210 | ||
211 | // Physics runs (online monitoring): | |
212 | else if (runType == "PHYSICS") { | |
213 | ||
214 | // Noisy pixels: | |
215 | // Read noisy from previous calibration | |
216 | AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy"); | |
217 | TObjArray* spdEntryNoisy; | |
218 | if(cdbEntry) { | |
219 | spdEntryNoisy = (TObjArray*)cdbEntry->GetObject(); | |
220 | if(!spdEntryNoisy) return 1; | |
221 | } | |
222 | else { | |
223 | Log("Old calibration not found in database. This is required for further processing."); | |
224 | return 1; | |
225 | } | |
226 | AliITSOnlineCalibrationSPDhandler* handOld = new AliITSOnlineCalibrationSPDhandler(); | |
227 | handOld->ReadNoisyFromCalibObj(spdEntryNoisy); | |
228 | // Retrieve and unpack tared calibration files from FXS | |
229 | TString idN = "SPD_phys_noisy"; | |
230 | TList* listN = GetFileSources(kDAQ,idN.Data()); | |
231 | if (listN) { | |
232 | UInt_t index = 0; | |
233 | while (listN->At(index)!=NULL) { | |
234 | TObjString* fileNameEntry = (TObjString*) listN->At(index); | |
235 | TString fileName = GetFile(kDAQ, idN.Data(), fileNameEntry->GetString().Data()); | |
236 | if (fileName.IsNull()) { | |
237 | Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data())); | |
238 | return 1; | |
239 | } | |
240 | if (!RemoveIdFromList(idN.Data())) { | |
241 | Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idN.Data())); | |
242 | } | |
243 | TString command = Form("tar -xf %s",fileName.Data()); | |
244 | gSystem->Exec(command.Data()); | |
245 | index++; | |
246 | } | |
247 | } | |
248 | AliITSOnlineCalibrationSPDhandler* handNew = new AliITSOnlineCalibrationSPDhandler(); | |
249 | handNew->SetFileLocation("."); | |
250 | handNew->ReadNoisyFromFiles(); | |
251 | // add the new list to the old one | |
252 | UInt_t nrNewNoisy = handOld->AddNoisyFrom(handNew); | |
253 | // If new noisy pixels were found: Update calibration objects | |
254 | if (nrNewNoisy>0) { | |
255 | for (Int_t module=0; module<240; module++) { | |
256 | ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBadSingle( handOld->GetNrNoisySingle(module) ); | |
257 | ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handOld->GetNoisyArray(module) ); | |
258 | } | |
259 | // Store the new calibration objects in OCDB | |
260 | Log("Noisy lists (phys) will be stored..."); | |
261 | AliCDBMetaData metaData; | |
262 | metaData.SetBeamPeriod(0); | |
263 | metaData.SetResponsible("Henrik Tydesjo"); | |
264 | metaData.SetComment("Created by SPD PreProcessor"); | |
265 | // validity for this run only | |
266 | if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kFALSE)) { | |
267 | Log("Failed to store calibration data."); | |
268 | return 1; | |
269 | } | |
270 | Log("Database updated."); | |
271 | } | |
272 | delete handNew; | |
273 | ||
274 | // Dead pixels: | |
275 | // Retrieve and unpack tared calibration files from FXS | |
276 | TString idD = "SPD_phys_dead"; | |
277 | TList* listD = GetFileSources(kDAQ,idD.Data()); | |
278 | UInt_t nrPhysDeadFiles = 0; | |
279 | if (listD) { | |
280 | UInt_t index = 0; | |
281 | while (listD->At(index)!=NULL) { | |
282 | TObjString* fileNameEntry = (TObjString*) listD->At(index); | |
283 | TString fileName = GetFile(kDAQ, idD.Data(), fileNameEntry->GetString().Data()); | |
284 | if (fileName.IsNull()) { | |
285 | Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data())); | |
286 | return 1; | |
287 | } | |
288 | nrPhysDeadFiles++; | |
289 | if (!RemoveIdFromList("SPD_phys_dead")) { | |
290 | Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idD.Data())); | |
291 | } | |
292 | TString command = Form("tar -xf %s",fileName.Data()); | |
293 | gSystem->Exec(command.Data()); | |
294 | index++; | |
295 | } | |
296 | } | |
297 | if (nrPhysDeadFiles==0) { | |
298 | Log(Form("Could not find files with id %s. Should be present for each run.",idD.Data())); | |
299 | return 1; | |
300 | } | |
301 | // Create new database entries | |
302 | TObjArray* spdEntryDead = new TObjArray(240); | |
303 | spdEntryDead->SetOwner(kTRUE); | |
304 | for(UInt_t module=0; module<240; module++){ | |
305 | AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD(); | |
306 | spdEntryDead->Add(calObj); | |
307 | } | |
308 | // Add dead from the copied FXS files | |
309 | handOld->SetFileLocation("."); | |
310 | handOld->ReadSilentFromFiles(); | |
311 | for (UInt_t module=0; module<240; module++) { | |
312 | AliITSCalibrationSPD* calibSPD = (AliITSCalibrationSPD*) spdEntryDead->At(module); | |
313 | calibSPD->SetNrBadSingle( handOld->GetNrDeadSingle(module) ); | |
314 | calibSPD->SetBadList( handOld->GetDeadArray(module) ); | |
315 | for (UInt_t chipIndex=0; chipIndex<5; chipIndex++) { | |
316 | UInt_t eq,hs,chip,col,row; | |
317 | AliITSRawStreamSPD::OfflineToOnline(module, chipIndex*32, 0, eq, hs, chip, col, row); | |
318 | if (handOld->IsSilentChip(eq,hs,chip)) { | |
319 | calibSPD->SetChipBad(chipIndex); | |
320 | } | |
321 | else { | |
322 | calibSPD->UnSetChipBad(chipIndex); | |
323 | } | |
324 | } | |
325 | } | |
326 | delete handOld; | |
327 | // Store the new calibration objects in OCDB | |
328 | Log("Dead lists (phys) will be stored..."); | |
329 | AliCDBMetaData metaData; | |
330 | metaData.SetBeamPeriod(0); | |
331 | metaData.SetResponsible("Henrik Tydesjo"); | |
332 | metaData.SetComment("Created by SPD PreProcessor"); | |
333 | // validity for this run only | |
334 | if (!Store("Calib", "SPDDead", spdEntryDead, &metaData, 0, kFALSE)) { | |
335 | Log("Failed to store calibration data."); | |
336 | return 1; | |
337 | } | |
338 | Log("Database updated."); | |
339 | delete spdEntryDead; | |
340 | ||
341 | } | |
342 | ||
343 | ||
344 | ||
345 | // ******************************************************************************************** // | |
346 | // check that there are no ids left in the list: | |
347 | if (fIdList.First()!=NULL) { | |
348 | TString logMessage = ""; | |
349 | TListIter *iter = new TListIter(&fIdList); | |
350 | while (TObjString *st = (TObjString*)iter->Next()) { | |
351 | logMessage.Append(st->GetString()); | |
352 | logMessage.Append(" "); | |
353 | } | |
354 | delete iter; | |
355 | Log(Form("Files with the following ids were never retrieved: %s.",logMessage.Data())); | |
356 | return 1; | |
357 | } | |
358 | fIdList.Clear(); | |
359 | ||
360 | ||
361 | return 0; // 0 means success | |
362 | ||
363 | } | |
364 | //_________________________________________________________________________________________ | |
365 | Bool_t AliITSPreprocessorSPD::RemoveIdFromList(const Char_t *id) { | |
366 | // removes id from the list of ids | |
367 | Bool_t found = kFALSE; | |
368 | TListIter *iter = new TListIter(&fIdList); | |
369 | while (TObjString *st = (TObjString*)iter->Next()) { | |
370 | if (st->GetString().CompareTo(id)==0) { | |
371 | fIdList.Remove(st); | |
372 | found = kTRUE; | |
373 | break; | |
374 | } | |
375 | } | |
376 | delete iter; | |
377 | return found; | |
378 | } | |
379 | //_________________________________________________________________________________________ | |
380 | Bool_t AliITSPreprocessorSPD::StoreRefForIdStartingWith(const Char_t *idStart) { | |
381 | // Store the standalone container files as reference data (0 or 1 file for each equipment) | |
382 | // idStart is the first part of the id string (which also should contain the actual eq) | |
383 | for (UInt_t eq=0; eq<20; eq++) { | |
384 | TString id = Form("%s_%d",idStart,eq); | |
385 | TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file) | |
386 | if (list) { | |
387 | TObjString* fileNameEntry = (TObjString*) list->First(); | |
388 | if (fileNameEntry!=NULL) { | |
389 | TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data()); | |
390 | if (fileName.IsNull()) { | |
391 | Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data())); | |
392 | return kFALSE; | |
393 | } | |
394 | if (!RemoveIdFromList(id.Data())) { | |
395 | Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data())); | |
396 | } | |
397 | TString refCAT = Form("%s_eq_%d",idStart,eq); | |
398 | if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) { | |
399 | Log(Form("Failed to store reference file %s.",fileName.Data())); | |
400 | return kFALSE; | |
401 | } | |
402 | } | |
403 | } | |
404 | } | |
405 | return kTRUE; | |
406 | } | |
407 | //_________________________________________________________________________________________ | |
408 | Bool_t AliITSPreprocessorSPD::StoreRefFromTarForId(const Char_t *id) { | |
409 | // store reference files from tar file for the id given (this is just to not duplicate code) | |
410 | TList* list = GetFileSources(kDAQ,id); | |
411 | if (list) { | |
412 | UInt_t index = 0; | |
413 | while (list->At(index)!=NULL) { | |
414 | TObjString* fileNameEntry = (TObjString*) list->At(index); | |
415 | TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data()); | |
416 | if (fileName.IsNull()) { | |
417 | Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data())); | |
418 | return kFALSE; | |
419 | } | |
420 | if (!RemoveIdFromList(id)) { | |
421 | Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id)); | |
422 | } | |
423 | // get the file names from the tar file | |
424 | // TString pwd = gSystem->pwd(); | |
425 | // TString tempFileName = Form("%s/tempTar.txt",pwd.Data()); | |
426 | TString tempFileName = "tempTar.txt"; | |
427 | TString command = Form("tar -tf %s > %s",fileName.Data(),tempFileName.Data()); | |
428 | gSystem->Exec(command.Data()); | |
429 | TList fList; | |
430 | ifstream tempFile; | |
431 | tempFile.open(tempFileName.Data(), ifstream::in); | |
432 | if (tempFile.fail()) { | |
433 | Log(Form("Could not open file (%s) for reading.",tempFileName.Data())); | |
434 | return kFALSE; | |
435 | } | |
436 | else { | |
437 | while(1) { | |
438 | Char_t fileN[100]; | |
439 | tempFile >> fileN; | |
440 | if (tempFile.eof()) break; | |
441 | fList.AddLast(new TObjString(fileN)); | |
442 | } | |
443 | } | |
444 | // close and remove temp file | |
445 | tempFile.close(); | |
446 | command = Form("rm -f %s",tempFileName.Data()); | |
447 | gSystem->Exec(command.Data()); | |
448 | // unpack | |
449 | command = Form("tar -xf %s",fileName.Data()); | |
450 | gSystem->Exec(command.Data()); | |
451 | // store each file | |
452 | UInt_t index2 = 0; | |
453 | while (fList.At(index2)!=NULL) { | |
454 | TString eqFileName = ((TObjString*)fList.At(index2))->GetString(); | |
455 | // get eq id | |
456 | TString eqStr = eqFileName.Data(); | |
457 | UInt_t len = eqStr.Length(); | |
458 | eqStr.Replace(0,len-7,"",0); | |
459 | eqStr.ReplaceAll("_",1,"",0); | |
460 | eqStr.ReplaceAll(".root",5,"",0); | |
461 | Int_t eqId = eqStr.Atoi(); | |
462 | if (eqId>=0 && eqId<20) { | |
463 | TString refCAT = Form("%s_eq_%d",id,eqId); | |
464 | if (!StoreReferenceFile(eqFileName.Data(),refCAT.Data())) { | |
465 | Log(Form("Failed to store reference file %s.",eqFileName.Data())); | |
466 | return kFALSE; | |
467 | } | |
468 | } | |
469 | else { | |
470 | Log(Form("Eq ID %d out of bounds for file %s",eqId,eqFileName.Data())); | |
471 | fList.Clear(); | |
472 | return kFALSE; | |
473 | } | |
474 | index2++; | |
475 | } | |
476 | fList.Clear(); | |
477 | index++; | |
478 | } | |
479 | } | |
480 | return kTRUE; | |
481 | } |