Belle II Software light-2406-ragdoll
PayloadFile.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
9#pragma once
10
11#include <framework/database/DBObjPtr.h>
12#include <string>
13
14
15namespace Belle2 {
24 public:
29 explicit PayloadFile(const std::string& fileName): m_fileName(fileName) {};
30
35 std::string getFileName() const {return m_fileName;};
36
41 std::string getContent() const;
42
43 private:
44 std::string m_fileName;
45 };
46
54 template<> class DBObjPtr<PayloadFile>: public DBAccessorBase {
55 public:
57 explicit DBObjPtr(const std::string& name = "", bool required = true):
58 DBAccessorBase(DBStoreEntry::c_RawFile, name, required), m_payloadFile(isValid() ? m_entry->getFilename() : "")
59 {
60 // if the payload changes also change the filename
61 addCallback([this](const std::string&) {m_payloadFile = PayloadFile(isValid() ? m_entry->getFilename() : "");});
62 }
64 inline bool isValid() const {return (m_entry) && (m_entry->getFilename() != "");}
65 inline const PayloadFile& operator *() const {return m_payloadFile; }
66 inline const PayloadFile* operator ->() const {return &m_payloadFile; }
67 private:
70 };
72}
Base class for DBObjPtr and DBArray for easier common treatment.
const std::string & getFilename() const
Get the filename this object is loaded from.
void addCallback(std::function< void(const std::string &)> callback, bool onDestruction=false)
Add a callback method.
bool isValid() const
Check whether a valid object was obtained from the database.
DBStoreEntry * m_entry
Pointer to the entry in the DBStore.
bool isValid() const
isValid is always true if we have a filename
Definition: PayloadFile.h:64
PayloadFile m_payloadFile
PayloadFile object which can be queried for the filename.
Definition: PayloadFile.h:69
DBObjPtr(const std::string &name="", bool required=true)
Constructor of a DBObjPtr object.
Definition: PayloadFile.h:57
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
const T & operator*() const
Imitate pointer functionality.
Definition: DBObjPtr.h:34
const T * operator->() const
Imitate pointer functionality.
Definition: DBObjPtr.h:35
Class to hold one entry from the ConditionsDB in the DBStore.
Definition: DBStoreEntry.h:47
const std::string & getFilename() const
get the filename for this payload
Definition: DBStoreEntry.h:101
A wrapper class for payload files used by the Database and DBStore classes.
Definition: PayloadFile.h:23
PayloadFile(const std::string &fileName)
Constructor.
Definition: PayloadFile.h:29
std::string getContent() const
Read the content of the payload (text) file.
Definition: PayloadFile.cc:17
std::string getFileName() const
Get the name of the downloaded payload file.
Definition: PayloadFile.h:35
std::string m_fileName
Name of the payload file.
Definition: PayloadFile.h:44
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24