]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliCorrectionManagerBase.h
Merge branch 'workdir'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliCorrectionManagerBase.h
CommitLineData
8449e3e0 1// -*- mode: C++ -*-
2/**
3 * @file AliCorrectionManagerBase.h
4 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
5 * @date Sun May 19 21:56:13 2013
6 *
7 * @brief Base class for correction managers
8 *
9 *
10 */
11#ifndef ALICORRECTIONMANAGERBASE_H
12#define ALICORRECTIONMANAGERBASE_H
13#include <TString.h>
14#include <TNamed.h>
15#include <TObjArray.h>
16class AliOADBForward;
17class TBrowser;
c8b1a7db 18class TAxis;
8449e3e0 19
20/**
21 * Base class for correction managers.
22 *
23 * A correction is added to the manager by calling RegisterCorrection
24 *
25 * @code
26 * class MyManager : public AliCorrectionManager
27 * {
28 * public:
29 * enum {
30 * kA,
31 * kB
32 * };
33 * MyManager()
34 * : AliCorrectionManager(Bool_t setup=false)
35 * {
36 * if (setup) {
37 * RegisterCorrection(kA, "A", "/some/path/to/file",
38 * TH2D::Class(), kStandard);
39 * RegisterCorrection(kB, "B", "/some/path/to/file",
40 * TParameter<float>::Class(), kStandard);
41 * }
42 * }
43 * void Init(Bool_t useA, Bool_t useB, ULong_t run, UShort_t sys,
44 * UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat,
45 * Bool_t force=false)
46 * {
47 * if (useA) GetCorrection(kA)->fEnabled = true;
48 * if (useB) GetCorrection(kB)->fEnabled = true;
49 *
50 * return InitCorrections(run, sys, sNN, fld, mc, sat, force);
51 * }
52 * TH2D* GetA() const { return static_cast<TH2D*>(Get(kA)); }
53 * TParameter<float>* GetB() const { return static_cast<TParameter<float>*>(Get(kB)); }
54 * };
55 * @endcode
56 *
57 * In case the derived object is to be a singleton, one has to take a
58 * little extra care about when the constructor is called - especially
59 * if the singleton is to be streamed to disk:
60 *
61 * @code
62 * class MyManager : public AliCorrectionManager
63 * {
64 * public:
65 * // As above, except the constructor must be private and
66 * MyManager& Instance()
67 * {
68 * if (!fgInstance) fgInstance = MyManager(true);
69 * return fgInstance;
70 * }
71 * static MyManager* fgInstance;
72 * };
73 * @endcode
74 *
75 * It is important - for I/O that default construction does not
76 * register the corrections. This should only be done in-code on
77 * first construction.
78 *
79 */
80class AliCorrectionManagerBase : public TObject
81{
82public:
83 enum EConstants {
84 kIgnoreValue = 0,
901f4bc0 85 kIgnoreField = 999 // Must be synced with AliOADBForward::kInvalidField
8449e3e0 86 };
87 enum EFields {
88 kRun = 0x01,
89 kSys = 0x02,
90 kSNN = 0x04,
91 kField = 0x08,
92 kMC = 0x10,
93 kSatellite = 0x20,
94 kStandard = kRun|kSys|kSNN|kField,
95 kFull = kStandard|kMC|kSatellite
96 };
97 /**
98 * Destructor
99 */
100 virtual ~AliCorrectionManagerBase();
101 /**
102 * Check if the manager is initialized
103 *
104 * @return True if initialized
105 */
106 virtual Bool_t IsInit() const { return fIsInit; }
107 /**
108 * Print information
109 *
110 * @param option Options:
111 *
112 * - R Recursive list each correction
113 * - D Also give details for each correction
114 */
115 virtual void Print(Option_t* option="") const;
116 /**
117 * Set the prefix to use when looking for the input files
118 *
119 * @param prefix Prefix to use for all corrections
120 */
121 virtual void SetPrefix(const TString& prefix);
901f4bc0 122 /**
123 * Set whether to enable fall-back queries
124 *
125 * @param use If true, enable fall-back queries
126 */
127 virtual void SetEnableFallBack(Bool_t use=true) { fFallBack = use; }
8449e3e0 128 /**
129 * Store a correction
130 *
131 * @param o Object to store
132 * @param runNo Run number of run this was created from
133 * @param sys Collision system (1:pp, 2:PbPb, 3:pPb)
134 * @param sNN Center of mass energy in GeV
135 * @param field L3 magnetic field in kG
136 * @param mc If true, this is for simulations
137 * @param sat If true, contain info for satellite interactions
138 * @param file (optional) file name to store in
139 * @param meth (optional) method for run look to use.
140 *
141 * @return true on success
142 */
143 virtual Bool_t Store(TObject* o,
144 ULong_t runNo,
145 UShort_t sys,
146 UShort_t sNN,
147 Short_t field,
148 Bool_t mc,
149 Bool_t sat,
150 const char* file,
151 const char* meth="NEAR") const;
152 /**
153 * Append the content of the file @a addition to the @a destination
154 * file for this manager. This used TFileMerger::PartialMerge
155 *
156 * @param destination Filename of destination storage (in OADB_PATH)
157 * @param addition Filename of addition.
158 *
159 * @return true on success
160 */
161 virtual Bool_t Append(const TString& addition,
162 const TString& destination="") const;
163 /**
164 * Browse this object
165 *
166 * @param b Browser to use
167 */
168 virtual void Browse(TBrowser* b);
169 /**
170 * Flag that this is a folder
171 *
172 * @return Always true
173 */
174 virtual Bool_t IsFolder() const { return true; }
175 /**
176 * Set whehter to enable debug information
177 *
178 * @param debug if true, do verbose queries
179 */
180 virtual void SetDebug(Bool_t debug) { fDebug = debug; }
c8b1a7db 181 /**
182 * Convinience function to enable corrections on-mass. User class
183 * should overload this to properly enable corrections based on the
184 * bit identifiers.
185 *
186 * @param what Bit mask of correction identifiers.
187 */
188 virtual void EnableCorrections(UInt_t what);
189 /**
190 * Check if the specified corrrections have been initialized
191 *
192 * @param what Corrections to check
193 * @param verbose If true, be verbose
194 *
195 * @return true if all specified the corrections have been
196 */
197 virtual Bool_t CheckCorrections(UInt_t what, Bool_t verbose=true) const;
198 /**
199 * Read in all corrections
200 *
201 * @param run Run number
202 * @param sys System
203 * @param sNN Center of mass energy
204 * @param fld L3 magnetic field
205 * @param mc For simulations
206 * @param sat For satellite interactions
207 * @param force Force-reread
208 *
209 * @return true on success
210 */
211 Bool_t InitCorrections(ULong_t run,
212 UShort_t sys,
213 UShort_t sNN,
214 Short_t fld,
215 Bool_t mc,
216 Bool_t sat,
217 Bool_t force=false);
218 /**
219 * @{
220 * @name Get axis objects.
221 */
222 /**
223 * Get the vertex axis
224 *
225 * @return The vertex axis or null
226 */
227 virtual const TAxis* GetVertexAxis() const { return 0; }
228 /**
229 * Get the @f$\eta@f$ axis
230 *
231 * @return The @f$\eta@f$ axis or null
232 */
233 virtual const TAxis* GetEtaAxis() const { return 0; }
234 /* @} */
8449e3e0 235protected:
236 /**
237 * Correction registration
238 */
239 struct Correction : public TNamed
240 {
241 /**
242 * Constructor - for I/O
243 */
244 Correction();
245 /**
246 * Constructor
247 *
c8b1a7db 248 * @param tableName Table name
249 * @param fileName File name
250 * @param cls Class
251 * @param queryFields Enabled fields
252 * @param enabled Enabled or not
8449e3e0 253 */
254 Correction(const TString& tableName,
255 const TString& fileName,
256 TClass* cls,
257 UShort_t queryFields=kStandard,
258 Bool_t enabled=false);
259 /**
260 * Copy constructor
261 *
262 * @param o Object to copy from
263 */
264 Correction(const Correction& o);
265 /**
266 * Assignement operator
267 *
268 * @param o Object to assign from
269 *
270 * @return reference to this obejct
271 */
272 Correction& operator=(const Correction& o);
273 /**
274 * Destructor
275 */
276 ~Correction() { delete fObject; }
277 /**
278 * Read the correction
279 *
280 * @param db Database interface
281 * @param run Run number
282 * @param sys Collision system
283 * @param sNN Center of mass energy per nucleon
284 * @param fld L3 magnetic field
285 * @param mc If true, for simulated data, else real
286 * @param sat If true, for satellite interactions
287 * @param vrb If true, do verbose query
c8b1a7db 288 * @param fbk Force read
8449e3e0 289 *
290 * @return true on success
291 */
292 Bool_t ReadIt(AliOADBForward* db,
293 ULong_t run,
294 UShort_t sys,
295 UShort_t sNN,
296 Short_t fld,
297 Bool_t mc,
298 Bool_t sat,
901f4bc0 299 Bool_t vrb=false,
300 Bool_t fbk=false);
8449e3e0 301 /**
302 * Store a correction
303 *
304 * @param db Possible database interface
305 * @param o Object to store
306 * @param run Run number
307 * @param sys Collision system
308 * @param sNN Center of mass energy per nucleon
309 * @param fld L3 magnetic field
310 * @param mc If true, for simulated data, else real
311 * @param sat If true, for satellite interactions
312 * @param file File to store in
313 * @param meth Default run method
314 *
315 * @return true on success
316 */
317 Bool_t StoreIt(AliOADBForward* db,
318 TObject* o,
319 ULong_t run,
320 UShort_t sys,
321 UShort_t sNN,
322 Short_t fld,
323 Bool_t mc,
324 Bool_t sat,
325 const char* file=0,
326 const char* meth="NEAR") const;
327 /**
328 * Enable this correction
329 *
330 * @param enabled If true, correction is enabled
331 */
332 void Enable(Bool_t enabled=true) { fEnabled = enabled; }
333 /**
334 * Get the data of the correction
335 *
336 * @return Data of the correction
337 */
338 TObject* Get();
339 /**
340 * Get the data of the correction
341 *
342 * @return Data of the correction
343 */
344 const TObject* Get() const;
345 /**
346 * Set the file the table is stored in
347 *
348 * @param fileName file name of file table is stored in
349 */
350 void SetFile(const TString& fileName) { fTitle = fileName; }
351 /**
352 * Get pointer to class meta information. Sets the internal
353 * member if not done already.
354 *
355 * @return Pointer to class meta information
356 */
357 const TClass* TheClass() const;
358 /**
359 * Print information to the screen
360 *
361 * @param option Options
362 */
363 void Print(Option_t* option="") const;
364 /**
365 * Browse this object
366 *
367 * @param b Browser to use
368 */
369 void Browse(TBrowser* b);
370 /**
371 * Flag that this is a folder
372 *
373 * @return Always true
374 */
375 Bool_t IsFolder() const { return true; }
376
377
378 mutable TClass* fCls; //! Class of correction objects
379 const TString fClientCls; // Class name
380 UShort_t fQueryFields; // Enabled query fields
381 Bool_t fEnabled; // Whether we're in use
382 TString fLastEntry; // Text representation of last entry
383 TObject* fObject; // The data
384 ClassDef(Correction,1) // Correction meta object
385 };
386 /**
387 * Constructor
388 */
389 AliCorrectionManagerBase();
390 /**
391 * Constructor
392 */
393 AliCorrectionManagerBase(Bool_t notUsed);
394 /**
395 * Copy Constructor
396 */
397 AliCorrectionManagerBase(const AliCorrectionManagerBase& o);
398 /**
399 * Assignement operator
400 *
401 * @param o Object to assign from
402 *
403 * @return Reference to this
404 */
405 AliCorrectionManagerBase& operator=(const AliCorrectionManagerBase& o);
406 /**
407 * Register a correction
408 *
409 * @param id Identifier
410 * @param corr Correction
411 */
412 void RegisterCorrection(Int_t id, Correction* corr);
413 /**
414 * Register a new correction.
415 *
416 * @param id Identifier
417 * @param tableName Table name
418 * @param fileName File name
419 * @param cls Class
420 * @param fields Fields
421 * @param enabled Enabled or not
422 */
423 void RegisterCorrection(Int_t id,
424 const TString& tableName,
425 const TString& fileName,
426 TClass* cls,
427 UShort_t fields=kStandard,
428 Bool_t enabled=false);
429 /**
430 * Enable the correction at @a id
431 *
432 * @param id Identifier
433 * @param enable Whether to enable (true) or disable (false)
434 */
435 void EnableCorrection(Int_t id, Bool_t enable=true);
436 /**
437 * Get the correction at @a id
438 *
439 * @param id Identifier
440 *
441 * @return Correction or null
442 */
443 Correction* GetCorrection(Int_t id);
444 /**
445 * Get the correction at @a id
446 *
447 * @param id Identifier
448 *
449 * @return Correction or null
450 */
451 const Correction* GetCorrection(Int_t id) const;
452 /**
453 * Set the correction file
454 *
455 * @param id Identifier
456 * @param fileName file
457 */
458 void SetCorrectionFile(Int_t id, const TString& fileName) const;
459 /**
460 * Get the id of the correction with a given name
461 *
462 * @param what Name of correction to look for
463 *
464 * @return Correction identifier
465 */
466 Int_t GetId(const TString& what) const;
467 /**
468 * Get the id of the correction to store an object
469 *
470 * @param obj Correction object
471 *
472 * @return Correction identifier
473 */
474 Int_t GetId(const TObject* obj) const;
475 /**
476 * Get the object corresponding to ID
477 *
478 * @param id Correction identifier
479 *
480 * @return Object of correction, or null if correction not found or in-active
481 */
482 TObject* Get(Int_t id);
483 /**
484 * Get the object corresponding to ID
485 *
486 * @param id Correction identifier
487 *
488 * @return Object of correction, or null if correction not found or in-active
489 */
490 const TObject* Get(Int_t id) const;
8449e3e0 491 /**
492 * Read in all corrections
493 *
494 * @param run Run number
495 * @param sys System
496 * @param sNN Center of mass energy
497 * @param fld L3 magnetic field
498 * @param mc For simulations
499 * @param sat For satellite interactions
500 *
501 * @return true on success
502 */
503 Bool_t CheckConditions(ULong_t run,
504 UShort_t sys,
505 UShort_t sNN,
506 Short_t fld,
507 Bool_t mc,
508 Bool_t sat);
509 /**
510 * Read in all corrections
511 *
512 * @param run Run number
513 * @param sys System
514 * @param sNN Center of mass energy
515 * @param fld L3 magnetic field
516 * @param mc For simulations
517 * @param sat For satellite interactions
518 *
519 * @return true on success
520 */
521 Bool_t ReadCorrections(ULong_t run,
522 UShort_t sys,
523 UShort_t sNN,
524 Short_t fld,
525 Bool_t mc,
526 Bool_t sat);
527 /**
528 * Read in a correction
529 *
530 * @param id Correction identifier
531 * @param run Run number
532 * @param sys System
533 * @param sNN Center of mass energy
534 * @param fld L3 magnetic field
535 * @param mc For simulations
536 * @param sat For satellite interactions
537 *
538 * @return true on success
539 */
540 Bool_t ReadCorrection(Int_t id,
541 ULong_t run,
542 UShort_t sys,
543 UShort_t sNN,
544 Short_t fld,
545 Bool_t mc,
546 Bool_t sat);
547 /**
548 * Set the correction file name for correction at @a i
549 *
550 * @param i Identifier
551 * @param file Filename
552 */
553 void SetCorrectionFile(Int_t i, const TString& file);
554
555 TObjArray fCorrections; // List of corrections
556 Bool_t fIsInit; // Whether we're intialized or not
557 ULong_t fRun; // Cached run number
558 UShort_t fSys; // Cached system (1:pp 2:PbPb 3:pPb)
559 UShort_t fSNN; // Cached center of mass energy [GeV]
560 Short_t fField; // Cached L3 magnetic field [kG]
561 Bool_t fMC; // Cached Simulation flag
562 Bool_t fSatellite; // Cached satellite interaction flat
563 AliOADBForward* fDB; //! do not store
564 Bool_t fDebug; // If true, do verbose queries
901f4bc0 565 Bool_t fFallBack; // If true, enable fall-back queries
566 ClassDef(AliCorrectionManagerBase,2);
8449e3e0 567};
568
569#endif
570
571
572
573