]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSPD.cxx
1. Improved implementation of AliITSIntMap and AliITSOnlineCalibrationSPDhandler...
[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
57
58   // *** REFERENCE DATA *** //
59
60   // Standalone runs:
61   if (runType == "DAQ_MIN_TH_SCAN" ||
62       runType == "DAQ_MEAN_TH_SCAN" ||
63       runType == "DAQ_UNIFORMITY_SCAN" ||
64       runType == "DAQ_NOISY_PIX_SCAN" ||
65       runType == "DAQ_PIX_DELAY_SCAN" ||
66       runType == "DAQ_FO_UNIF_SCAN") {
67     // Store the scan container files as reference data (one file for each equipment)
68     for (UInt_t eq=0; eq<20; eq++) {
69       TString id = Form("SPD_reference_%d",eq);
70       TList* list = GetFileSources(kDAQ,id.Data()); // (the id should be unique, so always 1 file)
71       if (list) {
72         TObjString* fileNameEntry = (TObjString*) list->First();
73         if (fileNameEntry!=NULL) {
74           TString fileName = GetFile(kDAQ, id, fileNameEntry->GetString().Data());
75           TString refCAT = Form("SPDref_eq_%d.root",eq);
76           if (!StoreReferenceFile(fileName.Data(),refCAT.Data())) {
77             Log(Form("Failed to store reference file %s.",fileName.Data()));
78             return 1;
79           }
80         }
81       }
82     }
83   }
84
85   // Physics runs (online monitoring):
86   if (runType == "PHYSICS") {
87     // *** code to be written *** //
88   }
89
90
91
92   // *** NOISY AND DEAD DATA *** //
93
94   if (runType == "DAQ_NOISY_PIX_SCAN" || runType == "PHYSICS") {
95     // Read old calibration
96     AliCDBEntry* cdbEntry = GetFromOCDB("Calib", "CalibSPD");
97     TObjArray* spdEntry;
98     if(cdbEntry) {
99       spdEntry = (TObjArray*)cdbEntry->GetObject();
100       if(!spdEntry) return 1;
101     }
102     else {
103       Log("Old calibration not found in database. This is required for further processing.");
104       return 1;
105     }
106
107     // Standalone runs:
108     if (runType == "DAQ_NOISY_PIX_SCAN") {
109       UInt_t nrUpdatedMods = 0;
110       // Retrieve and unpack tared calibration files from FXS
111       TList* list = GetFileSources(kDAQ,"SPD_noisy");
112       if (list) {
113         UInt_t index = 0;
114         while (list->At(index)!=NULL) {
115           TObjString* fileNameEntry = (TObjString*) list->At(index);
116           TString fileName = GetFile(kDAQ, "SPD_noisy", fileNameEntry->GetString().Data());
117           TString command = Form("tar -xf %s",fileName.Data());
118           gSystem->Exec(command.Data());
119           index++;
120         }
121       }
122       // Update the database entries for the modules that were scanned
123       AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
124       TString fileLoc = ".";
125       handler->SetFileLocation(fileLoc.Data());
126       for (Int_t module=0; module<240; module++) {
127         if (handler->ReadFromFile(module)) {
128           ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( handler->GetNrNoisy(module) );
129           ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( handler->GetNoisyArray(module) );
130           nrUpdatedMods++;
131         }
132       }
133       delete handler;
134       // Store the new calibration objects (if any modifications were made) in OCDB
135       if (nrUpdatedMods>0) {
136         Log(Form("Noisy lists for %d modules will be updated and stored...",nrUpdatedMods));
137         AliCDBMetaData metaData;
138         metaData.SetBeamPeriod(0);
139         metaData.SetResponsible("Henrik Tydesjo");
140         metaData.SetComment("Preprocessor test for SPD.");  
141         if (!Store("Calib", "CalibSPD", spdEntry, &metaData, 0, kTRUE)) {
142           Log("Failed to store calibration data.");
143           return 1;
144         }
145         Log("Database updated.");
146       }
147     }
148
149     // Physics runs (online monitoring):
150     if (runType == "PHYSICS") {
151       // *** code to be written *** //
152     }
153
154
155   }
156
157
158
159   return 0; // 0 means success
160
161 }
162