Belle II Software  release-05-02-19
FrontEndMapper.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - 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 #pragma once
12 
13 #include <top/dbobjects/TOPFrontEndMap.h>
14 #include <framework/gearbox/GearDir.h>
15 #include <framework/database/DBArray.h>
16 #include <framework/database/IntervalOfValidity.h>
17 
18 #include <map>
19 #include <unordered_set>
20 
21 
22 namespace Belle2 {
27  namespace TOP {
28 
33  class FrontEndMapper {
34 
35  public:
36 
41 
46 
51  void initialize(const GearDir& frontEndMapping);
52 
56  void initialize();
57 
62  bool isValid() const {return m_valid;}
63 
68  void import(const IntervalOfValidity& iov) const;
69 
76  const TOPFrontEndMap* getMap(int moduleID, int bs) const
77  {
78  moduleID--;
79  if (moduleID >= 0 and moduleID < c_numModules and bs >= 0 and bs < c_numColumns)
80  return m_fromModule[moduleID][bs];
81  return 0;
82  }
83 
89  const TOPFrontEndMap* getMap(unsigned short scrodID) const
90  {
91  std::map<unsigned short, const TOPFrontEndMap*>::const_iterator it =
92  m_fromScrod.find(scrodID);
93  if (it == m_fromScrod.end()) return 0;
94  return it->second;
95  }
96 
103  const TOPFrontEndMap* getMapFromCopper(unsigned copperID, int finesse) const
104  {
105  std::map<unsigned int, const TOPFrontEndMap*>::const_iterator it =
106  m_fromCopper.find(copperID * 4 + finesse);
107  if (it == m_fromCopper.end()) return 0;
108  return it->second;
109  }
110 
115  int getMapSize() const
116  {
117  if (m_fromDB) {
118  return m_mappingDB->getEntries();
119  } else {
120  return m_mapping.size();
121  }
122  }
123 
128  const std::unordered_set<unsigned int>& getCopperIDs() const
129  {
130  return m_copperIDs;
131  }
132 
138  int getModuleCNumber(int moduleID) const
139  {
140  for (int bs = 0; bs < c_numColumns; bs++) {
141  const auto* map = getMap(moduleID, bs);
142  if (map) return map->getModuleCNumber();
143  }
144  return 0;
145  }
146 
150  void print() const;
151 
152  private:
153 
158  enum {c_numModules = 16, c_numColumns = 4};
159 
164  {}
165 
170  {return *this;}
171 
175  void clear();
176 
180  void update();
181 
182  std::vector<TOPFrontEndMap> m_mapping;
184  bool m_valid = false;
185  bool m_fromDB = false;
187  std::unordered_set<unsigned int> m_copperIDs;
188  const TOPFrontEndMap* m_fromModule[c_numModules][c_numColumns] = {{0}};
189  std::map<unsigned short, const TOPFrontEndMap*> m_fromScrod;
190  std::map<unsigned int, const TOPFrontEndMap*> m_fromCopper;
192  };
193 
194  } // TOP namespace
196 } // Belle2 namespace
197 
Belle2::TOPFrontEndMap
Mapping of a boardstack number within a module to SCROD and COPPER/Finesse.
Definition: TOPFrontEndMap.h:32
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::TOP::FrontEndMapper::m_fromDB
bool m_fromDB
true, if from database
Definition: FrontEndMapper.h:193
Belle2::TOP::FrontEndMapper::initialize
void initialize()
Initialize from database.
Definition: FrontEndMapper.cc:150
Belle2::TOP::FrontEndMapper::m_copperIDs
std::unordered_set< unsigned int > m_copperIDs
COPPER ID's.
Definition: FrontEndMapper.h:195
Belle2::TOP::FrontEndMapper::getMapSize
int getMapSize() const
Return size of the map.
Definition: FrontEndMapper.h:123
Belle2::TOP::FrontEndMapper::getMapFromCopper
const TOPFrontEndMap * getMapFromCopper(unsigned copperID, int finesse) const
Return map from COPPER/Finesse side.
Definition: FrontEndMapper.h:111
Belle2::TOP::FrontEndMapper
Provides mapping between electronics module position within a TOP module and SCROD ID,...
Definition: FrontEndMapper.h:41
Belle2::TOP::FrontEndMapper::m_fromModule
const TOPFrontEndMap * m_fromModule[c_numModules][c_numColumns]
conversion
Definition: FrontEndMapper.h:196
Belle2::DBArray
Class for accessing arrays of objects in the database.
Definition: DBArray.h:36
Belle2::TOP::FrontEndMapper::update
void update()
re-do conversion maps when DBArray has changed
Definition: FrontEndMapper.cc:198
Belle2::TOP::FrontEndMapper::print
void print() const
Print mappings to terminal screen.
Definition: FrontEndMapper.cc:214
Belle2::TOP::FrontEndMapper::m_mapping
std::vector< TOPFrontEndMap > m_mapping
mappings from gearbox
Definition: FrontEndMapper.h:190
Belle2::TOP::FrontEndMapper::getMap
const TOPFrontEndMap * getMap(int moduleID, int bs) const
Return map from TOP module side.
Definition: FrontEndMapper.h:84
Belle2::TOP::FrontEndMapper::~FrontEndMapper
~FrontEndMapper()
destructor
Definition: FrontEndMapper.cc:36
Belle2::TOP::FrontEndMapper::getCopperIDs
const std::unordered_set< unsigned int > & getCopperIDs() const
Return a set of copper ID's.
Definition: FrontEndMapper.h:136
Belle2::TOP::FrontEndMapper::m_fromScrod
std::map< unsigned short, const TOPFrontEndMap * > m_fromScrod
conversion
Definition: FrontEndMapper.h:197
Belle2::TOP::FrontEndMapper::isValid
bool isValid() const
check if the mapping is available
Definition: FrontEndMapper.h:70
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOP::FrontEndMapper::m_fromCopper
std::map< unsigned int, const TOPFrontEndMap * > m_fromCopper
conversion
Definition: FrontEndMapper.h:198
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::TOP::FrontEndMapper::m_mappingDB
DBArray< TOPFrontEndMap > * m_mappingDB
mappings from database
Definition: FrontEndMapper.h:191
Belle2::TOP::FrontEndMapper::operator=
FrontEndMapper & operator=(const FrontEndMapper &)
assignment operator
Definition: FrontEndMapper.h:177
Belle2::TOP::FrontEndMapper::m_valid
bool m_valid
true, if mapping available
Definition: FrontEndMapper.h:192
Belle2::TOP::FrontEndMapper::FrontEndMapper
FrontEndMapper()
constructor
Definition: FrontEndMapper.cc:26
Belle2::TOP::FrontEndMapper::getModuleCNumber
int getModuleCNumber(int moduleID) const
Returns module construction number.
Definition: FrontEndMapper.h:146
Belle2::TOP::FrontEndMapper::clear
void clear()
Clear.
Definition: FrontEndMapper.cc:182