CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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>
13 #include <xercesc/util/PlatformUtils.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) return "";
28  WideString wstr(ch);
29  AnsiString astr(wstr);
30  return astr.c_str();
31 #else
32  if(ch == 0) return "";
33 
34  //auto_ptr<char> v(XMLString::transcode(ch));
35  //return string(v.get());
36  char* buf = XMLString::transcode(ch);
37  string str(buf);
38  XMLString::release(&buf);
39  return str;
40 #endif
41 }
42 
44  TPatternsVecsMap::const_iterator patVecIt = m_PatternsVecsMap.find(coneCrds);
45  if(patVecIt == m_PatternsVecsMap.end()){
46 
47  std::stringstream ss;
48  ss << coneCrds.m_Tower << " " << coneCrds.m_LogSector << " " << coneCrds.m_LogSegment;
49  throw RPCException( std::string("no such a cone in m_PatternsVecsMap: ")+ ss.str() );
50  //edm::LogError("RPCTrigger")<< "no such a cone in m_PatternsVecsMap";
51  }
52  return patVecIt->second; // XXX - TMF - was in if{}, changed to avoid warning
53 }
54 
55 const RPCPattern::RPCPatVec& RPCPatternsParser::getPatternsVec(const int tower, const int sc, const int sg) const {
56 
57  RPCConst::l1RpcConeCrdnts cords(tower,sc,sg);
58 
59  return getPatternsVec(cords);
60 
61 }
62 
63 
64 // ---------------------------------------------------------------------------
65 // This is a simple class that lets us do easy(though not terribly efficient)
66 // trancoding of char* data to XMLCh data.
67 // ---------------------------------------------------------------------------
68 class XStr
69 {
70 public :
71  // -----------------------------------------------------------------------
72  // Constructors and Destructor
73  // -----------------------------------------------------------------------
74  XStr(const char* const toTranscode)
75  {
76  // Call the private transcoding method
77  m_fUnicodeForm = XMLString::transcode(toTranscode);
78  }
79 
81  {
82  XMLString::release(&m_fUnicodeForm);
83  }
84 
85 
86  // -----------------------------------------------------------------------
87  // Getter methods
88  // -----------------------------------------------------------------------
89  const XMLCh* unicodeForm() const
90  {
91  return m_fUnicodeForm;
92  }
93 
94 private :
95  // -----------------------------------------------------------------------
96  // Private data members
97  //
98  // m_fUnicodeForm
99  // This is the Unicode XMLCh format of the string.
100  // -----------------------------------------------------------------------
102 };
103 
104 #define Char2XMLCh(str) XStr(str).unicodeForm()
105 
107 
109 {
110  if(m_InstanceCount == 0) {
111  try {
112  XMLPlatformUtils::Initialize();
113  //XPathEvaluator::initialize();
114  m_InstanceCount++;
115  }
116  catch(const XMLException &toCatch) {
117  throw RPCException("Error during Xerces-c Initialization: "
118  + xMLCh2String(toCatch.getMessage()));
119  //edm::LogError("RPCTrigger")<< "Error during Xerces-c Initialization: "
120  // + xMLCh2String(toCatch.getMessage());
121  }
122  }
123 }
124 
125 
126 
128 }
129 
131 {
132  ifstream fin;
133  fin.open(fileName.c_str());
134  if(fin.fail()) {
135  throw RPCException("Cannot open the file" + fileName);
136  //edm::LogError("RPCTrigger") << "Cannot open the file" + fileName;
137  }
138  fin.close();
139 
140  SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
141  parser->setContentHandler(this);
142 
143  m_QualityVec.clear();
144  parser->parse(fileName.c_str());
145  delete parser;
146 }
147 
148 void RPCPatternsParser::startElement(const XMLCh* const uri,
149  const XMLCh* const localname,
150  const XMLCh* const qname,
151  const Attributes& attrs) {
152  RPCConst rpcconst;
153 
154  m_CurrElement = xMLCh2String(localname);
155  if(m_CurrElement == "quality") {
156  //<quality id = "0" planes = "011110" val = 1/>
157  RPCPattern::TQuality quality;
158 
159 
160  quality.m_QualityTabNumber = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("id"))));
161  std::bitset<8> firedPl( xMLCh2String(attrs.getValue(Char2XMLCh("planes")) )) ;
162  unsigned long fpUL = firedPl.to_ulong();
163  quality.m_FiredPlanes = (unsigned char) (fpUL & 0xFF );
164  //quality.m_FiredPlanes = xMLCh2String(attrs.getValue(Char2XMLCh("planes")));
165  quality.m_QualityValue = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("val"))));
166 
167  m_QualityVec.push_back(quality);
168  }
169  else if(m_CurrElement == "pac") {
170  //<pac id ="0" m_tower = "0" logSector = "0" logSegment = "0" descr = "">
172  cone.m_Tower = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("tower"))));
173  cone.m_LogSector = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("logSector"))));
174  cone.m_LogSegment = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("logSegment"))));
175  pair <TPatternsVecsMap::iterator, bool> res = m_PatternsVecsMap.insert(TPatternsVecsMap::value_type(cone,
177  if(res.second == true)
178  m_CurPacIt = res.first;
179  else
180  throw RPCException( std::string("m_PatternsVecsMap insertion failed - cone already exixsts?"));
181  //edm::LogError("RPCTrigger") << "m_PatternsVecsMap insertion failed - cone already exixsts?";
182  }
183  else if(m_CurrElement == "pat") {
184  //<pat type="E" grp="0" qual="0" sign="0" code="31" num="0">
185  string pt = xMLCh2String(attrs.getValue(Char2XMLCh("type")));
186  if(pt == "E")
187  m_CurPattern.setPatternType(RPCPattern::PAT_TYPE_E);
188  else if(pt == "T")
189  m_CurPattern.setPatternType(RPCPattern::PAT_TYPE_T);
190  else
191  throw RPCException("unknown pattern type: " + pt);
192  //edm::LogError("RPCTrigger") << "unknown pattern type: " + pt;
193 
194  m_CurPattern.setRefGroup(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("grp")))));
195  m_CurPattern.setQualityTabNumber(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("qual")))));
196 
197  m_CurPattern.setSign(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("sign")))));
198  m_CurPattern.setCode(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("code")))));
199  m_CurPattern.setNumber(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("num")))));
200  }
201  else if(m_CurrElement == "str") {
202  //<logstrip plane="m_LOGPLANE1" from="32" to="32"/>
203  int logPlane = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("Pl"))));
204  m_CurPattern.setStripFrom(logPlane, rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("f")))));
205  m_CurPattern.setStripTo(logPlane, rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("t")))) + 1);
206  }
207 }
208 
209 void RPCPatternsParser::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) {
210  string element = xMLCh2String(localname);
211  if(element == "pat") {
212  m_CurPacIt->second.push_back(m_CurPattern);
213  }
214 }
string xMLCh2String(const XMLCh *ch)
The coordinates of Logic Cone: m_Tower, m_LogSector, m_LogSegment.
Definition: RPCConst.h:119
const XMLCh * unicodeForm() const
#define Char2XMLCh(str)
static const TPatternType PAT_TYPE_T
Definition: RPCPattern.h:51
unsigned char m_FiredPlanes
Definition: RPCPattern.h:35
std::vector< RPCPattern > RPCPatVec
Definition: RPCPattern.h:32
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
XMLCh * m_fUnicodeForm
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
XStr(const char *const toTranscode)
const RPCPattern::RPCPatVec & getPatternsVec(const RPCConst::l1RpcConeCrdnts &coneCrds) const
Container::value_type value_type
static int m_InstanceCount
static const TPatternType PAT_TYPE_E
Definition: RPCPattern.h:52
def qname
Definition: asciidump.py:315
void parse(std::string fileName)
int stringToInt(std::string str)
Converts string to inteager number. If string contains chars, that are not digits, throws RPCException.
Definition: RPCConst.cc:243