Belle II Software  release-08-01-10
BackgroundMetaData.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/dataobjects/BackgroundMetaData.h>
10 #include <framework/logging/Logger.h>
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 
16 bool BackgroundMetaData::canBeMerged(const BackgroundMetaData* otherObj)
17 {
18 
19  if (otherObj->getBackgroundType() != m_backgroundType) {
20  B2ERROR("BackgroundMetaData: objects cannot be merged (different backgroundType)");
21  return false;
22  }
23 
24  if (otherObj->getBackgroundTag() != m_backgroundTag) {
25  B2ERROR("BackgroundMetaData: objects cannot be merged (different backgroundTag)");
26  return false;
27  }
28 
29  if (otherObj->getFileType() != m_fileType) {
30  B2ERROR("BackgroundMetaData: objects cannot be merged (different fileType)");
31  return false;
32  }
33 
34  return true;
35 }
36 
37 
39 {
40  auto otherObj = static_cast<const BackgroundMetaData*>(other);
41 
42  if (otherObj->getBackgroundType().empty()) return; // no merge for empty object
43 
44  if (m_backgroundType.empty()) { // empty, replace it with other
45  *this = *otherObj;
46  return;
47  }
48 
49  if (!canBeMerged(otherObj)) throw BackgroundMetaDataNotMergeable();
50 
51  m_realTime += otherObj->getRealTime();
52 
53 }
54 
55 void BackgroundMetaData::clear()
56 {
57  m_realTime = 0;
58 }
Metadata information about the beam background file.
const std::string & getBackgroundType() const
Returns the type of background.
float getRealTime() const
Returns real time that corresponds to this background sample.
EFileType getFileType() const
Returns file type.
BG_TAG getBackgroundTag() const
Returns background tag value.
Abstract base class for objects that can be merged.
Definition: Mergeable.h:31
std::vector< std::vector< double > > merge(std::vector< std::vector< std::vector< double >>> toMerge)
merge { vector<double> a, vector<double> b} into {a, b}
Definition: tools.h:41
Abstract base class for different kinds of events.