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
52 * Return the mode as a string
56 * @return Stringified mode
58 static const char* Mode2String(ERunSelectMode mode);
60 * Parse a string to get the mode
62 * @param str Input string
66 static ERunSelectMode String2Mode(const TString& str);
68 * Return mode as an integer
72 * @return Mode identifier
74 static ERunSelectMode Int2Mode(Int_t mode);
81 * The maximum distance to the given run when selecting in kNear
82 * mode. Currently this is set to a large number to allow
83 * selection of any entry. This should change
85 kMaxNearDistance = 1000000,
88 //=== Entry ========================================================
90 * An entry in the FORWARD OADB database tables
93 class Entry : public TObject
99 * @param runNo Run number
100 * @param sys Collision system (1:pp, 2:pbpb, 3:ppb)
101 * @param sNN Center of mass energy (GeV)
102 * @param field L3 magnetic field (kG)
103 * @param mc True if for MC only
104 * @param sat For satellite events
105 * @param o Correction object
107 Entry(ULong_t runNo = 0,
117 * @param o Object to copy from
119 Entry(const Entry& o);
125 * Assignment operator
127 * @param o Object to assign from
129 * @return Reference to this object
131 Entry& operator=(const Entry& o);
133 * Get the title of the entry
135 * @return stringified fields
137 const char* GetTitle() const;
141 * @param option Not used
143 void Print(Option_t* option="") const; //*MENU*
144 ULong_t fRunNo; // Run number
145 UShort_t fSys; // Collision system (1: pp, 2: pbpb, 3: ppb)
146 UShort_t fSNN; // Center of mass energy
147 Short_t fField; // L3 magnetic field
148 Bool_t fMC; // True if only for MC
149 Bool_t fSatellite; // Satelitte events
150 TObject* fData; // Correction object
151 UInt_t fTimestamp; // When the object was stored
152 ULong_t fAliROOTRevision; // Revision of AliROOT used
153 TString fAuthor; // Author of calibration/correction
155 ClassDef(Entry,2); // Entry in PWGLF/Forward OADB
158 //=== Table ========================================================
160 * A table on the Forward OADB - the underlying storage is a TTree
161 * containing Entry objects.
164 class Table : public TObject
171 * @param isNew Whether to make the branch
172 * @param mode How to select on the run number
176 Table(TTree* tree, Bool_t isNew, ERunSelectMode mode=kNear);
180 * @param other Object to copy from
182 Table(const Table& other);
186 * Closes the corresponding file
192 * @param other Object to assign form
194 * @return Reference to this object
196 Table& operator=(const Table& other);
202 void SetVerbose(Bool_t verb=true) { fVerbose = verb; }
204 * Set wheter to enable fall-back queries
206 * @param use If true, enable fall-back queries
208 void SetEnableFallBack(Bool_t use=true) { fFallBack = use; }
209 // -----------------------------------------------------------------
211 * Get the name of the tree
215 const Char_t* GetTableName() const;
217 * Overload TObject::GetName
221 const Char_t* GetName() const;
223 // -----------------------------------------------------------------
226 * @name Open/close/flush
231 * @return true on success
237 * @return true on success
241 // -----------------------------------------------------------------
249 * @param runNo Run number
250 * @param mode Run selection mode
251 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
252 * @param sNN Center of mass energy (GeV)
253 * @param fld L3 magnetic field (kG)
254 * @param mc For MC only
255 * @param sat For satellite events
256 * @param mode How to select on the run number
258 * @return Found entry number or negative number in case of problems
260 Int_t Query(ULong_t runNo = 0,
261 ERunSelectMode mode = kNear,
264 Short_t fld = kInvalidField,
266 Bool_t sat = false) const;
268 * Run a query with pre-build conditions
270 * @param q query string
271 * @param runNo The given run number
272 * @param mode Run selection mode
274 * @return Entry number of selected entry
276 Int_t Query(ULong_t runNo,
278 const TString& q) const;
280 * Insert a new entry into the tree
282 * @param o Object to write
283 * @param runNo Run number
284 * @param sys Collision system (1: pp, 2:PbPb, 3:pPb)
285 * @param sNN Center of mass energy (GeV)
286 * @param field L3 magnetic field (kG)
287 * @param mc If true, only for MC
288 * @param sat For satellite interactions
289 * @param aliRev AliROOT revision
290 * @param author Creater of this correction
292 * @return true on success
294 Bool_t Insert(TObject* o,
302 const TString& author="");
304 * Query the tree for an object. The strategy is as follows.
306 * - First query with all fields
307 * - If this returns a single entry, return that.
308 * - If not, then ignore the run number (if given)
309 * - If this returns a single entry, return that
310 * - If not, and fall-back is enabled, then
311 * - Ignore the collision energy (if given)
312 * - If this returns a single entry, return that.
313 * - If not, ignore all passed values
314 * - If this returns a single entry, return that.
315 * - Otherwise, give up and return null
316 * - Otherwise, give up and return null
318 * This allow us to specify default objects for a period, and for
319 * collision system, energy, and field setting.
321 * @param run Run number
322 * @param mode Run selection mode
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
327 * @param sat For satellite interactions
329 * @return Found entry, or null
331 Entry* Get(ULong_t run = 0,
332 ERunSelectMode mode = kNear,
337 Bool_t sat = false) const;
339 * Query the tree for an object. The strategy is as follows.
341 * - First query with all fields
342 * - If this returns a single entry, return that.
343 * - If not, then ignore the run number (if given)
344 * - If this returns a single entry, return that
345 * - Otherwise, give up and return null
347 * This allow us to specify default objects for a period, and for
348 * collision system, energy, and field setting.
350 * @param run Run number
351 * @param mode Run selection mode
352 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
353 * @param sNN Center of mass energy (GeV)
354 * @param fld L3 magnetic field (kG)
355 * @param mc For MC only
356 * @param sat For satellite interactions
358 * @return Found data, or null
360 TObject* GetData(ULong_t run = 0,
361 ERunSelectMode mode = kNear,
366 Bool_t sat = false) const;
369 * Print the contents of the tree
371 * @param option Passed to TTree::Scan
373 void Print(Option_t* option="") const; //*MENU*
377 void Browse(TBrowser* b);
379 * Check if the tree was opened.
381 * @param rw If true, also check if the file is read/write
383 * @return true if everything is dandy
385 Bool_t IsOpen(Bool_t rw=false) const;
387 TTree* fTree; // Our tree
388 Entry* fEntry; // Entry cache
389 Bool_t fVerbose; // To be verbose or not
390 ERunSelectMode fMode; // Run query mode
391 Bool_t fFallBack; // Enable fall-back
395 // === Interface ===================================================
405 // --- Open/close/update -------------------------------------------
411 * Open a file containing tables. Note, this member function can be
412 * called multiple times to open tables in different files.
414 * If a table is already associated with this handler, it will not
417 * @param fileName Path to file to get/write tables from/in
418 * @param rw if true, open read+write, otherwise read-only
419 * @param tables Tables to open
420 * @param verb Verbosity flag
421 * @param fallback If true allow for fall-backs
423 * @return true on success
425 Bool_t Open(const TString& fileName,
426 const TString& tables = "*",
429 Bool_t fallback= false);
431 * Open a file containing tables. Note, this member function can be
432 * called multiple times to open tables in different files.
434 * If a table is already associated with this handler, it will not
437 * @param file File to get/write tables from/in
438 * @param rw if true, open read+write, otherwise read-only
439 * @param tables Tables to open
440 * @param verb Verbosity flag
441 * @param fallback If true allow for fall-backs
443 * @return true on success
445 Bool_t Open(TFile* file,
446 const TString& tables,
449 Bool_t fallback= false);
451 * Close this database
454 * @return true on success
460 * @return true on success
464 // --- Queries -----------------------------------------------------
470 * Query the table for an object. The strategy is as follows.
472 * - First query with all fields
473 * - If this returns a single entry, return that.
474 * - If not, then ignore the run number (if given)
475 * - If this returns a single entry, return that
476 * - Otherwise, give up and return null
478 * This allow us to specify default objects for a period, and for
479 * collision system, energy, and field setting.
481 * @param table Table name
482 * @param run Run number
483 * @param mode Run selection mode
484 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
485 * @param sNN Center of mass energy (GeV)
486 * @param fld L3 magnetic field (kG)
487 * @param mc For MC only
488 * @param sat For satellite interactions
490 * @return Found entry, or null
492 Entry* Get(const TString& table,
494 ERunSelectMode mode = kNear,
499 Bool_t sat = false) const;
501 * Query the table for an object. The strategy is as follows.
503 * - First query with all fields
504 * - If this returns a single entry, return that.
505 * - If not, then ignore the run number (if given)
506 * - If this returns a single entry, return that
507 * - Otherwise, give up and return null
509 * This allow us to specify default objects for a period, and for
510 * collision system, energy, and field setting.
512 * @param table Table name
513 * @param run Run number
514 * @param mode Run selection mode
515 * @param sys Collision system (1: pp, 2: PbPb, 3: pPb)
516 * @param sNN Center of mass energy (GeV)
517 * @param fld L3 magnetic field (kG)
518 * @param mc For MC only
519 * @param sat For satellite interactions
521 * @return Found data, or null
523 TObject* GetData(const TString& table,
525 ERunSelectMode mode = kNear,
530 Bool_t sat = false) const;
531 // --- Insert ------------------------------------------------------
533 * Insert a new entry into the table
535 * @param table Table name
536 * @param o Object to write
537 * @param runNo Run number
538 * @param sys Collision system (1: pp, 2:PbPb, 3:pPb)
539 * @param sNN Center of mass energy (GeV)
540 * @param field L3 magnetic field (kG)
541 * @param mc If true, only for MC
542 * @param sat For satellite interactions
543 * @param aliRev AliROOT revision
544 * @param author Creater of this correction
546 * @return true on success
548 Bool_t Insert(const TString& table,
557 const TString& author="");
560 * Print the content of all tables
562 * @param option Passed on to tables
564 void Print(const Option_t* option="") const; //*MENU*
566 * Browse this database
570 void Browse(TBrowser* b);
572 * Find a table by name
574 * @param name Name of table
575 * @param quite Do not print warning if not found
576 * @return Table or null
578 Table* FindTable(const TString& name, Bool_t quite=false) const;
583 * @return Map of all tables
585 const TMap& GetTables() const { return fTables; }
588 * Get a list of associated files
590 * @param files On return, contains list of files
592 * @return Number of associated files found
594 Int_t GetFiles(TList& files) const;
596 * Get a table (TTree) from a file
598 * @param file File to look in
599 * @param rw If true, open read/write, false read-only
600 * @param name Name of the table
601 * @param mode Default mode for new table, or override mode
602 * for existing tables if not default
604 * @return Table or (if rw=true) possibly newly created table
606 Table* GetTableFromFile(TFile* file, Bool_t rw,
608 const TString& mode) const;
610 * Helper function to append to query string
612 * @param q String to attach to
613 * @param s What to attach
614 * @param andNotOr If true, assume @b and, otherwise @b or
616 static void AppendToQuery(TString& q, const TString& s, Bool_t andNotOr=true);
618 * Helper function to build a query string
620 * @param sys Collision system (1:pp, 2: PbPb, 3:pPb)
621 * @param sNN Collision energy in GeV
622 * @param fld L3-Field strength and polarity
623 * @param mc For Monte-carlo
624 * @param sat For satelitte collisions
626 * @return Query string
628 static TString Conditions(UShort_t sys = 0,
630 Short_t fld = kInvalidField,
634 ClassDef(AliOADBForward,0); // PWGLF/Forward OADB interface
637 // =================================================================
642 static void TestGet(AliOADBForward& t,
643 const TString& table,
645 ERunSelectMode mode = kNear,
651 static void TestInsert(AliOADBForward& t,
652 const TString& table,