]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSPreprocessorSPD.cxx
modifications to satisfy the coding conventions
[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++) {
4821f07d 262 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBadSingle( handler->GetNrNoisySingle(module) );
6727e2db 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++) {
4821f07d 326 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBadSingle( handOld->GetNrNoisySingle(module) );
6727e2db 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(".");
b696414b 380 handOld->ReadSilentFromFiles();
478d804c 381 for (UInt_t module=0; module<240; module++) {
382 AliITSCalibrationSPD* calibSPD = (AliITSCalibrationSPD*) spdEntryDead->At(module);
4821f07d 383 calibSPD->SetNrBadSingle( handOld->GetNrDeadSingle(module) );
478d804c 384 calibSPD->SetBadList( handOld->GetDeadArray(module) );
385 for (UInt_t chipIndex=0; chipIndex<5; chipIndex++) {
386 UInt_t eq,hs,chip,col,row;
387 AliITSRawStreamSPD::OfflineToOnline(module, chipIndex*32, 0, eq, hs, chip, col, row);
388 if (handOld->IsSilentChip(eq,hs,chip)) {
389 calibSPD->SetChipBad(chipIndex);
390 }
391 else {
392 calibSPD->UnSetChipBad(chipIndex);
393 }
394 }
6727e2db 395 }
396 delete handOld;
397 // Store the new calibration objects in OCDB
398 Log("Dead lists (phys) will be stored...");
399 AliCDBMetaData metaData;
400 metaData.SetBeamPeriod(0);
401 metaData.SetResponsible("Henrik Tydesjo");
402 metaData.SetComment("Created by SPD PreProcessor");
403 // validity for this run only
404 if (!Store("Calib", "SPDDead", spdEntryDead, &metaData, 0, kFALSE)) {
405 Log("Failed to store calibration data.");
406 return 1;
407 }
408 Log("Database updated.");
409 delete spdEntryDead;
53ae21ce 410
03fc6773 411 }
412
03fc6773 413
4f88491f 414 // check that there are no ids left in the list:
415 if (fIdList.First()!=NULL) {
416 TString logMessage = "";
417 TListIter *iter = new TListIter(&fIdList);
418 while (TObjString *st = (TObjString*)iter->Next()) {
419 logMessage.Append(st->GetString());
420 logMessage.Append(" ");
421 }
422 delete iter;
423 Log(Form("Files with the following ids were never retrieved: %s.",logMessage.Data()));
424 return 1;
425 }
426
427 fIdList.Clear();
428
53ae21ce 429 return 0; // 0 means success
03fc6773 430
fcf95fc7 431}
4f88491f 432//_________________________________________________________________________________________
433Bool_t AliITSPreprocessorSPD::RemoveIdFromList(const Char_t *id) {
434 // removes id from the list of ids
435 Bool_t found = kFALSE;
436 TListIter *iter = new TListIter(&fIdList);
437 while (TObjString *st = (TObjString*)iter->Next()) {
438 if (st->GetString().CompareTo(id)==0) {
439 fIdList.Remove(st);
440 found = kTRUE;
441 break;
442 }
443 }
444 delete iter;
445 return found;
446}
447//_________________________________________________________________________________________
448Bool_t AliITSPreprocessorSPD::StoreRefFromTarForId(const Char_t *id) {
449 // store reference files from tar file for the id given (this is just to not duplicate code)
450 TList* list = GetFileSources(kDAQ,id);
451 if (list) {
452 UInt_t index = 0;
453 while (list->At(index)!=NULL) {
454 TObjString* fileNameEntry = (TObjString*) list->At(index);
455 TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
456 if (fileName.IsNull()) {
457 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
458 return kFALSE;
459 }
460 if (!RemoveIdFromList(id)) {
461 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id));
462 }
463 // get the file names from the tar file
464 // TString pwd = gSystem->pwd();
465 // TString tempFileName = Form("%s/tempTar.txt",pwd.Data());
466 TString tempFileName = "tempTar.txt";
467 TString command = Form("tar -tf %s > %s",fileName.Data(),tempFileName.Data());
468 gSystem->Exec(command.Data());
469 TList fList;
470 ifstream tempFile;
471 tempFile.open(tempFileName.Data(), ifstream::in);
472 if (tempFile.fail()) {
473 Log(Form("Could not open file (%s) for reading.",tempFileName.Data()));
474 return kFALSE;
475 }
476 else {
477 while(1) {
478 Char_t fileN[100];
479 tempFile >> fileN;
480 if (tempFile.eof()) break;
481 fList.AddLast(new TObjString(fileN));
482 }
483 }
484 // close and remove temp file
485 tempFile.close();
486 command = Form("rm -f %s",tempFileName.Data());
487 gSystem->Exec(command.Data());
488 // unpack
489 command = Form("tar -xf %s",fileName.Data());
490 gSystem->Exec(command.Data());
491 // store each file
492 UInt_t index2 = 0;
493 while (fList.At(index2)!=NULL) {
8f02666b 494 TString eqFileName = ((TObjString*)fList.At(index2))->GetString();
4f88491f 495 // get eq id
8f02666b 496 TString eqStr = eqFileName.Data();
4f88491f 497 UInt_t len = eqStr.Length();
498 eqStr.Replace(0,len-7,"",0);
499 eqStr.ReplaceAll("_",1,"",0);
500 eqStr.ReplaceAll(".root",5,"",0);
501 Int_t eqId = eqStr.Atoi();
502 if (eqId>=0 && eqId<20) {
503 TString refCAT = Form("%s_eq_%d",id,eqId);
8f02666b 504 if (!StoreReferenceFile(eqFileName.Data(),refCAT.Data())) {
505 Log(Form("Failed to store reference file %s.",eqFileName.Data()));
4f88491f 506 return kFALSE;
507 }
508 }
509 else {
8f02666b 510 Log(Form("Eq ID %d out of bounds for file %s",eqId,eqFileName.Data()));
4f88491f 511 fList.Clear();
512 return kFALSE;
513 }
514 index2++;
515 }
516 fList.Clear();
517 index++;
518 }
519 }
520 return kTRUE;
521}