9#include <pxd/online/PXDIgnoredPixelsMap.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;
21 m_Map(0), m_MapSingles(0), m_lastSensorID(0), m_lastSensorVCells(0)
25 if (xmlFilename ==
"") {
26 B2DEBUG(10,
"No xml list of ignored pixels specified.");
38 B2WARNING(
"The xml filename: " << xmlFilename << endl <<
39 "resolved to: " << xmlFullPath << endl <<
40 "by FileSystem::findFile does not exist." << endl <<
41 "PXD ignored pixels map cannot be initialized." << endl
47 read_xml(xmlFullPath, propertyTree);
48 }
catch (std::exception
const& ex) {
49 B2WARNING(
"STD excpetion raised during xml parsing " << ex.what() << endl <<
50 "PXD ignored pixels map cannot be initialized." << endl);
53 B2WARNING(
"Unknown excpetion raised during xml parsing "
54 "PXD ignored pixels map cannot be initialized." << endl);
61 for (ptree::value_type
const& layer : propertyTree.get_child(
"PXD"))
62 if (layer.first ==
"layer") {
63 sensorID.
setLayerNumber(
static_cast<unsigned short>(layer.second.get<
int>(
"<xmlattr>.n")));
64 for (ptree::value_type
const& ladder : layer.second)
65 if (ladder.first ==
"ladder") {
66 sensorID.
setLadderNumber(
static_cast<unsigned short>(ladder.second.get<
int>(
"<xmlattr>.n")));
67 for (ptree::value_type
const& sensor : ladder.second)
68 if (sensor.first ==
"sensor") {
69 sensorID.
setSensorNumber(
static_cast<unsigned short>(sensor.second.get<
int>(
"<xmlattr>.n")));
73 for (ptree::value_type
const& tag : sensor.second) {
74 if (tag.first ==
"pixels") {
75 auto limits = tag.second;
77 short uStart = limits.get<
short>(
"<xmlattr>.uStart", -1);
78 short uEnd = limits.get<
short>(
"<xmlattr>.uEnd", -1);
79 short vStart = limits.get<
short>(
"<xmlattr>.vStart", -1);
80 short vEnd = limits.get<
short>(
"<xmlattr>.vEnd", -1);
83 if (uStart != -1 && vStart != -1 && uEnd == -1 && vEnd == -1) {
87 }
else if (uStart != -1 && vStart == -1 && uEnd == -1 && vEnd == -1) {
91 vEnd = info.getVCells() - 1;
92 }
else if (uStart == -1 && vStart != -1 && uEnd == -1 && vEnd == -1) {
96 uEnd = info.getUCells() - 1;
97 }
else if (uStart != -1 && vStart == -1 && uEnd != -1 && vEnd == -1) {
100 vEnd = info.getVCells() - 1;
101 }
else if (uStart == -1 && vStart != -1 && uEnd == -1 && vEnd != -1) {
104 uEnd = info.getUCells() - 1;
105 }
else if (uStart != -1 && vStart != -1 && uEnd != -1 && vEnd != -1) {
112 unsigned short uS(uStart);
113 unsigned short vS(vStart);
114 unsigned short uE(uEnd);
115 unsigned short vE(vEnd);
116 if (uE >= info.getUCells()) uE = info.getUCells() - 1;
117 if (vE >= info.getVCells()) vE = info.getVCells() - 1;
118 if (vS > vE) vS = vE;
119 if (uS > uE) uS = uE;
121 unsigned int area = (uE - uS + 1) * (vE - vS + 1);
125 unsigned int uid = uStart * info.getVCells() + vStart;
131 [ = ](
unsigned int u,
unsigned int v) ->
bool
132 {
return (uS <= u && u <= uE && vS <= v && v <= vE); };
134 ranges.insert(std::make_pair(area, range_mask));
138 m_Map.insert(std::pair<unsigned short, PXDIgnoredPixelsMap::IgnoredPixelsRangeSet>(sensorID.
getID(), ranges));
139 m_MapSingles.insert(std::pair<unsigned short, PXDIgnoredPixelsMap::IgnoredSinglePixelsSet>(sensorID.
getID(), singles));
144 B2WARNING(
"Unknown exception raised during map initialization! "
145 "PXD ignored pixels map may be corrupted." << endl);
155 std::set<PXDIgnoredPixelsMap::map_pixel> pixels;
159 for (
int pixelU = 0; pixelU < info.getUCells(); pixelU++) {
160 for (
int pixelV = 0; pixelV < info.getVCells(); pixelV++) {
176 auto mapIter =
m_Map.find(
id);
179 if (mapIter !=
m_Map.end())
195 const unsigned int u = pixel.first;
196 const unsigned int v = pixel.second;
202 if (iter->second(u, v))
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.
std::unordered_set< unsigned int > IgnoredSinglePixelsSet
Structure to hold set of masked single pixels indexed by their unique id (unsigned int),...
std::pair< unsigned short, unsigned short > map_pixel
Simple structure for a pixel, u = map_pixel.first, v = map_pixel.second.
std::unordered_map< unsigned short, IgnoredSinglePixelsSet > m_MapSingles
Structure holding sets of ingored single pixels for all sensors by sensor id (unsigned short).
std::unordered_map< unsigned short, IgnoredPixelsRangeSet > m_Map
Structure holding sets of ignored pixel ranges for all sensors by sensor id (unsigned short).
std::multimap< unsigned int, pixel_range_test_prototype, std::greater< unsigned int > > IgnoredPixelsRangeSet
Structure to hold set of masked pixel ranges ordered from largest to smallest by their area (unsigned...
IgnoredSinglePixelsSet m_lastIgnoredSingles
Set of ignored single pixels for the most currently queried sensor.
unsigned short m_lastSensorVCells
The most currently queried sensor number of V pixels (for quick pixel uid evaluation)
IgnoredPixelsRangeSet m_lastIgnored
Set of ignored pixel ranges for the most currently queried sensor.
PXDIgnoredPixelsMap()=delete
No default constructor.
VxdID m_lastSensorID
The most currently queried sensor number.
std::function< bool(unsigned short, unsigned short) > pixel_range_test_prototype
Prototype for lambda function used to check if a pixel is in masked range.
bool pixelOK(VxdID id, map_pixel pixel)
Check whether a pixel on a given sensor is OK or not.
const std::set< map_pixel > getIgnoredPixels(VxdID id)
Get the set of ignored pixels for a sensor.
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
static GeoCache & getInstance()
Return a reference to the singleton instance.
Base class to provide Sensor Information for PXD and SVD.
int getVCells() const
Return number of pixel/strips in v direction.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getID() const
Get the unique id.
void setSensorNumber(baseType sensor)
Set the sensor id.
void setLadderNumber(baseType ladder)
Set the ladder id.
void setLayerNumber(baseType layer)
Set the layer id.
Abstract base class for different kinds of events.