Belle II Software  release-08-01-10
SVDOnlineToOfflineMap.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 #ifndef FADC_APV_MAPPER_H_
10 #define FADC_APV_MAPPER_H_
11 
12 #include <vxd/dataobjects/VxdID.h>
13 #include <svd/dataobjects/SVDShaperDigit.h>
14 #include <boost/property_tree/ptree.hpp>
15 #include <unordered_map>
16 #include <unordered_set>
17 #include <string>
18 
19 namespace Belle2 {
31  public:
32 
34  void setErrorRate(int errorRate) {m_errorRate = errorRate;}
35 
37  class ChipID {
38  public:
40  typedef unsigned short baseType; // id
42  typedef unsigned char chipNumberType; // FADC/APV number
43 
44 
46  explicit ChipID(baseType id = 0) { m_id.id = id; }
49  { m_id.parts.FADC = FADC; m_id.parts.APV25 = APV25; }
51  ChipID(const ChipID& other): m_id(other.m_id) {}
52 
54  ChipID& operator=(ChipID other) { m_id.id = other.m_id.id; return *this; }
56  ChipID& operator=(baseType id) { m_id.id = id; return *this; }
58  operator baseType() { return m_id.id; }
60  bool operator==(const ChipID& other) const { return (m_id.id == other.m_id.id); }
62  bool operator<(const ChipID& other) const { return (m_id.id < other.m_id.id); }
63 
64 
66  baseType getID() const { return m_id.id; }
68  chipNumberType getFADC() const {return m_id.parts.FADC; }
70  chipNumberType getAPV25() const {return m_id.parts.APV25; }
72  void setID(baseType id) { m_id.id = id; }
74  void setFADC(chipNumberType FADC) { m_id.parts.FADC = FADC; }
76  void setAPV25(chipNumberType APV25) { m_id.parts.APV25 = APV25; }
77 
78  private:
80  union {
82  baseType id : 8 * sizeof(baseType);
84  struct {
85  chipNumberType FADC : 8 * sizeof(chipNumberType);
86  chipNumberType APV25: 8 * sizeof(chipNumberType);
87  } parts;
88  } m_id;
89  }; //ChipID class
90 
92  class SensorID {
93  public:
95  typedef unsigned short baseType;
97  typedef unsigned short sensorNumberType;
98 
99 
101  explicit SensorID(baseType id = 0) { m_ID.id = id; }
104  { m_ID.PARTS.layer = layer; m_ID.PARTS.ladder = ladder; m_ID.PARTS.dssd = dssd; m_ID.PARTS.side = side; }
105 
107  SensorID& operator=(baseType id) { m_ID.id = id; return *this; }
108 
110  operator baseType() { return m_ID.id; }
111 
112  private:
113 
115  union {
117  baseType id : 10;
119  struct {
120  sensorNumberType layer : 2;
121  sensorNumberType ladder : 4;
122  sensorNumberType dssd : 3;
123  bool side : 1;
124  } PARTS;
125  } m_ID;
126  }; //SensorID class
127 
129  struct SensorInfo {
131  bool m_uSide;
132  bool m_parallel;
133  unsigned short m_channel0;
134  unsigned short m_channel127;
135  }; // SensorInfo struct
136 
138  struct ChipInfo {
139  unsigned short fadc;
140  unsigned char apv;
141  unsigned short stripFirst;
142  unsigned short stripLast;
143  unsigned char apvChannel;
144  }; // ChipInfo struct
145 
146  // SVDOnlineOffLineMap
147 
151  explicit SVDOnlineToOfflineMap(const std::string& xml_filename);
152 
155 
156 
168  SVDShaperDigit* NewShaperDigit(unsigned char FADC, unsigned char APV25,
169  unsigned char channel, short samples[6], float time = 0.0);
170 
177  const SensorInfo& getSensorInfo(unsigned char FADC, unsigned char APV25);
178 
187  bool isAPVinMap(unsigned short layer, unsigned short ladder, unsigned short dssd, bool side, unsigned short strip);
188 
195  bool isAPVinMap(VxdID sensorID, bool side, unsigned short strip);
196 
202  struct missingAPV {
204  bool m_isUSide;
205  float m_halfStrip;
206  };
207 
210  std::vector< missingAPV > m_missingAPVs;
211 
214  {
215  return m_missingAPVs.size();
216  }
217 
227  const ChipInfo& getChipInfo(unsigned short layer, unsigned short ladder, unsigned short dssd, bool side, unsigned short strip);
228 
234  short getStripNumber(unsigned char channel, const SensorInfo& info) const
235  { return (info.m_channel0 + ((unsigned short)channel) * (info.m_parallel ? 1 : -1)); }
236 
237 
239  std::unordered_set<unsigned char> FADCnumbers;
240 
242  std::unordered_multimap<unsigned char, unsigned char> APVforFADCmap;
243 
244 
245  typedef std::unordered_map<unsigned short, unsigned short> FADCmap;
248  void prepFADCmaps(FADCmap&, FADCmap&);
249 
251  unsigned short getFADCboardsNumber()
252  {
253  return FADCnumbers.size();
254  }
255 
256  private:
257 
260  void ReadLayer(int nLayer, boost::property_tree::ptree const& xml_layer);
261 
264  void ReadLadder(int nLayer, int nLadder, boost::property_tree::ptree const& xml_ladder);
265 
268  void ReadSensor(int nLayer, int nLadder, int nSensor, boost::property_tree::ptree const& xml_sensor);
269 
273  void ReadSensorSide(int nLayer, int nLadder, int nSensor, bool isU, boost::property_tree::ptree const& xml_side);
274 
276  std::string m_MapUniqueName;
277 
281  std::unordered_map< ChipID::baseType, SensorInfo > m_sensors;
282  std::unordered_map< SensorID::baseType, std::vector<ChipInfo> > m_chips;
285  unsigned int nBadMappingErrors = 0;
286 
288  int m_errorRate{1000};
289 
292  void addChip(unsigned char chipN,
293  unsigned char FADCn,
294  int nlayer, int nladder, int nsensor, bool isU,
295  unsigned short stripNumberCh0,
296  bool isParallel);
297 
300  void addChip(unsigned char chipN,
301  unsigned char FADCn,
302  unsigned short stripNumberCh0,
303  bool isParallel
304  );
305 
310  };
311 
313 } // namespace Belle2
314 #endif
315 
Class to hold FADC+APV25 numbers.
chipNumberType getAPV25() const
Get APV25 number.
void setAPV25(chipNumberType APV25)
Set APV25 number.
chipNumberType getFADC() const
Get FADC number.
unsigned char chipNumberType
Type of chip numbers.
ChipID & operator=(ChipID other)
Assignment from same type.
ChipID(baseType id=0)
Constructor taking a compound id.
void setFADC(chipNumberType FADC)
Set FADC number.
bool operator<(const ChipID &other) const
ordering
ChipID(chipNumberType FADC, chipNumberType APV25)
Constructor taking chip numbers.
void setID(baseType id)
Set chip ID.
unsigned short baseType
Typedefs of the compound id type and chip number types.
struct Belle2::SVDOnlineToOfflineMap::ChipID::@244::@245 parts
Alternative struct representation.
ChipID & operator=(baseType id)
Assignment from base type.
ChipID(const ChipID &other)
Copy ctor.
union Belle2::SVDOnlineToOfflineMap::ChipID::@244 m_id
Union type representing the ChipID compound.
bool operator==(const ChipID &other) const
equality
Class to hold numbers related to sensor.
struct Belle2::SVDOnlineToOfflineMap::SensorID::@246::@247 PARTS
Alternative struct representation.
SensorID & operator=(baseType id)
check if VxdID is the same or not
unsigned short baseType
Typedefs of the compound id type and chip number types.
SensorID(baseType id=0)
Constructor taking a compound id.
union Belle2::SVDOnlineToOfflineMap::SensorID::@246 m_ID
Union type representing the SensorID compound.
unsigned short sensorNumberType
Type of chip numbers.
SensorID(sensorNumberType layer, sensorNumberType ladder, sensorNumberType dssd, bool side)
Constructor taking sensor info.
This class implements the methods to map raw SVD hits to basf2 SVD hits.
unsigned short getFADCboardsNumber()
get the num,ner of FADC boards
void prepareListOfMissingAPVs()
prepares the list of the missing APVs using the channel mapping
std::unordered_map< unsigned short, unsigned short > FADCmap
FADC map typedef.
const SensorInfo & getSensorInfo(unsigned char FADC, unsigned char APV25)
Get SensorInfo for a given FADC/APV combination.
SensorInfo m_currentSensorInfo
current sensor info
int getNumberOfMissingAPVs()
Get number of missing APVs.
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.
SVDShaperDigit * NewShaperDigit(unsigned char FADC, unsigned char APV25, unsigned char channel, short samples[6], float time=0.0)
Return a pointer to a new SVDShpaerDigit whose VxdID, isU and cellID is set.
std::unordered_multimap< unsigned char, unsigned char > APVforFADCmap
map containing FADC numbers assigned to multiple APVs, from xml file
int m_errorRate
The suppression factor of BadMapping ERRORs messages to be shown.
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.
unsigned int nBadMappingErrors
Counter of the BadMapping errors.
SVDOnlineToOfflineMap()=delete
No default constructor.
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)
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.
std::unordered_set< unsigned char > FADCnumbers
container for FADC numbers from current mapping file
void addChip(unsigned char chipN, unsigned char FADCn, unsigned short stripNumberCh0, bool isParallel)
add chipN on FADCn to the map
ChipInfo m_currentChipInfo
internal instance of chipinfo used by the getter
void ReadLayer(int nLayer, boost::property_tree::ptree const &xml_layer)
Read from the ptree v in the xml file the layer nLayer.
std::string m_MapUniqueName
Human readable unique name of this map.
std::unordered_map< SensorID::baseType, std::vector< ChipInfo > > m_chips
needed for the packer, map of VxdID to chips
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...
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
void prepFADCmaps(FADCmap &, FADCmap &)
function that maps FADC numbers as 0-(nFADCboards-1) from FADCnumbers unordered_set
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.
void setErrorRate(int errorRate)
Setter for suppression factor given by the Unpacker.
short getStripNumber(unsigned char channel, const SensorInfo &info) const
Convert APV channel number to a strip number using a ChipInfo object.
std::vector< missingAPV > m_missingAPVs
list of the missing APVs
The SVD ShaperDigit class.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Abstract base class for different kinds of events.
Struct to hold data about an APV25 chip.
unsigned short stripLast
last strip number
unsigned short stripFirst
first strip number
Struct to hold data about a sensor.
bool m_uSide
True if u-side of the sensor.
unsigned short m_channel127
Strip corresponding to channel 127.
bool m_parallel
False if numbering is reversed.
unsigned short m_channel0
Strip corresponding to channel 0.
struct to hold missing APVs informations
float m_halfStrip
floating strip in the middle of the APV
bool m_isUSide
True if u-side of the sensor.