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 XStr {
27 public:
28  XStr(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) XStr(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 
142  std::sort(m_muons.begin(), m_muons.end(), RPCMuonExtraStruct::lvlCompare);
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 }
personalPlayback.level
level
Definition: personalPlayback.py:22
MuonsGrabber::m_trigConfig
RPCBasicTrigConfig * m_trigConfig
Definition: MuonsGrabber.h:72
MuonsGrabber
Definition: MuonsGrabber.h:50
RPCTBMuon
Definition: RPCTBMuon.h:17
mps_fire.i
i
Definition: mps_fire.py:355
RPCMuonExtraStruct
Definition: MuonsGrabber.h:39
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
X
#define X(str)
Definition: MuonsGrabber.cc:38
XStr
Definition: MuonsGrabber.cc:26
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
MuonsGrabber::m_doc
XERCES_CPP_NAMESPACE::DOMDocument * m_doc
Definition: MuonsGrabber.h:77
XERCES_CPP_NAMESPACE_USE
Definition: XMLConfigWriter.cc:40
MuonsGrabber::Instance
static MuonsGrabber & Instance()
Definition: MuonsGrabber.cc:48
MuonsGrabber::m_dom
XERCES_CPP_NAMESPACE::DOMImplementation * m_dom
Definition: MuonsGrabber.h:76
MuonsGrabber::startNewEvent
void startNewEvent(int event, int bx)
Definition: MuonsGrabber.cc:107
MuonsGrabber::m_currentEvent
int m_currentEvent
Definition: MuonsGrabber.h:74
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
RPCMuonExtraStruct::lvlCompare
static bool lvlCompare(const RPCMuonExtraStruct &a, const RPCMuonExtraStruct &b)
Definition: MuonsGrabber.h:47
MuonsGrabber::m_currentBX
int m_currentBX
Definition: MuonsGrabber.h:75
RPCBasicTrigConfig::getTBNum
int getTBNum(const RPCConst::l1RpcConeCrdnts &coneCrdnts) override
Returns the index of TB (in TC) that should run given LogCone.
Definition: RPCBasicTrigConfig.cc:71
MuonsGrabber::m_currEvent
XERCES_CPP_NAMESPACE::DOMElement * m_currEvent
Definition: MuonsGrabber.h:79
MuonsGrabber::writeDataForRelativeBX
void writeDataForRelativeBX(int bx)
Definition: MuonsGrabber.cc:123
RPCBasicTrigConfig::getTCNum
int getTCNum(const RPCConst::l1RpcConeCrdnts &coneCrdnts) override
Returns the index of TC that should run given LogCone.
Definition: RPCBasicTrigConfig.cc:44
RPCBasicTrigConfig::getTowerNumOnTb
int getTowerNumOnTb(const RPCConst::l1RpcConeCrdnts &coneCrdnts) override
Definition: RPCBasicTrigConfig.cc:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
XStr::unicodeForm
const XMLCh * unicodeForm() const
Definition: MuonsGrabber.cc:32
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
XStr::~XStr
~XStr()
Definition: MuonsGrabber.cc:30
MuonsGrabber::m_muons
std::vector< RPCMuonExtraStruct > m_muons
Definition: MuonsGrabber.h:71
createfilelist.int
int
Definition: createfilelist.py:10
Xerces.h
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
XStr::fUnicodeForm
XMLCh * fUnicodeForm
Definition: MuonsGrabber.cc:35
MuonsGrabber::IntToString
std::string IntToString(int i)
Definition: MuonsGrabber.cc:277
impl
Definition: trackAlgoPriorityOrder.h:18
Exception
Definition: hltDiff.cc:246
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
MuonsGrabber::addMuon
void addMuon(RPCTBMuon &mu, int lvl, int region, int hs, int index)
Definition: MuonsGrabber.cc:118
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
cms::cuda::be
int be
Definition: HistoContainer.h:126
MuonsGrabber::MuonsGrabber
MuonsGrabber()
Definition: MuonsGrabber.cc:56
event
Definition: event.py:1
event
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of "!*" before the partial wildcard feature was incorporated). The per-event "cost" of each negative criterion with multiple relevant triggers is about the same as ! *was in the past
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
MuonsGrabber::m_rootElem
XERCES_CPP_NAMESPACE::DOMElement * m_rootElem
Definition: MuonsGrabber.h:78
XStr::XStr
XStr(const char *const toTranscode)
Definition: MuonsGrabber.cc:28
MuonsGrabber::~MuonsGrabber
virtual ~MuonsGrabber()
Definition: MuonsGrabber.cc:82
MuonsGrabber.h