Belle II Software light-2406-ragdoll
TestingPayloadStorage.h
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#pragma once
9
10#include <framework/database/PayloadMetadata.h>
11
12#include <functional>
13#include <unordered_map>
14
15namespace Belle2 {
20 class EventMetaData;
21
22 namespace Conditions {
23
40 public:
42 explicit TestingPayloadStorage(const std::string& filename);
45 bool get(const EventMetaData& event, PayloadMetadata& info);
49 bool storeData(const std::string& name, TObject* object, const IntervalOfValidity& iov);
53 bool storePayload(const std::string& name, const std::string& fileName, const IntervalOfValidity& iov);
55 void reset() { m_initialized = false; }
56 private:
58 void read();
60 std::unordered_map<std::string, std::vector<std::tuple<std::string, IntervalOfValidity>>> m_payloads;
62 std::string m_filename;
64 std::string m_absoluteFilename;
68 std::string m_payloadDir;
70 bool m_initialized{false};
72 static std::string payloadFilename(const std::string& path, const std::string& name, const std::string& revision);
76 bool writePayload(const std::string& fileName, const std::string& name, const TObject* object);
88 bool store(const std::string& name, const IntervalOfValidity& iov, const std::string& source,
89 const std::function<bool(const std::string&)>& writer);
90 };
91 } // Conditions namespace
93} // Belle2 namespace
Class to store and retrieve temporary payloads.
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.
bool m_initialized
Remember whether we read the file already.
std::string m_payloadDir
Directory containing the storage file as absolute file name.
bool writePayload(const std::string &fileName, const std::string &name, const TObject *object)
Write a payload file from the given object and name.
static std::string payloadFilename(const std::string &path, const std::string &name, const std::string &revision)
Build the filename for a new payload with a given name and revision in a directory.
std::unordered_map< std::string, std::vector< std::tuple< std::string, IntervalOfValidity > > > m_payloads
Map of known payloads to a list of known revisions and their interval of validity.
void read()
Read the given storage file, done lazily on first access to get() after construction or call to reset...
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.
bool store(const std::string &name, const IntervalOfValidity &iov, const std::string &source, const std::function< bool(const std::string &)> &writer)
Try to store a new payload with the given name and interval of validity.
bool get(const EventMetaData &event, PayloadMetadata &info)
Try to fill the PayloadMetaData for the given EventMetaData, return true on success,...
std::string m_filename
Storage file where to look for payloads.
std::string m_absoluteFilename
Storage file where to look for payloads converted to an absolute path to be robust against directory ...
void reset()
Reset the list of known payloads.
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.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
Simple struct to group all information necessary for a single payload.