9#include "svd/online/SVDOnlineToOfflineMap.h"
10#include <boost/property_tree/xml_parser.hpp>
11#include <framework/logging/Logger.h>
12#include <framework/utilities/FileSystem.h>
13#include <vxd/geometry/GeoCache.h>
17using boost::property_tree::ptree;
23 , m_currentSensorInfo()
35 B2ERROR(
"The xml filename: " << xmlFilename << endl <<
36 "resolved to: " << xmlFullPath << endl <<
37 "by FileSystem::findFile does not exist." << endl <<
38 "SVD online to offline map cannot be initialized." << endl <<
39 "Be aware: no SVDShaperDigit will be produced by this module." << endl
45 read_xml(xmlFullPath, propertyTree);
46 }
catch (std::exception
const& ex) {
47 B2ERROR(
"STD excpetion rised during xml parsing " << ex.what() << endl <<
48 "SVD online to offline map cannot be initialized." << endl <<
49 "Be aware: no SVDShaperDigits will be produced by this module." << endl);
52 B2ERROR(
"Unknown excpetion rised during xml parsing "
53 "SVD online to offline map cannot be initialized." << endl <<
54 "Be aware: no SVDShaperDigits will be produced by this module." << endl);
60 for (ptree::value_type
const& v : propertyTree.get_child(
"SVD")) {
61 if (v.first ==
"unique") {
63 B2INFO(
"Loading the offline -> online SVD map named " <<
m_MapUniqueName);
66 if (v.first ==
"layer")
67 ReadLayer(v.second.get<
int>(
"<xmlattr>.n"), v.second);
70 B2ERROR(
"Unknown excpetion rised during map initialization! "
71 "SVD online to offline map corrupted." << endl <<
72 "Be aware: the SVDShaperDigits will be unreliable." << endl);
89 int(FADC)) <<
LogVar(
"APV",
int(APV25)));
103 unsigned short dssd,
bool side,
unsigned short strip)
105 SensorID id(layer, ladder, dssd, side);
106 auto chipIter =
m_chips.find(
id);
108 if (chipIter ==
m_chips.end()) B2WARNING(
" The following combination: sensorID: " << layer <<
"." << ladder <<
"." << dssd <<
109 ", isU=" << side <<
", strip=" << strip <<
110 " - is not found in the SVD Off-line to On-line map! The payload retrieved from database may be wrong! ");
113 vector<ChipInfo> vecChipInfo = chipIter->second;
118 for (std::vector<ChipInfo>::iterator it = vecChipInfo.begin() ; it != vecChipInfo.end(); ++it) {
123 if (strip >= channelFirst and strip <= channelLast) {
128 if (pinfo->
fadc == 0) B2WARNING(
"The strip number " << strip <<
" is not found in the SVDOnlineToOfflineMap for sensor " << layer <<
129 "." << ladder <<
"." << dssd <<
" on side " << (side ?
"u" :
"v") <<
"! Related APV chip is excluded in the hardware mapping.");
136 unsigned short dssd,
bool side,
unsigned short strip)
138 SensorID id(layer, ladder, dssd, side);
139 auto chipIter =
m_chips.find(
id);
141 if (chipIter ==
m_chips.end())
return false;
143 vector<ChipInfo> vecChipInfo = chipIter->second;
148 for (std::vector<ChipInfo>::iterator it = vecChipInfo.begin() ; it != vecChipInfo.end(); ++it) {
153 if (strip >= channelFirst and strip <= channelLast) {
158 if (pinfo->
fadc == 0)
return false;
170 unsigned char APV25,
unsigned char channel,
short samples[6],
float time)
174 B2WARNING(
" channel out of range (0-127):" <<
LogVar(
"channel",
int(channel)));
184 if (info.m_sensorID) {
185 return new SVDShaperDigit(info.m_sensorID, info.m_uSide, strip, rawSamples, time);
196 for (ptree::value_type
const& v : xml_layer) {
198 if (v.first ==
"ladder") {
199 ReadLadder(nlayer, v.second.get<
int>(
"<xmlattr>.n"), v.second);
208 for (ptree::value_type
const& v : xml_ladder) {
210 if (v.first ==
"sensor") {
211 ReadSensor(nlayer, nladder, v.second.get<
int>(
"<xmlattr>.n"), v.second);
220 for (ptree::value_type
const& v : xml_sensor) {
222 if (v.first ==
"side") {
223 std::string tagSide = v.second.get<std::string>(
"<xmlattr>.side");
225 bool isOnSideU = (tagSide ==
"U" || tagSide ==
"u");
226 bool isOnSideV = (tagSide ==
"V" || tagSide ==
"v");
228 if ((! isOnSideU) && (! isOnSideV)) {
229 B2ERROR(
"Side '" << tagSide <<
"' on layer " << nlayer
230 <<
" ladder " << nladder <<
" sensor " << nsensor
231 <<
" is neither 'U' nor 'V'");
242 ptree
const& xml_side)
248 vector<ChipInfo> vecInfo;
249 SensorID sid(nlayer, nladder, nsensor, isU);
251 for (ptree::value_type
const& v : xml_side) {
254 if (v.first ==
"chip") {
255 auto tags = v.second;
256 unsigned char chipN = tags.get<
unsigned char>(
"<xmlattr>.n");
257 unsigned char FADCn = tags.get<
unsigned char>(
"<xmlattr>.FADCn");
261 APVforFADCmap.insert(std::pair<unsigned char, unsigned char>(FADCn, chipN));
268 B2WARNING(
"Repeated insertion for FADC " << FADCn <<
" and APV "
269 << chipN <<
", layer/ladder/sensor " << nlayer <<
"/" << nladder
270 <<
"/" << nsensor <<
", side " << (isU ?
"u" :
"v"));
272 unsigned short stripNumberCh0 = tags.get<
unsigned short>(
"<xmlattr>.strip_number_of_ch0");
273 unsigned short stripNumberCh127 = tags.get<
unsigned short>(
"<xmlattr>.strip_number_of_ch127");
279 sinfo.m_parallel = (stripNumberCh127 > stripNumberCh0);
280 sinfo.m_channel0 = stripNumberCh0;
281 sinfo.m_channel127 = stripNumberCh127;
293 vecInfo.push_back(cinfo);
304 unsigned short it = 0;
319 for (
auto ladder : geoCache.getLadders(layer))
321 for (
int view = 0; view < 2; view++) {
324 if (layer.getLayerNumber() != 3 && view == 0)
328 for (
int apv = 0; apv < nAPVs; apv++) {
329 B2DEBUG(29,
"checking " << sensor.getLayerNumber() <<
"." << sensor.getLadderNumber() <<
"." << sensor.getSensorNumber() <<
330 ", view = " << view <<
", apv = " << apv);
331 if (!
isAPVinMap(sensor, view, apv * 128 + 63.5)) {
338 B2DEBUG(29,
"FOUND MISSING APV: " << sensor <<
", " << view <<
", " << apv);
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Class to hold FADC+APV25 numbers.
Class to hold numbers related to sensor.
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
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
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 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.
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.
static const std::size_t c_nAPVSamples
Number of APV samples stored.
std::array< APVRawSampleType, c_nAPVSamples > APVRawSamples
array of APVRawSamplesType objects
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
static GeoCache & getInstance()
Return a reference to the singleton instance.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getSensorNumber() const
Get the sensor id.
baseType getLadderNumber() const
Get the ladder id.
baseType getLayerNumber() const
Get the layer id.
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.
Struct to hold data about an APV25 chip.
unsigned short fadc
fadc number
unsigned short stripLast
last strip number
unsigned char apv
apv number
unsigned short stripFirst
first strip number
unsigned char apvChannel
apv channel
Struct to hold data about a sensor.
unsigned short m_channel127
Strip corresponding to channel 127.
unsigned short m_channel0
Strip corresponding to channel 0.
VxdID m_sensorID
Sensor ID.
struct to hold missing APVs informations
float m_halfStrip
floating strip in the middle of the APV
VxdID m_sensorID
Sensor ID.
bool m_isUSide
True if u-side of the sensor.