CMS 3D CMS Logo

MuonsGrabber.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RPCTrigger
4 // Class : MuonsGrabber
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Thu Sep 17 14:21:01 CEST 2009
11 //
12 
13 // system include files
14 
15 // user include files
18 #include <xercesc/util/XMLString.hpp>
19 #include <xercesc/dom/DOM.hpp>
20 #include <xercesc/framework/LocalFileFormatTarget.hpp>
21 #include <sstream>
22 #include <algorithm>
23 
25 
26 class XStrPrivate {
27 public:
28  XStrPrivate(const char* const toTranscode) { fUnicodeForm = XMLString::transcode(toTranscode); }
29 
31 
32  const XMLCh* unicodeForm() const { return fUnicodeForm; }
33 
34 private:
35  XMLCh* fUnicodeForm;
36 };
37 
38 #define X(str) XStrPrivate(str).unicodeForm()
39 
40 //
41 // constants, enums and typedefs
42 //
43 
44 //
45 // static data member definitions
46 //
47 
49  static MuonsGrabber grabber;
50  return grabber;
51 }
52 
53 //
54 // constructors and destructor
55 //
57  try {
59  } catch (const XMLException& toCatch) {
60  throw std::string("Error during Xerces-c Initialization: " +
61  std::string(XMLString::transcode(toCatch.getMessage())));
62  }
63 
64  m_dom = DOMImplementationRegistry::getDOMImplementation(X("Core"));
65  if (m_dom == nullptr)
66  throw cms::Exception("RPCMuonsGrabber") << "Cannot get DOM" << std::endl;
67 
68  m_doc = m_dom->createDocument(nullptr, // root element namespace URI.
69  X("rpctDataStream"), // root element name
70  nullptr); // document type object (DTD).
71 
72  m_rootElem = m_doc->getDocumentElement();
73 
74  m_currEvent = nullptr;
75 }
76 
77 // MuonsGrabber::MuonsGrabber(const MuonsGrabber& rhs)
78 // {
79 // // do actual copying here;
80 // }
81 
83  // save xmlfile
84  XMLCh tempStr[100];
85  XMLString::transcode("LS", tempStr, 99);
86  DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
87  DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
88  DOMConfiguration* dc = theSerializer->getDomConfig();
89  dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
90  DOMLSOutput* outputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
91  outputDesc->setEncoding(X("UTF-8"));
92 
93  XMLFormatTarget* myFormTarget = new LocalFileFormatTarget(X("testpulses.xml"));
94  outputDesc->setByteStream(myFormTarget);
95  DOMNode* xmlstylesheet =
96  m_doc->createProcessingInstruction(X("xml-stylesheet"), X("type=\"text/xsl\"href=\"default.xsl\""));
97 
98  m_doc->insertBefore(xmlstylesheet, m_rootElem);
99  theSerializer->write(m_doc, outputDesc);
100 
101  delete theSerializer;
102  delete myFormTarget;
103  m_doc->release();
105 }
106 
108  //<event bx="0" num="0">
109  m_currEvent = m_doc->createElement(X("event"));
110  m_currEvent->setAttribute(X("num"), X(IntToString(event).c_str()));
111  m_currEvent->setAttribute(X("bx"), X(IntToString(bx).c_str()));
112  m_rootElem->appendChild(m_currEvent);
113 
115  m_currentBX = bx;
116 }
117 
118 void MuonsGrabber::addMuon(RPCTBMuon& mu, int lvl, int region, int hs, int index) {
119  if (mu.getPtCode() > 0)
120  m_muons.push_back(RPCMuonExtraStruct(lvl, region, hs, index, mu));
121 }
122 
124  if (m_muons.empty())
125  return;
126 
127  //<bxData num="11">
128  DOMElement* currRelBx = m_doc->createElement(X("bxData"));
129  currRelBx->setAttribute(X("num"), X(IntToString(bx).c_str()));
130  m_currEvent->appendChild(currRelBx);
131 
132  //std::cout << "Writing out for relBx " << bx << std::endl;
133 
134  // <hs num="1" be="0">
135  // levels
136  // 0 - PAC
137  // 1 - tbgs
138  // 2 - tcgs
139  // 3 - hs
140  // 4 fs
141 
143  for (int tcNum = 0; tcNum <= 11; ++tcNum) {
144  DOMElement* tc = nullptr;
145  DOMElement* tcgs = nullptr;
146  for (int tbNum = 0; tbNum <= 10; ++tbNum) { // check actual range, probably till 9 total
147  DOMElement* tb = nullptr;
148  DOMElement* tbgs = nullptr;
149  for (int PAC = 0; PAC <= 4; ++PAC) { // same here
150 
151  DOMElement* pac = nullptr;
152  // for (int segment = 0; segment <= 11; ++segment ) {
153  std::vector<RPCMuonExtraStruct>::iterator it = m_muons.begin();
154  while (it != m_muons.end()) {
155  int muSegment = it->_mu.getLogSegment();
156  //if
157 
158  int muTBno = m_trigConfig->getTBNum(it->_mu.getConeCrdnts());
159  int muPACChipNo = m_trigConfig->getTowerNumOnTb(it->_mu.getConeCrdnts());
160  int muTC = m_trigConfig->getTCNum(it->_mu.getConeCrdnts());
161 
162  if (!((int(it->_level) == 0 && tbNum == muTBno && muTC == tcNum && PAC == muPACChipNo) ||
163  (int(it->_level) == 1 && tbNum == muTBno && muTC == tcNum) || (int(it->_level) == 2 && muTC == tcNum)))
164 
165  {
166  ++it;
167  continue;
168  }
169  // std::cout << int(it->_level) << int(it->_region) << int(it->_hsHalf)
170  // << " " << int(it->_index)
171  // << " " << it->_mu.printDebugInfo(2) << std::endl;
172 
173  if (tc == nullptr) {
174  tc = m_doc->createElement(X("tc"));
175  currRelBx->appendChild(tc);
176  tc->setAttribute(X("num"), X(IntToString(tcNum).c_str()));
177 
178  tcgs = m_doc->createElement(X("tcgs"));
179  tc->appendChild(tcgs);
180  }
181  if (tb == nullptr && int(it->_level) <= 1) {
182  tb = m_doc->createElement(X("tb"));
183  tc->appendChild(tb);
184  tb->setAttribute(X("num"), X(IntToString(tbNum).c_str()));
185 
186  tbgs = m_doc->createElement(X("tbgs"));
187  tb->appendChild(tbgs);
188  }
189 
190  if (pac == nullptr && int(it->_level) == 0) {
191  pac = m_doc->createElement(X("pac"));
192  tb->appendChild(pac);
193  pac->setAttribute(X("num"), X(IntToString(muPACChipNo).c_str()));
194  }
195 
196  DOMElement* mu = m_doc->createElement(X("mu"));
197  mu->setAttribute(X("pt"), X(IntToString(int(it->_mu.getPtCode())).c_str()));
198  mu->setAttribute(X("qual"), X(IntToString(int(it->_mu.getQuality())).c_str()));
199  mu->setAttribute(X("sign"), X(IntToString(int(it->_mu.getSign())).c_str()));
200 
201  if (int(it->_level) == 0) {
202  mu->setAttribute(X("num"), X(IntToString(muSegment).c_str()));
203  pac->appendChild(mu);
204  } else {
205  mu->setAttribute(X("num"), X(IntToString(int(it->_index)).c_str()));
206  mu->setAttribute(X("phi"), X(IntToString(int(it->_mu.getPhiAddr())).c_str()));
207  mu->setAttribute(X("eta"), X(IntToString(int(it->_mu.getEtaAddr())).c_str()));
208  mu->setAttribute(X("gbD"), X(IntToString(int(it->_mu.getGBData())).c_str()));
209  if (int(it->_level) == 1) {
210  tbgs->appendChild(mu);
211  } else if (int(it->_level) == 2) {
212  tcgs->appendChild(mu);
213  } else {
214  throw cms::Exception("RPCMuonsGrabber") << "xx Unexpected level" << std::endl;
215  }
216  }
217 
218  it = m_muons.erase(it);
219 
220  } // muons iter
221  // } // segment
222  } // PAC
223  } // TB
224  } // TC
225 
226  for (int level = 3; level <= 4; ++level) {
227  for (int half = 0; half <= 1; ++half) {
228  for (int be = 0; be <= 1; ++be) { // brl/endcap
229 
230  std::vector<RPCMuonExtraStruct>::iterator it = m_muons.begin();
231  DOMElement* hs = nullptr;
232  while (it != m_muons.end()) {
233  if ((int(it->_level) != level) || int(it->_hsHalf) != half || int(it->_region) != be) {
234  ++it;
235  continue;
236  }
237 
238  if (hs == nullptr) {
239  if (level == 3) {
240  hs = m_doc->createElement(X("hs"));
241  hs->setAttribute(X("num"), X(IntToString(half).c_str()));
242  } else if (level == 4) {
243  hs = m_doc->createElement(X("fs"));
244  } else { // shoudlnt get here
245  throw cms::Exception("RPCMuonsGrabber") << "Problem writing out muons - lvl " << level << std::endl;
246  }
247  hs->setAttribute(X("be"), X(IntToString(be).c_str()));
248  currRelBx->appendChild(hs);
249  }
250 
251  DOMElement* mu = m_doc->createElement(X("mu"));
252  hs->appendChild(mu);
253  mu->setAttribute(X("num"), X(IntToString(int(it->_index)).c_str()));
254  mu->setAttribute(X("pt"), X(IntToString(int(it->_mu.getPtCode())).c_str()));
255  mu->setAttribute(X("qual"), X(IntToString(int(it->_mu.getQuality())).c_str()));
256  mu->setAttribute(X("sign"), X(IntToString(int(it->_mu.getSign())).c_str()));
257  mu->setAttribute(X("phi"), X(IntToString(int(it->_mu.getPhiAddr())).c_str()));
258  mu->setAttribute(X("eta"), X(IntToString(int(it->_mu.getEtaAddr())).c_str()));
259  mu->setAttribute(X("gbD"), X(IntToString(int(it->_mu.getGBData())).c_str()));
260 
261  //std::cout << int(it->_level) << int(it->_region) << int(it->_hsHalf)
262  // << " " << int(it->_index)
263  // << " " << it->_mu.printDebugInfo(2) << std::endl;
264 
265  it = m_muons.erase(it);
266 
267  } // muons iter
268  } // be iter
269  } //half iteration
270  } // lvl iteration
271 
272  if (!m_muons.empty()) {
273  throw cms::Exception("RPCMuonsGrabber") << " There are still some muons in muons vec" << std::endl;
274  }
275 }
276 
278  std::stringstream ss;
279  ss << i;
280 
281  return ss.str();
282 }
const XMLCh * unicodeForm() const
Definition: MuonsGrabber.cc:32
XERCES_CPP_NAMESPACE::DOMImplementation * m_dom
Definition: MuonsGrabber.h:77
std::vector< RPCMuonExtraStruct > m_muons
Definition: MuonsGrabber.h:72
XMLCh * fUnicodeForm
Definition: MuonsGrabber.cc:35
int getTCNum(const RPCConst::l1RpcConeCrdnts &coneCrdnts) override
Returns the index of TC that should run given LogCone.
void xercesTerminate()
Definition: Xerces.cc:23
std::string IntToString(int i)
#define X(str)
Definition: MuonsGrabber.cc:38
void xercesInitialize()
Definition: Xerces.cc:18
static MuonsGrabber & Instance()
Definition: MuonsGrabber.cc:48
static bool lvlCompare(const RPCMuonExtraStruct &a, const RPCMuonExtraStruct &b)
Definition: MuonsGrabber.h:47
void startNewEvent(int event, int bx)
RPCBasicTrigConfig * m_trigConfig
Definition: MuonsGrabber.h:73
XERCES_CPP_NAMESPACE::DOMElement * m_rootElem
Definition: MuonsGrabber.h:79
int getTBNum(const RPCConst::l1RpcConeCrdnts &coneCrdnts) override
Returns the index of TB (in TC) that should run given LogCone.
XERCES_CPP_NAMESPACE::DOMDocument * m_doc
Definition: MuonsGrabber.h:78
XERCES_CPP_NAMESPACE::DOMElement * m_currEvent
Definition: MuonsGrabber.h:80
void addMuon(RPCTBMuon &mu, int lvl, int region, int hs, int index)
XStrPrivate(const char *const toTranscode)
Definition: MuonsGrabber.cc:28
virtual ~MuonsGrabber()
Definition: MuonsGrabber.cc:82
int m_currentEvent
Definition: MuonsGrabber.h:75
void writeDataForRelativeBX(int bx)
int getTowerNumOnTb(const RPCConst::l1RpcConeCrdnts &coneCrdnts) override
Definition: event.py:1