Belle II Software  release-05-02-19
PayloadFile.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016-2018 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Kuhr, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/database/DBObjPtr.h>
14 #include <string>
15 
16 
17 namespace Belle2 {
25  class PayloadFile {
26  public:
31  explicit PayloadFile(const std::string& fileName): m_fileName(fileName) {};
32 
37  std::string getFileName() const {return m_fileName;};
38 
43  std::string getContent() const;
44 
45  private:
46  std::string m_fileName;
47  };
48 
56  template<> class DBObjPtr<PayloadFile>: public DBAccessorBase {
57  public:
59  explicit DBObjPtr(const std::string& name = "", bool required = true):
60  DBAccessorBase(DBStoreEntry::c_RawFile, name, required), m_payloadFile(isValid() ? m_entry->getFilename() : "")
61  {
62  // if the payload changes also change the filename
63  addCallback([this](const std::string&) {m_payloadFile = PayloadFile(isValid() ? m_entry->getFilename() : "");});
64  }
66  inline bool isValid() const {return (m_entry) && (m_entry->getFilename() != "");}
67  inline const PayloadFile& operator *() const {return m_payloadFile; }
68  inline const PayloadFile* operator ->() const {return &m_payloadFile; }
69  private:
71  PayloadFile m_payloadFile;
72  };
74 }
Belle2::DBAccessorBase::m_entry
DBStoreEntry * m_entry
Pointer to the entry in the DBStore.
Definition: DBAccessorBase.h:200
Belle2::DBStoreEntry::getFilename
const std::string & getFilename() const
get the filename for this payload
Definition: DBStoreEntry.h:98
Belle2::DBObjPtr::DBObjPtr
DBObjPtr(const std::string &name="", bool required=true)
Constructor to access an object in the DBStore.
Definition: DBObjPtr.h:38
Belle2::DBAccessorBase
Base class for DBObjPtr and DBArray for easier common treatment.
Definition: DBAccessorBase.h:28
Belle2::operator*
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
Definition: B2Vector3.h:528
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::PayloadFile::PayloadFile
PayloadFile(const std::string &fileName)
Constructor.
Definition: PayloadFile.h:39
Belle2::PayloadFile::m_fileName
std::string m_fileName
Name of the payload file.
Definition: PayloadFile.h:54
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PayloadFile::getFileName
std::string getFileName() const
Get the name of the downloaded payload file.
Definition: PayloadFile.h:45
Belle2::DBAccessorBase::isValid
bool isValid() const
Check whether a valid object was obtained from the database.
Definition: DBAccessorBase.h:75
Belle2::PayloadFile::getContent
std::string getContent() const
Read the content of the payload (text) file.
Definition: PayloadFile.cc:19
Belle2::PayloadFile
A wrapper class for payload files used by the Database and DBStore classes.
Definition: PayloadFile.h:33
Belle2::DBAccessorBase::DBAccessorBase
DBAccessorBase(const std::string &name, const TClass *objClass, bool isArray, bool isRequired)
Constructor to access an object in the DBStore.
Definition: DBAccessorBase.h:38
Belle2::DBStoreEntry::c_RawFile
@ c_RawFile
Just a plain old file, we don't look at it just provide the filename.
Definition: DBStoreEntry.h:54
Belle2::DBAccessorBase::addCallback
void addCallback(std::function< void(const std::string &)> callback, bool onDestruction=false)
Add a callback method.
Definition: DBAccessorBase.h:108