Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef _STAND_ALONE
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #endif // _STAND_ALONE
00010 #include "L1Trigger/RPCTrigger/interface/RPCPatternsParser.h"
00011 #include <xercesc/sax2/SAX2XMLReader.hpp>
00012 #include <xercesc/sax2/XMLReaderFactory.hpp>
00013 #include <xercesc/util/PlatformUtils.hpp>
00014 #include <sstream>
00015 #include <fstream>
00016 #include <iostream>
00017 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
00018
00019
00020
00021
00022 using namespace xercesc;
00023 using namespace std;
00024
00025 string xMLCh2String(const XMLCh* ch) {
00026 #ifdef __BORLANDC__
00027 if(ch == 0) return "";
00028 WideString wstr(ch);
00029 AnsiString astr(wstr);
00030 return astr.c_str();
00031 #else
00032 if(ch == 0) return "";
00033
00034
00035
00036 char* buf = XMLString::transcode(ch);
00037 string str(buf);
00038 XMLString::release(&buf);
00039 return str;
00040 #endif
00041 }
00042
00043 const RPCPattern::RPCPatVec& RPCPatternsParser::getPatternsVec(const RPCConst::l1RpcConeCrdnts& coneCrds) const {
00044 TPatternsVecsMap::const_iterator patVecIt = m_PatternsVecsMap.find(coneCrds);
00045 if(patVecIt == m_PatternsVecsMap.end()){
00046
00047 std::stringstream ss;
00048 ss << coneCrds.m_Tower << " " << coneCrds.m_LogSector << " " << coneCrds.m_LogSegment;
00049 throw RPCException( std::string("no such a cone in m_PatternsVecsMap: ")+ ss.str() );
00050
00051 }
00052 return patVecIt->second;
00053 }
00054
00055 const RPCPattern::RPCPatVec& RPCPatternsParser::getPatternsVec(const int tower, const int sc, const int sg) const {
00056
00057 RPCConst::l1RpcConeCrdnts cords(tower,sc,sg);
00058
00059 return getPatternsVec(cords);
00060
00061 }
00062
00063
00064
00065
00066
00067
00068 class XStr
00069 {
00070 public :
00071
00072
00073
00074 XStr(const char* const toTranscode)
00075 {
00076
00077 m_fUnicodeForm = XMLString::transcode(toTranscode);
00078 }
00079
00080 ~XStr()
00081 {
00082 XMLString::release(&m_fUnicodeForm);
00083 }
00084
00085
00086
00087
00088
00089 const XMLCh* unicodeForm() const
00090 {
00091 return m_fUnicodeForm;
00092 }
00093
00094 private :
00095
00096
00097
00098
00099
00100
00101 XMLCh* m_fUnicodeForm;
00102 };
00103
00104 #define Char2XMLCh(str) XStr(str).unicodeForm()
00105
00106 int RPCPatternsParser::m_InstanceCount = 0;
00107
00108 RPCPatternsParser::RPCPatternsParser()
00109 {
00110 if(m_InstanceCount == 0) {
00111 try {
00112 XMLPlatformUtils::Initialize();
00113
00114 m_InstanceCount++;
00115 }
00116 catch(const XMLException &toCatch) {
00117 throw RPCException("Error during Xerces-c Initialization: "
00118 + xMLCh2String(toCatch.getMessage()));
00119
00120
00121 }
00122 }
00123 }
00124
00125
00126
00127 RPCPatternsParser::~RPCPatternsParser() {
00128 }
00129
00130 void RPCPatternsParser::parse(std::string fileName)
00131 {
00132 ifstream fin;
00133 fin.open(fileName.c_str());
00134 if(fin.fail()) {
00135 throw RPCException("Cannot open the file" + fileName);
00136
00137 }
00138 fin.close();
00139
00140 SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
00141 parser->setContentHandler(this);
00142
00143 m_QualityVec.clear();
00144 parser->parse(fileName.c_str());
00145 delete parser;
00146 }
00147
00148 void RPCPatternsParser::startElement(const XMLCh* const uri,
00149 const XMLCh* const localname,
00150 const XMLCh* const qname,
00151 const Attributes& attrs) {
00152 RPCConst rpcconst;
00153
00154 m_CurrElement = xMLCh2String(localname);
00155 if(m_CurrElement == "quality") {
00156
00157 RPCPattern::TQuality quality;
00158
00159
00160 quality.m_QualityTabNumber = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("id"))));
00161 std::bitset<8> firedPl( xMLCh2String(attrs.getValue(Char2XMLCh("planes")) )) ;
00162 unsigned long fpUL = firedPl.to_ulong();
00163 quality.m_FiredPlanes = (unsigned char) (fpUL & 0xFF );
00164
00165 quality.m_QualityValue = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("val"))));
00166
00167 m_QualityVec.push_back(quality);
00168 }
00169 else if(m_CurrElement == "pac") {
00170
00171 RPCConst::l1RpcConeCrdnts cone;
00172 cone.m_Tower = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("tower"))));
00173 cone.m_LogSector = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("logSector"))));
00174 cone.m_LogSegment = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("logSegment"))));
00175 pair <TPatternsVecsMap::iterator, bool> res = m_PatternsVecsMap.insert(TPatternsVecsMap::value_type(cone,
00176 RPCPattern::RPCPatVec()));
00177 if(res.second == true)
00178 m_CurPacIt = res.first;
00179 else
00180 throw RPCException( std::string("m_PatternsVecsMap insertion failed - cone already exixsts?"));
00181
00182 }
00183 else if(m_CurrElement == "pat") {
00184
00185 string pt = xMLCh2String(attrs.getValue(Char2XMLCh("type")));
00186 if(pt == "E")
00187 m_CurPattern.setPatternType(RPCPattern::PAT_TYPE_E);
00188 else if(pt == "T")
00189 m_CurPattern.setPatternType(RPCPattern::PAT_TYPE_T);
00190 else
00191 throw RPCException("unknown pattern type: " + pt);
00192
00193
00194 m_CurPattern.setRefGroup(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("grp")))));
00195 m_CurPattern.setQualityTabNumber(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("qual")))));
00196
00197 m_CurPattern.setSign(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("sign")))));
00198 m_CurPattern.setCode(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("code")))));
00199 m_CurPattern.setNumber(rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("num")))));
00200 }
00201 else if(m_CurrElement == "str") {
00202
00203 int logPlane = rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("Pl"))));
00204 m_CurPattern.setStripFrom(logPlane, rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("f")))));
00205 m_CurPattern.setStripTo(logPlane, rpcconst.stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("t")))) + 1);
00206 }
00207 }
00208
00209 void RPCPatternsParser::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) {
00210 string element = xMLCh2String(localname);
00211 if(element == "pat") {
00212 m_CurPacIt->second.push_back(m_CurPattern);
00213 }
00214 }