Belle II Software  release-08-01-10
FrontEndMapper.h
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 #pragma once
10 
11 #include <top/dbobjects/TOPFrontEndMap.h>
12 #include <framework/gearbox/GearDir.h>
13 #include <framework/database/DBArray.h>
14 #include <framework/database/IntervalOfValidity.h>
15 
16 #include <map>
17 #include <unordered_set>
18 
19 
20 namespace Belle2 {
25  namespace TOP {
26 
32 
33  public:
34 
39 
44 
49  void initialize(const GearDir& frontEndMapping);
50 
54  void initialize();
55 
60  bool isValid() const {return m_valid;}
61 
66  void importPayload(const IntervalOfValidity& iov) const;
67 
74  const TOPFrontEndMap* getMap(int moduleID, int bs) const
75  {
76  moduleID--;
77  if (moduleID >= 0 and moduleID < c_numModules and bs >= 0 and bs < c_numColumns)
78  return m_fromModule[moduleID][bs];
79  return 0;
80  }
81 
87  const TOPFrontEndMap* getMap(unsigned short scrodID) const
88  {
89  std::map<unsigned short, const TOPFrontEndMap*>::const_iterator it =
90  m_fromScrod.find(scrodID);
91  if (it == m_fromScrod.end()) return 0;
92  return it->second;
93  }
94 
101  const TOPFrontEndMap* getMapFromCopper(unsigned copperID, int finesse) const
102  {
103  std::map<unsigned int, const TOPFrontEndMap*>::const_iterator it =
104  m_fromCopper.find(copperID * 4 + finesse);
105  if (it == m_fromCopper.end()) return 0;
106  return it->second;
107  }
108 
113  int getMapSize() const
114  {
115  if (m_fromDB) {
116  return m_mappingDB->getEntries();
117  } else {
118  return m_mapping.size();
119  }
120  }
121 
126  const std::unordered_set<unsigned int>& getCopperIDs() const
127  {
128  return m_copperIDs;
129  }
130 
136  int getModuleCNumber(int moduleID) const
137  {
138  for (int bs = 0; bs < c_numColumns; bs++) {
139  const auto* map = getMap(moduleID, bs);
140  if (map) return map->getModuleCNumber();
141  }
142  return 0;
143  }
144 
148  void print() const;
149 
150  private:
151 
156  enum {c_numModules = 16, c_numColumns = 4};
157 
162  {}
163 
168  {return *this;}
169 
173  void clear();
174 
178  void update();
179 
180  std::vector<TOPFrontEndMap> m_mapping;
182  bool m_valid = false;
183  bool m_fromDB = false;
185  std::unordered_set<unsigned int> m_copperIDs;
186  const TOPFrontEndMap* m_fromModule[c_numModules][c_numColumns] = {{0}};
187  std::map<unsigned short, const TOPFrontEndMap*> m_fromScrod;
188  std::map<unsigned int, const TOPFrontEndMap*> m_fromCopper;
190  };
191 
192  } // TOP namespace
194 } // Belle2 namespace
195 
Class for accessing arrays of objects in the database.
Definition: DBArray.h:26
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
A class that describes the interval of experiments/runs for which an object in the database is valid.
Mapping of a boardstack number within a module to SCROD and COPPER/Finesse.
Provides mapping between electronics module position within a TOP module and SCROD ID,...
const TOPFrontEndMap * getMap(int moduleID, int bs) const
Return map from TOP module side.
void initialize()
Initialize from database.
bool m_fromDB
true, if from database
const TOPFrontEndMap * getMapFromCopper(unsigned copperID, int finesse) const
Return map from COPPER/Finesse side.
const std::unordered_set< unsigned int > & getCopperIDs() const
Return a set of copper ID's.
const TOPFrontEndMap * m_fromModule[c_numModules][c_numColumns]
conversion
bool isValid() const
check if the mapping is available
DBArray< TOPFrontEndMap > * m_mappingDB
mappings from database
FrontEndMapper(const FrontEndMapper &)
copy constructor
bool m_valid
true, if mapping available
int getMapSize() const
Return size of the map.
FrontEndMapper & operator=(const FrontEndMapper &)
assignment operator
std::unordered_set< unsigned int > m_copperIDs
COPPER ID's.
std::map< unsigned int, const TOPFrontEndMap * > m_fromCopper
conversion
std::map< unsigned short, const TOPFrontEndMap * > m_fromScrod
conversion
int getModuleCNumber(int moduleID) const
Returns module construction number.
void update()
re-do conversion maps when DBArray has changed
void importPayload(const IntervalOfValidity &iov) const
import mappings to database
void print() const
Print mappings to terminal screen.
std::vector< TOPFrontEndMap > m_mapping
mappings from gearbox
const TOPFrontEndMap * getMap(unsigned short scrodID) const
Return map from SCROD side.
Abstract base class for different kinds of events.