Belle II Software  release-05-01-25
ECLDBTool.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * ECLDBTool *
6  * *
7  * Utility designed to read / write object from / to database. *
8  * *
9  * Author: The Belle II Collaboration *
10  * Contributors: Sergei Gribanov (S.S.Gribanov@inp.nsk.su) (BINP) *
11  * *
12  * This software is provided "as is" without any warranty. *
13  **************************************************************************/
14 // FRAMEWORK
15 #include <framework/database/Database.h>
16 #include <framework/database/Configuration.h>
17 // ECL
18 #include <ecl/utility/ECLDBTool.h>
19 using namespace Belle2;
20 // Constructor.
21 ECLDBTool::ECLDBTool(bool isLocal,
22  const char* dbName,
23  const char* payloadName):
24  m_isLocal(isLocal),
25  m_dbName(dbName),
26  m_payloadName(payloadName)
27 {
28 }
29 // Destructor.
31 {
32 }
33 // Connect to a database.
34 void ECLDBTool::connect() const
35 {
37  if (m_isLocal) {
38  conf.prependTestingPayloadLocation(m_dbName.c_str());
39  } else {
40  conf.prependGlobalTag(m_dbName.c_str());
41  }
42 }
43 // Write object and validity interval to a database.
44 void ECLDBTool::write(TObject* const obj,
45  const IntervalOfValidity& iov) const
46 {
48  obj, iov);
49 }
50 // Read object and validity interval from a database.
51 void ECLDBTool::read(TObject** obj,
52  IntervalOfValidity** iov,
53  const EventMetaData& event) const
54 {
55  auto data = Database::Instance().
56  getData(event, m_payloadName.c_str());
57  *obj = std::get<0>(data);
58  *iov = new IntervalOfValidity(std::get<1>(data));
59 }
60 // Read just validity interval from a database.
62  const EventMetaData& event) const
63 {
64  auto data = Database::Instance().
65  getData(event, m_payloadName.c_str());
66  auto obj = std::get<0>(data);
67  *iov = new IntervalOfValidity(std::get<1>(data));
68  delete obj;
69 }
70 // Change validity interval (Make copy of current
71 // payload with other validity interval).
73  const IntervalOfValidity& iov) const
74 {
75  auto data = Database::Instance().
76  getData(event, m_payloadName.c_str());
77  auto obj = std::get<0>(data);
78  write(obj, iov);
79  delete obj;
80 }
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::ECLDBTool::read
void read(TObject **obj, IntervalOfValidity **iov, const EventMetaData &event) const
Read object and validity interval from a database.
Definition: ECLDBTool.cc:51
Belle2::ECLDBTool::connect
void connect() const
Connect to a database.
Definition: ECLDBTool.cc:34
Belle2::Database::storeData
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:152
Belle2::ECLDBTool::m_payloadName
std::string m_payloadName
Name of payload.
Definition: ECLDBTool.h:112
Belle2::ECLDBTool::write
void write(TObject *const obj, const IntervalOfValidity &iov) const
Write object and validity interval to a database.
Definition: ECLDBTool.cc:44
Belle2::ECLDBTool::changeIoV
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:72
Belle2::ECLDBTool::~ECLDBTool
~ECLDBTool()
Destructor.
Definition: ECLDBTool.cc:30
Belle2::Conditions::Configuration::getInstance
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ECLDBTool::ECLDBTool
ECLDBTool(bool isLocal, const char *dbName, const char *payloadName)
Constructor.
Definition: ECLDBTool.cc:21
Belle2::ECLDBTool::m_dbName
std::string m_dbName
Tag in the central database or path to a local database.
Definition: ECLDBTool.h:108
Belle2::Database::Instance
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:54
Belle2::EventMetaData
Store event, run, and experiment numbers.
Definition: EventMetaData.h:43
Belle2::ECLDBTool::m_isLocal
bool m_isLocal
If m_isLocal is true, local database is used.
Definition: ECLDBTool.h:103