Belle II Software  release-08-01-10
DBImportBase.cc
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 #include <framework/database/DBImportBase.h>
10 #include <framework/database/EventDependency.h>
11 #include <framework/database/Database.h>
12 #include <framework/logging/Logger.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 void DBImportBase::addIntraRunDependency(unsigned long long int tag,
18  EIntraRunDependency dependency)
19 {
20 
21  if (!m_object) return;
22 
23  if (m_dependency == c_None) m_dependency = dependency;
24  if (dependency == m_dependency) {
25  m_objects.push_back(m_object);
26  m_tags.push_back(tag);
27  m_object = nullptr;
28  } else {
29  B2FATAL("DBImportBase::addIntraRunDependency: " <<
30  "intra run dependency cannot be of mixed types");
31  }
32 
33 }
34 
35 
36 bool DBImportBase::import(const IntervalOfValidity& iov)
37 {
38 
39  switch (m_dependency) {
40  case c_Event:
41  return import<EventDependency>(iov);
42  case c_TimeStamp:
43  B2ERROR("DBImportBase::import: " <<
44  "intra run dependency of type 'time stamp' not supported yet");
45  return false;
46  case c_Subrun:
47  B2ERROR("DBImportBase::import: " <<
48  "intra run dependency of type 'subrun' not supported yet");
49  return false;
50  default:
51  if (!m_object) return false;
52  return Database::Instance().storeData(m_name, m_object, iov);
53  }
54 
55 }
56 
57 
58 void DBImportBase::clear()
59 {
60  if (m_object) {
61  delete m_object;
62  m_object = nullptr;
63  }
64 
65  m_dependency = c_None;
66  for (auto& object : m_objects) delete object;
67  m_objects.clear();
68  m_tags.clear();
69 }
70 
71 bool DBImportBase::storeData(TObject* intraRun, const IntervalOfValidity& iov)
72 {
73  return Database::Instance().storeData(m_name, intraRun, iov);
74 }
75 
76 DBImportBase::~DBImportBase()
77 {
78  for (auto& object : m_objects) delete object;
79 }
EIntraRunDependency
Intra run dependency types (used only internaly)
Definition: DBImportBase.h:86
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.