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 AddRunType("DAQ_MIN_TH_SCAN");
29 AddRunType("DAQ_MEAN_TH_SCAN");
30 AddRunType("DAQ_UNIFORMITY_SCAN");
31 AddRunType("DAQ_NOISY_PIX_SCAN");
32 AddRunType("DAQ_PIX_DELAY_SCAN");
33 AddRunType("DAQ_FO_UNIF_SCAN");
34 AddRunType("PHYSICS");
36 fIdList.SetOwner(kTRUE);
39 //______________________________________________________________________________________________
40 AliITSPreprocessorSPD::~AliITSPreprocessorSPD()
45 //______________________________________________________________________________________________
46 void AliITSPreprocessorSPD::Initialize(Int_t run, UInt_t startTime,
50 AliPreprocessor::Initialize(run, startTime, endTime);
52 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
53 TTimeStamp(startTime).AsString(),
54 TTimeStamp(endTime).AsString()));
57 //______________________________________________________________________________________________
58 UInt_t AliITSPreprocessorSPD::Process(TMap* /*dcsAliasMap*/)
60 // Do the actual preprocessing
63 // *** GET RUN TYPE ***
65 TString runType = GetRunType();
69 UInt_t nrEqForScan = 0;
70 // UInt_t nrEqForPhysN = 0;
71 // UInt_t nrEqForPhysD = 0;
73 // ******************************************************************************************** //
74 // *** GET THE FILE IDs FOR DEBUGGING *** //
75 if (runType == "DAQ_MIN_TH_SCAN" ||
76 runType == "DAQ_MEAN_TH_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());
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()));
95 idFile.open(fileName.Data(), ifstream::in);
97 Log(Form("Could not open file (%s) for reading.",fileName.Data()));
104 if (idFile.eof()) break;
105 // Add id to the list;
106 fIdList.AddLast(new TObjString(id));
114 Log("Failed to retrieve any id list file.");
120 // ******************************************************************************************** //
121 // *** REFERENCE DATA *** //
124 if (runType == "DAQ_MIN_TH_SCAN" ||
125 runType == "DAQ_MEAN_TH_SCAN" ||
126 runType == "DAQ_UNIFORMITY_SCAN" ||
127 runType == "DAQ_NOISY_PIX_SCAN" ||
128 runType == "DAQ_PIX_DELAY_SCAN" ||
129 runType == "DAQ_FO_UNIF_SCAN") {
130 // Store the scan container files as reference data (0 or 1 file for each equipment)
131 for (UInt_t eq=0; eq<20; eq++) {
132 TString id = Form("SPD_ref_scan_%d",eq);
133 TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
135 TObjString* fileNameEntry = (TObjString*) list->First();
136 if (fileNameEntry!=NULL) {
138 TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
139 if (fileName.IsNull()) {
140 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
143 if (!RemoveIdFromList(id.Data())) {
144 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
146 TString refCAT = Form("SPD_ref_scan_eq_%d",eq);
147 if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
148 Log(Form("Failed to store reference file %s.",fileName.Data()));
156 // Physics runs (online monitoring):
157 if (runType == "PHYSICS") {
158 // Store the phys "per run" container files as reference data
159 if (!StoreRefFromTarForId("SPD_ref_phys")) return 1;
160 // Store the phys "dead" container files as reference data
161 if (!StoreRefFromTarForId("SPD_ref_phys_dead")) return 1;
165 // *** OLD CODE NOT TARED
166 // for (UInt_t eq=0; eq<20; eq++) {
167 // TString id = Form("SPD_ref_phys_%d",eq);
168 // TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
170 // TObjString* fileNameEntry = (TObjString*) list->First();
171 // if (fileNameEntry!=NULL) {
173 // TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
174 // if (fileName.IsNull()) {
175 // Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
178 // if (!RemoveIdFromList(id.Data())) {
179 // Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
181 // TString refCAT = Form("SPD_ref_phys_eq_%d",eq);
182 // if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
183 // Log(Form("Failed to store reference file %s.",fileName.Data()));
191 // *** OLD CODE NOT TARED
192 // // Store the phys "dead" container files as reference data (0 or 1 file for each equipment)
193 // for (UInt_t eq=0; eq<20; eq++) {
194 // TString id = Form("SPD_ref_phys_dead_%d",eq);
195 // TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
197 // TObjString* fileNameEntry = (TObjString*) list->First();
198 // if (fileNameEntry!=NULL) {
200 // TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
201 // if (fileName.IsNull()) {
202 // Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
205 // if (!RemoveIdFromList(id.Data())) {
206 // Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
208 // TString refCAT = Form("SPD_ref_phys_dead_eq_%d",eq);
209 // if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
210 // Log(Form("Failed to store reference file %s.",fileName.Data()));
219 // ******************************************************************************************** //
222 // *** NOISY AND DEAD DATA *** //
225 if (runType == "DAQ_NOISY_PIX_SCAN") {
226 // Retrieve and unpack tared calibration files from FXS
227 TString id = "SPD_scan_noisy";
228 TList* list = GetFileSources(kDAQ,id.Data());
231 while (list->At(index)!=NULL) {
232 TObjString* fileNameEntry = (TObjString*) list->At(index);
233 TString fileName = GetFile(kDAQ, id.Data(), fileNameEntry->GetString().Data());
234 if (fileName.IsNull()) {
235 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
238 if (!RemoveIdFromList("SPD_scan_noisy")) {
239 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
241 TString command = Form("tar -xf %s",fileName.Data());
242 gSystem->Exec(command.Data());
246 // Create new database entries
247 TObjArray* spdEntryNoisy = new TObjArray(240);
248 spdEntryNoisy->SetOwner(kTRUE);
249 for(UInt_t module=0; module<240; module++){
250 AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
251 spdEntryNoisy->Add(calObj);
253 // Add noisy from the copied FXS files
254 AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
255 TString fileLoc = ".";
256 handler->SetFileLocation(fileLoc.Data());
257 handler->ReadNoisyFromFiles();
258 for (Int_t module=0; module<240; module++) {
259 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBad( handler->GetNrNoisy(module) );
260 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handler->GetNoisyArray(module) );
263 // Store the new calibration objects in OCDB
264 Log("Noisy lists (scan) will be stored...");
265 AliCDBMetaData metaData;
266 metaData.SetBeamPeriod(0);
267 metaData.SetResponsible("Henrik Tydesjo");
268 metaData.SetComment("Created by SPD PreProcessor");
269 // validity for this run until infinity
270 if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kTRUE)) {
271 Log("Failed to store calibration data.");
274 Log("Database updated.");
275 delete spdEntryNoisy;
278 // Physics runs (online monitoring):
279 else if (runType == "PHYSICS") {
282 // Read noisy from previous calibration
283 AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
284 TObjArray* spdEntryNoisy;
286 spdEntryNoisy = (TObjArray*)cdbEntry->GetObject();
287 if(!spdEntryNoisy) return 1;
290 Log("Old calibration not found in database. This is required for further processing.");
293 AliITSOnlineCalibrationSPDhandler* handOld = new AliITSOnlineCalibrationSPDhandler();
294 handOld->ReadNoisyFromCalibObj(spdEntryNoisy);
295 // Retrieve and unpack tared calibration files from FXS
296 TString idN = "SPD_phys_noisy";
297 TList* listN = GetFileSources(kDAQ,idN.Data());
300 while (listN->At(index)!=NULL) {
301 TObjString* fileNameEntry = (TObjString*) listN->At(index);
302 TString fileName = GetFile(kDAQ, idN.Data(), fileNameEntry->GetString().Data());
303 if (fileName.IsNull()) {
304 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
307 if (!RemoveIdFromList(idN.Data())) {
308 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idN.Data()));
310 TString command = Form("tar -xf %s",fileName.Data());
311 gSystem->Exec(command.Data());
315 AliITSOnlineCalibrationSPDhandler* handNew = new AliITSOnlineCalibrationSPDhandler();
316 handNew->SetFileLocation(".");
317 handNew->ReadNoisyFromFiles();
318 // add the new list to the old one
319 UInt_t nrNewNoisy = handOld->AddNoisyFrom(handNew);
320 // If new noisy pixels were found: Update calibration objects
322 for (Int_t module=0; module<240; module++) {
323 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBad( handOld->GetNrNoisy(module) );
324 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handOld->GetNoisyArray(module) );
326 // Store the new calibration objects in OCDB
327 Log("Noisy lists (phys) will be stored...");
328 AliCDBMetaData metaData;
329 metaData.SetBeamPeriod(0);
330 metaData.SetResponsible("Henrik Tydesjo");
331 metaData.SetComment("Created by SPD PreProcessor");
332 // validity for this run only
333 if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kFALSE)) {
334 Log("Failed to store calibration data.");
337 Log("Database updated.");
342 // Retrieve and unpack tared calibration files from FXS
343 TString idD = "SPD_phys_dead";
344 TList* listD = GetFileSources(kDAQ,idD.Data());
345 UInt_t nrPhysDeadFiles = 0;
348 while (listD->At(index)!=NULL) {
349 TObjString* fileNameEntry = (TObjString*) listD->At(index);
350 TString fileName = GetFile(kDAQ, idD.Data(), fileNameEntry->GetString().Data());
351 if (fileName.IsNull()) {
352 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
356 if (!RemoveIdFromList("SPD_phys_dead")) {
357 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idD.Data()));
359 TString command = Form("tar -xf %s",fileName.Data());
360 gSystem->Exec(command.Data());
364 if (nrPhysDeadFiles==0) {
365 Log(Form("Could not find files with id %s. Should be present for each run.",idD.Data()));
368 // Create new database entries
369 TObjArray* spdEntryDead = new TObjArray(240);
370 spdEntryDead->SetOwner(kTRUE);
371 for(UInt_t module=0; module<240; module++){
372 AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
373 spdEntryDead->Add(calObj);
375 // Add dead from the copied FXS files
376 handOld->SetFileLocation(".");
377 handOld->ReadDeadFromFiles();
378 for (Int_t module=0; module<240; module++) {
379 ((AliITSCalibrationSPD*) spdEntryDead->At(module)) -> SetNrBad( handOld->GetNrDead(module) );
380 ((AliITSCalibrationSPD*) spdEntryDead->At(module)) -> SetBadList( handOld->GetDeadArray(module) );
383 // Store the new calibration objects in OCDB
384 Log("Dead lists (phys) will be stored...");
385 AliCDBMetaData metaData;
386 metaData.SetBeamPeriod(0);
387 metaData.SetResponsible("Henrik Tydesjo");
388 metaData.SetComment("Created by SPD PreProcessor");
389 // validity for this run only
390 if (!Store("Calib", "SPDDead", spdEntryDead, &metaData, 0, kFALSE)) {
391 Log("Failed to store calibration data.");
394 Log("Database updated.");
400 // check that there are no ids left in the list:
401 if (fIdList.First()!=NULL) {
402 TString logMessage = "";
403 TListIter *iter = new TListIter(&fIdList);
404 while (TObjString *st = (TObjString*)iter->Next()) {
405 logMessage.Append(st->GetString());
406 logMessage.Append(" ");
409 Log(Form("Files with the following ids were never retrieved: %s.",logMessage.Data()));
415 return 0; // 0 means success
418 //_________________________________________________________________________________________
419 Bool_t AliITSPreprocessorSPD::RemoveIdFromList(const Char_t *id) {
420 // removes id from the list of ids
421 Bool_t found = kFALSE;
422 TListIter *iter = new TListIter(&fIdList);
423 while (TObjString *st = (TObjString*)iter->Next()) {
424 if (st->GetString().CompareTo(id)==0) {
433 //_________________________________________________________________________________________
434 Bool_t AliITSPreprocessorSPD::StoreRefFromTarForId(const Char_t *id) {
435 // store reference files from tar file for the id given (this is just to not duplicate code)
436 TList* list = GetFileSources(kDAQ,id);
439 while (list->At(index)!=NULL) {
440 TObjString* fileNameEntry = (TObjString*) list->At(index);
441 TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
442 if (fileName.IsNull()) {
443 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
446 if (!RemoveIdFromList(id)) {
447 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id));
449 // get the file names from the tar file
450 // TString pwd = gSystem->pwd();
451 // TString tempFileName = Form("%s/tempTar.txt",pwd.Data());
452 TString tempFileName = "tempTar.txt";
453 TString command = Form("tar -tf %s > %s",fileName.Data(),tempFileName.Data());
454 gSystem->Exec(command.Data());
457 tempFile.open(tempFileName.Data(), ifstream::in);
458 if (tempFile.fail()) {
459 Log(Form("Could not open file (%s) for reading.",tempFileName.Data()));
466 if (tempFile.eof()) break;
467 fList.AddLast(new TObjString(fileN));
470 // close and remove temp file
472 command = Form("rm -f %s",tempFileName.Data());
473 gSystem->Exec(command.Data());
475 command = Form("tar -xf %s",fileName.Data());
476 gSystem->Exec(command.Data());
479 while (fList.At(index2)!=NULL) {
480 TString fileName = ((TObjString*)fList.At(index2))->GetString();
482 TString eqStr = fileName.Data();
483 UInt_t len = eqStr.Length();
484 eqStr.Replace(0,len-7,"",0);
485 eqStr.ReplaceAll("_",1,"",0);
486 eqStr.ReplaceAll(".root",5,"",0);
487 Int_t eqId = eqStr.Atoi();
488 if (eqId>=0 && eqId<20) {
489 TString refCAT = Form("%s_eq_%d",id,eqId);
490 if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
491 Log(Form("Failed to store reference file %s.",fileName.Data()));
496 Log(Form("Eq ID %d out of bounds for file %s",eqId,fileName.Data()));