Belle II Software  release-05-02-19
RunRange.h
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <set>
6 #include <TNamed.h>
7 #include <TCollection.h>
8 #include <framework/database/IntervalOfValidity.h>
9 #include <framework/logging/Logger.h>
10 #include <calibration/Utilities.h>
11 
12 namespace Belle2 {
17  class RunRange : public TNamed {
19 
20  public:
22  RunRange() : TNamed() {};
23 
25  explicit RunRange(std::vector<Calibration::ExpRun> expRuns) : TNamed()
26  {
27  for (auto expRun : expRuns) {
28  this->add(expRun.first, expRun.second);
29  }
30  };
31 
33  virtual ~RunRange()
34  {
35  m_expRunSet.clear();
36  }
37 
39  virtual void clear()
40  {
41  m_expRunSet.clear();
42  }
43 
45  virtual void merge(const RunRange* other)
46  {
47  m_expRunSet.insert(other->m_expRunSet.begin(), other->m_expRunSet.end());
48  }
49 
51  void add(int exp, int run)
52  {
53  m_expRunSet.insert(std::make_pair(exp, run));
54  }
55 
57  const std::set<Calibration::ExpRun>& getExpRunSet()
58  {
59  return m_expRunSet;
60  }
61 
64  {
65  if (m_expRunSet.empty())
66  return IntervalOfValidity();
67 
68  auto low = m_expRunSet.begin();
69  auto high = m_expRunSet.rbegin();
70 
71  return IntervalOfValidity(low->first, low->second, high->first, high->second);
72  }
73 
75  Long64_t Merge(TCollection* hlist)
76  {
77  B2DEBUG(100, "Running Merge() on " << this->GetName());
78  Long64_t nMerged = 0;
79  if (hlist) {
80  const RunRange* xh = 0;
81  TIter nxh(hlist);
82  while ((xh = dynamic_cast<RunRange*>(nxh()))) {
83  // Add xh to me
84  merge(xh);
85  ++nMerged;
86  }
87  }
88  B2DEBUG(100, "Merged " << nMerged << " objects");
89  return nMerged;
90  }
91 
93  void setGranularity(std::string& granularity)
94  {
95  if (granularity == "all" || granularity == "run") {
96  m_granularity = granularity;
97  } else {
98  B2WARNING("Tried to set RunRange granularity to something other than 'run' or 'all' -> " << granularity);
99  }
100  }
101 
103  std::string getGranularity() const {return m_granularity;}
105  void Reset() {clear();}
107  void SetDirectory(TDirectory*) {}
108 
110  bool operator<(const RunRange& other) const
111  {
112  if (m_granularity == other.m_granularity) {
113  return m_expRunSet < other.m_expRunSet;
114  }
115  return m_granularity < other.m_granularity;
116  }
117 
118  private:
120  std::set<Calibration::ExpRun> m_expRunSet = {};
121 
123  std::string m_granularity = "run";
124 
125  ClassDef(RunRange, 2)
126  };
128 }
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::RunRange::setGranularity
void setGranularity(std::string &granularity)
Set the m_granularity to an allowed value.
Definition: RunRange.h:93
Belle2::RunRange::m_expRunSet
std::set< Calibration::ExpRun > m_expRunSet
The set of (exp,run) stored in object.
Definition: RunRange.h:120
Belle2::RunRange::getExpRunSet
const std::set< Calibration::ExpRun > & getExpRunSet()
Get access to the stored set.
Definition: RunRange.h:57
Belle2::RunRange::RunRange
RunRange(std::vector< Calibration::ExpRun > expRuns)
Constructor from vector of ExpRun objects.
Definition: RunRange.h:25
Belle2::RunRange::add
void add(int exp, int run)
Add an experiment and run number to the set.
Definition: RunRange.h:51
Belle2::RunRange::getIntervalOfValidity
IntervalOfValidity getIntervalOfValidity()
Make IntervalOfValidity from the set, spanning all runs. Works because sets are sorted by default.
Definition: RunRange.h:63
Belle2::RunRange::Reset
void Reset()
Root-like Reset function for "template compatibility" with ROOT objects.
Definition: RunRange.h:105
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RunRange::merge
virtual void merge(const RunRange *other)
Implementation of merging - other is added to the set (union)
Definition: RunRange.h:45
Belle2::RunRange::Merge
Long64_t Merge(TCollection *hlist)
Allow merging using TFileMerger if saved directly to a file.
Definition: RunRange.h:75
Belle2::RunRange::SetDirectory
void SetDirectory(TDirectory *)
Root-like SetDirectory function for "template compatibility" with ROOT objects. Does nothing.
Definition: RunRange.h:107
Belle2::RunRange::clear
virtual void clear()
Implementation of clearing - resets stored run set.
Definition: RunRange.h:39
Belle2::RunRange::getGranularity
std::string getGranularity() const
Gets the m_granularity.
Definition: RunRange.h:103
Belle2::RunRange::~RunRange
virtual ~RunRange()
Destructor.
Definition: RunRange.h:33
Belle2::RunRange::m_granularity
std::string m_granularity
granularity used by the collector storing the information.
Definition: RunRange.h:123
Belle2::RunRange::RunRange
RunRange()
Constructor.
Definition: RunRange.h:22
Belle2::RunRange::operator<
bool operator<(const RunRange &other) const
Comparison operator so that we can use RunRange in a map as a key.
Definition: RunRange.h:110
Belle2::RunRange
Mergeable object holding (unique) set of (exp,run) pairs.
Definition: RunRange.h:18