Belle II Software  release-05-02-19
TestingPayloadStorage.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/database/PayloadMetadata.h>
13 
14 #include <functional>
15 #include <unordered_map>
16 
17 namespace Belle2 {
22  class EventMetaData;
23 
24  namespace Conditions {
25 
41  class TestingPayloadStorage {
42  public:
44  explicit TestingPayloadStorage(const std::string& filename);
47  bool get(const EventMetaData& event, PayloadMetadata& info);
51  bool storeData(const std::string& name, TObject* object, const IntervalOfValidity& iov);
55  bool storePayload(const std::string& name, const std::string& fileName, const IntervalOfValidity& iov);
57  void reset() { m_initialized = false; }
58  private:
60  void read();
62  std::unordered_map<std::string, std::vector<std::tuple<size_t, IntervalOfValidity>>> m_payloads;
64  std::string m_filename;
66  std::string m_absoluteFilename;
70  std::string m_payloadDir;
72  bool m_initialized{false};
74  static std::string payloadFilename(const std::string& path, const std::string& name, int revision);
78  bool writePayload(const std::string& fileName, const std::string& name, const TObject* object);
84  bool store(const std::string& name, const IntervalOfValidity& iov, const std::function<bool(const std::string&)>& writer);
85  };
86  } // Conditions namespace
88 } // Belle2 namespace
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::Conditions::TestingPayloadStorage::m_initialized
bool m_initialized
Remember whether we read the file already.
Definition: TestingPayloadStorage.h:80
Belle2::Conditions::TestingPayloadStorage::m_filename
std::string m_filename
Storage file where to look for payloads.
Definition: TestingPayloadStorage.h:72
Belle2::Conditions::TestingPayloadStorage::read
void read()
Read the given storage file, done lazily on first access to get() after construction or call to reset...
Definition: TestingPayloadStorage.cc:75
Belle2::Conditions::TestingPayloadStorage::m_payloadDir
std::string m_payloadDir
Directory containing the storage file as absolute file name.
Definition: TestingPayloadStorage.h:78
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Conditions::TestingPayloadStorage::get
bool get(const EventMetaData &event, PayloadMetadata &info)
Try to fill the PayloadMetaData for the given EventMetaData, return true on success,...
Definition: TestingPayloadStorage.cc:40
Belle2::Conditions::TestingPayloadStorage::storeData
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store a TObject instance as a payload with given name and interval of validity.
Definition: TestingPayloadStorage.cc:144
Belle2::Conditions::TestingPayloadStorage::writePayload
bool writePayload(const std::string &fileName, const std::string &name, const TObject *object)
Write a payload file from the given object and name.
Definition: TestingPayloadStorage.cc:220
Belle2::Conditions::TestingPayloadStorage::m_absoluteFilename
std::string m_absoluteFilename
Storage file where to look for payloads converted to an absolute path to be robust against directory ...
Definition: TestingPayloadStorage.h:74
Belle2::Conditions::TestingPayloadStorage::store
bool store(const std::string &name, const IntervalOfValidity &iov, const std::function< bool(const std::string &)> &writer)
Try to store a new payload with the given name and interval of validity.
Definition: TestingPayloadStorage.cc:166
Belle2::Conditions::TestingPayloadStorage::payloadFilename
static std::string payloadFilename(const std::string &path, const std::string &name, int revision)
Build the filename for a new payload with a given name and revision in a directory.
Definition: TestingPayloadStorage.cc:135
Belle2::Conditions::TestingPayloadStorage::m_payloads
std::unordered_map< std::string, std::vector< std::tuple< size_t, IntervalOfValidity > > > m_payloads
Map of known payloads to a list of known revisions and their interval of validity.
Definition: TestingPayloadStorage.h:70
Belle2::Conditions::TestingPayloadStorage::reset
void reset()
Reset the list of known payloads.
Definition: TestingPayloadStorage.h:65
Belle2::Conditions::TestingPayloadStorage::TestingPayloadStorage
TestingPayloadStorage(const std::string &filename)
Create a new instance to work on a given filename.
Definition: TestingPayloadStorage.cc:35
Belle2::Conditions::TestingPayloadStorage::storePayload
bool storePayload(const std::string &name, const std::string &fileName, const IntervalOfValidity &iov)
Store an existing file as payload with given name and interval of validity.
Definition: TestingPayloadStorage.cc:151