Added new 'status' histogram to the DQM data maker and checker. This histogram
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.h
CommitLineData
e9c06036 1// -*- mode: C++ -*-
a3b36d36 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//
e9c06036 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.
a3b36d36 19//
e9c06036 20// Author: Hans Hjersing Dalsgaard, hans.dalsgaard@cern.ch
a3b36d36 21//
22
23#include "TNamed.h"
24#include "TObjArray.h"
a7e41e8d 25#include "TString.h"
427e8f99 26#include "TArrayS.h"
09b6c804 27#include <iosfwd>
28#include <fstream>
29class AliFMDDigit;
30class AliRawReader;
31class AliFMDParameters;
3effc6e7 32class AliFMDRawReader;
09b6c804 33class TDirectory;
2a082c96 34class TH2;
09b6c804 35class TFile;
36class TClonesArray;
a3b36d36 37
6cf6e7a0 38class AliFMDBaseDA: public TNamed
39{
e9c06036 40public:
6cf6e7a0 41 /**
42 * Constructor
43 *
44 */
a3b36d36 45 AliFMDBaseDA() ;
6cf6e7a0 46 /**
47 * Copy constructor
48 *
49 * @param baseDA
50 */
a3b36d36 51 AliFMDBaseDA(const AliFMDBaseDA & baseDA) ;
fb10ff39 52 // AliFMDBaseDA& operator = (const AliFMDBaseDA & baseDA) ;
6cf6e7a0 53 /**
54 * Destructor
55 *
56 */
a3b36d36 57 ~AliFMDBaseDA() ;
d015ecfe 58 AliFMDBaseDA& operator=(const AliFMDBaseDA&) { return *this; }
6cf6e7a0 59 /**
60 * Run this DA
61 *
62 * @param fmdReader Raw input reader
63 */
a3b36d36 64 void Run(AliRawReader* fmdReader);
6cf6e7a0 65 /**
66 * Set whether to save diagnostics
67 *
68 * @param save If true, will output diagnostics file
69 */
a3b36d36 70 void SetSaveDiagnostics(Bool_t save) {fSaveHistograms = save;}
6cf6e7a0 71 /**
a31ea3ce 72 * Set the diagnostics file name
73 *
74 * @param f Diagnostics file name
75 */
76 void SetDiagnosticsFilename(const TString& f) { fDiagnosticsFilename = f; }
77 /**
2a082c96 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 /**
6cf6e7a0 84 * Set the number of requried events
85 *
86 * @param nEvents Number of event we need
87 */
a3b36d36 88 void SetRequiredEvents(Int_t nEvents) {fRequiredEvents = nEvents;}
6cf6e7a0 89 /**
90 * Get the number of required events
91 *
92 *
93 * @return number of required events
94 */
c5569fbc 95 Int_t GetRequiredEvents() const {return fRequiredEvents ;}
2a082c96 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 */
09b6c804 108 Bool_t HasSeenDetector(UShort_t d) const;
a31ea3ce 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 };
e9c06036 127protected:
6cf6e7a0 128 /**
129 * Initialize
6cf6e7a0 130 */
26be6417 131 virtual void Init() {};
6cf6e7a0 132 /**
133 * Fill channels
6cf6e7a0 134 */
26be6417 135 virtual void FillChannels(AliFMDDigit* ) {};
6cf6e7a0 136 /**
137 * Analyse a single strip result
6cf6e7a0 138 */
2a082c96 139 virtual void Analyse(UShort_t, Char_t, UShort_t, UShort_t) {};
6cf6e7a0 140 /**
141 * Write header to output file
6cf6e7a0 142 */
26be6417 143 virtual void WriteHeaderToFile() {};
6cf6e7a0 144 /**
145 * Add a strip container
6cf6e7a0 146 */
147 virtual void AddChannelContainer(TObjArray*, UShort_t, Char_t,
148 UShort_t, UShort_t ) {};
149 /**
a31ea3ce 150 * Add summary(s) for sectors
151 *
152 */
153 virtual void AddSectorSummary(TObjArray*, UShort_t, Char_t, UShort_t,
154 UShort_t) {}
155 /**
6cf6e7a0 156 * End of event
6cf6e7a0 157 */
26be6417 158 virtual void FinishEvent() {};
6cf6e7a0 159 /**
160 * End of run
6cf6e7a0 161 */
f7f0b643 162 virtual void Terminate(TFile* ) {};
6cf6e7a0 163 /**
164 * Current event number
165 *
166 *
167 * @return
168 */
c5569fbc 169 Int_t GetCurrentEvent() const {return fCurrentEvent;}
6cf6e7a0 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;
6cf6e7a0 181 /**
182 * Ge the half-ring index
183 *
184 * @param UShort_t
185 * @param Char_t
186 * @param UShort_t
187 *
188 * @return
189 */
c5569fbc 190 Int_t GetHalfringIndex(UShort_t, Char_t, UShort_t) const;
6cf6e7a0 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 */
427e8f99 200 Int_t GetPulseSize(UShort_t det ,
201 Char_t ring,
6cf6e7a0 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 */
427e8f99 215 Int_t GetPulseLength(UShort_t det,
216 Char_t ring,
6cf6e7a0 217 UShort_t board)
218 {
219 return fPulseLength.At(GetHalfringIndex(det,ring,board));
220 }
427e8f99 221
6cf6e7a0 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 */
e9c06036 230 const char* GetDetectorPath(UShort_t det, Bool_t full=kTRUE) const;
6cf6e7a0 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 */
e9c06036 240 const char* GetRingPath(UShort_t det, Char_t ring, Bool_t full=kTRUE) const;
6cf6e7a0 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 */
e9c06036 251 const char* GetSectorPath(UShort_t det, Char_t ring, UShort_t sec,
252 Bool_t full=kTRUE) const;
6cf6e7a0 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 */
e9c06036 264 const char* GetStripPath(UShort_t det, Char_t ring, UShort_t sec,
265 UShort_t str, Bool_t full=kTRUE) const;
a31ea3ce 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);
6cf6e7a0 271 /**
272 * Write conditions file
273 *
274 * @param fmdReader Raw input
275 */
3effc6e7 276 void WriteConditionsData(AliFMDRawReader* fmdReader);
6cf6e7a0 277 /**
278 * Set the current event
279 *
280 * @param currentEvent
281 */
a3b36d36 282 void SetCurrentEvent(Int_t currentEvent) {fCurrentEvent = currentEvent; }
6cf6e7a0 283 /**
284 * Initialize container
285 *
286 * @param dir Directory to make containers in
287 */
a31ea3ce 288 virtual void InitContainer(TDirectory* dir);
2a082c96 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);
09b6c804 299 /**
300 * Make a summary
301 *
302 */
2a082c96 303 virtual void MakeSummary(UShort_t, Char_t) { }
a31ea3ce 304
305 virtual Bool_t HaveEnough(Int_t nEvent) const;
306 virtual UShort_t GetProgress(Int_t nEvent) const;
09b6c804 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
a31ea3ce 321 UInt_t fNEventsPerDetector[3];// # events per detector
09b6c804 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
427e8f99 326
6cf6e7a0 327 ClassDef(AliFMDBaseDA,0) // Base Detector algorithm for all run types
a3b36d36 328
329};
09b6c804 330//____________________________________________________________________
331inline Bool_t
332AliFMDBaseDA::HasSeenDetector(UShort_t d) const
333{
334 return (d == 0 || d > 3) ? false : fSeenDetectors[d-1];
335}
336
a3b36d36 337#endif
338