File indexing completed on 2024-09-07 04:37:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "L1Trigger/RPCTrigger/interface/MuonsGrabber.h"
0017 #include "Utilities/Xerces/interface/Xerces.h"
0018 #include <xercesc/util/XMLString.hpp>
0019 #include <xercesc/dom/DOM.hpp>
0020 #include <xercesc/framework/LocalFileFormatTarget.hpp>
0021 #include <sstream>
0022 #include <algorithm>
0023
0024 XERCES_CPP_NAMESPACE_USE
0025
0026 class XStrPrivate {
0027 public:
0028 XStrPrivate(const char* const toTranscode) { fUnicodeForm = XMLString::transcode(toTranscode); }
0029
0030 ~XStrPrivate() { XMLString::release(&fUnicodeForm); }
0031
0032 const XMLCh* unicodeForm() const { return fUnicodeForm; }
0033
0034 private:
0035 XMLCh* fUnicodeForm;
0036 };
0037
0038 #define X(str) XStrPrivate(str).unicodeForm()
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 MuonsGrabber& MuonsGrabber::Instance() {
0049 static MuonsGrabber grabber;
0050 return grabber;
0051 }
0052
0053
0054
0055
0056 MuonsGrabber::MuonsGrabber() {
0057 try {
0058 cms::concurrency::xercesInitialize();
0059 } catch (const XMLException& toCatch) {
0060 throw std::string("Error during Xerces-c Initialization: " +
0061 std::string(XMLString::transcode(toCatch.getMessage())));
0062 }
0063
0064 m_dom = DOMImplementationRegistry::getDOMImplementation(X("Core"));
0065 if (m_dom == nullptr)
0066 throw cms::Exception("RPCMuonsGrabber") << "Cannot get DOM" << std::endl;
0067
0068 m_doc = m_dom->createDocument(nullptr,
0069 X("rpctDataStream"),
0070 nullptr);
0071
0072 m_rootElem = m_doc->getDocumentElement();
0073
0074 m_currEvent = nullptr;
0075 }
0076
0077
0078
0079
0080
0081
0082 MuonsGrabber::~MuonsGrabber() {
0083
0084 XMLCh tempStr[100];
0085 XMLString::transcode("LS", tempStr, 99);
0086 DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
0087 DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
0088 DOMConfiguration* dc = theSerializer->getDomConfig();
0089 dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0090 DOMLSOutput* outputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
0091 outputDesc->setEncoding(X("UTF-8"));
0092
0093 XMLFormatTarget* myFormTarget = new LocalFileFormatTarget(X("testpulses.xml"));
0094 outputDesc->setByteStream(myFormTarget);
0095 DOMNode* xmlstylesheet =
0096 m_doc->createProcessingInstruction(X("xml-stylesheet"), X("type=\"text/xsl\"href=\"default.xsl\""));
0097
0098 m_doc->insertBefore(xmlstylesheet, m_rootElem);
0099 theSerializer->write(m_doc, outputDesc);
0100
0101 delete theSerializer;
0102 delete myFormTarget;
0103 m_doc->release();
0104 cms::concurrency::xercesTerminate();
0105 }
0106
0107 void MuonsGrabber::startNewEvent(int event, int bx) {
0108
0109 m_currEvent = m_doc->createElement(X("event"));
0110 m_currEvent->setAttribute(X("num"), X(IntToString(event).c_str()));
0111 m_currEvent->setAttribute(X("bx"), X(IntToString(bx).c_str()));
0112 m_rootElem->appendChild(m_currEvent);
0113
0114 m_currentEvent = event;
0115 m_currentBX = bx;
0116 }
0117
0118 void MuonsGrabber::addMuon(RPCTBMuon& mu, int lvl, int region, int hs, int index) {
0119 if (mu.getPtCode() > 0)
0120 m_muons.push_back(RPCMuonExtraStruct(lvl, region, hs, index, mu));
0121 }
0122
0123 void MuonsGrabber::writeDataForRelativeBX(int bx) {
0124 if (m_muons.empty())
0125 return;
0126
0127
0128 DOMElement* currRelBx = m_doc->createElement(X("bxData"));
0129 currRelBx->setAttribute(X("num"), X(IntToString(bx).c_str()));
0130 m_currEvent->appendChild(currRelBx);
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 std::sort(m_muons.begin(), m_muons.end(), RPCMuonExtraStruct::lvlCompare);
0143 for (int tcNum = 0; tcNum <= 11; ++tcNum) {
0144 DOMElement* tc = nullptr;
0145 DOMElement* tcgs = nullptr;
0146 for (int tbNum = 0; tbNum <= 10; ++tbNum) {
0147 DOMElement* tb = nullptr;
0148 DOMElement* tbgs = nullptr;
0149 for (int PAC = 0; PAC <= 4; ++PAC) {
0150
0151 DOMElement* pac = nullptr;
0152
0153 std::vector<RPCMuonExtraStruct>::iterator it = m_muons.begin();
0154 while (it != m_muons.end()) {
0155 int muSegment = it->_mu.getLogSegment();
0156
0157
0158 int muTBno = m_trigConfig->getTBNum(it->_mu.getConeCrdnts());
0159 int muPACChipNo = m_trigConfig->getTowerNumOnTb(it->_mu.getConeCrdnts());
0160 int muTC = m_trigConfig->getTCNum(it->_mu.getConeCrdnts());
0161
0162 if (!((int(it->_level) == 0 && tbNum == muTBno && muTC == tcNum && PAC == muPACChipNo) ||
0163 (int(it->_level) == 1 && tbNum == muTBno && muTC == tcNum) || (int(it->_level) == 2 && muTC == tcNum)))
0164
0165 {
0166 ++it;
0167 continue;
0168 }
0169
0170
0171
0172
0173 if (tc == nullptr) {
0174 tc = m_doc->createElement(X("tc"));
0175 currRelBx->appendChild(tc);
0176 tc->setAttribute(X("num"), X(IntToString(tcNum).c_str()));
0177
0178 tcgs = m_doc->createElement(X("tcgs"));
0179 tc->appendChild(tcgs);
0180 }
0181 if (tb == nullptr && int(it->_level) <= 1) {
0182 tb = m_doc->createElement(X("tb"));
0183 tc->appendChild(tb);
0184 tb->setAttribute(X("num"), X(IntToString(tbNum).c_str()));
0185
0186 tbgs = m_doc->createElement(X("tbgs"));
0187 tb->appendChild(tbgs);
0188 }
0189
0190 if (pac == nullptr && int(it->_level) == 0) {
0191 pac = m_doc->createElement(X("pac"));
0192 tb->appendChild(pac);
0193 pac->setAttribute(X("num"), X(IntToString(muPACChipNo).c_str()));
0194 }
0195
0196 DOMElement* mu = m_doc->createElement(X("mu"));
0197 mu->setAttribute(X("pt"), X(IntToString(int(it->_mu.getPtCode())).c_str()));
0198 mu->setAttribute(X("qual"), X(IntToString(int(it->_mu.getQuality())).c_str()));
0199 mu->setAttribute(X("sign"), X(IntToString(int(it->_mu.getSign())).c_str()));
0200
0201 if (int(it->_level) == 0) {
0202 mu->setAttribute(X("num"), X(IntToString(muSegment).c_str()));
0203 pac->appendChild(mu);
0204 } else {
0205 mu->setAttribute(X("num"), X(IntToString(int(it->_index)).c_str()));
0206 mu->setAttribute(X("phi"), X(IntToString(int(it->_mu.getPhiAddr())).c_str()));
0207 mu->setAttribute(X("eta"), X(IntToString(int(it->_mu.getEtaAddr())).c_str()));
0208 mu->setAttribute(X("gbD"), X(IntToString(int(it->_mu.getGBData())).c_str()));
0209 if (int(it->_level) == 1) {
0210 tbgs->appendChild(mu);
0211 } else if (int(it->_level) == 2) {
0212 tcgs->appendChild(mu);
0213 } else {
0214 throw cms::Exception("RPCMuonsGrabber") << "xx Unexpected level" << std::endl;
0215 }
0216 }
0217
0218 it = m_muons.erase(it);
0219
0220 }
0221
0222 }
0223 }
0224 }
0225
0226 for (int level = 3; level <= 4; ++level) {
0227 for (int half = 0; half <= 1; ++half) {
0228 for (int be = 0; be <= 1; ++be) {
0229
0230 std::vector<RPCMuonExtraStruct>::iterator it = m_muons.begin();
0231 DOMElement* hs = nullptr;
0232 while (it != m_muons.end()) {
0233 if ((int(it->_level) != level) || int(it->_hsHalf) != half || int(it->_region) != be) {
0234 ++it;
0235 continue;
0236 }
0237
0238 if (hs == nullptr) {
0239 if (level == 3) {
0240 hs = m_doc->createElement(X("hs"));
0241 hs->setAttribute(X("num"), X(IntToString(half).c_str()));
0242 } else if (level == 4) {
0243 hs = m_doc->createElement(X("fs"));
0244 } else {
0245 throw cms::Exception("RPCMuonsGrabber") << "Problem writing out muons - lvl " << level << std::endl;
0246 }
0247 hs->setAttribute(X("be"), X(IntToString(be).c_str()));
0248 currRelBx->appendChild(hs);
0249 }
0250
0251 DOMElement* mu = m_doc->createElement(X("mu"));
0252 hs->appendChild(mu);
0253 mu->setAttribute(X("num"), X(IntToString(int(it->_index)).c_str()));
0254 mu->setAttribute(X("pt"), X(IntToString(int(it->_mu.getPtCode())).c_str()));
0255 mu->setAttribute(X("qual"), X(IntToString(int(it->_mu.getQuality())).c_str()));
0256 mu->setAttribute(X("sign"), X(IntToString(int(it->_mu.getSign())).c_str()));
0257 mu->setAttribute(X("phi"), X(IntToString(int(it->_mu.getPhiAddr())).c_str()));
0258 mu->setAttribute(X("eta"), X(IntToString(int(it->_mu.getEtaAddr())).c_str()));
0259 mu->setAttribute(X("gbD"), X(IntToString(int(it->_mu.getGBData())).c_str()));
0260
0261
0262
0263
0264
0265 it = m_muons.erase(it);
0266
0267 }
0268 }
0269 }
0270 }
0271
0272 if (!m_muons.empty()) {
0273 throw cms::Exception("RPCMuonsGrabber") << " There are still some muons in muons vec" << std::endl;
0274 }
0275 }
0276
0277 std::string MuonsGrabber::IntToString(int i) {
0278 std::stringstream ss;
0279 ss << i;
0280
0281 return ss.str();
0282 }