3 * @file AliCorrectionManagerBase.h
4 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
5 * @date Sun May 19 21:56:13 2013
7 * @brief Base class for correction managers
11 #ifndef ALICORRECTIONMANAGERBASE_H
12 #define ALICORRECTIONMANAGERBASE_H
15 #include <TObjArray.h>
21 * Base class for correction managers.
23 * A correction is added to the manager by calling RegisterCorrection
26 * class MyManager : public AliCorrectionManager
34 * : AliCorrectionManager(Bool_t setup=false)
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);
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,
47 * if (useA) GetCorrection(kA)->fEnabled = true;
48 * if (useB) GetCorrection(kB)->fEnabled = true;
50 * return InitCorrections(run, sys, sNN, fld, mc, sat, force);
52 * TH2D* GetA() const { return static_cast<TH2D*>(Get(kA)); }
53 * TParameter<float>* GetB() const { return static_cast<TParameter<float>*>(Get(kB)); }
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:
62 * class MyManager : public AliCorrectionManager
65 * // As above, except the constructor must be private and
66 * MyManager& Instance()
68 * if (!fgInstance) fgInstance = MyManager(true);
71 * static MyManager* fgInstance;
75 * It is important - for I/O that default construction does not
76 * register the corrections. This should only be done in-code on
80 class AliCorrectionManagerBase : public TObject
85 kIgnoreField = 999 // Must be synced with AliOADBForward::kInvalidField
94 kStandard = kRun|kSys|kSNN|kField,
95 kFull = kStandard|kMC|kSatellite
100 virtual ~AliCorrectionManagerBase();
102 * Check if the manager is initialized
104 * @return True if initialized
106 virtual Bool_t IsInit() const { return fIsInit; }
110 * @param option Options:
112 * - R Recursive list each correction
113 * - D Also give details for each correction
115 virtual void Print(Option_t* option="") const;
117 * Set the prefix to use when looking for the input files
119 * @param prefix Prefix to use for all corrections
121 virtual void SetPrefix(const TString& prefix);
123 * Set whether to enable fall-back queries
125 * @param use If true, enable fall-back queries
127 virtual void SetEnableFallBack(Bool_t use=true) { fFallBack = use; }
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.
141 * @return true on success
143 virtual Bool_t Store(TObject* o,
151 const char* meth="NEAR") const;
153 * Append the content of the file @a addition to the @a destination
154 * file for this manager. This used TFileMerger::PartialMerge
156 * @param destination Filename of destination storage (in OADB_PATH)
157 * @param addition Filename of addition.
159 * @return true on success
161 virtual Bool_t Append(const TString& addition,
162 const TString& destination="") const;
166 * @param b Browser to use
168 virtual void Browse(TBrowser* b);
170 * Flag that this is a folder
172 * @return Always true
174 virtual Bool_t IsFolder() const { return true; }
176 * Set whehter to enable debug information
178 * @param debug if true, do verbose queries
180 virtual void SetDebug(Bool_t debug) { fDebug = debug; }
182 * Convinience function to enable corrections on-mass. User class
183 * should overload this to properly enable corrections based on the
186 * @param what Bit mask of correction identifiers.
188 virtual void EnableCorrections(UInt_t what);
190 * Check if the specified corrrections have been initialized
192 * @param what Corrections to check
193 * @param verbose If true, be verbose
195 * @return true if all specified the corrections have been
197 virtual Bool_t CheckCorrections(UInt_t what, Bool_t verbose=true) const;
199 * Read in all corrections
201 * @param run Run number
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
209 * @return true on success
211 Bool_t InitCorrections(ULong_t run,
220 * @name Get axis objects.
223 * Get the vertex axis
225 * @return The vertex axis or null
227 virtual const TAxis* GetVertexAxis() const { return 0; }
229 * Get the @f$\eta@f$ axis
231 * @return The @f$\eta@f$ axis or null
233 virtual const TAxis* GetEtaAxis() const { return 0; }
237 * Correction registration
239 struct Correction : public TNamed
242 * Constructor - for I/O
248 * @param tableName Table name
249 * @param fileName File name
251 * @param queryFields Enabled fields
252 * @param enabled Enabled or not
254 Correction(const TString& tableName,
255 const TString& fileName,
257 UShort_t queryFields=kStandard,
258 Bool_t enabled=false);
262 * @param o Object to copy from
264 Correction(const Correction& o);
266 * Assignement operator
268 * @param o Object to assign from
270 * @return reference to this obejct
272 Correction& operator=(const Correction& o);
276 ~Correction() { delete fObject; }
278 * Read the correction
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
288 * @param fbk Force read
290 * @return true on success
292 Bool_t ReadIt(AliOADBForward* db,
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
315 * @return true on success
317 Bool_t StoreIt(AliOADBForward* db,
326 const char* meth="NEAR") const;
328 * Enable this correction
330 * @param enabled If true, correction is enabled
332 void Enable(Bool_t enabled=true) { fEnabled = enabled; }
334 * Get the data of the correction
336 * @return Data of the correction
340 * Get the data of the correction
342 * @return Data of the correction
344 const TObject* Get() const;
346 * Set the file the table is stored in
348 * @param fileName file name of file table is stored in
350 void SetFile(const TString& fileName) { fTitle = fileName; }
352 * Get pointer to class meta information. Sets the internal
353 * member if not done already.
355 * @return Pointer to class meta information
357 const TClass* TheClass() const;
359 * Print information to the screen
361 * @param option Options
363 void Print(Option_t* option="") const;
367 * @param b Browser to use
369 void Browse(TBrowser* b);
371 * Flag that this is a folder
373 * @return Always true
375 Bool_t IsFolder() const { return true; }
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
389 AliCorrectionManagerBase();
393 AliCorrectionManagerBase(Bool_t notUsed);
397 AliCorrectionManagerBase(const AliCorrectionManagerBase& o);
399 * Assignement operator
401 * @param o Object to assign from
403 * @return Reference to this
405 AliCorrectionManagerBase& operator=(const AliCorrectionManagerBase& o);
407 * Register a correction
409 * @param id Identifier
410 * @param corr Correction
412 void RegisterCorrection(Int_t id, Correction* corr);
414 * Register a new correction.
416 * @param id Identifier
417 * @param tableName Table name
418 * @param fileName File name
420 * @param fields Fields
421 * @param enabled Enabled or not
423 void RegisterCorrection(Int_t id,
424 const TString& tableName,
425 const TString& fileName,
427 UShort_t fields=kStandard,
428 Bool_t enabled=false);
430 * Enable the correction at @a id
432 * @param id Identifier
433 * @param enable Whether to enable (true) or disable (false)
435 void EnableCorrection(Int_t id, Bool_t enable=true);
437 * Get the correction at @a id
439 * @param id Identifier
441 * @return Correction or null
443 Correction* GetCorrection(Int_t id);
445 * Get the correction at @a id
447 * @param id Identifier
449 * @return Correction or null
451 const Correction* GetCorrection(Int_t id) const;
453 * Set the correction file
455 * @param id Identifier
456 * @param fileName file
458 void SetCorrectionFile(Int_t id, const TString& fileName) const;
460 * Get the id of the correction with a given name
462 * @param what Name of correction to look for
464 * @return Correction identifier
466 Int_t GetId(const TString& what) const;
468 * Get the id of the correction to store an object
470 * @param obj Correction object
472 * @return Correction identifier
474 Int_t GetId(const TObject* obj) const;
476 * Get the object corresponding to ID
478 * @param id Correction identifier
480 * @return Object of correction, or null if correction not found or in-active
482 TObject* Get(Int_t id);
484 * Get the object corresponding to ID
486 * @param id Correction identifier
488 * @return Object of correction, or null if correction not found or in-active
490 const TObject* Get(Int_t id) const;
492 * Read in all corrections
494 * @param run Run number
496 * @param sNN Center of mass energy
497 * @param fld L3 magnetic field
498 * @param mc For simulations
499 * @param sat For satellite interactions
501 * @return true on success
503 Bool_t CheckConditions(ULong_t run,
510 * Read in all corrections
512 * @param run Run number
514 * @param sNN Center of mass energy
515 * @param fld L3 magnetic field
516 * @param mc For simulations
517 * @param sat For satellite interactions
519 * @return true on success
521 Bool_t ReadCorrections(ULong_t run,
528 * Read in a correction
530 * @param id Correction identifier
531 * @param run Run number
533 * @param sNN Center of mass energy
534 * @param fld L3 magnetic field
535 * @param mc For simulations
536 * @param sat For satellite interactions
538 * @return true on success
540 Bool_t ReadCorrection(Int_t id,
548 * Set the correction file name for correction at @a i
550 * @param i Identifier
551 * @param file Filename
553 void SetCorrectionFile(Int_t i, const TString& file);
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
565 Bool_t fFallBack; // If true, enable fall-back queries
566 ClassDef(AliCorrectionManagerBase,2);