]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDBaseDA.cxx
Updated Detector Algorithm base class to write the conditions data to file. The class...
[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 AliFMDBaseDA::~AliFMDBaseDA() {
66
67   //destructor
68   
69 }
70
71 //_____________________________________________________________________
72 void AliFMDBaseDA::Run(AliRawReader* reader) {
73   
74   
75   
76   InitContainer();
77
78   Init();
79
80   TFile* diagFile = 0;
81   if(fSaveHistograms)
82     {
83       diagFile = TFile::Open(fDiagnosticsFilename,"RECREATE");
84       for(UShort_t det=1;det<=3;det++) {
85         UShort_t FirstRing = (det == 1 ? 1 : 0);
86         
87         for (UShort_t ir = FirstRing; ir < 2; ir++) {
88           Char_t   ring = (ir == 0 ? 'O' : 'I');
89           UShort_t nsec = (ir == 0 ? 40  : 20);
90           UShort_t nstr = (ir == 0 ? 256 : 512);
91           
92           gDirectory->cd(Form("%s:/",fDiagnosticsFilename));
93           gDirectory->mkdir(Form("FMD%d%c",det,ring),Form("FMD%d%c",det,ring));
94           for(UShort_t sec =0; sec < nsec;  sec++)  {
95             gDirectory->cd(Form("%s:/FMD%d%c",fDiagnosticsFilename,det,ring));
96             gDirectory->mkdir(Form("sector_%d",sec));
97             for(UShort_t strip = 0; strip < nstr; strip++) {
98               gDirectory->cd(Form("%s:/FMD%d%c/sector_%d",fDiagnosticsFilename,det,ring,sec));
99               gDirectory->mkdir(Form("strip_%d",strip));
100               
101              }
102           }
103         }
104       }
105       
106     }
107     
108   reader->Reset();
109   
110   
111   
112   AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
113   TClonesArray* digitArray   = new TClonesArray("AliFMDDigit",0);
114   
115   WriteConditionsData();
116   
117   reader->NextEvent();
118   reader->NextEvent();
119   
120   
121   for(Int_t n =1;n <= GetRequiredEvents(); n++)
122     {
123       if(!reader->NextEvent()) 
124         continue;
125       
126       SetCurrentEvent(*(reader->GetEventId()));
127       
128       digitArray->Clear();
129       fmdReader->ReadAdcs(digitArray);
130       
131       
132       //std::cout<<"In event # "<< *(reader->GetEventId()) << " with " <<digitArray->GetEntries()<<" digits     \r"<<std::flush;
133       
134       
135       for(Int_t i = 0; i<digitArray->GetEntries();i++) {
136         AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
137         FillChannels(digit);
138       }
139       
140       FinishEvent();
141       
142     }
143   AliInfo(Form("Looped over %d events",GetCurrentEvent()));
144   WriteHeaderToFile();
145   
146   for(UShort_t det=1;det<=3;det++) {
147     UShort_t FirstRing = (det == 1 ? 1 : 0);
148     for (UShort_t ir = FirstRing; ir < 2; ir++) {
149       Char_t   ring = (ir == 0 ? 'O' : 'I');
150       UShort_t nsec = (ir == 0 ? 40  : 20);
151       UShort_t nstr = (ir == 0 ? 256 : 512);
152       for(UShort_t sec =0; sec < nsec;  sec++)  {
153         for(UShort_t strip = 0; strip < nstr; strip++) {
154           Analyse(det,ring,sec,strip);
155           
156         }
157       }
158     }
159   }
160
161   if(fOutputFile.is_open()) {
162     
163     fOutputFile.write("# EOF\n",6);
164     fOutputFile.close();
165     
166   }
167   
168   if(fSaveHistograms ) {
169     AliInfo("Closing diagnostics file...please wait");
170     diagFile->Close();
171   }
172 }
173 //_____________________________________________________________________
174
175 void AliFMDBaseDA::InitContainer(){
176
177   TObjArray* detArray;
178   TObjArray* ringArray;
179   TObjArray* sectorArray;
180     
181   for(UShort_t det=1;det<=3;det++) {
182     detArray = new TObjArray();
183     detArray->SetOwner();
184     fDetectorArray.AddAtAndExpand(detArray,det);
185     UShort_t FirstRing = (det == 1 ? 1 : 0);
186     for (UShort_t ir = FirstRing; ir < 2; ir++) {
187       Char_t   ring = (ir == 0 ? 'O' : 'I');
188       UShort_t nsec = (ir == 0 ? 40  : 20);
189       UShort_t nstr = (ir == 0 ? 256 : 512);
190       ringArray = new TObjArray();
191       ringArray->SetOwner();
192       detArray->AddAtAndExpand(ringArray,ir);
193       for(UShort_t sec =0; sec < nsec;  sec++)  {
194         sectorArray = new TObjArray();
195         sectorArray->SetOwner();
196         ringArray->AddAtAndExpand(sectorArray,sec);
197         for(UShort_t strip = 0; strip < nstr; strip++) {
198           AddChannelContainer(sectorArray, det, ring, sec, strip);
199         }
200       }
201     }
202   }
203 }
204
205 //_____________________________________________________________________ 
206 void AliFMDBaseDA::WriteConditionsData() {
207   
208   AliFMDParameters* pars       = AliFMDParameters::Instance();
209   fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
210   fConditionsFile.write("# Sample Rate, timebins \n",25);
211   
212   UInt_t sampleRate = 4;
213   UInt_t timebins   = 544;
214   fConditionsFile     << sampleRate   << ',' 
215                       << timebins     <<"\n";
216   //if(fConditionsFile.is_open()) {
217   //  
218   //  fConditionsFile.write("# EOF\n",6);
219   //  fConditionsFile.close();
220     
221   //}
222   
223 }
224
225 //_____________________________________________________________________ 
226 //
227 // EOF
228 //