]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSPD.cxx
Run number initialized to -1.
[u/mrichter/AliRoot.git] / ITS / AliITSPreprocessorSPD.cxx
1 ///////////////////////////////////////////////
2 //  Author: Henrik Tydesjo                   //
3 //  Preprocessor Class for the SPD           //
4 //                                           //
5 ///////////////////////////////////////////////
6
7 #include "AliITSPreprocessorSPD.h"
8 #include "AliITSCalibrationSPD.h"
9 #include "AliITSOnlineCalibrationSPDhandler.h"
10 #include "AliCDBEntry.h"
11 #include "AliCDBMetaData.h"
12 #include "AliShuttleInterface.h"
13 #include "AliLog.h"
14 #include <TTimeStamp.h>
15 #include <TObjString.h>
16 #include <TSystem.h>
17 #include <TList.h>
18
19 ClassImp(AliITSPreprocessorSPD)
20
21 //______________________________________________________________________________________________
22 AliITSPreprocessorSPD::AliITSPreprocessorSPD(AliShuttleInterface* shuttle) :
23   AliPreprocessor("SPD", shuttle)
24 {
25   // constructor
26 }
27
28 //______________________________________________________________________________________________
29 AliITSPreprocessorSPD::~AliITSPreprocessorSPD()
30 {
31   // destructor
32 }
33
34 //______________________________________________________________________________________________
35 void AliITSPreprocessorSPD::Initialize(Int_t run, UInt_t startTime,
36         UInt_t endTime)
37 {
38   // initialize
39   AliPreprocessor::Initialize(run, startTime, endTime);
40
41   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
42                TTimeStamp(startTime).AsString(),
43                TTimeStamp(endTime).AsString()));
44 }
45
46 //______________________________________________________________________________________________
47 UInt_t AliITSPreprocessorSPD::Process(TMap* /*dcsAliasMap*/)
48 {
49   // Do the actual preprocessing
50
51
52   // *** GET RUN TYPE ***
53
54   TString runType = GetRunType();
55
56   UInt_t nrEqForScan  = 0;
57   UInt_t nrEqForPhysN = 0;
58   UInt_t nrEqForPhysD = 0;
59
60   // ******************************************************************************************** //
61   // *** REFERENCE DATA *** //
62
63   // Standalone runs:
64   if (runType == "DAQ_MIN_TH_SCAN" ||
65       runType == "DAQ_MEAN_TH_SCAN" ||
66       runType == "DAQ_UNIFORMITY_SCAN" ||
67       runType == "DAQ_NOISY_PIX_SCAN" ||
68       runType == "DAQ_PIX_DELAY_SCAN" ||
69       runType == "DAQ_FO_UNIF_SCAN") {
70     // Store the scan container files as reference data (0 or 1 file for each equipment)
71     for (UInt_t eq=0; eq<20; eq++) {
72       TString id = Form("SPD_ref_scan_%d",eq);
73       TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
74       if (list) {
75         TObjString* fileNameEntry = (TObjString*) list->First();
76         if (fileNameEntry!=NULL) {
77           nrEqForScan++;
78           TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
79           TString refCAT = Form("SPD_ref_scan_eq_%d",eq);
80           if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
81             Log(Form("Failed to store reference file %s.",fileName.Data()));
82             return 1;
83           }
84         }
85       }
86     }
87   }
88
89   // Physics runs (online monitoring):
90   if (runType == "PHYSICS") {
91     // Store the phys "per run" container files as reference data (0 or 1 file for each equipment)
92     for (UInt_t eq=0; eq<20; eq++) {
93       TString id = Form("SPD_ref_phys_%d",eq);
94       TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
95       if (list) {
96         TObjString* fileNameEntry = (TObjString*) list->First();
97         if (fileNameEntry!=NULL) {
98           nrEqForPhysN++;
99           TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
100           TString refCAT = Form("SPD_ref_phys_eq_%d",eq);
101           if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
102             Log(Form("Failed to store reference file %s.",fileName.Data()));
103             return 1;
104           }
105         }
106       }
107     }
108     // Store the phys "dead" container files as reference data (0 or 1 file for each equipment)
109     for (UInt_t eq=0; eq<20; eq++) {
110       TString id = Form("SPD_ref_phys_dead_%d",eq);
111       TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
112       if (list) {
113         TObjString* fileNameEntry = (TObjString*) list->First();
114         if (fileNameEntry!=NULL) {
115           nrEqForPhysD++;
116           TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
117           TString refCAT = Form("SPD_ref_phys_dead_eq_%d",eq);
118           if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
119             Log(Form("Failed to store reference file %s.",fileName.Data()));
120             return 1;
121           }
122         }
123       }
124     }
125   }
126
127   // ******************************************************************************************** //
128
129
130   // *** NOISY AND DEAD DATA *** //
131
132   // Standalone runs:
133   if (runType == "DAQ_NOISY_PIX_SCAN") {
134     // Retrieve and unpack tared calibration files from FXS
135     TList* list = GetFileSources(kDAQ,"SPD_scan_noisy");
136     if (list) {
137       UInt_t index = 0;
138       while (list->At(index)!=NULL) {
139         TObjString* fileNameEntry = (TObjString*) list->At(index);
140         TString fileName = GetFile(kDAQ, "SPD_scan_noisy", fileNameEntry->GetString().Data());
141         TString command = Form("tar -xf %s",fileName.Data());
142         gSystem->Exec(command.Data());
143         index++;
144       }
145     }
146     // Create new database entries
147     TObjArray* spdEntryNoisy = new TObjArray(240);
148     spdEntryNoisy->SetOwner(kTRUE);
149     for(UInt_t module=0; module<240; module++){
150       AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
151       spdEntryNoisy->Add(calObj);
152     }
153     // Add noisy from the copied FXS files
154     AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
155     TString fileLoc = ".";
156     handler->SetFileLocation(fileLoc.Data());
157     handler->ReadNoisyFromFiles();
158     for (Int_t module=0; module<240; module++) {
159       ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBad( handler->GetNrNoisy(module) );
160       ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handler->GetNoisyArray(module) );
161     }
162     delete handler;
163     // Store the new calibration objects in OCDB
164     Log("Noisy lists (scan) will be stored...");
165     AliCDBMetaData metaData;
166     metaData.SetBeamPeriod(0);
167     metaData.SetResponsible("Henrik Tydesjo");
168     metaData.SetComment("Created by SPD PreProcessor");
169     // validity for this run until infinity
170     if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kTRUE)) {
171       Log("Failed to store calibration data.");
172       return 1;
173     }
174     Log("Database updated.");
175     delete spdEntryNoisy;
176   }
177
178   // Physics runs (online monitoring):
179   else if (runType == "PHYSICS") {
180
181     // Noisy pixels:
182     // Read noisy from previous calibration
183     AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "SPDNoisy");
184     TObjArray* spdEntryNoisy;
185     if(cdbEntry) {
186       spdEntryNoisy = (TObjArray*)cdbEntry->GetObject();
187       if(!spdEntryNoisy) return 1;
188     }
189     else {
190       Log("Old calibration not found in database. This is required for further processing.");
191       return 1;
192     }
193     AliITSOnlineCalibrationSPDhandler* handOld = new AliITSOnlineCalibrationSPDhandler();
194     handOld->ReadNoisyFromCalibObj(spdEntryNoisy);
195     // Retrieve and unpack tared calibration files from FXS
196     TList* listN = GetFileSources(kDAQ,"SPD_phys_noisy");
197     if (listN) {
198       UInt_t index = 0;
199       while (listN->At(index)!=NULL) {
200         TObjString* fileNameEntry = (TObjString*) listN->At(index);
201         TString fileName = GetFile(kDAQ, "SPD_phys_noisy", fileNameEntry->GetString().Data());
202         TString command = Form("tar -xf %s",fileName.Data());
203         gSystem->Exec(command.Data());
204         index++;
205       }
206     }
207     AliITSOnlineCalibrationSPDhandler* handNew = new AliITSOnlineCalibrationSPDhandler();
208     handNew->SetFileLocation(".");
209     handNew->ReadNoisyFromFiles();
210     // add the new list to the old one
211     UInt_t nrNewNoisy = handOld->AddNoisyFrom(handNew);
212     // If new noisy pixels were found: Update calibration objects
213     if (nrNewNoisy>0) {
214       for (Int_t module=0; module<240; module++) {
215         ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetNrBad( handOld->GetNrNoisy(module) );
216         ((AliITSCalibrationSPD*) spdEntryNoisy->At(module)) -> SetBadList( handOld->GetNoisyArray(module) );
217       }
218       // Store the new calibration objects in OCDB
219       Log("Noisy lists (phys) will be stored...");
220       AliCDBMetaData metaData;
221       metaData.SetBeamPeriod(0);
222       metaData.SetResponsible("Henrik Tydesjo");
223       metaData.SetComment("Created by SPD PreProcessor");  
224       // validity for this run only
225       if (!Store("Calib", "SPDNoisy", spdEntryNoisy, &metaData, 0, kFALSE)) {
226         Log("Failed to store calibration data.");
227         return 1;
228       }
229       Log("Database updated.");
230     }
231     delete handNew;
232
233     // Dead pixels:
234     // Retrieve and unpack tared calibration files from FXS
235     TList* listD = GetFileSources(kDAQ,"SPD_phys_dead");
236     if (listD) {
237       UInt_t index = 0;
238       while (listD->At(index)!=NULL) {
239         TObjString* fileNameEntry = (TObjString*) listD->At(index);
240         TString fileName = GetFile(kDAQ, "SPD_phys_dead", fileNameEntry->GetString().Data());
241         TString command = Form("tar -xf %s",fileName.Data());
242         gSystem->Exec(command.Data());
243         index++;
244       }
245     }
246     // Create new database entries
247     TObjArray* spdEntryDead = new TObjArray(240);
248     spdEntryDead->SetOwner(kTRUE);
249     for(UInt_t module=0; module<240; module++){
250       AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
251       spdEntryDead->Add(calObj);
252     }
253     // Add dead from the copied FXS files
254     handOld->SetFileLocation(".");
255     handOld->ReadDeadFromFiles();
256     for (Int_t module=0; module<240; module++) {
257       ((AliITSCalibrationSPD*) spdEntryDead->At(module)) -> SetNrBad( handOld->GetNrDead(module) );
258       ((AliITSCalibrationSPD*) spdEntryDead->At(module)) -> SetBadList( handOld->GetDeadArray(module) );
259     }
260     delete handOld;
261     // Store the new calibration objects in OCDB
262     Log("Dead lists (phys) will be stored...");
263     AliCDBMetaData metaData;
264     metaData.SetBeamPeriod(0);
265     metaData.SetResponsible("Henrik Tydesjo");
266     metaData.SetComment("Created by SPD PreProcessor");
267     // validity for this run only
268     if (!Store("Calib", "SPDDead", spdEntryDead, &metaData, 0, kFALSE)) {
269       Log("Failed to store calibration data.");
270       return 1;
271     }
272     Log("Database updated.");
273     delete spdEntryDead;
274
275   }
276
277
278   return 0; // 0 means success
279
280 }
281