Belle II Software  release-08-01-10
ECLDBTool.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 // FRAMEWORK
9 #include <framework/database/Database.h>
10 #include <framework/database/Configuration.h>
11 // ECL
12 #include <ecl/utility/ECLDBTool.h>
13 using namespace Belle2;
14 // Constructor.
15 ECLDBTool::ECLDBTool(bool isLocal,
16  const char* dbName,
17  const char* payloadName):
18  m_isLocal(isLocal),
19  m_dbName(dbName),
20  m_payloadName(payloadName)
21 {
22 }
23 // Destructor.
25 {
26 }
27 // Connect to a database.
28 void ECLDBTool::connect() const
29 {
31  if (m_isLocal) {
32  conf.prependTestingPayloadLocation(m_dbName.c_str());
33  } else {
34  conf.prependGlobalTag(m_dbName.c_str());
35  }
36 }
37 // Write object and validity interval to a database.
38 void ECLDBTool::write(TObject* const obj,
39  const IntervalOfValidity& iov) const
40 {
42  obj, iov);
43 }
44 // Read object and validity interval from a database.
45 void ECLDBTool::read(TObject** obj,
46  IntervalOfValidity** iov,
47  const EventMetaData& event) const
48 {
49  auto data = Database::Instance().
50  getData(event, m_payloadName.c_str());
51  *obj = std::get<0>(data);
52  *iov = new IntervalOfValidity(std::get<1>(data));
53 }
54 // Read just validity interval from a database.
56  const EventMetaData& event) const
57 {
58  auto data = Database::Instance().
59  getData(event, m_payloadName.c_str());
60  auto obj = std::get<0>(data);
61  *iov = new IntervalOfValidity(std::get<1>(data));
62  delete obj;
63 }
64 // Change validity interval (Make copy of current
65 // payload with other validity interval).
67  const IntervalOfValidity& iov) const
68 {
69  auto data = Database::Instance().
70  getData(event, m_payloadName.c_str());
71  auto obj = std::get<0>(data);
72  write(obj, iov);
73  delete obj;
74 }
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
std::string m_dbName
Tag in the central database or path to a local database.
Definition: ECLDBTool.h:90
void changeIoV(const EventMetaData &event, const IntervalOfValidity &iov) const
Change interval of validity (Make a copy of the current payload with other validity interval).
Definition: ECLDBTool.cc:66
bool m_isLocal
If m_isLocal is true, local database is used.
Definition: ECLDBTool.h:85
ECLDBTool(bool isLocal, const char *dbName, const char *payloadName)
Constructor.
Definition: ECLDBTool.cc:15
std::string m_payloadName
Name of payload.
Definition: ECLDBTool.h:94
~ECLDBTool()
Destructor.
Definition: ECLDBTool.cc:24
void read(TObject **obj, IntervalOfValidity **iov, const EventMetaData &event) const
Read object and validity interval from a database.
Definition: ECLDBTool.cc:45
void write(TObject *const obj, const IntervalOfValidity &iov) const
Write object and validity interval to a database.
Definition: ECLDBTool.cc:38
void connect() const
Connect to a database.
Definition: ECLDBTool.cc:28
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
A class that describes the interval of experiments/runs for which an object in the database is valid.
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:141
Abstract base class for different kinds of events.