]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSSD.cxx
Parameters for track finding in AliITStrackerSA added to AliITSRecoParam (F. Prino)
[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_array.AddAt(badch,i);
103         }
104         //-----------------------------------------
105         
106         //---------------------------------------
107         // in case some module was not calibrated!
108         for(Int_t i=0; i<fgkNumberOfSSD; i++) {
109           AliITSPedestalSSD *pedel = new AliITSPedestalSSD();
110           pedel->SetMod((UShort_t) i+500);
111           pedel->SetNPedestalP(768);
112           pedel->SetNPedestalN(768);
113           for(Int_t j=0; j<768; j++) {
114             pedel->AddPedestalP(j,0.);
115             pedel->AddPedestalN(j,0.);
116           }
117           ped_array.AddAt(pedel,i);
118         }
119         //-----------------------------------------
120         
121         
122         
123         // expect to iterate 3 times (LDC0, LDC1, LDC2)
124         while ( (ok = (TObjString*) next()) ) {                               
125           
126           TString key = ok->String();
127           
128           TString fileName = GetFile(kDAQ, "CALIBRATION", key.Data());
129           if (fileName.Length() > 0) {
130             
131             Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
132             
133             TFile *f = new TFile(fileName.Data());
134             if(!f || !f->IsOpen()){
135                 Log("Error opening file!");
136                 delete list;
137                 return 2;
138             }
139             
140             TObjArray *cal; 
141             f->GetObject("Noise;1", cal); 
142             if(!cal) {
143                 Log("File does not contain expected data for the noise!");
144                 delete list;
145                 return 3;
146             }       
147
148             Int_t nmod = cal->GetEntries();
149             Log(Form("\n#Mod %d", nmod ));
150             for(Int_t mod=0; mod<nmod; mod++) {
151               AliITSNoiseSSD *calib = (AliITSNoiseSSD*) cal->At(mod);
152               Log(Form("\nModId %d", calib->GetMod() ));
153               if((calib->GetMod()<500)||(calib->GetMod()>2198)) continue;
154               calib_array.AddAt(calib,calib->GetMod()-500);
155             }
156
157             TObjArray *bad; 
158             f->GetObject("BadChannels;1", bad); 
159             if(!bad) {
160                 Log("File does not contain expected data for bad channels  !");
161                 delete list;
162                 return 4;
163             }       
164             nmod = bad->GetEntries();
165             for(Int_t mod=0; mod<nmod; mod++) {
166               AliITSBadChannelsSSD *badch = (AliITSBadChannelsSSD*) bad->At(mod);
167               if((badch->GetMod()<500)||(badch->GetMod()>2198)) continue;
168               badch_array.AddAt(badch,badch->GetMod()-500);
169             }
170
171             TObjArray *ped; 
172             f->GetObject("Pedestal;1", ped); 
173             if(!ped) {
174                 Log("File does not contain expected data for the pedestals!");
175                 delete list;
176                 return 5;
177             }       
178             nmod = ped->GetEntries();
179             for(Int_t mod=0; mod<nmod; mod++) {
180               AliITSPedestalSSD *pedel = (AliITSPedestalSSD*) ped->At(mod);
181               if((pedel->GetMod()<500)||(pedel->GetMod()>2198)) continue;
182               ped_array.AddAt(pedel,pedel->GetMod()-500);
183             }
184
185             f->Close(); delete f;           
186                 
187           } else {
188                 Log("GetFile error!");
189                 delete list;
190                 return 6;
191           } // if filename
192         } // end iteration over LDCs
193         
194         delete list;
195       } else {
196           Log("GetFileSources error!");
197           if(list) delete list;
198           return 7;
199       } // if list
200     
201       //Now we have to store the final CDB file
202       AliCDBMetaData metaData;
203       metaData.SetBeamPeriod(0);
204       metaData.SetResponsible("Enrico Fragiacomo");
205       metaData.SetComment("Fills noise, pedestal and bad channels TObjArray");
206   
207       if(!Store("Calib", "NoiseSSD", &calib_array, &metaData, 0, 1)) {
208         Log("no store");
209         return 1;
210       }  
211       
212       if(!Store("Calib", "BadChannelsSSD", &badch_array, &metaData, 0, 1)) {
213         Log("no store");
214         return 1;
215       }  
216       
217       if(!StoreReferenceData("Calib","PedestalSSD", &ped_array, &metaData)) {
218         Log("no store");
219         return 1;
220       }
221          
222   } // end if pedestal run
223   else {
224     Log("Nothing to do");
225     return 0;
226   }
227   
228   Log("Database updated");
229   return 0; // 0 means success
230
231 }
232