]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPreprocessorSSD.cxx
Label for the ITS tracklets (Jan Fiete)
[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 void AliITSPreprocessorSSD::Initialize(Int_t run, UInt_t startTime,
31         UInt_t endTime)
32 {
33  
34   AliPreprocessor::Initialize(run, startTime, endTime);
35   
36   Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
37                TTimeStamp(startTime).AsString(),
38                TTimeStamp(endTime).AsString()));
39   
40 }
41
42 //______________________________________________________________________________________________
43 UInt_t AliITSPreprocessorSSD::Process(TMap* /*dcsAliasMap*/)
44 {
45
46   // Note. To be modified: dcsAliasMap is not needed but I can not get rid
47   // of it unless the base class AliPreprocessor is modified accordingly.
48
49   TObjArray calib_array(fgkNumberOfSSD); 
50   TObjArray badch_array(fgkNumberOfSSD); 
51   TObjArray ped_array(fgkNumberOfSSD); 
52   //Float_t noise=0, gain=0;
53   
54   TString runType = GetRunType();
55   if(runType == "ELECTRONICS_CALIBRATION_RUN") {
56     
57   }
58   else if(runType == "PEDESTAL") {
59
60     TList* list = GetFileSources(kDAQ, "CALIBRATION");
61     if (list && list->GetEntries() > 0)
62       {
63         Log("The following sources produced files with the id CALIBRATION");
64         list->Print();
65         
66         // create iterator over list of LDCs (provides list of TObjString)
67         TIter next(list);
68         TObjString *ok;
69         
70         // expect to iterate 3 times (LDC0, LDC1, LDC2)
71         while ( (ok = (TObjString*) next()) ) {                               
72           
73           TString key = ok->String();
74           
75           TString fileName = GetFile(kDAQ, "CALIBRATION", key.Data());
76           if (fileName.Length() > 0) {
77             
78             Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
79             
80             TFile *f = new TFile(fileName.Data());
81             if(!f || !f->IsOpen()){
82                 Log("Error opening file!");
83                 delete list;
84                 return 2;
85             }
86             
87             TObjArray *cal; 
88             f->GetObject("Noise;1", cal); 
89             if(!cal) {
90                 Log("File does not contain expected data for the noise!");
91                 delete list;
92                 return 3;
93             }       
94
95             //---------------------------------------
96             // in case some module was not calibrated!
97             for(Int_t i=0; i<fgkNumberOfSSD; i++) {
98               AliITSNoiseSSD *calib = new AliITSNoiseSSD();
99               calib->SetMod((UShort_t) i+500);
100               calib->SetNNoiseP(768);
101               calib->SetNNoiseN(768);
102               // take a reasonable averaged value for the noise on P- and N-side strips
103               for(Int_t j=0; j<768; j++) {
104                 calib->AddNoiseP(j,2.);
105                 calib->AddNoiseN(j,4.);
106               }
107               calib_array.AddAt(calib,i);
108             }
109             //-----------------------------------------
110
111             Int_t nmod = cal->GetEntries();
112             for(Int_t mod=0; mod<nmod; mod++) {
113               AliITSNoiseSSD *calib = (AliITSNoiseSSD*) cal->At(mod);
114               if((calib->GetMod()<500)||(calib->GetMod()>2198)) continue;
115               calib_array.AddAt(calib,calib->GetMod()-500);
116             }
117
118
119             //---------------------------------------
120             // in case some module was not calibrated!
121             for(Int_t i=0; i<fgkNumberOfSSD; i++) {
122               AliITSBadChannelsSSD *badch = new AliITSBadChannelsSSD();
123               badch->SetMod((UShort_t) i+500);
124               badch_array.AddAt(badch,i);
125             }
126             //-----------------------------------------
127
128             //-----------------------------------------
129             TObjArray *bad; 
130             f->GetObject("BadChannels;1", bad); 
131             if(!bad) {
132                 Log("File does not contain expected data for bad channels  !");
133                 delete list;
134                 return 4;
135             }       
136             nmod = bad->GetEntries();
137             for(Int_t mod=0; mod<nmod; mod++) {
138               AliITSBadChannelsSSD *badch = (AliITSBadChannelsSSD*) bad->At(mod);
139               if((badch->GetMod()<500)||(badch->GetMod()>2198)) continue;
140               badch_array.AddAt(badch,badch->GetMod()-500);
141             }
142
143             //---------------------------------------
144             // in case some module was not calibrated!
145             for(Int_t i=0; i<fgkNumberOfSSD; i++) {
146               AliITSPedestalSSD *pedel = new AliITSPedestalSSD();
147               pedel->SetMod((UShort_t) i+500);
148               pedel->SetNPedestalP(768);
149               pedel->SetNPedestalN(768);
150               for(Int_t j=0; j<768; j++) {
151                 pedel->AddPedestalP(j,0.);
152                 pedel->AddPedestalN(j,0.);
153               }
154               ped_array.AddAt(pedel,i);
155             }
156             //-----------------------------------------
157
158             TObjArray *ped; 
159             f->GetObject("Pedestal;1", ped); 
160             if(!ped) {
161                 Log("File does not contain expected data for the pedestals!");
162                 delete list;
163                 return 5;
164             }       
165             nmod = ped->GetEntries();
166             for(Int_t mod=0; mod<nmod; mod++) {
167               AliITSPedestalSSD *pedel = (AliITSPedestalSSD*) ped->At(mod);
168               if((pedel->GetMod()<500)||(pedel->GetMod()>2198)) continue;
169               ped_array.AddAt(pedel,pedel->GetMod()-500);
170             }
171
172             f->Close(); delete f;           
173                 
174           } else {
175                 Log("GetFile error!");
176                 delete list;
177                 return 6;
178           } // if filename
179         } // end iteration over LDCs
180         
181         delete list;
182       } else {
183           Log("GetFileSources error!");
184           if(list) delete list;
185           return 7;
186       } // if list
187     
188       //Now we have to store the final CDB file
189       AliCDBMetaData metaData;
190       metaData.SetBeamPeriod(0);
191       metaData.SetResponsible("Enrico Fragiacomo");
192       metaData.SetComment("Fills noise, pedestal and bad channels TObjArray");
193   
194       if(!Store("Calib", "NoiseSSD", &calib_array, &metaData, 0, 1)) {
195         Log("no store");
196         return 1;
197       }  
198       
199       if(!Store("Calib", "BadChannelsSSD", &badch_array, &metaData, 0, 1)) {
200         Log("no store");
201         return 1;
202       }  
203       
204       if(!StoreReferenceData("Calib","PedestalSSD", &ped_array, &metaData)) {
205         Log("no store");
206         return 1;
207       }
208          
209   } // end if noise_run
210   else {
211     Log("Nothing to do");
212     return 0;
213   }
214   
215   Log("Database updated");
216   return 0; // 0 means success
217
218 }
219