Belle II Software  release-05-02-19
SVDOnlineToOfflineMap.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Giulia Casarosa, Eugenio Paoloni, Jarek Wiechczynski *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef FADC_APV_MAPPER_H_
12 #define FADC_APV_MAPPER_H_
13 
14 #include <vxd/dataobjects/VxdID.h>
15 #include <svd/dataobjects/SVDModeByte.h>
16 #include <svd/dataobjects/SVDShaperDigit.h>
17 #include <boost/property_tree/ptree.hpp>
18 #include <unordered_map>
19 #include <unordered_set>
20 #include <string>
21 
22 namespace Belle2 {
39  class SVDOnlineToOfflineMap {
40  public:
41 
43  void setErrorRate(int errorRate) {m_errorRate = errorRate;}
44 
46  class ChipID {
47  public:
49  typedef unsigned short baseType; // id
51  typedef unsigned char chipNumberType; // FADC/APV number
52 
53 
55  explicit ChipID(baseType id = 0) { m_id.id = id; }
58  { m_id.parts.FADC = FADC; m_id.parts.APV25 = APV25; }
60  ChipID(const ChipID& other): m_id(other.m_id) {}
61 
63  ChipID& operator=(ChipID other) { m_id.id = other.m_id.id; return *this; }
65  ChipID& operator=(baseType id) { m_id.id = id; return *this; }
67  operator baseType() { return m_id.id; }
69  bool operator==(const ChipID& other) const { return (m_id.id == other.m_id.id); }
71  bool operator<(const ChipID& other) const { return (m_id.id < other.m_id.id); }
72 
73 
75  baseType getID() const { return m_id.id; }
77  chipNumberType getFADC() const {return m_id.parts.FADC; }
79  chipNumberType getAPV25() const {return m_id.parts.APV25; }
81  void setID(baseType id) { m_id.id = id; }
83  void setFADC(chipNumberType FADC) { m_id.parts.FADC = FADC; }
85  void setAPV25(chipNumberType APV25) { m_id.parts.APV25 = APV25; }
86 
87  private:
89  union {
91  baseType id : 8 * sizeof(baseType);
93  struct {
94  chipNumberType FADC : 8 * sizeof(chipNumberType);
95  chipNumberType APV25: 8 * sizeof(chipNumberType);
96  } parts;
97  } m_id;
98  }; //ChipID class
99 
101  class SensorID {
102  public:
104  typedef unsigned short baseType;
106  typedef unsigned short sensorNumberType;
107 
108 
110  explicit SensorID(baseType id = 0) { m_ID.id = id; }
113  { m_ID.PARTS.layer = layer; m_ID.PARTS.ladder = ladder; m_ID.PARTS.dssd = dssd; m_ID.PARTS.side = side; }
114 
116  SensorID& operator=(baseType id) { m_ID.id = id; return *this; }
117 
119  operator baseType() { return m_ID.id; }
120 
121  private:
122 
124  union {
126  baseType id : 10;
128  struct {
129  sensorNumberType layer : 2;
130  sensorNumberType ladder : 4;
131  sensorNumberType dssd : 3;
132  bool side : 1;
133  } PARTS;
134  } m_ID;
135  }; //SensorID class
136 
138  struct SensorInfo {
139  VxdID m_sensorID;
140  bool m_uSide;
141  bool m_parallel;
142  unsigned short m_channel0;
143  unsigned short m_channel127;
144  }; // SensorInfo struct
145 
147  struct ChipInfo {
148  unsigned short fadc;
149  unsigned char apv;
150  unsigned short stripFirst;
151  unsigned short stripLast;
152  unsigned char apvChannel;
153  }; // ChipInfo struct
154 
155  // SVDOnlineOffLineMap
156 
160  explicit SVDOnlineToOfflineMap(const std::string& xml_filename);
161 
163  SVDOnlineToOfflineMap() = delete;
164 
165 
175  SVDShaperDigit* NewShaperDigit(unsigned char FADC, unsigned char APV25,
176  unsigned char channel, short samples[6], float time = 0.0,
177  SVDModeByte mode = SVDModeByte());
178 
185  const SensorInfo& getSensorInfo(unsigned char FADC, unsigned char APV25);
186 
195  bool isAPVinMap(unsigned short layer, unsigned short ladder, unsigned short dssd, bool side, unsigned short strip);
196 
203  bool isAPVinMap(VxdID sensorID, bool side, unsigned short strip);
204 
210  struct missingAPV {
211  VxdID m_sensorID;
212  bool m_isUSide;
213  float m_halfStrip;
214  };
215 
218  std::vector< missingAPV > m_missingAPVs;
219 
222  {
223  return m_missingAPVs.size();
224  }
225 
235  const ChipInfo& getChipInfo(unsigned short layer, unsigned short ladder, unsigned short dssd, bool side, unsigned short strip);
236 
242  short getStripNumber(unsigned char channel, const SensorInfo& info) const
243  { return (info.m_channel0 + ((unsigned short)channel) * (info.m_parallel ? 1 : -1)); }
244 
245 
247  std::unordered_set<unsigned char> FADCnumbers;
248 
250  std::unordered_multimap<unsigned char, unsigned char> APVforFADCmap;
251 
252 
253  typedef std::unordered_map<unsigned short, unsigned short> FADCmap;
256  void prepFADCmaps(FADCmap&, FADCmap&);
257 
259  unsigned short getFADCboardsNumber()
260  {
261  return FADCnumbers.size();
262  }
263 
264  private:
265 
268  void ReadLayer(int nLayer, boost::property_tree::ptree const& xml_layer);
269 
272  void ReadLadder(int nLayer, int nLadder, boost::property_tree::ptree const& xml_ladder);
273 
276  void ReadSensor(int nLayer, int nLadder, int nSensor, boost::property_tree::ptree const& xml_sensor);
277 
281  void ReadSensorSide(int nLayer, int nLadder, int nSensor, bool isU, boost::property_tree::ptree const& xml_side);
282 
284  std::string m_MapUniqueName;
285 
289  std::unordered_map< ChipID::baseType, SensorInfo > m_sensors;
290  std::unordered_map< SensorID::baseType, std::vector<ChipInfo> > m_chips;
293  unsigned int nBadMappingErrors = 0;
294 
296  int m_errorRate{1000};
297 
300  void addChip(unsigned char chipN,
301  unsigned char FADCn,
302  int nlayer, int nladder, int nsensor, bool isU,
303  unsigned short stripNumberCh0,
304  bool isParallel);
305 
308  void addChip(unsigned char chipN,
309  unsigned char FADCn,
310  unsigned short stripNumberCh0,
311  bool isParallel
312  );
313 
318  };
319 
321 } // namespace Belle2
322 #endif
323 
Belle2::SVDOnlineToOfflineMap::m_sensors
std::unordered_map< ChipID::baseType, SensorInfo > m_sensors
m_sensors[ChipID(FADC,APV25)] gives the SensorInfo for the given APV25 on the given FADC (Unpacker)
Definition: SVDOnlineToOfflineMap.h:297
Belle2::SVDOnlineToOfflineMap::SensorID::operator=
SensorID & operator=(baseType id)
check if VxdID is the same or not
Definition: SVDOnlineToOfflineMap.h:124
Belle2::SVDOnlineToOfflineMap::SensorID::id
baseType id
unique id
Definition: SVDOnlineToOfflineMap.h:134
Belle2::SVDOnlineToOfflineMap::APVforFADCmap
std::unordered_multimap< unsigned char, unsigned char > APVforFADCmap
map containing FADC numbers assigned to multiple APVs, from xml file
Definition: SVDOnlineToOfflineMap.h:258
Belle2::SVDOnlineToOfflineMap::ChipID::getAPV25
chipNumberType getAPV25() const
Get APV25 number.
Definition: SVDOnlineToOfflineMap.h:87
Belle2::SVDOnlineToOfflineMap::FADCnumbers
std::unordered_set< unsigned char > FADCnumbers
container for FADC numbers from current mapping file
Definition: SVDOnlineToOfflineMap.h:255
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::SVDOnlineToOfflineMap::getNumberOfMissingAPVs
int getNumberOfMissingAPVs()
Get number of missing APVs.
Definition: SVDOnlineToOfflineMap.h:229
Belle2::SVDOnlineToOfflineMap::ReadLayer
void ReadLayer(int nLayer, boost::property_tree::ptree const &xml_layer)
Read from the ptree v in the xml file the layer nLayer.
Definition: SVDOnlineToOfflineMap.cc:192
Belle2::SVDOnlineToOfflineMap::ChipID::baseType
unsigned short baseType
Typedefs of the compound id type and chip number types.
Definition: SVDOnlineToOfflineMap.h:57
Belle2::SVDOnlineToOfflineMap::ChipID::setAPV25
void setAPV25(chipNumberType APV25)
Set APV25 number.
Definition: SVDOnlineToOfflineMap.h:93
Belle2::SVDOnlineToOfflineMap::ChipID::operator=
ChipID & operator=(ChipID other)
Assignment from same type.
Definition: SVDOnlineToOfflineMap.h:71
Belle2::SVDOnlineToOfflineMap::ReadSensor
void ReadSensor(int nLayer, int nLadder, int nSensor, boost::property_tree::ptree const &xml_sensor)
Read from the ptree xml_sensor the sensor nSensor in ladder nLadder in layer nLayer.
Definition: SVDOnlineToOfflineMap.cc:216
Belle2::SVDOnlineToOfflineMap::SensorInfo::m_channel127
unsigned short m_channel127
Strip corresponding to channel 127.
Definition: SVDOnlineToOfflineMap.h:151
Belle2::SVDOnlineToOfflineMap::ChipInfo
Struct to hold data about an APV25 chip.
Definition: SVDOnlineToOfflineMap.h:155
Belle2::SVDOnlineToOfflineMap::ChipID::operator==
bool operator==(const ChipID &other) const
equality
Definition: SVDOnlineToOfflineMap.h:77
Belle2::SVDOnlineToOfflineMap::prepareListOfMissingAPVs
void prepareListOfMissingAPVs()
prepares the list of the missing APVs using the channel mapping
Definition: SVDOnlineToOfflineMap.cc:310
Belle2::SVDOnlineToOfflineMap::SensorInfo::m_sensorID
VxdID m_sensorID
Sensor ID.
Definition: SVDOnlineToOfflineMap.h:147
Belle2::SVDModeByte
Class to store SVD mode information.
Definition: SVDModeByte.h:79
Belle2::SVDOnlineToOfflineMap::missingAPV::m_sensorID
VxdID m_sensorID
Sensor ID.
Definition: SVDOnlineToOfflineMap.h:219
Belle2::SVDOnlineToOfflineMap::ChipID::ChipID
ChipID(baseType id=0)
Constructor taking a compound id.
Definition: SVDOnlineToOfflineMap.h:63
Belle2::SVDOnlineToOfflineMap::missingAPV::m_isUSide
bool m_isUSide
True if u-side of the sensor.
Definition: SVDOnlineToOfflineMap.h:220
Belle2::SVDOnlineToOfflineMap::ChipID::id
baseType id
unique id
Definition: SVDOnlineToOfflineMap.h:99
Belle2::SVDOnlineToOfflineMap::getStripNumber
short getStripNumber(unsigned char channel, const SensorInfo &info) const
Convert APV channel number to a strip number using a ChipInfo object.
Definition: SVDOnlineToOfflineMap.h:250
Belle2::SVDOnlineToOfflineMap::SensorID::sensorNumberType
unsigned short sensorNumberType
Type of chip numbers.
Definition: SVDOnlineToOfflineMap.h:114
Belle2::SVDOnlineToOfflineMap::ReadLadder
void ReadLadder(int nLayer, int nLadder, boost::property_tree::ptree const &xml_ladder)
Read from the ptree xml_ladde the ladder nLadder in layer nLayer.
Definition: SVDOnlineToOfflineMap.cc:204
Belle2::SVDOnlineToOfflineMap::SensorInfo::m_channel0
unsigned short m_channel0
Strip corresponding to channel 0.
Definition: SVDOnlineToOfflineMap.h:150
Belle2::SVDOnlineToOfflineMap::missingAPV::m_halfStrip
float m_halfStrip
floating strip in the middle of the APV
Definition: SVDOnlineToOfflineMap.h:221
Belle2::SVDShaperDigit
The SVD ShaperDigit class.
Definition: SVDShaperDigit.h:46
Belle2::SVDOnlineToOfflineMap::SensorID::baseType
unsigned short baseType
Typedefs of the compound id type and chip number types.
Definition: SVDOnlineToOfflineMap.h:112
Belle2::SVDOnlineToOfflineMap::SensorInfo::m_parallel
bool m_parallel
False if numbering is reversed.
Definition: SVDOnlineToOfflineMap.h:149
Belle2::SVDOnlineToOfflineMap::SensorID::SensorID
SensorID(baseType id=0)
Constructor taking a compound id.
Definition: SVDOnlineToOfflineMap.h:118
Belle2::SVDOnlineToOfflineMap::ChipInfo::stripFirst
unsigned short stripFirst
first strip number
Definition: SVDOnlineToOfflineMap.h:158
Belle2::SVDOnlineToOfflineMap::setErrorRate
void setErrorRate(int errorRate)
Setter for suppression factor given by the Unpacker.
Definition: SVDOnlineToOfflineMap.h:51
Belle2::PXD::SensorInfo
Specific implementation of SensorInfo for PXD Sensors which provides additional pixel specific inform...
Definition: SensorInfo.h:34
Belle2::SVDOnlineToOfflineMap::missingAPV
struct to hold missing APVs informations
Definition: SVDOnlineToOfflineMap.h:218
Belle2::SVDOnlineToOfflineMap::m_errorRate
int m_errorRate
The suppression factor of BadMapping ERRORs messages to be shown.
Definition: SVDOnlineToOfflineMap.h:304
Belle2::SVDOnlineToOfflineMap::isAPVinMap
bool isAPVinMap(unsigned short layer, unsigned short ladder, unsigned short dssd, bool side, unsigned short strip)
is the APV of the strips in the map? for a given layer/ladder/dssd/side/strip combination.
Definition: SVDOnlineToOfflineMap.cc:134
Belle2::SVDOnlineToOfflineMap::SensorInfo
Struct to hold data about a sensor.
Definition: SVDOnlineToOfflineMap.h:146
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDOnlineToOfflineMap::addChip
void addChip(unsigned char chipN, unsigned char FADCn, int nlayer, int nladder, int nsensor, bool isU, unsigned short stripNumberCh0, bool isParallel)
add chipN on FADCn to the map
Belle2::SVDOnlineToOfflineMap::ChipInfo::stripLast
unsigned short stripLast
last strip number
Definition: SVDOnlineToOfflineMap.h:159
Belle2::SVDOnlineToOfflineMap::m_currentSensorInfo
SensorInfo m_currentSensorInfo
current sensor info
Definition: SVDOnlineToOfflineMap.h:323
Belle2::SVDOnlineToOfflineMap::ChipInfo::fadc
unsigned short fadc
fadc number
Definition: SVDOnlineToOfflineMap.h:156
Belle2::SVDOnlineToOfflineMap::getChipInfo
const ChipInfo & getChipInfo(unsigned short layer, unsigned short ladder, unsigned short dssd, bool side, unsigned short strip)
Get ChipInfo for a given layer/ladder/dssd/side/strip combination.
Definition: SVDOnlineToOfflineMap.cc:101
Belle2::SVDOnlineToOfflineMap::ChipID
Class to hold FADC+APV25 numbers.
Definition: SVDOnlineToOfflineMap.h:54
Belle2::SVDOnlineToOfflineMap::ChipID::parts
struct Belle2::SVDOnlineToOfflineMap::ChipID::@243::@244 parts
Alternative struct representation.
Belle2::SVDOnlineToOfflineMap::ReadSensorSide
void ReadSensorSide(int nLayer, int nLadder, int nSensor, bool isU, boost::property_tree::ptree const &xml_side)
Read from the ptree xml_side the U-side, if isU, (the V-side otherwise) of the sensor nSensor in ladd...
Definition: SVDOnlineToOfflineMap.cc:240
Belle2::SVDOnlineToOfflineMap::ChipID::getFADC
chipNumberType getFADC() const
Get FADC number.
Definition: SVDOnlineToOfflineMap.h:85
Belle2::SVDOnlineToOfflineMap::FADCmap
std::unordered_map< unsigned short, unsigned short > FADCmap
FADC map typedef.
Definition: SVDOnlineToOfflineMap.h:261
Belle2::SVDOnlineToOfflineMap::NewShaperDigit
SVDShaperDigit * NewShaperDigit(unsigned char FADC, unsigned char APV25, unsigned char channel, short samples[6], float time=0.0, SVDModeByte mode=SVDModeByte())
Return a pointer to a new SVDShpaerDigit whose VxdID, isU and cellID is set.
Definition: SVDOnlineToOfflineMap.cc:168
Belle2::SVDOnlineToOfflineMap::SVDOnlineToOfflineMap
SVDOnlineToOfflineMap()=delete
No default constructor.
Belle2::SVDOnlineToOfflineMap::ChipID::chipNumberType
unsigned char chipNumberType
Type of chip numbers.
Definition: SVDOnlineToOfflineMap.h:59
Belle2::SVDOnlineToOfflineMap::ChipInfo::apvChannel
unsigned char apvChannel
apv channel
Definition: SVDOnlineToOfflineMap.h:160
Belle2::SVDOnlineToOfflineMap::m_missingAPVs
std::vector< missingAPV > m_missingAPVs
list of the missing APVs
Definition: SVDOnlineToOfflineMap.h:226
Belle2::SVDOnlineToOfflineMap::ChipInfo::apv
unsigned char apv
apv number
Definition: SVDOnlineToOfflineMap.h:157
Belle2::SVDOnlineToOfflineMap::ChipID::m_id
union Belle2::SVDOnlineToOfflineMap::ChipID::@243 m_id
Union type representing the ChipID compound.
Belle2::SVDOnlineToOfflineMap::ChipID::setFADC
void setFADC(chipNumberType FADC)
Set FADC number.
Definition: SVDOnlineToOfflineMap.h:91
Belle2::SVDOnlineToOfflineMap::m_chips
std::unordered_map< SensorID::baseType, std::vector< ChipInfo > > m_chips
needed for the packer, map of VxdID to chips
Definition: SVDOnlineToOfflineMap.h:298
Belle2::SVDOnlineToOfflineMap::SensorID::m_ID
union Belle2::SVDOnlineToOfflineMap::SensorID::@245 m_ID
Union type representing the SensorID compound.
Belle2::SVDOnlineToOfflineMap::m_MapUniqueName
std::string m_MapUniqueName
Human readable unique name of this map.
Definition: SVDOnlineToOfflineMap.h:292
Belle2::SVDOnlineToOfflineMap::getFADCboardsNumber
unsigned short getFADCboardsNumber()
get the num,ner of FADC boards
Definition: SVDOnlineToOfflineMap.h:267
Belle2::SVDOnlineToOfflineMap::ChipID::setID
void setID(baseType id)
Set chip ID.
Definition: SVDOnlineToOfflineMap.h:89
Belle2::SVDOnlineToOfflineMap::getSensorInfo
const SensorInfo & getSensorInfo(unsigned char FADC, unsigned char APV25)
Get SensorInfo for a given FADC/APV combination.
Definition: SVDOnlineToOfflineMap.cc:78
Belle2::SVDOnlineToOfflineMap::nBadMappingErrors
unsigned int nBadMappingErrors
Counter of the BadMapping errors.
Definition: SVDOnlineToOfflineMap.h:301
Belle2::SVDOnlineToOfflineMap::SensorID::PARTS
struct Belle2::SVDOnlineToOfflineMap::SensorID::@245::@246 PARTS
Alternative struct representation.
Belle2::SVDOnlineToOfflineMap::ChipID::operator<
bool operator<(const ChipID &other) const
ordering
Definition: SVDOnlineToOfflineMap.h:79
Belle2::SVDOnlineToOfflineMap::SensorInfo::m_uSide
bool m_uSide
True if u-side of the sensor.
Definition: SVDOnlineToOfflineMap.h:148
Belle2::SVDOnlineToOfflineMap::ChipID::getID
baseType getID() const
Get chip ID.
Definition: SVDOnlineToOfflineMap.h:83
Belle2::SVDOnlineToOfflineMap::m_currentChipInfo
ChipInfo m_currentChipInfo
internal instance of chipinfo used by the getter
Definition: SVDOnlineToOfflineMap.h:322
Belle2::SVDOnlineToOfflineMap::prepFADCmaps
void prepFADCmaps(FADCmap &, FADCmap &)
function that maps FADC numbers as 0-(nFADCboards-1) from FADCnumbers unordered_set
Definition: SVDOnlineToOfflineMap.cc:300
Belle2::SVDOnlineToOfflineMap::SensorID
Class to hold numbers related to sensor.
Definition: SVDOnlineToOfflineMap.h:109