]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDBaseDA.cxx
The Gain DA executable for FMD
[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 detector 
23 //algorithms(DA). It implements the creation of the relevant containers and handles the 
24 //loop over the raw data. The derived classes can control the parameters and action
25 //to be taken making this the base class for the Pedestal, Gain and Physics DA.
26 //
27
28 #include "AliFMDBaseDA.h"
29 #include "iostream"
30
31 #include "AliFMDRawReader.h"
32 #include "AliLog.h"
33 //_____________________________________________________________________
34 ClassImp(AliFMDBaseDA)
35
36 //_____________________________________________________________________
37 AliFMDBaseDA::AliFMDBaseDA() : TNamed(),
38   fDiagnosticsFilename("diagnosticsHistograms.root"),
39   fOutputFile(),
40   fConditionsFile(),
41   fSaveHistograms(kFALSE),
42   fDetectorArray(),
43   fRequiredEvents(0),
44   fCurrentEvent(0)
45 {
46   fDetectorArray.SetOwner();
47   fConditionsFile.open("conditions.csv");
48 }
49 //_____________________________________________________________________
50 AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) : 
51   TNamed(baseDA),
52   fDiagnosticsFilename(baseDA.fDiagnosticsFilename),
53   fOutputFile(),
54   fConditionsFile(),
55   fSaveHistograms(baseDA.fSaveHistograms),
56   fDetectorArray(baseDA.fDetectorArray),
57   fRequiredEvents(baseDA.fRequiredEvents),
58   fCurrentEvent(baseDA.fCurrentEvent)
59 {
60   fDetectorArray.SetOwner();
61   
62 }
63
64
65 //_____________________________________________________________________
66 AliFMDBaseDA::~AliFMDBaseDA() {
67
68   //destructor
69   
70 }
71
72 //_____________________________________________________________________
73 void AliFMDBaseDA::Run(AliRawReader* reader) {
74   
75   
76   
77   InitContainer();
78
79   Init();
80
81   TFile* diagFile = 0;
82   if(fSaveHistograms)
83     {
84       diagFile = TFile::Open(fDiagnosticsFilename,"RECREATE");
85       for(UShort_t det=1;det<=3;det++) {
86         UShort_t FirstRing = (det == 1 ? 1 : 0);
87         
88         for (UShort_t ir = FirstRing; ir < 2; ir++) {
89           Char_t   ring = (ir == 0 ? 'O' : 'I');
90           UShort_t nsec = (ir == 0 ? 40  : 20);
91           UShort_t nstr = (ir == 0 ? 256 : 512);
92           
93           gDirectory->cd(Form("%s:/",fDiagnosticsFilename));
94           gDirectory->mkdir(Form("FMD%d%c",det,ring),Form("FMD%d%c",det,ring));
95           for(UShort_t sec =0; sec < nsec;  sec++)  {
96             gDirectory->cd(Form("%s:/FMD%d%c",fDiagnosticsFilename,det,ring));
97             gDirectory->mkdir(Form("sector_%d",sec));
98             for(UShort_t strip = 0; strip < nstr; strip++) {
99               gDirectory->cd(Form("%s:/FMD%d%c/sector_%d",fDiagnosticsFilename,det,ring,sec));
100               gDirectory->mkdir(Form("strip_%d",strip));
101               
102              }
103           }
104         }
105       }
106       
107     }
108     
109   reader->Reset();
110   
111   
112   
113   AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
114   TClonesArray* digitArray   = new TClonesArray("AliFMDDigit",0);
115   
116   WriteConditionsData();
117   
118   reader->NextEvent();
119   reader->NextEvent();
120   
121   
122   for(Int_t n =1;n <= GetRequiredEvents(); n++)
123     {
124       if(!reader->NextEvent()) 
125         continue;
126       
127       SetCurrentEvent(*(reader->GetEventId()));
128       
129       digitArray->Clear();
130       fmdReader->ReadAdcs(digitArray);
131       
132       
133       //std::cout<<"In event # "<< *(reader->GetEventId()) << " with " <<digitArray->GetEntries()<<" digits     \r"<<std::flush;
134       
135       
136       for(Int_t i = 0; i<digitArray->GetEntries();i++) {
137         AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
138         FillChannels(digit);
139       }
140       
141       FinishEvent();
142       
143     }
144   AliInfo(Form("Looped over %d events",GetCurrentEvent()));
145   WriteHeaderToFile();
146   
147   for(UShort_t det=1;det<=3;det++) {
148     UShort_t FirstRing = (det == 1 ? 1 : 0);
149     for (UShort_t ir = FirstRing; ir < 2; ir++) {
150       Char_t   ring = (ir == 0 ? 'O' : 'I');
151       UShort_t nsec = (ir == 0 ? 40  : 20);
152       UShort_t nstr = (ir == 0 ? 256 : 512);
153       for(UShort_t sec =0; sec < nsec;  sec++)  {
154         for(UShort_t strip = 0; strip < nstr; strip++) {
155           Analyse(det,ring,sec,strip);
156           
157         }
158       }
159     }
160   }
161
162   if(fOutputFile.is_open()) {
163     
164     fOutputFile.write("# EOF\n",6);
165     fOutputFile.close();
166     
167   }
168   
169   if(fSaveHistograms ) {
170     AliInfo("Closing diagnostics file...please wait");
171     diagFile->Close();
172   }
173 }
174 //_____________________________________________________________________
175
176 void AliFMDBaseDA::InitContainer(){
177
178   TObjArray* detArray;
179   TObjArray* ringArray;
180   TObjArray* sectorArray;
181     
182   for(UShort_t det=1;det<=3;det++) {
183     detArray = new TObjArray();
184     detArray->SetOwner();
185     fDetectorArray.AddAtAndExpand(detArray,det);
186     UShort_t FirstRing = (det == 1 ? 1 : 0);
187     for (UShort_t ir = FirstRing; ir < 2; ir++) {
188       Char_t   ring = (ir == 0 ? 'O' : 'I');
189       UShort_t nsec = (ir == 0 ? 40  : 20);
190       UShort_t nstr = (ir == 0 ? 256 : 512);
191       ringArray = new TObjArray();
192       ringArray->SetOwner();
193       detArray->AddAtAndExpand(ringArray,ir);
194       for(UShort_t sec =0; sec < nsec;  sec++)  {
195         sectorArray = new TObjArray();
196         sectorArray->SetOwner();
197         ringArray->AddAtAndExpand(sectorArray,sec);
198         for(UShort_t strip = 0; strip < nstr; strip++) {
199           AddChannelContainer(sectorArray, det, ring, sec, strip);
200         }
201       }
202     }
203   }
204 }
205
206 //_____________________________________________________________________ 
207 void AliFMDBaseDA::WriteConditionsData() {
208   
209   AliFMDParameters* pars       = AliFMDParameters::Instance();
210   fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
211   fConditionsFile.write("# Sample Rate, timebins \n",25);
212   
213   UInt_t sampleRate = 4;
214   UInt_t timebins   = 544;
215   fConditionsFile     << sampleRate   << ',' 
216                       << timebins     <<"\n";
217   //if(fConditionsFile.is_open()) {
218   //  
219   //  fConditionsFile.write("# EOF\n",6);
220   //  fConditionsFile.close();
221     
222   //}
223   
224 }
225
226 //_____________________________________________________________________ 
227 //
228 // EOF
229 //