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_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");
37 fIdList.SetOwner(kTRUE);
40 //______________________________________________________________________________________________
41 AliITSPreprocessorSPD::~AliITSPreprocessorSPD()
46 //______________________________________________________________________________________________
47 void AliITSPreprocessorSPD::Initialize(Int_t run, UInt_t startTime,
51 AliPreprocessor::Initialize(run, startTime, endTime);
53 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
54 TTimeStamp(startTime).AsString(),
55 TTimeStamp(endTime).AsString()));
58 //______________________________________________________________________________________________
59 UInt_t AliITSPreprocessorSPD::Process(TMap* /*dcsAliasMap*/)
61 // Do the actual preprocessing
64 // *** GET RUN TYPE ***
66 TString runType = GetRunType();
70 UInt_t nrEqForScan = 0;
71 // UInt_t nrEqForPhysN = 0;
72 // UInt_t nrEqForPhysD = 0;
74 // ******************************************************************************************** //
75 // *** GET THE FILE IDs FOR DEBUGGING *** //
76 if (runType == "DAQ_MIN_TH_SCAN" ||
77 runType == "DAQ_MEAN_TH_SCAN" ||
78 runType == "DAQ_GEN_DAC_SCAN" ||
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());
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()));
97 idFile.open(fileName.Data(), ifstream::in);
99 Log(Form("Could not open file (%s) for reading.",fileName.Data()));
106 if (idFile.eof()) break;
107 // Add id to the list;
108 fIdList.AddLast(new TObjString(id));
116 Log("Failed to retrieve any id list file.");
122 // ******************************************************************************************** //
123 // *** REFERENCE DATA *** //
126 if (runType == "DAQ_MIN_TH_SCAN" ||
127 runType == "DAQ_MEAN_TH_SCAN" ||
128 runType == "DAQ_GEN_DAC_SCAN" ||
129 runType == "DAQ_UNIFORMITY_SCAN" ||
130 runType == "DAQ_NOISY_PIX_SCAN" ||
131 runType == "DAQ_PIX_DELAY_SCAN" ||
132 runType == "DAQ_FO_UNIF_SCAN") {
133 // Store the scan container files as reference data (0 or 1 file for each equipment)
134 for (UInt_t eq=0; eq<20; eq++) {
135 TString id = Form("SPD_ref_scan_%d",eq);
136 TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
138 TObjString* fileNameEntry = (TObjString*) list->First();
139 if (fileNameEntry!=NULL) {
141 TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
142 if (fileName.IsNull()) {
143 Log(Form("GetFile failed to retrieve file %s.",fileNameEntry->GetString().Data()));
146 if (!RemoveIdFromList(id.Data())) {
147 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
149 TString refCAT = Form("SPD_ref_scan_eq_%d",eq);
150 if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
151 Log(Form("Failed to store reference file %s.",fileName.Data()));
159 // Physics runs (online monitoring):
160 if (runType == "PHYSICS") {
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;
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)
173 // TObjString* fileNameEntry = (TObjString*) list->First();
174 // if (fileNameEntry!=NULL) {
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()));
181 // if (!RemoveIdFromList(id.Data())) {
182 // Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
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()));
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)
200 // TObjString* fileNameEntry = (TObjString*) list->First();
201 // if (fileNameEntry!=NULL) {
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()));
208 // if (!RemoveIdFromList(id.Data())) {
209 // Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
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()));
222 // ******************************************************************************************** //
225 // *** NOISY AND DEAD DATA *** //
228 if (runType == "DAQ_NOISY_PIX_SCAN") {
229 // Retrieve and unpack tared calibration files from FXS
230 TString id = "SPD_scan_noisy";
231 TList* list = GetFileSources(kDAQ,id.Data());
234 while (list->At(index)!=NULL) {
235 TObjString* fileNameEntry = (TObjString*) list->At(index);
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()));
241 if (!RemoveIdFromList("SPD_scan_noisy")) {
242 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id.Data()));
244 TString command = Form("tar -xf %s",fileName.Data());
245 gSystem->Exec(command.Data());
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);
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) );
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.");
277 Log("Database updated.");
278 delete spdEntryNoisy;
281 // Physics runs (online monitoring):
282 else if (runType == "PHYSICS") {
285 // Read noisy from previous calibration
286 AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
287 TObjArray* spdEntryNoisy;
289 spdEntryNoisy = (TObjArray*)cdbEntry->GetObject();
290 if(!spdEntryNoisy) return 1;
293 Log("Old calibration not found in database. This is required for further processing.");
296 AliITSOnlineCalibrationSPDhandler* handOld = new AliITSOnlineCalibrationSPDhandler();
297 handOld->ReadNoisyFromCalibObj(spdEntryNoisy);
298 // Retrieve and unpack tared calibration files from FXS
299 TString idN = "SPD_phys_noisy";
300 TList* listN = GetFileSources(kDAQ,idN.Data());
303 while (listN->At(index)!=NULL) {
304 TObjString* fileNameEntry = (TObjString*) listN->At(index);
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()));
310 if (!RemoveIdFromList(idN.Data())) {
311 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idN.Data()));
313 TString command = Form("tar -xf %s",fileName.Data());
314 gSystem->Exec(command.Data());
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
325 for (Int_t module=0; module<240; module++) {
326 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBad( handOld->GetNrNoisy(module) );
327 ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handOld->GetNoisyArray(module) );
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.");
340 Log("Database updated.");
345 // Retrieve and unpack tared calibration files from FXS
346 TString idD = "SPD_phys_dead";
347 TList* listD = GetFileSources(kDAQ,idD.Data());
348 UInt_t nrPhysDeadFiles = 0;
351 while (listD->At(index)!=NULL) {
352 TObjString* fileNameEntry = (TObjString*) listD->At(index);
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()));
359 if (!RemoveIdFromList("SPD_phys_dead")) {
360 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",idD.Data()));
362 TString command = Form("tar -xf %s",fileName.Data());
363 gSystem->Exec(command.Data());
367 if (nrPhysDeadFiles==0) {
368 Log(Form("Could not find files with id %s. Should be present for each run.",idD.Data()));
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);
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) );
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.");
397 Log("Database updated.");
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(" ");
412 Log(Form("Files with the following ids were never retrieved: %s.",logMessage.Data()));
418 return 0; // 0 means success
421 //_________________________________________________________________________________________
422 Bool_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) {
436 //_________________________________________________________________________________________
437 Bool_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);
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()));
449 if (!RemoveIdFromList(id)) {
450 Log(Form("Warning: Retrieved file with id %s, that was not in the id list!",id));
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());
460 tempFile.open(tempFileName.Data(), ifstream::in);
461 if (tempFile.fail()) {
462 Log(Form("Could not open file (%s) for reading.",tempFileName.Data()));
469 if (tempFile.eof()) break;
470 fList.AddLast(new TObjString(fileN));
473 // close and remove temp file
475 command = Form("rm -f %s",tempFileName.Data());
476 gSystem->Exec(command.Data());
478 command = Form("tar -xf %s",fileName.Data());
479 gSystem->Exec(command.Data());
482 while (fList.At(index2)!=NULL) {
483 TString eqFileName = ((TObjString*)fList.At(index2))->GetString();
485 TString eqStr = eqFileName.Data();
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);
493 if (!StoreReferenceFile(eqFileName.Data(),refCAT.Data())) {
494 Log(Form("Failed to store reference file %s.",eqFileName.Data()));
499 Log(Form("Eq ID %d out of bounds for file %s",eqId,eqFileName.Data()));