Belle II Software  release-05-01-25
SVDIgnoredStripsMap.cc
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 *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <svd/online/SVDIgnoredStripsMap.h>
12 #include <boost/property_tree/xml_parser.hpp>
13 #include <framework/logging/Logger.h>
14 #include <framework/utilities/FileSystem.h>
15 
16 using namespace Belle2;
17 using namespace std;
18 using boost::property_tree::ptree;
19 
20 
21 SVDIgnoredStripsMap::SVDIgnoredStripsMap(const string& xmlFilename):
22  m_Map(12), m_lastSensorID(0)
23 {
24  // If the xmlFilename is empty, the user apparently doesn't want the map.
25  // So keep low-profile, don't bother.
26  if (xmlFilename == "") {
27  B2INFO("No xml list of ignored strips specified.");
28  return;
29  }
30  // Create an empty property tree object
31 
32  ptree propertyTree;
33 
34  // Load the XML file into the property tree. If reading fails
35  // (cannot open file, parse error), an exception is thrown.
36  string xmlFullPath = FileSystem::findFile(xmlFilename);
37 
38  if (! FileSystem::fileExists(xmlFullPath)) {
39  B2WARNING("The xml filename: " << xmlFilename << endl <<
40  "resolved to: " << xmlFullPath << endl <<
41  "by FileSystem::findFile does not exist." << endl <<
42  "SVD ignored strips map cannot be initialized." << endl
43  );
44  return;
45  }
46 
47  try {
48  read_xml(xmlFullPath, propertyTree);
49  } catch (std::exception const& ex) {
50  B2WARNING("STD excpetion raised during xml parsing " << ex.what() << endl <<
51  "SVD ignored strips map cannot be initialized." << endl);
52  return;
53  } catch (...) {
54  B2WARNING("Unknown excpetion raised during xml parsing "
55  "SVD ignored strips map cannot be initialized." << endl);
56  return;
57  }
58 
59  try {
60  // traverse the xml tree: navigate through the daughters of <SVD>
61  VxdID sensorID;
62  for (ptree::value_type const & layer : propertyTree.get_child("SVD"))
63  if (layer.first == "layer") {
64  sensorID.setLayerNumber(static_cast<unsigned short>(layer.second.get<int>("<xmlattr>.n")));
65  for (ptree::value_type const & ladder : layer.second)
66  if (ladder.first == "ladder") {
67  sensorID.setLadderNumber(static_cast<unsigned short>(ladder.second.get<int>("<xmlattr>.n")));
68  for (ptree::value_type const & sensor : ladder.second)
69  if (sensor.first == "sensor") {
70  sensorID.setSensorNumber(static_cast<unsigned short>(sensor.second.get<int>("<xmlattr>.n")));
71  for (ptree::value_type const & side : sensor.second)
72  if (side.first == "side") {
73  std::string tagSide = side.second.get<std::string>("<xmlattr>.side");
74  sensorID.setSegmentNumber((tagSide == "U" || tagSide == "u") ? 1 : 0);
75  // We have complete VxdID, now we read the list of strips.
76  IgnoredStripsSet strips;
77  for (ptree::value_type const & tag : side.second)
78  if (tag.first == "strip") {
79  strips.insert(tag.second.get<unsigned short>("<xmlattr>.stripNo"));
80  } else if (tag.first == "stripsFromTo") {
81  auto limits = tag.second;
82  unsigned short fromStrip = limits.get<unsigned short>("<xmlattr>.fromStrip");
83  unsigned short toStrip = limits.get<unsigned short>("<xmlattr>.toStrip");
84  for (unsigned short iStrip = fromStrip; iStrip <= toStrip; iStrip++)
85  strips.insert(iStrip);
86  }
87  m_Map.insert(std::pair<unsigned short, IgnoredStripsSet>(sensorID.getID(), strips));
88  } // if side
89  } // if sensor
90  } // if ladder
91  } // if sensor
92  } catch (...) {
93  B2WARNING("Unknown excpetion raised during map initialization! "
94  "SVD ignored strips map may be corrupted." << endl);
95  return;
96  }
97 }
98 
99 const std::set<unsigned short>& SVDIgnoredStripsMap::getIgnoredStrips(VxdID id)
100 {
101  if (id == m_lastSensorID)
102  return m_lastIgnored;
103  else {
104  m_lastSensorID = id;
105  auto mapIter = m_Map.find(id);
106  if (mapIter != m_Map.end()) {
107  m_lastIgnored = mapIter->second;
108  } else {
109  m_lastIgnored.clear();
110  }
111  return m_lastIgnored;
112  }
113 }
114 
115 bool SVDIgnoredStripsMap::stripOK(VxdID id, unsigned short strip)
116 {
117  if (id != m_lastSensorID) {
118  m_lastSensorID = id;
119  auto mapIter = m_Map.find(id);
120  if (mapIter != m_Map.end()) {
121  m_lastIgnored = mapIter->second;
122  } else {
123  m_lastIgnored.clear();
124  return true;
125  }
126  }
127  return (m_lastIgnored.count(strip) == 0);
128 }
129 
130 
131 
132 
Belle2::SVDIgnoredStripsMap::IgnoredStripsSet
std::set< unsigned short > IgnoredStripsSet
A set of ignored strips.
Definition: SVDIgnoredStripsMap.h:42
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VxdID::setLayerNumber
void setLayerNumber(baseType layer)
Set the layer id.
Definition: VxdID.h:117
Belle2::VxdID::getID
baseType getID() const
Get the unique id.
Definition: VxdID.h:104
Belle2::SVDIgnoredStripsMap::stripOK
bool stripOK(VxdID id, unsigned short strip)
Check whether a strip on a given sensor is OK or not.
Definition: SVDIgnoredStripsMap.cc:115
Belle2::SVDIgnoredStripsMap::m_lastIgnored
IgnoredStripsSet m_lastIgnored
Set of ingored strips for the most currently queried sensor.
Definition: SVDIgnoredStripsMap.h:72
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VxdID::setSegmentNumber
void setSegmentNumber(baseType segment)
Set the sensor segment.
Definition: VxdID.h:123
Belle2::SVDIgnoredStripsMap::SVDIgnoredStripsMap
SVDIgnoredStripsMap()=delete
No default constructor.
Belle2::SVDIgnoredStripsMap::getIgnoredStrips
const std::set< unsigned short > & getIgnoredStrips(VxdID id)
Get the set of ignored strips for a sensor.
Definition: SVDIgnoredStripsMap.cc:99
Belle2::VxdID::setSensorNumber
void setSensorNumber(baseType sensor)
Set the sensor id.
Definition: VxdID.h:121
Belle2::FileSystem::fileExists
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:33
Belle2::SVDIgnoredStripsMap::m_Map
std::unordered_map< unsigned short, IgnoredStripsSet > m_Map
Structure holiding sets of ingored strips for all sensors.
Definition: SVDIgnoredStripsMap.h:69
Belle2::VxdID::setLadderNumber
void setLadderNumber(baseType ladder)
Set the ladder id.
Definition: VxdID.h:119
Belle2::FileSystem::findFile
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...
Definition: FileSystem.cc:147
Belle2::SVDIgnoredStripsMap::m_lastSensorID
VxdID m_lastSensorID
The most currently queried sensor number.
Definition: SVDIgnoredStripsMap.h:75