]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSSD.cxx
Remowing shadow warnings
[u/mrichter/AliRoot.git] / ITS / AliITSPreprocessorSSD.cxx
1 #include "AliITSPreprocessorSSD.h"
2  
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"
12 #include "AliITSPedestalSSD.h"
13 #include "AliITSBadChannelsSSD.h"
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
25 const Int_t AliITSPreprocessorSSD::fgkNumberOfSSD = 1698;
26
27 ClassImp(AliITSPreprocessorSSD)
28
29 //-----------------------------------------------------------------------
30 AliITSPreprocessorSSD::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 ///______________________________________________________________________________________________
42 void 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 //______________________________________________________________________________________________
55 UInt_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
61   TObjArray calib_array(fgkNumberOfSSD); 
62   TObjArray badch_array(fgkNumberOfSSD); 
63   TObjArray ped_array(fgkNumberOfSSD); 
64   //Float_t noise=0, gain=0;
65   
66   TString runType = GetRunType();
67   if(runType == "ELECTRONICS_CALIBRATION_RUN") {
68     
69   }
70   else if(runType == "PEDESTAL") {
71
72     TList* list = GetFileSources(kDAQ, "CALIBRATION");
73     if (list && list->GetEntries() > 0)
74       {
75         Log("The following sources produced files with the id CALIBRATION");
76         list->Print();
77         
78         // create iterator over list of LDCs (provides list of TObjString)
79         TIter next(list);
80         TObjString *ok;
81         
82         //---------------------------------------
83         // in case some module was not calibrated!
84         for(Int_t i=0; i<fgkNumberOfSSD; i++) {
85           AliITSNoiseSSD *calib = new AliITSNoiseSSD();
86           calib->SetMod((UShort_t) i+500);
87           calib->SetNNoiseP(768);
88           calib->SetNNoiseN(768);
89           // take a reasonable averaged value for the noise on P- and N-side strips
90           for(Int_t j=0; j<768; j++) {
91             calib->AddNoiseP(j,1000.);
92             calib->AddNoiseN(j,1000.);
93           }
94           calib_array.AddAt(calib,i);
95         }
96         //-----------------------------------------
97         //---------------------------------------
98         // in case some module was not calibrated!
99         for(Int_t i=0; i<fgkNumberOfSSD; i++) {
100           AliITSBadChannelsSSD *badch = new AliITSBadChannelsSSD();
101           badch->SetMod((UShort_t) i+500);
102           badch->SetNBadPChannelsList(768);
103           badch->SetNBadNChannelsList(768);
104           badch_array.AddAt(badch,i);
105         }
106         //-----------------------------------------
107         
108         //---------------------------------------
109         // in case some module was not calibrated!
110         for(Int_t i=0; i<fgkNumberOfSSD; i++) {
111           AliITSPedestalSSD *pedel = new AliITSPedestalSSD();
112           pedel->SetMod((UShort_t) i+500);
113           pedel->SetNPedestalP(768);
114           pedel->SetNPedestalN(768);
115           for(Int_t j=0; j<768; j++) {
116             pedel->AddPedestalP(j,0.);
117             pedel->AddPedestalN(j,0.);
118           }
119           ped_array.AddAt(pedel,i);
120         }
121         //-----------------------------------------
122         
123         
124         
125         // expect to iterate 3 times (LDC0, LDC1, LDC2)
126         while ( (ok = (TObjString*) next()) ) {                               
127           
128           TString key = ok->String();
129           
130           TString fileName = GetFile(kDAQ, "CALIBRATION", key.Data());
131           if (fileName.Length() > 0) {
132             
133             Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
134             
135             TFile *f = new TFile(fileName.Data());
136             if(!f || !f->IsOpen()){
137                 Log("Error opening file!");
138                 delete list;
139                 return 2;
140             }
141             
142             TObjArray *cal; 
143             f->GetObject("Noise;1", cal); 
144             if(!cal) {
145                 Log("File does not contain expected data for the noise!");
146                 delete list;
147                 return 3;
148             }       
149
150             Int_t nmod = cal->GetEntries();
151             Log(Form("\n#Mod %d", nmod ));
152             for(Int_t mod=0; mod<nmod; mod++) {
153               AliITSNoiseSSD *calib = (AliITSNoiseSSD*) cal->At(mod);
154               Log(Form("\nModId %d", calib->GetMod() ));
155               if((calib->GetMod()<500)||(calib->GetMod()>2198)) continue;
156               calib_array.AddAt(calib,calib->GetMod()-500);
157             }
158
159             TObjArray *bad; 
160             f->GetObject("BadChannels;1", bad); 
161             if(!bad) {
162                 Log("File does not contain expected data for bad channels  !");
163                 delete list;
164                 return 4;
165             }       
166             nmod = bad->GetEntries();
167             for(Int_t mod=0; mod<nmod; mod++) {
168               AliITSBadChannelsSSD *badch = (AliITSBadChannelsSSD*) bad->At(mod);
169               if((badch->GetMod()<500)||(badch->GetMod()>2198)) continue;
170               badch_array.AddAt(badch,badch->GetMod()-500);
171             }
172
173             TObjArray *ped; 
174             f->GetObject("Pedestal;1", ped); 
175             if(!ped) {
176                 Log("File does not contain expected data for the pedestals!");
177                 delete list;
178                 return 5;
179             }       
180             nmod = ped->GetEntries();
181             for(Int_t mod=0; mod<nmod; mod++) {
182               AliITSPedestalSSD *pedel = (AliITSPedestalSSD*) ped->At(mod);
183               if((pedel->GetMod()<500)||(pedel->GetMod()>2198)) continue;
184               ped_array.AddAt(pedel,pedel->GetMod()-500);
185             }
186
187             f->Close(); delete f;           
188                 
189           } else {
190                 Log("GetFile error!");
191                 delete list;
192                 return 6;
193           } // if filename
194         } // end iteration over LDCs
195         
196         delete list;
197       } else {
198           Log("GetFileSources error!");
199           if(list) delete list;
200           return 7;
201       } // if list
202     
203       //Now we have to store the final CDB file
204       AliCDBMetaData metaData;
205       metaData.SetBeamPeriod(0);
206       metaData.SetResponsible("Enrico Fragiacomo");
207       metaData.SetComment("Fills noise, pedestal and bad channels TObjArray");
208   
209       if(!Store("Calib", "NoiseSSD", &calib_array, &metaData, 0, 1)) {
210         Log("no store");
211         return 1;
212       }  
213       
214       if(!Store("Calib", "BadChannelsSSD", &badch_array, &metaData, 0, 1)) {
215         Log("no store");
216         return 1;
217       }  
218       
219       if(!StoreReferenceData("Calib","PedestalSSD", &ped_array, &metaData)) {
220         Log("no store");
221         return 1;
222       }
223          
224   } // end if pedestal run
225   else {
226     Log("Nothing to do");
227     return 0;
228   }
229   
230   Log("Database updated");
231   return 0; // 0 means success
232
233 }
234