]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDBaseDA.h
Simulation response function treatment.
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.h
1 // -*- mode: C++ -*- 
2 #ifndef ALIFMDBASEDA_H
3 #define ALIFMDBASEDA_H
4
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights
6  * reserved. 
7  *
8  * See cxx source for full Copyright notice                               
9  */
10 //
11 // This class provides a base interface for the Detector Algorithms
12 // (DA) of the FMD.  At least three implementations are needed:
13 // AliFMDPedestalDA, AliFMDGainDA and AliFMDPhysicsDA .  These classes
14 // will provide the calibration data for the AliFMDPreprocessor to be
15 // used in the shuttle.  The input for this class are raw data
16 // (AliRawReader) and the output is a comma-separated file
17 // (std::ofstream) that contains the values defined in the
18 // implementations of this class.
19 //
20 // Author: Hans Hjersing Dalsgaard, hans.dalsgaard@cern.ch
21 //
22
23 #include "TNamed.h"
24 #include "TObjArray.h"
25 #include "TString.h"
26 #include "TArrayS.h"
27 #include <iosfwd>
28 #include <fstream>
29 class AliFMDDigit;
30 class AliRawReader;
31 class AliFMDParameters;
32 class AliFMDRawReader;
33 class TDirectory;
34 class TH2;
35 class TFile;
36 class TClonesArray;
37
38 class AliFMDBaseDA: public TNamed 
39 {
40 public:
41   /** 
42    * Constructor 
43    * 
44    */
45   AliFMDBaseDA() ;
46   /** 
47    * Copy constructor 
48    * 
49    * @param baseDA 
50    */
51   AliFMDBaseDA(const AliFMDBaseDA & baseDA) ;
52   //  AliFMDBaseDA& operator = (const AliFMDBaseDA & baseDA) ; 
53   /** 
54    * Destructor
55    * 
56    */  
57   ~AliFMDBaseDA() ;
58   AliFMDBaseDA& operator=(const AliFMDBaseDA&) { return *this; }
59   /** 
60    * Run this DA
61    * 
62    * @param fmdReader Raw input reader
63    */  
64   void Run(AliRawReader* fmdReader);
65   /** 
66    * Set whether to save diagnostics 
67    * 
68    * @param save If true, will output diagnostics file
69    */
70   void SetSaveDiagnostics(Bool_t save) {fSaveHistograms = save;}
71   /** 
72    * Set the diagnostics file name 
73    * 
74    * @param f Diagnostics file name 
75    */
76   void SetDiagnosticsFilename(const TString& f) { fDiagnosticsFilename = f; }
77   /** 
78    * Set whether to make summary histograms to be published to AMORE
79    * 
80    * @param save If true, will generate summary QA histograms
81    */
82   void SetMakeSummaries(Bool_t save) {fMakeSummaries = save;}
83   /** 
84    * Set the number of requried events
85    * 
86    * @param nEvents Number of event we need
87    */
88   void SetRequiredEvents(Int_t nEvents) {fRequiredEvents = nEvents;}
89   /** 
90    * Get the number of required events
91    * 
92    * 
93    * @return number of required events
94    */
95   Int_t GetRequiredEvents() const {return fRequiredEvents ;}
96   /** 
97    * Get list of summary histograms 
98    *
99    * @return Array of summary histograms or null if not defined 
100    */
101   const TObjArray& GetSummaries() const { return fSummaries; }
102   /** 
103    * Check if we saw data for detector 
104    * 
105    * @param det Detector number to check 
106    * @return true if the code has seen data from the detector 
107    */
108   Bool_t HasSeenDetector(UShort_t d) const;
109
110   /**
111    * Class to run the DAs 
112    */
113   struct Runner {
114     Runner();
115     Runner(const Runner&) : fReader(0), fDiagFile(""), fDiag(false) {}
116     ~Runner() {} 
117     Runner& operator=(const Runner&) { return *this; }
118     void   AddHandlers();
119     void   ShowUsage(std::ostream& o, const char* progname);
120     Int_t  Init(int argc, char** argv);
121     void   Exec(AliFMDBaseDA& da);
122     Int_t  RunNumber() const;
123     AliRawReader* fReader;
124     TString       fDiagFile;
125     Bool_t        fDiag;
126   };
127 protected:
128   /** 
129    * Initialize 
130    */  
131   virtual void Init()  {};
132   /** 
133    * Fill channels 
134    */
135   virtual void FillChannels(AliFMDDigit* )  {};
136   /** 
137    * Analyse a single strip result
138    */
139   virtual void Analyse(UShort_t, Char_t, UShort_t, UShort_t)  {};
140   /** 
141    * Write header to output file
142    */
143   virtual void WriteHeaderToFile()  {};
144   /** 
145    * Add a strip container 
146    */
147   virtual void AddChannelContainer(TObjArray*, UShort_t, Char_t, 
148                                    UShort_t, UShort_t )  {};
149   /** 
150    * Add summary(s) for sectors 
151    * 
152    */
153   virtual void AddSectorSummary(TObjArray*, UShort_t, Char_t, UShort_t, 
154                                 UShort_t) {}
155   /** 
156    * End of event
157    */
158   virtual void FinishEvent()  {};
159   /** 
160    * End of run
161    */
162   virtual void Terminate(TFile* ) {};
163   /** 
164    * Current event number
165    * 
166    * 
167    * @return 
168    */  
169   Int_t GetCurrentEvent() const {return fCurrentEvent;}
170   /** 
171    * Rotate a set of files.   @a base is the basic name of the files.
172    * If the file @a base.max exists it is removed. 
173    * If the file @a base.n exists (where n < max) it is renamed to @a
174    * base.(n-1).  
175    * If the file @a base exists, it is renamed to @a base.1 
176    * 
177    * @param base Base name of the files
178    * @param max  Maximum number to keep (minus one for the current).
179    */
180   void Rotate(const char* base, int max) const;
181   /** 
182    * Ge the half-ring index 
183    * 
184    * @param UShort_t 
185    * @param Char_t 
186    * @param UShort_t 
187    * 
188    * @return 
189    */
190   Int_t GetHalfringIndex(UShort_t, Char_t, UShort_t) const;
191   /** 
192    * Get the pulse size 
193    * 
194    * @param det   Detector number
195    * @param ring  Rin identifier
196    * @param board Board number 
197    * 
198    * @return Pulse step size
199    */
200   Int_t GetPulseSize(UShort_t det , 
201                      Char_t ring, 
202                      UShort_t board) 
203   {
204     return fPulseSize.At(GetHalfringIndex(det,ring,board));
205   }
206   /** 
207    * Get number of events per pulse size 
208    * 
209    * @param det   Detector number
210    * @param ring  Rin identifier
211    * @param board Board number 
212    * 
213    * @return number of events per Pulse size
214    */
215   Int_t GetPulseLength(UShort_t det, 
216                        Char_t ring, 
217                        UShort_t board) 
218   {
219     return fPulseLength.At(GetHalfringIndex(det,ring,board));
220   }
221
222   /** 
223    * Get the detector path in diagnositcs file
224    * 
225    * @param det  Detector number
226    * @param full If true, return full path
227    * 
228    * @return Path to detector
229    */  
230   const char* GetDetectorPath(UShort_t det, Bool_t full=kTRUE) const;
231   /** 
232    * Get the ring path in diagnositcs file
233    * 
234    * @param det  Detector number
235    * @param ring Ring identifier 
236    * @param full If true, return full path
237    * 
238    * @return Path to ring
239    */  
240   const char* GetRingPath(UShort_t det, Char_t ring, Bool_t full=kTRUE) const;
241   /** 
242    * Get the sector path in diagnositcs file
243    * 
244    * @param det  Detector number
245    * @param ring Ring identifier 
246    * @param sec  Sector number
247    * @param full If true, return full path
248    * 
249    * @return Path to sector
250    */  
251   const char* GetSectorPath(UShort_t det, Char_t ring, UShort_t sec, 
252                             Bool_t full=kTRUE) const;
253   /** 
254    * Get the strip path in diagnositcs file
255    * 
256    * @param det  Detector number
257    * @param ring Ring identifier 
258    * @param sec  Sector number
259    * @param str  Strip number
260    * @param full If true, return full path
261    * 
262    * @return Path to strip
263    */  
264   const char* GetStripPath(UShort_t det, Char_t ring, UShort_t sec, 
265                            UShort_t str, Bool_t full=kTRUE) const;
266   TObjArray* GetDetectorArray(UShort_t det);
267   TObjArray* GetRingArray(UShort_t det, Char_t ring);
268   TObjArray* GetSectorArray(UShort_t det, Char_t ring, UShort_t sector);
269   TObjArray* GetStripArray(UShort_t det, Char_t ring, 
270                            UShort_t sector, UShort_t strip);
271   /** 
272    * Write conditions file 
273    * 
274    * @param fmdReader Raw input
275    */ 
276   void WriteConditionsData(AliFMDRawReader* fmdReader);
277   /** 
278    * Set the current event 
279    * 
280    * @param currentEvent 
281    */
282   void SetCurrentEvent(Int_t currentEvent) {fCurrentEvent = currentEvent; }
283   /** 
284    * Initialize container 
285    * 
286    * @param dir Directory to make containers in 
287    */
288   virtual void InitContainer(TDirectory* dir);
289   /** 
290    * Utility function for defining summary histograms 
291    *
292    * @param det    Detector 
293    * @param ring   Ring identifier 
294    * @param prefix Histogram prefix 
295    * @param title  Histogram title 
296    */
297   TH2* MakeSummaryHistogram(const char* prefix, const char* title, 
298                             UShort_t det, Char_t ring);
299   /** 
300    * Make a summary
301    * 
302    */
303   virtual void  MakeSummary(UShort_t, Char_t) { }
304   
305   virtual Bool_t HaveEnough(Int_t nEvent) const;
306   virtual UShort_t GetProgress(Int_t nEvent) const;
307
308
309
310   static const UInt_t fgkBaseDDL = 3072;   // base FMD ddl
311   //Char_t* fDiagnosticsFilename;
312   TString       fDiagnosticsFilename;  // name of diagnostics file
313   std::ofstream fOutputFile;           // output file
314   std::ofstream fConditionsFile;       // conditions file
315   Bool_t        fSaveHistograms;       // save hists or not
316   Bool_t        fMakeSummaries;        // save hists or not
317   TObjArray     fDetectorArray;        // array indiced by detector
318   TArrayS       fPulseSize;            // Pulse size for gain calib
319   TArrayS       fPulseLength;          // Pulse length for gain calib
320   Bool_t        fSeenDetectors[3];     // Detectors seen so far
321   UInt_t        fNEventsPerDetector[3];// # events per detector
322   Int_t         fRequiredEvents;       // # events required for this calib
323   Int_t         fCurrentEvent;         // the current event       
324   UInt_t        fRunno;                // Current run number 
325   TObjArray     fSummaries;            // Summary histograms 
326   
327   ClassDef(AliFMDBaseDA,0) // Base Detector algorithm for all run types
328
329 };
330 //____________________________________________________________________
331 inline Bool_t
332 AliFMDBaseDA::HasSeenDetector(UShort_t d) const
333
334   return (d == 0 || d > 3) ? false : fSeenDetectors[d-1]; 
335 }
336
337 #endif
338