CMS 3D CMS Logo

RPCPatternsParser.cc
Go to the documentation of this file.
1 /*******************************************************************************
2 * *
3 * Karol Bunkowski *
4 * Warsaw University 2005 *
5 * *
6 *******************************************************************************/
7 #ifndef _STAND_ALONE
9 #endif // _STAND_ALONE
11 #include <xercesc/sax2/SAX2XMLReader.hpp>
12 #include <xercesc/sax2/XMLReaderFactory.hpp>
14 #include <sstream>
15 #include <fstream>
16 #include <iostream>
18 //#ifndef __BORLANDC__
19 //#include "xoap.h"
20 //#endif
21 
22 using namespace xercesc;
23 using namespace std;
24 
25 string xMLCh2String(const XMLCh* ch) {
26 #ifdef __BORLANDC__
27  if (ch == 0)
28  return "";
29  WideString wstr(ch);
30  AnsiString astr(wstr);
31  return astr.c_str();
32 #else
33  if (ch == nullptr)
34  return "";
35 
36  //unique_ptr<char> v(XMLString::transcode(ch));
37  //return string(v.get());
38  char* buf = XMLString::transcode(ch);
39  string str(buf);
41  return str;
42 #endif
43 }
44 
46  TPatternsVecsMap::const_iterator patVecIt = m_PatternsVecsMap.find(coneCrds);
47  if (patVecIt == m_PatternsVecsMap.end()) {
48  std::stringstream ss;
49  ss << coneCrds.m_Tower << " " << coneCrds.m_LogSector << " " << coneCrds.m_LogSegment;
50  throw RPCException(std::string("no such a cone in m_PatternsVecsMap: ") + ss.str());
51  //edm::LogError("RPCTrigger")<< "no such a cone in m_PatternsVecsMap";
52  }
53  return patVecIt->second; // XXX - TMF - was in if{}, changed to avoid warning
54 }
55 
56 const RPCPattern::RPCPatVec& RPCPatternsParser::getPatternsVec(const int tower, const int sc, const int sg) const {
57  RPCConst::l1RpcConeCrdnts cords(tower, sc, sg);
58 
59  return getPatternsVec(cords);
60 }
61 
62 // ---------------------------------------------------------------------------
63 // This is a simple class that lets us do easy(though not terribly efficient)
64 // trancoding of char* data to XMLCh data.
65 // ---------------------------------------------------------------------------
66 class XStr {
67 public:
68  // -----------------------------------------------------------------------
69  // Constructors and Destructor
70  // -----------------------------------------------------------------------
71  XStr(const char* const toTranscode) {
72  // Call the private transcoding method
73  m_fUnicodeForm = XMLString::transcode(toTranscode);
74  }
75 
76  ~XStr() { XMLString::release(&m_fUnicodeForm); }
77 
78  // -----------------------------------------------------------------------
79  // Getter methods
80  // -----------------------------------------------------------------------
81  const XMLCh* unicodeForm() const { return m_fUnicodeForm; }
82 
83 private:
84  // -----------------------------------------------------------------------
85  // Private data members
86  //
87  // m_fUnicodeForm
88  // This is the Unicode XMLCh format of the string.
89  // -----------------------------------------------------------------------
90  XMLCh* m_fUnicodeForm;
91 };
92 
93 #define Char2XMLCh(str) XStr(str).unicodeForm()
94 
96 
98  if (m_InstanceCount == 0) {
99  try {
101  //XPathEvaluator::initialize();
102  m_InstanceCount++;
103  } catch (const XMLException& toCatch) {
104  throw RPCException("Error during Xerces-c Initialization: " + xMLCh2String(toCatch.getMessage()));
105  //edm::LogError("RPCTrigger")<< "Error during Xerces-c Initialization: "
106  // + xMLCh2String(toCatch.getMessage());
107  }
108  }
109 }
110 
112 
114  ifstream fin;
115  fin.open(fileName.c_str());
116  if (fin.fail()) {
117  throw RPCException("Cannot open the file" + fileName);
118  //edm::LogError("RPCTrigger") << "Cannot open the file" + fileName;
119  }
120  fin.close();
121 
122  SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
123  parser->setContentHandler(this);
124 
125  m_QualityVec.clear();
126  parser->parse(fileName.c_str());
127  delete parser;
128 }
129 
130 void RPCPatternsParser::startElement(const XMLCh* const uri,
131  const XMLCh* const localname,
132  const XMLCh* const qname,
133  const Attributes& attrs) {
134  RPCConst rpcconst;
135 
136  m_CurrElement = xMLCh2String(localname);
137  if (m_CurrElement == "quality") {
138  //<quality id = "0" planes = "011110" val = 1/>
140 
141  quality.m_QualityTabNumber = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("id"))));
142  std::bitset<8> firedPl(xMLCh2String(attrs.getValue(Char2XMLCh("planes"))));
143  unsigned long fpUL = firedPl.to_ulong();
144  quality.m_FiredPlanes = (unsigned char)(fpUL & 0xFF);
145  //quality.m_FiredPlanes = xMLCh2String(attrs.getValue(Char2XMLCh("planes")));
146  quality.m_QualityValue = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("val"))));
147 
148  m_QualityVec.push_back(quality);
149  } else if (m_CurrElement == "pac") {
150  //<pac id ="0" m_tower = "0" logSector = "0" logSegment = "0" descr = "">
152  cone.m_Tower = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("tower"))));
153  cone.m_LogSector = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("logSector"))));
154  cone.m_LogSegment = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("logSegment"))));
155  pair<TPatternsVecsMap::iterator, bool> res =
156  m_PatternsVecsMap.insert(TPatternsVecsMap::value_type(cone, RPCPattern::RPCPatVec()));
157  if (res.second == true)
158  m_CurPacIt = res.first;
159  else
160  throw RPCException(std::string("m_PatternsVecsMap insertion failed - cone already exixsts?"));
161  //edm::LogError("RPCTrigger") << "m_PatternsVecsMap insertion failed - cone already exixsts?";
162  } else if (m_CurrElement == "pat") {
163  //<pat type="E" grp="0" qual="0" sign="0" code="31" num="0">
164  string pt = xMLCh2String(attrs.getValue(Char2XMLCh("type")));
165  if (pt == "E")
166  m_CurPattern.setPatternType(RPCPattern::PAT_TYPE_E);
167  else if (pt == "T")
168  m_CurPattern.setPatternType(RPCPattern::PAT_TYPE_T);
169  else
170  throw RPCException("unknown pattern type: " + pt);
171  //edm::LogError("RPCTrigger") << "unknown pattern type: " + pt;
172 
173  m_CurPattern.setRefGroup(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("grp")))));
174  m_CurPattern.setQualityTabNumber(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("qual")))));
175 
176  m_CurPattern.setSign(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("sign")))));
177  m_CurPattern.setCode(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("code")))));
178  m_CurPattern.setNumber(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("num")))));
179  } else if (m_CurrElement == "str") {
180  //<logstrip plane="m_LOGPLANE1" from="32" to="32"/>
181  int logPlane = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("Pl"))));
182  m_CurPattern.setStripFrom(logPlane, rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("f")))));
183  m_CurPattern.setStripTo(logPlane, rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("t")))) + 1);
184  }
185 }
186 
187 void RPCPatternsParser::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) {
188  string element = xMLCh2String(localname);
189  if (element == "pat") {
190  m_CurPacIt->second.push_back(m_CurPattern);
191  }
192 }
RPCPatternsParser::RPCPatternsParser
RPCPatternsParser()
Definition: RPCPatternsParser.cc:96
RPCPatternsParser::parse
void parse(std::string fileName)
Definition: RPCPatternsParser.cc:112
MessageLogger.h
RPCConst::stringToInt
int stringToInt(std::string str)
Converts string to inteager number. If string contains chars, that are not digits,...
Definition: RPCConst.cc:255
Char2XMLCh
#define Char2XMLCh(str)
Definition: RPCPatternsParser.cc:92
RPCException.h
RPCConst::l1RpcConeCrdnts::m_Tower
int m_Tower
Definition: RPCConst.h:119
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
XStr
Definition: MuonsGrabber.cc:26
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:3
RPCPattern::PAT_TYPE_E
static const TPatternType PAT_TYPE_E
Definition: RPCPattern.h:56
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
RPCPatternsParser::endElement
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
Definition: RPCPatternsParser.cc:186
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
RPCPattern::TQuality
Definition: RPCPattern.h:38
RPCConst::l1RpcConeCrdnts
The coordinates of Logic Cone: m_Tower, m_LogSector, m_LogSegment.
Definition: RPCConst.h:118
RPCPatternsParser::getPatternsVec
const RPCPattern::RPCPatVec & getPatternsVec(const RPCConst::l1RpcConeCrdnts &coneCrds) const
Definition: RPCPatternsParser.cc:44
groupFilesInBlocks.fin
fin
Definition: groupFilesInBlocks.py:94
str
#define str(s)
Definition: TestProcessor.cc:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
RPCConst::l1RpcConeCrdnts::m_LogSegment
int m_LogSegment
Definition: RPCConst.h:121
RPCException
Definition: RPCException.h:21
RPCPatternsParser.h
Xerces.h
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
RPCPatternsParser::startElement
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const XERCES_CPP_NAMESPACE::Attributes &attrs) override
Definition: RPCPatternsParser.cc:129
res
Definition: Electron.h:6
xMLCh2String
string xMLCh2String(const XMLCh *ch)
Definition: RPCPatternsParser.cc:24
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
RPCPattern::RPCPatVec
std::vector< RPCPattern > RPCPatVec
Definition: RPCPattern.h:36
std
Definition: JetResolutionObject.h:76
RPCPatternsParser::m_InstanceCount
static int m_InstanceCount
Definition: RPCPatternsParser.h:54
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
RPCPattern::PAT_TYPE_T
static const TPatternType PAT_TYPE_T
Definition: RPCPattern.h:55
RPCConst::l1RpcConeCrdnts::m_LogSector
int m_LogSector
Definition: RPCConst.h:120
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
RPCConst
Definition: RPCConst.h:23
RPCPatternsParser::~RPCPatternsParser
~RPCPatternsParser() override
Definition: RPCPatternsParser.cc:110