2 #ifndef ALIOADBFORWARD_H
3 #define ALIOADBFORWARD_H
13 * Container/handler of Forward calibration objects.
15 class AliOADBForward : public TObject
18 //=== Options ======================================================
20 * Options for selecting the entries according to the run number
26 * Select only entries from exactly the run given.
30 * Select the entry with the largest run number
34 * Select entries from the run nearest (possibly constrained to be
35 * older or newer) to the run given in the query
39 * Select entries from runs that are older than the run given in
40 * the query. The oldest entry with the largest run number
41 * smaller than the given run is selected.
45 * Select entries from runs that are newer than the run given.
46 * Select the entries with the smallest run number which is larger
51 static const char* Mode2String(ERunSelectMode mode);
52 static ERunSelectMode String2Mode(const TString& str);
53 static ERunSelectMode Int2Mode(Int_t mode);
60 * The maximum distance to the given run when selecting in kNear
61 * mode. Currently this is set to a large number to allow
62 * selection of any entry. This should change
64 kMaxNearDistance = 1000000,
67 //=== Entry ========================================================
69 * An entry in the FORWARD OADB database tables
72 class Entry : public TObject
78 * @param runNo Run number
79 * @param sys Collision system (1:pp, 2:pbpb, 3:ppb)
80 * @param sNN Center of mass energy (GeV)
81 * @param field L3 magnetic field (kG)
82 * @param mc True if for MC only
83 * @param o Correction object
85 Entry(ULong_t runNo = 0,
95 * @param o Object to copy from
97 Entry(const Entry& o);
103 * Assignment operator
105 * @param o Object to assign from
107 * @return Reference to this object
109 Entry& operator=(const Entry& o);
111 * Get the title of the entry
113 * @return stringified fields
115 const char* GetTitle() const;
119 * @param option Not used
121 void Print(Option_t* option="") const; //*MENU*
122 ULong_t fRunNo; // Run number
123 UShort_t fSys; // Collision system (1: pp, 2: pbpb, 3: ppb)
124 UShort_t fSNN; // Center of mass energy
125 Short_t fField; // L3 magnetic field
126 Bool_t fMC; // True if only for MC
127 Bool_t fSatellite; // Satelitte events
128 TObject* fData; // Correction object
129 UInt_t fTimestamp; // When the object was stored
130 ULong_t fAliROOTRevision; // Revision of AliROOT used
131 TString fAuthor; // Author of calibration/correction
133 ClassDef(Entry,2); // Entry in PWGLF/Forward OADB
136 //=== Table ========================================================
138 * A table on the Forward OADB - the underlying storage is a TTree
139 * containing Entry objects.
142 class Table : public TObject
149 * @param isNew Whether to make the branch
153 Table(TTree* tree, Bool_t isNew, ERunSelectMode mode=kNear);
157 * @param other Object to copy from
159 Table(const Table& other);
163 * Closes the corresponding file
169 * @param other Object to assign form
171 * @return Reference to this object
173 Table& operator=(const Table& other);
179 void SetVerbose(Bool_t verb=true) { fVerbose = verb; }
181 * Set wheter to enable fall-back queries
183 * @param use If true, enable fall-back queries
185 void SetEnableFallBack(Bool_t use=true) { fFallBack = use; }
186 // -----------------------------------------------------------------
188 * Get the name of the tree
192 const Char_t* GetTableName() const;
194 * Overload TObject::GetName
198 const Char_t* GetName() const;
200 // -----------------------------------------------------------------
203 * @name Open/close/flush
208 * @return true on success
214 * @return true on success
218 // -----------------------------------------------------------------
226 * @param run Run number
227 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
228 * @param sNN Center of mass energy (GeV)
229 * @param fld L3 magnetic field (kG)
230 * @param mc For MC only
231 * @param sat For satellite events
232 * @param mode How to select on the run number
234 * @return Found entry number or negative number in case of problems
236 Int_t Query(ULong_t runNo = 0,
237 ERunSelectMode mode = kNear,
240 Short_t fld = kInvalidField,
242 Bool_t sat = false) const;
244 * Run a query with pre-build conditions
246 * @param q query string
247 * @param runNo The given run number
248 * @param mode Run selection mode
250 * @return Entry number of selected entry
252 Int_t Query(ULong_t runNo,
254 const TString& q) const;
256 * Insert a new entry into the tree
258 * @param o Object to write
259 * @param runNo Run number
260 * @param sys Collision system (1: pp, 2:PbPb, 3:pPb)
261 * @param sNN Center of mass energy (GeV)
262 * @param field L3 magnetic field (kG)
263 * @param mc If true, only for MC
264 * @param aliRev AliROOT revision
266 * @return true on success
268 Bool_t Insert(TObject* o,
276 const TString& author="");
278 * Query the tree for an object. The strategy is as follows.
280 * - First query with all fields
281 * - If this returns a single entry, return that.
282 * - If not, then ignore the run number (if given)
283 * - If this returns a single entry, return that
284 * - If not, and fall-back is enabled, then
285 * - Ignore the collision energy (if given)
286 * - If this returns a single entry, return that.
287 * - If not, ignore all passed values
288 * - If this returns a single entry, return that.
289 * - Otherwise, give up and return null
290 * - Otherwise, give up and return null
292 * This allow us to specify default objects for a period, and for
293 * collision system, energy, and field setting.
295 * @param run Run number
296 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
297 * @param sNN Center of mass energy (GeV)
298 * @param fld L3 magnetic field (kG)
299 * @param mc For MC only
301 * @return Found entry, or null
303 Entry* Get(ULong_t run = 0,
304 ERunSelectMode mode = kNear,
309 Bool_t sat = false) const;
311 * Query the tree for an object. The strategy is as follows.
313 * - First query with all fields
314 * - If this returns a single entry, return that.
315 * - If not, then ignore the run number (if given)
316 * - If this returns a single entry, return that
317 * - Otherwise, give up and return null
319 * This allow us to specify default objects for a period, and for
320 * collision system, energy, and field setting.
322 * @param run Run number
323 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
324 * @param sNN Center of mass energy (GeV)
325 * @param fld L3 magnetic field (kG)
326 * @param mc For MC only
328 * @return Found data, or null
330 TObject* GetData(ULong_t run = 0,
331 ERunSelectMode mode = kNear,
336 Bool_t sat = false) const;
339 * Print the contents of the tree
341 * @param option Passed to TTree::Scan
343 void Print(Option_t* option="") const; //*MENU*
347 void Browse(TBrowser* b);
349 * Check if the tree was opened.
351 * @param rw If true, also check if the file is read/write
353 * @return true if everything is dandy
355 Bool_t IsOpen(Bool_t rw=false) const;
357 TTree* fTree; // Our tree
358 Entry* fEntry; // Entry cache
359 Bool_t fVerbose; // To be verbose or not
360 ERunSelectMode fMode; // Run query mode
361 Bool_t fFallBack; // Enable fall-back
365 // === Interface ===================================================
369 * @param file File that stores the DB
377 // --- Open/close/update -------------------------------------------
383 * Open a file containing tables. Note, this member function can be
384 * called multiple times to open tables in different files.
386 * If a table is already associated with this handler, it will not
389 * @param fileName Path to file to get/write tables from/in
390 * @param rw if true, open read+write, otherwise read-only
391 * @param tables Tables to open
392 * @param verb Verbosity flag
394 * @return true on success
396 Bool_t Open(const TString& fileName,
397 const TString& tables = "*",
400 Bool_t fallback= false);
402 * Open a file containing tables. Note, this member function can be
403 * called multiple times to open tables in different files.
405 * If a table is already associated with this handler, it will not
408 * @param file File to get/write tables from/in
409 * @param rw if true, open read+write, otherwise read-only
410 * @param tables Tables to open
411 * @param verb Verbosity flag
413 * @return true on success
415 Bool_t Open(TFile* file,
416 const TString& tables,
419 Bool_t fallback= false);
421 * Close this database
424 * @return true on success
430 * @return true on success
434 // --- Queries -----------------------------------------------------
440 * Query the table for an object. The strategy is as follows.
442 * - First query with all fields
443 * - If this returns a single entry, return that.
444 * - If not, then ignore the run number (if given)
445 * - If this returns a single entry, return that
446 * - Otherwise, give up and return null
448 * This allow us to specify default objects for a period, and for
449 * collision system, energy, and field setting.
451 * @param run Run number
452 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
453 * @param sNN Center of mass energy (GeV)
454 * @param fld L3 magnetic field (kG)
455 * @param mc For MC only
457 * @return Found entry, or null
459 Entry* Get(const TString& table,
461 ERunSelectMode mode = kNear,
466 Bool_t sat = false) const;
468 * Query the table for an object. The strategy is as follows.
470 * - First query with all fields
471 * - If this returns a single entry, return that.
472 * - If not, then ignore the run number (if given)
473 * - If this returns a single entry, return that
474 * - Otherwise, give up and return null
476 * This allow us to specify default objects for a period, and for
477 * collision system, energy, and field setting.
479 * @param run Run number
480 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
481 * @param sNN Center of mass energy (GeV)
482 * @param fld L3 magnetic field (kG)
483 * @param mc For MC only
485 * @return Found data, or null
487 TObject* GetData(const TString& table,
489 ERunSelectMode mode = kNear,
494 Bool_t sat = false) const;
495 // --- Insert ------------------------------------------------------
497 * Insert a new entry into the table
499 * @param o Object to write
500 * @param runNo Run number
501 * @param sys Collision system (1: pp, 2:PbPb, 3:pPb)
502 * @param sNN Center of mass energy (GeV)
503 * @param field L3 magnetic field (kG)
504 * @param mc If true, only for MC
505 * @param aliRev AliROOT revision
507 * @return true on success
509 Bool_t Insert(const TString& table,
518 const TString& author="");
521 * Print the content of all tables
523 * @param option Passed on to tables
525 void Print(const Option_t* option="") const; //*MENU*
527 * Browse this database
531 void Browse(TBrowser* b);
533 * Find a table by name
535 * @param name Name of table
536 * @param quite Do not print warning if not found
537 * @return Table or null
539 Table* FindTable(const TString& name, Bool_t quite=false) const;
544 * @return Map of all tables
546 const TMap& GetTables() const { return fTables; }
549 * Get a list of associated files
551 * @param files On return, contains list of files
553 * @return Number of associated files found
555 Int_t GetFiles(TList& files) const;
557 * Get a table (TTree) from a file
559 * @param file File to look in
560 * @param rw If true, open read/write, false read-only
561 * @param name Name of the table
562 * @param mode Default mode for new table, or override mode
563 * for existing tables if not default
565 * @return Table or (if rw=true) possibly newly created table
567 Table* GetTableFromFile(TFile* file, Bool_t rw,
569 const TString& mode) const;
571 * Helper function to append to query string
573 * @param q String to attach to
574 * @param s What to attach
575 * @param andNotOr If true, assume @b and, otherwise @b or
577 static void AppendToQuery(TString& q, const TString& s, Bool_t andNotOr=true);
579 * Helper function to build a query string
581 * @param sys Collision system (1:pp, 2: PbPb, 3:pPb)
582 * @param sNN Collision energy in GeV
583 * @param fld L3-Field strength and polarity
584 * @param mc For Monte-carlo
585 * @param sat For satelitte collisions
587 * @return Query string
589 static TString Conditions(UShort_t sys = 0,
591 Short_t fld = kInvalidField,
595 ClassDef(AliOADBForward,0); // PWGLF/Forward OADB interface
598 // =================================================================
603 static void TestGet(AliOADBForward& t,
604 const TString& table,
606 ERunSelectMode mode = kNear,
612 static void TestInsert(AliOADBForward& t,
613 const TString& table,