1 ///////////////////////////////////////////////
2 // Author: Henrik Tydesjo //
3 // Preprocessor Class for the SPD //
5 ///////////////////////////////////////////////
7 #include "AliITSPreprocessorSPD.h"
8 #include "AliITSCalibrationSPD.h"
9 #include "AliITSOnlineCalibrationSPDhandler.h"
10 #include "AliCDBEntry.h"
11 #include "AliCDBMetaData.h"
12 #include "AliShuttleInterface.h"
14 #include <TTimeStamp.h>
15 #include <TObjString.h>
21 ClassImp(AliITSPreprocessorSPD)
23 //______________________________________________________________________________________________
24 AliITSPreprocessorSPD::AliITSPreprocessorSPD(AliShuttleInterface* shuttle) :
25 AliPreprocessor("SPD", shuttle), fIdList()
28 fIdList.SetOwner(kTRUE);
31 //______________________________________________________________________________________________
32 AliITSPreprocessorSPD::~AliITSPreprocessorSPD()
37 //______________________________________________________________________________________________
38 void AliITSPreprocessorSPD::Initialize(Int_t run, UInt_t startTime,
42 AliPreprocessor::Initialize(run, startTime, endTime);
44 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
45 TTimeStamp(startTime).AsString(),
46 TTimeStamp(endTime).AsString()));
49 //______________________________________________________________________________________________
50 UInt_t AliITSPreprocessorSPD::Process(TMap* /*dcsAliasMap*/)
52 // Do the actual preprocessing
55 // *** GET RUN TYPE ***
57 TString runType = GetRunType();
61 UInt_t nrEqForScan = 0;
62 // UInt_t nrEqForPhysN = 0;
63 // UInt_t nrEqForPhysD = 0;
65 // ******************************************************************************************** //
66 // *** GET THE FILE IDs FOR DEBUGGING *** //
67 if (runType == "DAQ_MIN_TH_SCAN" ||
68 runType == "DAQ_MEAN_TH_SCAN" ||
69 runType == "DAQ_UNIFORMITY_SCAN" ||
70 runType == "DAQ_NOISY_PIX_SCAN" ||
71 runType == "DAQ_PIX_DELAY_SCAN" ||
72 runType == "DAQ_FO_UNIF_SCAN" ||
73 runType == "PHYSICS") {
74 TString idListId = "SPD_id_list";
75 TList* list = GetFileSources(kDAQ,idListId.Data());
78 TListIter *iter = new TListIter(list);
79 while (TObjString* fileNameEntry = (TObjString*) iter->Next()) {
80 TString fileName = GetFile(kDAQ, idListId.Data(), fileNameEntry->GetString().Data());
81 if (fileName.IsNull()) {
82 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
87 idFile.open(fileName.Data(), ifstream::in);
89 Log(Form("Could not open file (%s) for reading.",fileName.Data()));
96 if (idFile.eof()) break;
97 // Add id to the list;
98 fIdList.AddLast(new TObjString(id));
106 Log("Failed to retrieve any id list file.");
112 // ******************************************************************************************** //
113 // *** REFERENCE DATA *** //
116 if (runType == "DAQ_MIN_TH_SCAN" ||
117 runType == "DAQ_MEAN_TH_SCAN" ||
118 runType == "DAQ_UNIFORMITY_SCAN" ||
119 runType == "DAQ_NOISY_PIX_SCAN" ||
120 runType == "DAQ_PIX_DELAY_SCAN" ||
121 runType == "DAQ_FO_UNIF_SCAN") {
122 // Store the scan container files as reference data (0 or 1 file for each equipment)
123 for (UInt_t eq=0; eq<20; eq++) {
124 TString id = Form("SPD_ref_scan_%d",eq);
125 TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
127 TObjString* fileNameEntry = (TObjString*) list->First();
128 if (fileNameEntry!=NULL) {
130 TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
131 if (fileName.IsNull()) {
132 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
135 if (!RemoveIdFromList(id.Data())) {
136 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
138 TString refCAT = Form("SPD_ref_scan_eq_%d",eq);
139 if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
140 Log(Form("Failed to store reference file %s.",fileName.Data()));
148 // Physics runs (online monitoring):
149 if (runType == "PHYSICS") {
150 // Store the phys "per run" container files as reference data
151 if (!StoreRefFromTarForId("SPD_ref_phys")) return 1;
152 // Store the phys "dead" container files as reference data
153 if (!StoreRefFromTarForId("SPD_ref_phys_dead")) return 1;
157 // *** OLD CODE NOT TARED
158 // for (UInt_t eq=0; eq<20; eq++) {
159 // TString id = Form("SPD_ref_phys_%d",eq);
160 // TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
162 // TObjString* fileNameEntry = (TObjString*) list->First();
163 // if (fileNameEntry!=NULL) {
165 // TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
166 // if (fileName.IsNull()) {
167 // Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
170 // if (!RemoveIdFromList(id.Data())) {
171 // Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
173 // TString refCAT = Form("SPD_ref_phys_eq_%d",eq);
174 // if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
175 // Log(Form("Failed to store reference file %s.",fileName.Data()));
183 // *** OLD CODE NOT TARED
184 // // Store the phys "dead" container files as reference data (0 or 1 file for each equipment)
185 // for (UInt_t eq=0; eq<20; eq++) {
186 // TString id = Form("SPD_ref_phys_dead_%d",eq);
187 // TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
189 // TObjString* fileNameEntry = (TObjString*) list->First();
190 // if (fileNameEntry!=NULL) {
192 // TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
193 // if (fileName.IsNull()) {
194 // Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
197 // if (!RemoveIdFromList(id.Data())) {
198 // Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
200 // TString refCAT = Form("SPD_ref_phys_dead_eq_%d",eq);
201 // if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
202 // Log(Form("Failed to store reference file %s.",fileName.Data()));
211 // ******************************************************************************************** //
214 // *** NOISY AND DEAD DATA *** //
217 if (runType == "DAQ_NOISY_PIX_SCAN") {
218 // Retrieve and unpack tared calibration files from FXS
219 TString id = "SPD_scan_noisy";
220 TList* list = GetFileSources(kDAQ,id.Data());
223 while (list->At(index)!=NULL) {
224 TObjString* fileNameEntry = (TObjString*) list->At(index);
225 TString fileName = GetFile(kDAQ, id.Data(), fileNameEntry->GetString().Data());
226 if (fileName.IsNull()) {
227 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
230 if (!RemoveIdFromList("SPD_scan_noisy")) {
231 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
233 TString command = Form("tar -xf %s",fileName.Data());
234 gSystem->Exec(command.Data());
238 // Create new database entries
239 TObjArray* spdEntryNoisy = new TObjArray(240);
240 spdEntryNoisy->SetOwner(kTRUE);
241 for(UInt_t module=0; module<240; module++){
242 AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
243 spdEntryNoisy->Add(calObj);
245 // Add noisy from the copied FXS files
246 AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
247 TString fileLoc = ".";
248 handler->SetFileLocation(fileLoc.Data());
249 handler->ReadNoisyFromFiles();
250 for (Int_t module=0; module<240; module++) {
251 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBad( handler->GetNrNoisy(module) );
252 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handler->GetNoisyArray(module) );
255 // Store the new calibration objects in OCDB
256 Log("Noisy lists (scan) will be stored...");
257 AliCDBMetaData metaData;
258 metaData.SetBeamPeriod(0);
259 metaData.SetResponsible("Henrik Tydesjo");
260 metaData.SetComment("Created by SPD PreProcessor");
261 // validity for this run until infinity
262 if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kTRUE)) {
263 Log("Failed to store calibration data.");
266 Log("Database updated.");
267 delete spdEntryNoisy;
270 // Physics runs (online monitoring):
271 else if (runType == "PHYSICS") {
274 // Read noisy from previous calibration
275 AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
276 TObjArray* spdEntryNoisy;
278 spdEntryNoisy = (TObjArray*)cdbEntry->GetObject();
279 if(!spdEntryNoisy) return 1;
282 Log("Old calibration not found in database. This is required for further processing.");
285 AliITSOnlineCalibrationSPDhandler* handOld = new AliITSOnlineCalibrationSPDhandler();
286 handOld->ReadNoisyFromCalibObj(spdEntryNoisy);
287 // Retrieve and unpack tared calibration files from FXS
288 TString idN = "SPD_phys_noisy";
289 TList* listN = GetFileSources(kDAQ,idN.Data());
292 while (listN->At(index)!=NULL) {
293 TObjString* fileNameEntry = (TObjString*) listN->At(index);
294 TString fileName = GetFile(kDAQ, idN.Data(), fileNameEntry->GetString().Data());
295 if (fileName.IsNull()) {
296 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
299 if (!RemoveIdFromList(idN.Data())) {
300 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idN.Data()));
302 TString command = Form("tar -xf %s",fileName.Data());
303 gSystem->Exec(command.Data());
307 AliITSOnlineCalibrationSPDhandler* handNew = new AliITSOnlineCalibrationSPDhandler();
308 handNew->SetFileLocation(".");
309 handNew->ReadNoisyFromFiles();
310 // add the new list to the old one
311 UInt_t nrNewNoisy = handOld->AddNoisyFrom(handNew);
312 // If new noisy pixels were found: Update calibration objects
314 for (Int_t module=0; module<240; module++) {
315 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBad( handOld->GetNrNoisy(module) );
316 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handOld->GetNoisyArray(module) );
318 // Store the new calibration objects in OCDB
319 Log("Noisy lists (phys) will be stored...");
320 AliCDBMetaData metaData;
321 metaData.SetBeamPeriod(0);
322 metaData.SetResponsible("Henrik Tydesjo");
323 metaData.SetComment("Created by SPD PreProcessor");
324 // validity for this run only
325 if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kFALSE)) {
326 Log("Failed to store calibration data.");
329 Log("Database updated.");
334 // Retrieve and unpack tared calibration files from FXS
335 TString idD = "SPD_phys_dead";
336 TList* listD = GetFileSources(kDAQ,idD.Data());
337 UInt_t nrPhysDeadFiles = 0;
340 while (listD->At(index)!=NULL) {
341 TObjString* fileNameEntry = (TObjString*) listD->At(index);
342 TString fileName = GetFile(kDAQ, idD.Data(), fileNameEntry->GetString().Data());
343 if (fileName.IsNull()) {
344 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
348 if (!RemoveIdFromList("SPD_phys_dead")) {
349 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idD.Data()));
351 TString command = Form("tar -xf %s",fileName.Data());
352 gSystem->Exec(command.Data());
356 if (nrPhysDeadFiles==0) {
357 Log(Form("Could not find files with id %s. Should be present for each run.",idD.Data()));
360 // Create new database entries
361 TObjArray* spdEntryDead = new TObjArray(240);
362 spdEntryDead->SetOwner(kTRUE);
363 for(UInt_t module=0; module<240; module++){
364 AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
365 spdEntryDead->Add(calObj);
367 // Add dead from the copied FXS files
368 handOld->SetFileLocation(".");
369 handOld->ReadDeadFromFiles();
370 for (Int_t module=0; module<240; module++) {
371 ((AliITSCalibrationSPD*) spdEntryDead->At(module)) -> SetNrBad( handOld->GetNrDead(module) );
372 ((AliITSCalibrationSPD*) spdEntryDead->At(module)) -> SetBadList( handOld->GetDeadArray(module) );
375 // Store the new calibration objects in OCDB
376 Log("Dead lists (phys) will be stored...");
377 AliCDBMetaData metaData;
378 metaData.SetBeamPeriod(0);
379 metaData.SetResponsible("Henrik Tydesjo");
380 metaData.SetComment("Created by SPD PreProcessor");
381 // validity for this run only
382 if (!Store("Calib", "SPDDead", spdEntryDead, &metaData, 0, kFALSE)) {
383 Log("Failed to store calibration data.");
386 Log("Database updated.");
392 // check that there are no ids left in the list:
393 if (fIdList.First()!=NULL) {
394 TString logMessage = "";
395 TListIter *iter = new TListIter(&fIdList);
396 while (TObjString *st = (TObjString*)iter->Next()) {
397 logMessage.Append(st->GetString());
398 logMessage.Append(" ");
401 Log(Form("Files with the following ids were never retrieved: %s.",logMessage.Data()));
407 return 0; // 0 means success
410 //_________________________________________________________________________________________
411 Bool_t AliITSPreprocessorSPD::RemoveIdFromList(const Char_t *id) {
412 // removes id from the list of ids
413 Bool_t found = kFALSE;
414 TListIter *iter = new TListIter(&fIdList);
415 while (TObjString *st = (TObjString*)iter->Next()) {
416 if (st->GetString().CompareTo(id)==0) {
425 //_________________________________________________________________________________________
426 Bool_t AliITSPreprocessorSPD::StoreRefFromTarForId(const Char_t *id) {
427 // store reference files from tar file for the id given (this is just to not duplicate code)
428 TList* list = GetFileSources(kDAQ,id);
431 while (list->At(index)!=NULL) {
432 TObjString* fileNameEntry = (TObjString*) list->At(index);
433 TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
434 if (fileName.IsNull()) {
435 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
438 if (!RemoveIdFromList(id)) {
439 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id));
441 // get the file names from the tar file
442 // TString pwd = gSystem->pwd();
443 // TString tempFileName = Form("%s/tempTar.txt",pwd.Data());
444 TString tempFileName = "tempTar.txt";
445 TString command = Form("tar -tf %s > %s",fileName.Data(),tempFileName.Data());
446 gSystem->Exec(command.Data());
449 tempFile.open(tempFileName.Data(), ifstream::in);
450 if (tempFile.fail()) {
451 Log(Form("Could not open file (%s) for reading.",tempFileName.Data()));
458 if (tempFile.eof()) break;
459 fList.AddLast(new TObjString(fileN));
462 // close and remove temp file
464 command = Form("rm -f %s",tempFileName.Data());
465 gSystem->Exec(command.Data());
467 command = Form("tar -xf %s",fileName.Data());
468 gSystem->Exec(command.Data());
471 while (fList.At(index2)!=NULL) {
472 TString fileName = ((TObjString*)fList.At(index2))->GetString();
474 TString eqStr = fileName.Data();
475 UInt_t len = eqStr.Length();
476 eqStr.Replace(0,len-7,"",0);
477 eqStr.ReplaceAll("_",1,"",0);
478 eqStr.ReplaceAll(".root",5,"",0);
479 Int_t eqId = eqStr.Atoi();
480 if (eqId>=0 && eqId<20) {
481 TString refCAT = Form("%s_eq_%d",id,eqId);
482 if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
483 Log(Form("Failed to store reference file %s.",fileName.Data()));
488 Log(Form("Eq ID %d out of bounds for file %s",eqId,fileName.Data()));