Fixes for SSD detector algorithms and preprocessor (Panos)
[u/mrichter/AliRoot.git] / ITS / AliITSPreprocessorSSD.cxx
CommitLineData
5ca85244 1#include "AliITSPreprocessorSSD.h"
51e983b7 2
5ca85244 3#include "AliCDBMetaData.h"
4#include "AliLog.h"
5#include "TFile.h"
6
7#include <TTimeStamp.h>
8#include <TObjString.h>
9
10#include "AliITSRawStreamSSD.h"
11#include "AliITSNoiseSSD.h"
a5edfa6f 12#include "AliITSPedestalSSD.h"
13#include "AliITSBadChannelsSSD.h"
5ca85244 14#include <Riostream.h>
15
16
17//
18// Author: Enrico Fragiacomo
19// Date: 13/10/2006
20//
21// SHUTTLE preprocessing class for SSD calibration files
22
23/* $Id$ */
24
a5edfa6f 25const Int_t AliITSPreprocessorSSD::fgkNumberOfSSD = 1698;
26
5ca85244 27ClassImp(AliITSPreprocessorSSD)
28
51e983b7 29//-----------------------------------------------------------------------
30AliITSPreprocessorSSD::AliITSPreprocessorSSD(AliShuttleInterface* shuttle) :
31 AliPreprocessor("SSD", shuttle)
32{
33 // constructor
34
35 AddRunType("ELECTRONICS_CALIBRATION_RUN");
36 AddRunType("PEDESTAL");
37 AddRunType("PHYSICS");
38
39}
40
41///______________________________________________________________________________________________
5ca85244 42void AliITSPreprocessorSSD::Initialize(Int_t run, UInt_t startTime,
43 UInt_t endTime)
44{
45
46 AliPreprocessor::Initialize(run, startTime, endTime);
47
48 Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
49 TTimeStamp(startTime).AsString(),
50 TTimeStamp(endTime).AsString()));
51
52}
53
54//______________________________________________________________________________________________
55UInt_t AliITSPreprocessorSSD::Process(TMap* /*dcsAliasMap*/)
56{
57
58 // Note. To be modified: dcsAliasMap is not needed but I can not get rid
59 // of it unless the base class AliPreprocessor is modified accordingly.
60
ced4d9bc 61 // TObjArray calib_array(fgkNumberOfSSD);
62 //TObjArray badch_array(fgkNumberOfSSD);
63 //TObjArray ped_array(fgkNumberOfSSD);
5ca85244 64 //Float_t noise=0, gain=0;
c9a38d3d 65
ced4d9bc 66 //---------------------------------------
67 // initialize the calibration objects
68 AliITSNoiseSSD *calib = new AliITSNoiseSSD();
69 AliITSBadChannelsSSD *badch = new AliITSBadChannelsSSD();
70 AliITSPedestalSSD *pedel = new AliITSPedestalSSD();
71
5ca85244 72 TString runType = GetRunType();
c9a38d3d 73 if(runType == "ELECTRONICS_CALIBRATION_RUN") {
74
5ca85244 75 }
c96050be 76 else if(runType == "PEDESTAL") {
5ca85244 77
78 TList* list = GetFileSources(kDAQ, "CALIBRATION");
79 if (list && list->GetEntries() > 0)
80 {
81 Log("The following sources produced files with the id CALIBRATION");
82 list->Print();
83
84 // create iterator over list of LDCs (provides list of TObjString)
85 TIter next(list);
86 TObjString *ok;
87
88 // expect to iterate 3 times (LDC0, LDC1, LDC2)
89 while ( (ok = (TObjString*) next()) ) {
90
91 TString key = ok->String();
92
93 TString fileName = GetFile(kDAQ, "CALIBRATION", key.Data());
94 if (fileName.Length() > 0) {
95
96 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
97
98 TFile *f = new TFile(fileName.Data());
99 if(!f || !f->IsOpen()){
100 Log("Error opening file!");
101 delete list;
102 return 2;
103 }
104
ced4d9bc 105 AliITSNoiseSSD *cal;
61a57d07 106 f->GetObject("AliITSNoiseSSD;1", cal);
5ca85244 107 if(!cal) {
a5edfa6f 108 Log("File does not contain expected data for the noise!");
5ca85244 109 delete list;
375ec901 110 return 3;
a5edfa6f 111 }
ced4d9bc 112 AliITSPedestalSSD *ped;
61a57d07 113 f->GetObject("AliITSPedestalSSD;1", ped);
ced4d9bc 114 if(!ped) {
115 Log("File does not contain expected data for the pedestals!");
116 delete list;
117 return 5;
118 }
119 AliITSBadChannelsSSD *bad;
61a57d07 120 f->GetObject("AliITSBadChannelsSSD;1", bad);
a5edfa6f 121 if(!bad) {
122 Log("File does not contain expected data for bad channels !");
123 delete list;
375ec901 124 return 4;
a5edfa6f 125 }
5ca85244 126
ced4d9bc 127 for(Int_t module=0; module<fgkNumberOfSSD; module++) {
128 for(Int_t strip=0; strip<768; strip++) {
129 if(cal->GetNoiseP(module,strip))
130 calib->AddNoiseP(module,strip,cal->GetNoiseP(module,strip));
131 if(cal->GetNoiseN(module,strip))
132 calib->AddNoiseN(module,strip,cal->GetNoiseN(module,strip));
133 if(ped->GetPedestalP(module,strip))
134 pedel->AddPedestalP(module,strip,
135 ped->GetPedestalP(module,strip));
136 if(ped->GetPedestalN(module,strip))
137 pedel->AddPedestalN(module,strip,
138 ped->GetPedestalN(module,strip));
139 if(bad->GetBadChannelP(module,strip))
140 badch->AddBadChannelP(module,strip,
141 bad->GetBadChannelP(module,strip));
142 if(bad->GetBadChannelN(module,strip))
143 badch->AddBadChannelN(module,strip,
144 bad->GetBadChannelN(module,strip));
145 }
5ca85244 146 }
a5edfa6f 147
148 f->Close(); delete f;
5ca85244 149
150 } else {
151 Log("GetFile error!");
152 delete list;
375ec901 153 return 6;
5ca85244 154 } // if filename
155 } // end iteration over LDCs
156
157 delete list;
158 } else {
159 Log("GetFileSources error!");
160 if(list) delete list;
375ec901 161 return 7;
5ca85244 162 } // if list
163
61a57d07 164 //Now we have to store the final CDB file
165 AliCDBMetaData metaData;
166 metaData.SetBeamPeriod(0);
167 metaData.SetResponsible("Enrico Fragiacomo");
168 metaData.SetComment("Fills noise, pedestal and bad channels TObjArray");
169
170 if(!Store("Calib", "NoiseSSD", (TObject *)calib, &metaData, 0, 1)) {
a5edfa6f 171 Log("no store");
5ca85244 172 return 1;
a5edfa6f 173 }
174
61a57d07 175 if(!Store("Calib", "BadChannelsSSD", (TObject*)badch, &metaData, 0, 1)) {
a5edfa6f 176 Log("no store");
177 return 1;
178 }
179
61a57d07 180 if(!StoreReferenceData("Calib","PedestalSSD", (TObject*)pedel, &metaData)) {
a5edfa6f 181 Log("no store");
182 return 1;
183 }
184
51e983b7 185 } // end if pedestal run
5ca85244 186 else {
187 Log("Nothing to do");
188 return 0;
189 }
190
191 Log("Database updated");
192 return 0; // 0 means success
193
194}
195