1 ///////////////////////////////////////////////
2 // Author: Henrik Tydesjo //
3 // Preprocessor Class for the SPD //
5 ///////////////////////////////////////////////
7 #include "AliITSPreprocessorSPD.h"
8 #include "AliITSCalibrationSPD.h"
9 #include "AliITSOnlineCalibrationSPD.h"
10 #include "AliITSOnlineCalibrationSPDhandler.h"
11 #include "AliCDBManager.h"
12 #include "AliCDBStorage.h"
13 #include "AliCDBEntry.h"
14 #include "AliCDBMetaData.h"
15 #include "AliShuttleInterface.h"
17 #include <TTimeStamp.h>
18 #include <TObjString.h>
21 ClassImp(AliITSPreprocessorSPD)
23 //______________________________________________________________________________________________
24 AliITSPreprocessorSPD::AliITSPreprocessorSPD(AliShuttleInterface* shuttle) :
25 AliPreprocessor("SPD", shuttle)
30 //______________________________________________________________________________________________
31 AliITSPreprocessorSPD::~AliITSPreprocessorSPD()
36 //______________________________________________________________________________________________
37 void AliITSPreprocessorSPD::Initialize(Int_t run, UInt_t startTime,
41 AliPreprocessor::Initialize(run, startTime, endTime);
43 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
44 TTimeStamp(startTime).AsString(),
45 TTimeStamp(endTime).AsString()));
48 //______________________________________________________________________________________________
49 UInt_t AliITSPreprocessorSPD::Process(TMap* /*dcsAliasMap*/)
51 // Do the actual preprocessing
54 // *** REFERENCE DATA ***
56 // OLD algorithm (commented out)!!!
57 // ***********************************************************
58 // // Store the container files as reference data (one for each equipment)
59 // for (UInt_t eq=0; eq<20; eq++) {
61 // sprintf(id,"SPDref%d",eq);
62 // TList* list = GetFileSources(kDAQ,id); // (the id is actually unique, so always 1 file)
64 // TObjString* fileNameEntry = (TObjString*) list->First();
65 // Char_t* fileName = (Char_t*) GetFile(kDAQ, id, fileNameEntry->GetString().Data());
66 // AliITSOnlineSPDscan *scan = new AliITSOnlineSPDscan((Char_t*)fileName);
67 // TObjArray* arr = scan->GetAsTObjArray();
69 // sprintf(refCAT,"Ref%d",eq);
70 // StoreReferenceData("SHUTTLE", refCAT, arr, &metaData, 0, 0);
73 // ***********************************************************
75 // Store the container files as reference data (one file for each equipment)
76 for (UInt_t eq=0; eq<20; eq++) {
78 sprintf(id,"SPD_reference_%d",eq);
79 TList* list = GetFileSources(kDAQ,id); // (the id should be unique, so always 1 file)
81 TObjString* fileNameEntry = (TObjString*) list->First();
82 if (fileNameEntry!=NULL) {
83 TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
85 sprintf(refCAT,"SPDref_eq_%d.root",eq);
86 if (!StoreReferenceFile(fileName.Data(),refCAT)) {
96 // OLD algorithm (commented out)!!!
97 // ***********************************************************
98 // // Read old calibration
99 // AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
100 // TObjArray* spdEntry;
102 // spdEntry = (TObjArray*)cdbEntry->GetObject();
103 // if(!spdEntry) return 0;
106 // Log(Form("Old calibration not found in database. A fresh one will be created."));
107 // // Create fresh calibration
108 // spdEntry = new TObjArray(240);
109 // for(Int_t module=0;module<240;module++){
110 // AliITSCalibrationSPD* cal = new AliITSCalibrationSPD();
111 // spdEntry->Add(cal);
113 // spdEntry->SetOwner(kTRUE);
115 // ***********************************************************
117 // Read old calibration
118 AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
121 spdEntry = (TObjArray*)cdbEntry->GetObject();
122 if(!spdEntry) return 1;
125 Log("Old calibration not found in database. This is required for further processing.");
129 TString pwd = gSystem->pwd(); // remember the working directory, to cd back later
130 TString tempDir = Form("%s",AliShuttleInterface::GetShuttleTempDir());
132 // Retrieve and unpack tared calibration files from FXS
133 TList* list = GetFileSources(kDAQ,"SPD_noisy");
136 while (list->At(index)!=NULL) {
137 TObjString* fileNameEntry = (TObjString*) list->At(index);
138 TString fileName = GetFile(kDAQ, "SPD_noisy", fileNameEntry->GetString().Data());
139 gSystem->cd(tempDir.Data());
141 sprintf(command,"tar -xf %s",fileName.Data());
142 gSystem->Exec(command);
147 gSystem->cd(pwd.Data());
149 // Update the database entries if needed
150 UInt_t nrUpdatedMods = 0;
151 AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
153 sprintf(fileLoc,"%s",AliShuttleInterface::GetShuttleTempDir());
154 handler->SetFileLocation(fileLoc);
155 for (Int_t module=0; module<240; module++) {
156 handler->SetModuleNr(module);
157 if (handler->ReadFromFile()) {
158 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( handler->GetNrNoisy() );
159 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( handler->GetNoisyArray() );
164 if (nrUpdatedMods>0) {
165 Log(Form("Noisy lists for %d modules will be updated and stored...",nrUpdatedMods));
166 // Store the cdb entry
167 AliCDBMetaData metaData;
168 metaData.SetBeamPeriod(0);
169 metaData.SetResponsible("Henrik Tydesjo");
170 metaData.SetComment("Preprocessor test for SPD.");
171 if (!Store("Calib", "SPDNoisy", spdEntry, &metaData, 0, kTRUE)) {
175 Log("Database updated.");
178 return 0; // 0 means success