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