Belle II Software  release-08-01-10
TOPCalTimebase.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 <top/dbobjects/TOPCalTimebase.h>
10 #include <framework/logging/Logger.h>
11 #include <cmath>
12 
13 using namespace std;
14 
15 namespace Belle2 {
21  typedef map<unsigned, size_t>::const_iterator Iterator;
24  void TOPCalTimebase::append(unsigned scrodID, unsigned channel,
25  const vector<double>& sampleTimes,
26  bool replace)
27  {
28  // sanitary checks for NaN's
29  for (double t : sampleTimes) {
30  if (isnan(t)) {
31  B2ERROR("TOPCalTimebase::append: sampleTimes contain NaN's - constants rejected."
32  << LogVar("scrodID", scrodID)
33  << LogVar("channel", channel));
34  return;
35  }
36  }
37 
38  // append
39  unsigned key = (scrodID << 16) + (channel % 128);
40  Iterator it = m_map.find(key);
41  if (it == m_map.end()) { // constants not appended yet
42  m_sampleTimes.push_back(TOPSampleTimes(scrodID, channel, m_syncTimeBase));
43  m_sampleTimes.back().setTimeAxis(sampleTimes, m_syncTimeBase);
44  m_map[key] = m_sampleTimes.size() - 1;
45  } else { // constants already there
46  if (replace) {
47  m_sampleTimes[it->second].setTimeAxis(sampleTimes, m_syncTimeBase);
48  B2WARNING("TOPCalTimebase::append: constants replaced."
49  << LogVar("scrodID", scrodID)
50  << LogVar("channel", channel));
51  } else {
52  B2WARNING("TOPCalTimebase::append old constants kept."
53  << LogVar("scrodID", scrodID)
54  << LogVar("channel", channel));
55  }
56  }
57 
58  }
59 
60 
61  const TOPSampleTimes* TOPCalTimebase::getSampleTimes(unsigned scrodID,
62  unsigned channel) const
63  {
64  if (m_map.empty()) createMap();
65 
66  unsigned key = (scrodID << 16) + (channel % 128);
67  Iterator it = m_map.find(key);
68  if (it == m_map.end()) {
69  if (!m_sampleTime) m_sampleTime = new TOPSampleTimes(0, 0, m_syncTimeBase);
70  return m_sampleTime;
71  }
72  return &m_sampleTimes[it->second];
73  }
74 
75 
76  bool TOPCalTimebase::isAvailable(unsigned scrodID, unsigned channel) const
77  {
78  if (m_map.empty()) createMap();
79 
80  unsigned key = (scrodID << 16) + (channel % 128);
81  Iterator it = m_map.find(key);
82  return (it != m_map.end());
83 
84  }
85 
86 
88  {
89  for (size_t i = 0; i < m_sampleTimes.size(); i++) {
90  const auto& sampleTime = m_sampleTimes[i];
91  unsigned key = (sampleTime.getScrodID() << 16) + sampleTime.getChannel();
92  m_map[key] = i;
93  }
94 
95  B2DEBUG(29, "TOPCalTimebase: map created, size = " << m_map.size());
96  }
97 
99 } // end Belle2 namespace
Calibration constants of a singe ASIC channel: time axis (sample times)
Class to store variables with their name which were sent to the logging service.
map< unsigned, size_t >::const_iterator Iterator
Iteratior for m_map.
i2dMap createMap(int nEntries, Functor funct)
create a multimap with
Abstract base class for different kinds of events.