Belle II Software  release-08-01-10
DBImportBase.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/DBStore.h>
11 #include <framework/database/IntervalOfValidity.h>
12 
13 namespace Belle2 {
23  class DBImportBase {
24  public:
25 
30  explicit DBImportBase(const std::string& name): m_name(name) {}
31 
35  virtual ~DBImportBase();
36 
41  const std::string& getName() const {return m_name;}
42 
47  virtual void addEventDependency(unsigned int eventNumber)
48  {
49  addIntraRunDependency(eventNumber, c_Event);
50  }
51 
56  virtual void addTimeStampDependency(unsigned long long int timeStamp)
57  {
58  addIntraRunDependency(timeStamp, c_TimeStamp);
59  }
60 
65  virtual void addSubrunDependency(int subrun)
66  {
67  addIntraRunDependency(subrun, c_Subrun);
68  }
69 
74  bool import(const IntervalOfValidity& iov);
75 
79  virtual void clear();
80 
81  protected:
82 
86  enum EIntraRunDependency { c_None = 0,
87  c_Event = 1,
88  c_TimeStamp = 2,
89  c_Subrun = 3
90  };
91 
97  void addIntraRunDependency(unsigned long long int tag, EIntraRunDependency type);
98 
99  std::string m_name;
100  TObject* m_object = 0;
102  private:
103 
109 
114  template<class IntraRun> bool import(const IntervalOfValidity& iov)
115  {
116  if (m_objects.empty()) return false;
117  IntraRun intraRun(m_objects[0], false); // IntraRun must not own the objects
118 
119  if (m_object) m_objects.push_back(m_object);
120  for (unsigned i = 1; i < m_objects.size(); i++) {
121  intraRun.add(m_tags[i - 1], m_objects[i]);
122  }
123  if (m_object) m_objects.pop_back(); // restore initial state (mandatory!)
124 
125  return storeData(&intraRun, iov);
126  }
127 
134  bool storeData(TObject* intraRun, const IntervalOfValidity& iov);
135 
136 
138  std::vector<TObject*> m_objects;
139  std::vector<unsigned long long int> m_tags;
141  };
143 }
Base class for importing objects to the database.
Definition: DBImportBase.h:23
virtual void addTimeStampDependency(unsigned long long int timeStamp)
add time stamp dependency
Definition: DBImportBase.h:56
void addIntraRunDependency(unsigned long long int tag, EIntraRunDependency type)
add intra run dependency
Definition: DBImportBase.cc:17
EIntraRunDependency
Intra run dependency types (used only internaly)
Definition: DBImportBase.h:86
DBImportBase(const DBImportBase &)
Hidden copy constructor.
virtual void addEventDependency(unsigned int eventNumber)
add event dependency
Definition: DBImportBase.h:47
virtual ~DBImportBase()
Destructor.
Definition: DBImportBase.cc:76
std::vector< unsigned long long int > m_tags
container for intra run dep.
Definition: DBImportBase.h:139
DBImportBase(const std::string &name)
Constructor.
Definition: DBImportBase.h:30
const std::string & getName() const
Returns the name under which the object will be stored in the database.
Definition: DBImportBase.h:41
bool storeData(TObject *intraRun, const IntervalOfValidity &iov)
Store intra run dependent objects.
Definition: DBImportBase.cc:71
std::vector< TObject * > m_objects
container for intra run dependency objects
Definition: DBImportBase.h:138
virtual void addSubrunDependency(int subrun)
add subrun dependency
Definition: DBImportBase.h:65
virtual void clear()
Clear the content, e.g.
Definition: DBImportBase.cc:58
std::string m_name
object or array name in database
Definition: DBImportBase.h:99
EIntraRunDependency m_dependency
dependency type
Definition: DBImportBase.h:137
TObject * m_object
pointer to allocated object or array
Definition: DBImportBase.h:100
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.