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>
20 * Base class for correction managers.
22 * A correction is added to the manager by calling RegisterCorrection
25 * class MyManager : public AliCorrectionManager
33 * : AliCorrectionManager(Bool_t setup=false)
36 * RegisterCorrection(kA, "A", "/some/path/to/file",
37 * TH2D::Class(), kStandard);
38 * RegisterCorrection(kB, "B", "/some/path/to/file",
39 * TParameter<float>::Class(), kStandard);
42 * void Init(Bool_t useA, Bool_t useB, ULong_t run, UShort_t sys,
43 * UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat,
46 * if (useA) GetCorrection(kA)->fEnabled = true;
47 * if (useB) GetCorrection(kB)->fEnabled = true;
49 * return InitCorrections(run, sys, sNN, fld, mc, sat, force);
51 * TH2D* GetA() const { return static_cast<TH2D*>(Get(kA)); }
52 * TParameter<float>* GetB() const { return static_cast<TParameter<float>*>(Get(kB)); }
56 * In case the derived object is to be a singleton, one has to take a
57 * little extra care about when the constructor is called - especially
58 * if the singleton is to be streamed to disk:
61 * class MyManager : public AliCorrectionManager
64 * // As above, except the constructor must be private and
65 * MyManager& Instance()
67 * if (!fgInstance) fgInstance = MyManager(true);
70 * static MyManager* fgInstance;
74 * It is important - for I/O that default construction does not
75 * register the corrections. This should only be done in-code on
79 class AliCorrectionManagerBase : public TObject
93 kStandard = kRun|kSys|kSNN|kField,
94 kFull = kStandard|kMC|kSatellite
99 virtual ~AliCorrectionManagerBase();
101 * Check if the manager is initialized
103 * @return True if initialized
105 virtual Bool_t IsInit() const { return fIsInit; }
109 * @param option Options:
111 * - R Recursive list each correction
112 * - D Also give details for each correction
114 virtual void Print(Option_t* option="") const;
116 * Set the prefix to use when looking for the input files
118 * @param prefix Prefix to use for all corrections
120 virtual void SetPrefix(const TString& prefix);
124 * @param o Object to store
125 * @param runNo Run number of run this was created from
126 * @param sys Collision system (1:pp, 2:PbPb, 3:pPb)
127 * @param sNN Center of mass energy in GeV
128 * @param field L3 magnetic field in kG
129 * @param mc If true, this is for simulations
130 * @param sat If true, contain info for satellite interactions
131 * @param file (optional) file name to store in
132 * @param meth (optional) method for run look to use.
134 * @return true on success
136 virtual Bool_t Store(TObject* o,
144 const char* meth="NEAR") const;
146 * Append the content of the file @a addition to the @a destination
147 * file for this manager. This used TFileMerger::PartialMerge
149 * @param destination Filename of destination storage (in OADB_PATH)
150 * @param addition Filename of addition.
152 * @return true on success
154 virtual Bool_t Append(const TString& addition,
155 const TString& destination="") const;
159 * @param b Browser to use
161 virtual void Browse(TBrowser* b);
163 * Flag that this is a folder
165 * @return Always true
167 virtual Bool_t IsFolder() const { return true; }
169 * Set whehter to enable debug information
171 * @param debug if true, do verbose queries
173 virtual void SetDebug(Bool_t debug) { fDebug = debug; }
176 * Correction registration
178 struct Correction : public TNamed
181 * Constructor - for I/O
187 * @param tableName Table name
188 * @param fileName File name
190 * @param fields Enabled fields
192 Correction(const TString& tableName,
193 const TString& fileName,
195 UShort_t queryFields=kStandard,
196 Bool_t enabled=false);
200 * @param o Object to copy from
202 Correction(const Correction& o);
204 * Assignement operator
206 * @param o Object to assign from
208 * @return reference to this obejct
210 Correction& operator=(const Correction& o);
214 ~Correction() { delete fObject; }
216 * Read the correction
218 * @param db Database interface
219 * @param run Run number
220 * @param sys Collision system
221 * @param sNN Center of mass energy per nucleon
222 * @param fld L3 magnetic field
223 * @param mc If true, for simulated data, else real
224 * @param sat If true, for satellite interactions
225 * @param vrb If true, do verbose query
227 * @return true on success
229 Bool_t ReadIt(AliOADBForward* db,
240 * @param db Possible database interface
241 * @param o Object to store
242 * @param run Run number
243 * @param sys Collision system
244 * @param sNN Center of mass energy per nucleon
245 * @param fld L3 magnetic field
246 * @param mc If true, for simulated data, else real
247 * @param sat If true, for satellite interactions
248 * @param file File to store in
249 * @param meth Default run method
251 * @return true on success
253 Bool_t StoreIt(AliOADBForward* db,
262 const char* meth="NEAR") const;
264 * Enable this correction
266 * @param enabled If true, correction is enabled
268 void Enable(Bool_t enabled=true) { fEnabled = enabled; }
270 * Get the data of the correction
272 * @return Data of the correction
276 * Get the data of the correction
278 * @return Data of the correction
280 const TObject* Get() const;
282 * Set the file the table is stored in
284 * @param fileName file name of file table is stored in
286 void SetFile(const TString& fileName) { fTitle = fileName; }
288 * Get pointer to class meta information. Sets the internal
289 * member if not done already.
291 * @return Pointer to class meta information
293 const TClass* TheClass() const;
295 * Print information to the screen
297 * @param option Options
299 void Print(Option_t* option="") const;
303 * @param b Browser to use
305 void Browse(TBrowser* b);
307 * Flag that this is a folder
309 * @return Always true
311 Bool_t IsFolder() const { return true; }
314 mutable TClass* fCls; //! Class of correction objects
315 const TString fClientCls; // Class name
316 UShort_t fQueryFields; // Enabled query fields
317 Bool_t fEnabled; // Whether we're in use
318 TString fLastEntry; // Text representation of last entry
319 TObject* fObject; // The data
320 ClassDef(Correction,1) // Correction meta object
325 AliCorrectionManagerBase();
329 AliCorrectionManagerBase(Bool_t notUsed);
333 AliCorrectionManagerBase(const AliCorrectionManagerBase& o);
335 * Assignement operator
337 * @param o Object to assign from
339 * @return Reference to this
341 AliCorrectionManagerBase& operator=(const AliCorrectionManagerBase& o);
343 * Register a correction
345 * @param id Identifier
346 * @param corr Correction
348 void RegisterCorrection(Int_t id, Correction* corr);
350 * Register a new correction.
352 * @param id Identifier
353 * @param tableName Table name
354 * @param fileName File name
356 * @param fields Fields
357 * @param enabled Enabled or not
359 void RegisterCorrection(Int_t id,
360 const TString& tableName,
361 const TString& fileName,
363 UShort_t fields=kStandard,
364 Bool_t enabled=false);
366 * Enable the correction at @a id
368 * @param id Identifier
369 * @param enable Whether to enable (true) or disable (false)
371 void EnableCorrection(Int_t id, Bool_t enable=true);
373 * Get the correction at @a id
375 * @param id Identifier
377 * @return Correction or null
379 Correction* GetCorrection(Int_t id);
381 * Get the correction at @a id
383 * @param id Identifier
385 * @return Correction or null
387 const Correction* GetCorrection(Int_t id) const;
389 * Set the correction file
391 * @param id Identifier
392 * @param fileName file
394 void SetCorrectionFile(Int_t id, const TString& fileName) const;
396 * Get the id of the correction with a given name
398 * @param what Name of correction to look for
400 * @return Correction identifier
402 Int_t GetId(const TString& what) const;
404 * Get the id of the correction to store an object
406 * @param obj Correction object
408 * @return Correction identifier
410 Int_t GetId(const TObject* obj) const;
412 * Get the object corresponding to ID
414 * @param id Correction identifier
416 * @return Object of correction, or null if correction not found or in-active
418 TObject* Get(Int_t id);
420 * Get the object corresponding to ID
422 * @param id Correction identifier
424 * @return Object of correction, or null if correction not found or in-active
426 const TObject* Get(Int_t id) const;
428 * Read in all corrections
430 * @param run Run number
432 * @param sNN Center of mass energy
433 * @param fld L3 magnetic field
434 * @param mc For simulations
435 * @param sat For satellite interactions
437 * @return true on success
439 Bool_t InitCorrections(ULong_t run,
447 * Read in all corrections
449 * @param run Run number
451 * @param sNN Center of mass energy
452 * @param fld L3 magnetic field
453 * @param mc For simulations
454 * @param sat For satellite interactions
456 * @return true on success
458 Bool_t CheckConditions(ULong_t run,
465 * Read in all corrections
467 * @param run Run number
469 * @param sNN Center of mass energy
470 * @param fld L3 magnetic field
471 * @param mc For simulations
472 * @param sat For satellite interactions
474 * @return true on success
476 Bool_t ReadCorrections(ULong_t run,
483 * Read in a correction
485 * @param id Correction identifier
486 * @param run Run number
488 * @param sNN Center of mass energy
489 * @param fld L3 magnetic field
490 * @param mc For simulations
491 * @param sat For satellite interactions
493 * @return true on success
495 Bool_t ReadCorrection(Int_t id,
503 * Set the correction file name for correction at @a i
505 * @param i Identifier
506 * @param file Filename
508 void SetCorrectionFile(Int_t i, const TString& file);
510 TObjArray fCorrections; // List of corrections
511 Bool_t fIsInit; // Whether we're intialized or not
512 ULong_t fRun; // Cached run number
513 UShort_t fSys; // Cached system (1:pp 2:PbPb 3:pPb)
514 UShort_t fSNN; // Cached center of mass energy [GeV]
515 Short_t fField; // Cached L3 magnetic field [kG]
516 Bool_t fMC; // Cached Simulation flag
517 Bool_t fSatellite; // Cached satellite interaction flat
518 AliOADBForward* fDB; //! do not store
519 Bool_t fDebug; // If true, do verbose queries
521 ClassDef(AliCorrectionManagerBase,1);