Belle II Software  release-05-02-19
TOPCalTimebase.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <top/dbobjects/TOPCalTimebase.h>
12 
13 #include <framework/logging/Logger.h>
14 
15 #include <iostream>
16 
17 using namespace std;
18 
19 namespace Belle2 {
25  typedef map<unsigned, const TOPSampleTimes*>::const_iterator Iterator;
28  void TOPCalTimebase::append(unsigned scrodID, unsigned channel,
29  const vector<double>& sampleTimes,
30  bool replace)
31  {
32  unsigned key = (scrodID << 16) + (channel % 128);
33  Iterator it = m_map.find(key);
34  if (it == m_map.end()) { // constants not appended yet
35  m_sampleTimes.push_back(TOPSampleTimes(scrodID, channel, m_syncTimeBase));
36  m_sampleTimes.back().setTimeAxis(sampleTimes, m_syncTimeBase);
37  m_map[key] = &m_sampleTimes.back();
38  } else { // constants already there
39  if (replace) {
40  const_cast<TOPSampleTimes*>(it->second)->setTimeAxis(sampleTimes, m_syncTimeBase);
41  B2WARNING("TOPCalTimebase: constants replaced."
42  << LogVar("scrodID", scrodID)
43  << LogVar("channel", channel));
44  } else {
45  B2WARNING("TOPCalTimebase: old constants kept."
46  << LogVar("scrodID", scrodID)
47  << LogVar("channel", channel));
48  }
49  }
50 
51  }
52 
53 
54  const TOPSampleTimes* TOPCalTimebase::getSampleTimes(unsigned scrodID,
55  unsigned channel) const
56  {
57  if (m_map.empty()) createMap();
58 
59  unsigned key = (scrodID << 16) + (channel % 128);
60  Iterator it = m_map.find(key);
61  if (it == m_map.end()) {
62  if (!m_sampleTime) m_sampleTime = new TOPSampleTimes(0, 0, m_syncTimeBase);
63  return m_sampleTime;
64  }
65  return it->second;
66  }
67 
68 
69  bool TOPCalTimebase::isAvailable(unsigned scrodID, unsigned channel) const
70  {
71  if (m_map.empty()) createMap();
72 
73  unsigned key = (scrodID << 16) + (channel % 128);
74  Iterator it = m_map.find(key);
75  return (it != m_map.end());
76 
77  }
78 
79 
81  {
82  for (const auto& sampleTime : m_sampleTimes) {
83  unsigned key = (sampleTime.getScrodID() << 16) + sampleTime.getChannel();
84  m_map[key] = &sampleTime;
85  }
86 
87  B2DEBUG(100, "Map created, size = " << m_map.size());
88  }
89 
91 } // end Belle2 namespace
Belle2::Iterator
map< unsigned, const TOPSampleTimes * >::const_iterator Iterator
Iteratior for m_map.
Definition: TOPCalTimebase.cc:25
Belle2::createMap
i2dMap createMap(int nEntries, Functor funct)
create a multimap with
Definition: mapHelperFunctions.cc:54
Belle2::TOPSampleTimes
Calibration constants of a singe ASIC channel: time axis (sample times)
Definition: TOPSampleTimes.h:34
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
LogVar
Class to store variables with their name which were sent to the logging service.
Definition: LogVariableStream.h:24