]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDBaseDA.cxx
Included ReadFromFile and WriteToFile methods to read/write from ASCII files and...
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
1 /**************************************************************************
2  * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /** @file    AliFMDBaseDA.cxx
17     @author  Hans Hjersing Dalsgaard <canute@nbi.dk>
18     @date    Wed Mar 26 11:30:45 2008
19     @brief   Base class for detector algorithms.
20 */
21 //
22 // This is the implementation of the (virtual) base class for the FMD
23 // detector algorithms(DA). It implements the creation of the relevant
24 // containers and handles the loop over the raw data. The derived
25 // classes can control the parameters and action to be taken making
26 // this the base class for the Pedestal, Gain and Physics DA.
27 //
28
29 #include "AliFMDBaseDA.h"
30 #include "iostream"
31
32 #include "AliFMDRawReader.h"
33 #include "AliFMDCalibSampleRate.h"
34 #include "AliFMDCalibStripRange.h"
35 #include "AliLog.h"
36 //_____________________________________________________________________
37 ClassImp(AliFMDBaseDA)
38 #if 0 
39 ; // Do not delete  - to let Emacs for mat the code
40 #endif
41
42 //_____________________________________________________________________
43 const char*
44 AliFMDBaseDA::GetStripPath(UShort_t det, 
45                            Char_t   ring, 
46                            UShort_t sec, 
47                            UShort_t str, 
48                            Bool_t   full) const
49 {
50   return Form("%s%sFMD%d%c[%02d,%03d]", 
51               (full ? GetSectorPath(det, ring, sec, full) : ""), 
52               (full ? "/" : ""), det, ring, sec, str);
53 }
54 //_____________________________________________________________________
55 const char*
56 AliFMDBaseDA::GetSectorPath(UShort_t det, 
57                             Char_t   ring, 
58                             UShort_t sec, 
59                             Bool_t   full) const
60 {
61   return Form("%s%sFMD%d%c[%02d]", 
62               (full ? GetRingPath(det, ring, full) : ""), 
63               (full ? "/" : ""), det, ring, sec);
64 }
65 //_____________________________________________________________________
66 const char*
67 AliFMDBaseDA::GetRingPath(UShort_t det, 
68                           Char_t   ring, 
69                           Bool_t   full) const
70 {
71   return Form("%s%sFMD%d%c", 
72               (full ? GetDetectorPath(det, full) : ""), 
73               (full ? "/" : ""), det, ring);
74 }
75 //_____________________________________________________________________
76 const char*
77 AliFMDBaseDA::GetDetectorPath(UShort_t det, 
78                               Bool_t   full) const
79 {
80   return Form("%s%sFMD%d", 
81               (full ? fDiagnosticsFilename.Data() : ""), 
82               (full ? ":/" : ""), det);
83 }
84
85 //_____________________________________________________________________
86 AliFMDBaseDA::AliFMDBaseDA() : 
87   TNamed(),
88   fDiagnosticsFilename("diagnosticsHistograms.root"),
89   fOutputFile(),
90   fConditionsFile(),
91   fSaveHistograms(kFALSE),
92   fDetectorArray(),
93   fPulseSize(16),
94   fPulseLength(16),
95   fRequiredEvents(0),
96   fCurrentEvent(0)
97  {
98   fDetectorArray.SetOwner();
99   fConditionsFile.open("conditions.csv");
100 }
101 //_____________________________________________________________________
102 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) : 
103   TNamed(baseDA),
104   fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
105   fOutputFile(),
106   fConditionsFile(),
107   fSaveHistograms(baseDA.fSaveHistograms),
108   fDetectorArray(baseDA.fDetectorArray),
109   fPulseSize(baseDA.fPulseSize),
110   fPulseLength(baseDA.fPulseLength),
111   fRequiredEvents(baseDA.fRequiredEvents),
112   fCurrentEvent(baseDA.fCurrentEvent)
113 {
114   fDetectorArray.SetOwner();
115   
116 }
117
118
119 //_____________________________________________________________________
120 AliFMDBaseDA::~AliFMDBaseDA() 
121 {
122   //destructor
123 }
124
125 //_____________________________________________________________________
126 void AliFMDBaseDA::Run(AliRawReader* reader) 
127 {
128   TFile* diagFile = 0;
129   if (fSaveHistograms)
130     diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
131
132   
133   WriteConditionsData();
134   
135   InitContainer(diagFile);
136   Init();
137
138
139   reader->Reset();
140   
141   AliFMDRawReader* fmdReader  = new AliFMDRawReader(reader,0);
142   TClonesArray*    digitArray = new TClonesArray("AliFMDDigit",0);
143     
144   reader->NextEvent(); // Read Start-of-Run event
145   reader->NextEvent(); // Read Start-of-Files event
146   int lastProgress = 0;
147   
148   for(Int_t n =1;n <= GetRequiredEvents(); n++) {
149     if(!reader->NextEvent()) continue;
150     
151     SetCurrentEvent(*(reader->GetEventId()));
152     
153     digitArray->Clear();
154     fmdReader->ReadAdcs(digitArray);
155     
156     AliDebug(5, Form("In event # %d with %d entries", 
157                      *(reader->GetEventId()), digitArray->GetEntriesFast()));
158     
159     for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
160       AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
161       FillChannels(digit);
162     }
163     
164     FinishEvent();
165     int progress = int((n *100)/ GetRequiredEvents()) ;
166     if (progress <= lastProgress) continue;
167     lastProgress = progress;
168     std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
169   }
170
171   AliInfo(Form("Looped over %d events",GetCurrentEvent()));
172   WriteHeaderToFile();
173   
174   for(UShort_t det=1;det<=3;det++) {
175     std::cout << "FMD" << det << std::endl;
176     UShort_t FirstRing = (det == 1 ? 1 : 0);
177     for (UShort_t ir = FirstRing; ir < 2; ir++) {
178       Char_t   ring = (ir == 0 ? 'O' : 'I');
179       UShort_t nsec = (ir == 0 ? 40  : 20);
180       UShort_t nstr = (ir == 0 ? 256 : 512);
181       std::cout << " Ring " << ring << ": " << std::flush;
182       for(UShort_t sec =0; sec < nsec;  sec++)  {
183         for(UShort_t strip = 0; strip < nstr; strip++) {
184           Analyse(det,ring,sec,strip);
185         }
186         std::cout << '.' << std::flush;
187       }
188       if(fSaveHistograms)
189         diagFile->Flush();
190       std::cout << "done" << std::endl;
191     }
192   }
193
194   if(fOutputFile.is_open()) {
195     fOutputFile.write("# EOF\n",6);
196     fOutputFile.close();
197   }
198   
199   if(fSaveHistograms ) {
200     
201     Terminate(diagFile);
202   
203     AliInfo("Closing diagnostics file - please wait ...");
204     // diagFile->Write();
205     diagFile->Close();
206     AliInfo("done");
207   }
208 }
209 //_____________________________________________________________________
210
211 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
212 {
213   TObjArray* detArray;
214   TObjArray* ringArray;
215   TObjArray* sectorArray;
216     
217   TDirectory* savDir   = gDirectory;
218
219   for(UShort_t det=1;det<=3;det++) {
220     detArray = new TObjArray();
221     detArray->SetOwner();
222     fDetectorArray.AddAtAndExpand(detArray,det);
223
224     TDirectory* detDir = 0;
225     if (diagFile) {
226       diagFile->cd();
227       detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
228     }
229
230     UShort_t FirstRing = (det == 1 ? 1 : 0);
231     for (UShort_t ir = FirstRing; ir < 2; ir++) {
232       Char_t   ring = (ir == 0 ? 'O' : 'I');
233       UShort_t nsec = (ir == 0 ? 40  : 20);
234       UShort_t nstr = (ir == 0 ? 256 : 512);
235       ringArray = new TObjArray();
236       ringArray->SetOwner();
237       detArray->AddAtAndExpand(ringArray,ir);
238
239
240       TDirectory* ringDir = 0;
241       if (detDir) { 
242         detDir->cd();
243         ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
244       }
245       
246
247       for(UShort_t sec =0; sec < nsec;  sec++)  {
248         sectorArray = new TObjArray();
249         sectorArray->SetOwner();
250         ringArray->AddAtAndExpand(sectorArray,sec);
251
252
253         TDirectory* secDir = 0;
254         if (ringDir) { 
255           ringDir->cd();
256           secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
257         }
258         
259         for(UShort_t strip = 0; strip < nstr; strip++) {
260           if (secDir) { 
261             secDir->cd();
262             secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
263           }
264           AddChannelContainer(sectorArray, det, ring, sec, strip);
265         }
266       }
267     }
268   }
269   savDir->cd();
270 }
271
272 //_____________________________________________________________________ 
273 void AliFMDBaseDA::WriteConditionsData() 
274 {
275   AliFMDParameters* pars       = AliFMDParameters::Instance();
276   fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
277   
278   // fConditionsFile.write("# Sample Rate, timebins \n",25);
279   
280   // Sample Rate
281   
282   UShort_t defSampleRate = 4;
283   UShort_t sampleRateFromSOD;
284   //UInt_t timebins   = 544;
285   AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
286
287   UShort_t firstStrip = 0;
288   UShort_t lastStrip  = 127;
289   UShort_t firstStripSOD;
290   UShort_t lastStripSOD;
291   AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
292   
293   for(Int_t det=1;det<=3;det++) {
294     UShort_t FirstRing = (det == 1 ? 1 : 0);
295     for (UShort_t ir = FirstRing; ir < 2; ir++) {
296       Char_t   ring = (ir == 0 ? 'O' : 'I');
297       UShort_t nsec = (ir == 0 ? 40  : 20);
298       for(UShort_t sec =0; sec < nsec;  sec++)  {
299         sampleRateFromSOD = defSampleRate;
300         sampleRate->Set(det,ring,sec,0,sampleRateFromSOD);
301         firstStripSOD = firstStrip;
302         lastStripSOD  = lastStrip;
303         stripRange->Set(det,ring,sec,0,firstStripSOD,lastStripSOD);
304         
305       }
306     }
307   }
308   
309   sampleRate->WriteToFile(fConditionsFile);
310   stripRange->WriteToFile(fConditionsFile);
311   pars->SetSampleRate(sampleRate);
312   pars->SetStripRange(stripRange);
313
314  
315   // Zero Suppresion
316   
317   // Strip Range
318   
319  
320   
321   
322   
323   // Gain Relevant stuff
324   
325   UShort_t defPulseSize = 32 ; 
326   UShort_t defPulseLength = 100 ; 
327   UShort_t pulseSizeFromSOD;
328   UShort_t pulseLengthFromSOD;  
329   
330   fPulseSize.Reset(defPulseSize);
331   fPulseLength.Reset(defPulseLength);
332   
333   for(UShort_t det=1;det<=3;det++)
334     for(UShort_t iring=0;iring<=1;iring++)
335       for(UShort_t board=0;board<=1;board++) {
336         pulseSizeFromSOD = defPulseSize;
337         pulseLengthFromSOD = defPulseLength;
338
339         fPulseSize.AddAt(pulseSizeFromSOD,GetHalfringIndex(det,iring,board));
340         fPulseLength.AddAt(pulseLengthFromSOD,GetHalfringIndex(det,iring,board));
341       }
342           
343   
344   //  fConditionsFile     << defSampleRate   << ',' 
345   //                  << timebins     <<"\n";
346   
347   if(fConditionsFile.is_open()) {
348     
349     fConditionsFile.write("# EOF\n",6);
350     fConditionsFile.close();
351     
352   }
353   
354 }
355 //_____________________________________________________________________ 
356 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) {
357
358   UShort_t iring  =  (ring == 'I' ? 1 : 0);
359   
360   Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
361   
362   return index;
363   
364 }
365
366
367 //_____________________________________________________________________ 
368 //
369 // EOF
370 //