Belle II Software development
|
Class to store and retrieve temporary payloads. More...
#include <TestingPayloadStorage.h>
Public Member Functions | |
TestingPayloadStorage (const std::string &filename) | |
Create a new instance to work on a given filename. | |
bool | get (const EventMetaData &event, PayloadMetadata &info) |
Try to fill the PayloadMetaData for the given EventMetaData, return true on success, false if no machting payload could be found. | |
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 | 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. | |
void | reset () |
Reset the list of known payloads. | |
Private Member Functions | |
void | read () |
Read the given storage file, done lazily on first access to get() after construction or call to reset() | |
bool | writePayload (const std::string &fileName, const std::string &name, const TObject *object) |
Write a payload file from the given object and name. | |
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. | |
Static Private Member Functions | |
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. | |
Private Attributes | |
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. | |
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 changes. | |
std::string | m_payloadDir |
Directory containing the storage file as absolute file name. | |
bool | m_initialized {false} |
Remember whether we read the file already. | |
Class to store and retrieve temporary payloads.
Temporary payloads are stored in a directory where we create a root files and a plain text file with name, revision and iov for each of these files. This is not very safe but ideal for testing and manual adjustments before final validation and upload to the cental server.
The interface is very basic: We create an instance with a filename and then we either get() payload information for a given event and payload metadata struct or we store a given payload either from an object (storeData()) or from an existing file (storePayload()).
Both call the underlying store() which tries to be robust against multiple processes trying to create payloads at the same time.
Definition at line 39 of file TestingPayloadStorage.h.
|
explicit |
Create a new instance to work on a given filename.
Definition at line 26 of file TestingPayloadStorage.cc.
bool get | ( | const EventMetaData & | event, |
PayloadMetadata & | info | ||
) |
Try to fill the PayloadMetaData for the given EventMetaData, return true on success, false if no machting payload could be found.
Definition at line 31 of file TestingPayloadStorage.cc.
|
staticprivate |
Build the filename for a new payload with a given name and revision in a directory.
Definition at line 125 of file TestingPayloadStorage.cc.
|
private |
Read the given storage file, done lazily on first access to get() after construction or call to reset()
Definition at line 67 of file TestingPayloadStorage.cc.
|
inline |
Reset the list of known payloads.
Will trigger re-reading the file on next access to get()
Definition at line 55 of file TestingPayloadStorage.h.
|
private |
Try to store a new payload with the given name and interval of validity.
This function first tries to find the next free revision and then call the writer function to write the payload to the given filename. If the writer function returns success the payload is added to the storage file
name | payload name |
iov | iov for the payload |
source | source filename to use. If this is empty there is no file yet and it has to be created first |
writer | callback function to create a file. Will be called with a destination filename if the source parameter was emty |
Definition at line 156 of file TestingPayloadStorage.cc.
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.
This will create a new ROOT file containing the object in the directory of the storage file
Definition at line 134 of file TestingPayloadStorage.cc.
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.
This will create a copy of the file with a different name in the directory of the storage file
Definition at line 141 of file TestingPayloadStorage.cc.
|
private |
Write a payload file from the given object and name.
Will create new root file containing object under the Key name with the name fileName
Definition at line 250 of file TestingPayloadStorage.cc.
|
private |
Storage file where to look for payloads converted to an absolute path to be robust against directory changes.
Definition at line 64 of file TestingPayloadStorage.h.
|
private |
Storage file where to look for payloads.
This is the logical file name as given by the user
Definition at line 62 of file TestingPayloadStorage.h.
|
private |
Remember whether we read the file already.
Definition at line 70 of file TestingPayloadStorage.h.
|
private |
Directory containing the storage file as absolute file name.
Will try to create it if it doesn't exist and storeData() or storePayload() is called
Definition at line 68 of file TestingPayloadStorage.h.
|
private |
Map of known payloads to a list of known revisions and their interval of validity.
Definition at line 60 of file TestingPayloadStorage.h.