CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
24 XERCES_CPP_NAMESPACE_USE
25 
26 class XStr
27 {
28 public :
29  XStr(const char* const toTranscode)
30  {
31  fUnicodeForm = XMLString::transcode(toTranscode);
32  }
33 
35  {
37  }
38 
39  const XMLCh* unicodeForm() const
40  {
41  return fUnicodeForm;
42  }
43 
44 private :
45  XMLCh* fUnicodeForm;
46 };
47 
48 #define X(str) XStr(str).unicodeForm()
49 
50 //
51 // constants, enums and typedefs
52 //
53 
54 //
55 // static data member definitions
56 //
57 
59 
60  static MuonsGrabber grabber;
61  return grabber;
62 
63 
64 }
65 
66 
67 //
68 // constructors and destructor
69 //
71 {
72 
73  try {
75  }
76  catch(const XMLException &toCatch) {
77  throw std::string("Error during Xerces-c Initialization: "
78  + std::string(XMLString::transcode(toCatch.getMessage())));
79  }
80 
81  m_dom = DOMImplementationRegistry::getDOMImplementation(X("Core"));
82  if (m_dom == 0) throw cms::Exception("RPCMuonsGrabber") << "Cannot get DOM" << std::endl;
83 
84  m_doc = m_dom->createDocument(
85  0, // root element namespace URI.
86  X("rpctDataStream"), // root element name
87  0); // document type object (DTD).
88 
89  m_rootElem = m_doc->getDocumentElement();
90 
91  m_currEvent = 0;
92 }
93 
94 
95 // MuonsGrabber::MuonsGrabber(const MuonsGrabber& rhs)
96 // {
97 // // do actual copying here;
98 // }
99 
101 {
102 
103  // save xmlfile
104  XMLCh tempStr[100];
105  XMLString::transcode("LS", tempStr, 99);
106  DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
107  DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
108 
109  theSerializer->setEncoding(X("UTF-8"));
110 
111  if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
112  theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
113 
114  XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(X("testpulses.xml"));
115  DOMNode* xmlstylesheet = m_doc->createProcessingInstruction(X("xml-stylesheet"),
116  X("type=\"text/xsl\"href=\"default.xsl\""));
117 
118  m_doc->insertBefore(xmlstylesheet, m_rootElem);
119  theSerializer->writeNode(myFormTarget, *m_doc);
120 
121  delete theSerializer;
122  delete myFormTarget;
123  m_doc->release();
124 
125 
126 
127 
128 }
129 
131 
132  //<event bx="0" num="0">
133  m_currEvent = m_doc->createElement(X("event"));
134  m_currEvent->setAttribute(X("num"), X( IntToString(event).c_str()));
135  m_currEvent->setAttribute(X("bx"), X( IntToString(bx).c_str()));
136  m_rootElem->appendChild(m_currEvent);
137 
138 
140  m_currentBX = bx;
141 }
142 
143 
144 void MuonsGrabber::addMuon(RPCTBMuon & mu, int lvl, int region, int hs, int index){
145 
146  if (mu.getPtCode()>0) m_muons.push_back( RPCMuonExtraStruct(lvl, region, hs, index, mu) );
147 }
148 
150 
151  if (m_muons.empty()) return;
152 
153  //<bxData num="11">
154  DOMElement* currRelBx = m_doc->createElement(X("bxData"));
155  currRelBx->setAttribute(X("num"), X( IntToString(bx).c_str()));
156  m_currEvent->appendChild(currRelBx);
157 
158  //std::cout << "Writing out for relBx " << bx << std::endl;
159 
160  // <hs num="1" be="0">
161  // levels
162  // 0 - PAC
163  // 1 - tbgs
164  // 2 - tcgs
165  // 3 - hs
166  // 4 fs
167 
169  for (int tcNum = 0; tcNum <= 11; ++tcNum ) {
170  DOMElement* tc = 0;
171  DOMElement* tcgs = 0;
172  for (int tbNum = 0; tbNum <= 10; ++tbNum ) { // check actual range, probably till 9 total
173  DOMElement* tb = 0;
174  DOMElement* tbgs = 0;
175  for (int PAC = 0; PAC <= 4; ++PAC ) { // same here
176 
177  DOMElement* pac = 0;
178  // for (int segment = 0; segment <= 11; ++segment ) {
179  std::vector< RPCMuonExtraStruct >::iterator it = m_muons.begin();
180  while ( it != m_muons.end()) {
181  int muSegment = it->_mu.getLogSegment();
182  //if
183 
184  int muTBno = m_trigConfig->getTBNum( it->_mu.getConeCrdnts() );
185  int muPACChipNo = m_trigConfig->getTowerNumOnTb(it->_mu.getConeCrdnts() );
186  int muTC = m_trigConfig->getTCNum(it->_mu.getConeCrdnts() );
187 
188  if (
189  !(
190  ( int(it->_level) == 0 && tbNum == muTBno && muTC == tcNum && PAC == muPACChipNo)
191  || ( int(it->_level) == 1 && tbNum == muTBno && muTC == tcNum )
192  || ( int(it->_level) == 2 && muTC == tcNum )
193  )
194  )
195 
196  {
197  ++it;
198  continue;
199  }
200  // std::cout << int(it->_level) << int(it->_region) << int(it->_hsHalf)
201  // << " " << int(it->_index)
202  // << " " << it->_mu.printDebugInfo(2) << std::endl;
203 
204 
205  if (tc==0) {
206  tc = m_doc->createElement(X("tc"));
207  currRelBx->appendChild(tc);
208  tc->setAttribute(X("num"), X( IntToString(tcNum).c_str()));
209 
210  tcgs = m_doc->createElement(X("tcgs"));
211  tc->appendChild(tcgs);
212 
213  }
214  if (tb==0 && int(it->_level) <= 1) {
215  tb = m_doc->createElement(X("tb"));
216  tc->appendChild(tb);
217  tb->setAttribute(X("num"), X( IntToString(tbNum).c_str()));
218 
219  tbgs = m_doc->createElement(X("tbgs"));
220  tb->appendChild(tbgs);
221  }
222 
223  if (pac == 0 && int(it->_level) == 0) {
224  pac =m_doc->createElement(X("pac"));
225  tb->appendChild(pac);
226  pac->setAttribute(X("num"), X( IntToString(muPACChipNo).c_str()));
227  }
228 
229  DOMElement* mu = m_doc->createElement(X("mu"));
230  mu->setAttribute(X("pt"), X( IntToString( int(it->_mu.getPtCode() ) ).c_str()));
231  mu->setAttribute(X("qual"), X( IntToString( int(it->_mu.getQuality() ) ).c_str()));
232  mu->setAttribute(X("sign"), X( IntToString( int(it->_mu.getSign() ) ).c_str()));
233 
234  if (int(it->_level) == 0 ) {
235  mu->setAttribute(X("num"), X( IntToString( muSegment ).c_str()));
236  pac->appendChild(mu);
237  } else {
238  mu->setAttribute(X("num"), X( IntToString( int(it->_index) ).c_str()));
239  mu->setAttribute(X("phi"), X( IntToString( int(it->_mu.getPhiAddr() ) ).c_str()));
240  mu->setAttribute(X("eta"), X( IntToString( int(it->_mu.getEtaAddr() ) ).c_str()));
241  mu->setAttribute(X("gbD"), X( IntToString( int(it->_mu.getGBData() ) ).c_str()));
242  if (int(it->_level) == 1 ) {
243  tbgs->appendChild(mu);
244  } else if (int(it->_level) == 2 ) {
245  tcgs->appendChild(mu);
246  } else {
247  throw cms::Exception("RPCMuonsGrabber") << "xx Unexpected level" << std::endl;
248  }
249  }
250 
251 
252  it = m_muons.erase(it);
253 
254  } // muons iter
255  // } // segment
256  } // PAC
257  } // TB
258  } // TC
259 
260 
261 
262 
263  for (int level=3; level<=4;++level) {
264  for (int half =0; half <= 1; ++half){
265  for (int be =0; be <= 1; ++be){ // brl/endcap
266 
267  std::vector< RPCMuonExtraStruct >::iterator it = m_muons.begin();
268  DOMElement* hs = 0;
269  while ( it != m_muons.end()) {
270  if ( (int(it->_level) != level) || int(it->_hsHalf)!=half || int(it->_region)!=be ) {
271  ++it;
272  continue;
273  }
274 
275  if (hs == 0) {
276  if (level == 3) {
277  hs = m_doc->createElement(X("hs"));
278  hs->setAttribute(X("num"), X( IntToString(half).c_str()));
279  } else if (level ==4 ) {
280  hs = m_doc->createElement(X("fs"));
281  } else { // shoudlnt get here
282  throw cms::Exception("RPCMuonsGrabber") << "Problem writing out muons - lvl " << level << std::endl;
283  }
284  hs->setAttribute(X("be"), X( IntToString(be).c_str()));
285  currRelBx->appendChild(hs);
286  }
287 
288  DOMElement* mu = m_doc->createElement(X("mu"));
289  hs->appendChild(mu);
290  mu->setAttribute(X("num"), X( IntToString( int(it->_index) ).c_str()));
291  mu->setAttribute(X("pt"), X( IntToString( int(it->_mu.getPtCode() ) ).c_str()));
292  mu->setAttribute(X("qual"), X( IntToString( int(it->_mu.getQuality() ) ).c_str()));
293  mu->setAttribute(X("sign"), X( IntToString( int(it->_mu.getSign() ) ).c_str()));
294  mu->setAttribute(X("phi"), X( IntToString( int(it->_mu.getPhiAddr() ) ).c_str()));
295  mu->setAttribute(X("eta"), X( IntToString( int(it->_mu.getEtaAddr() ) ).c_str()));
296  mu->setAttribute(X("gbD"), X( IntToString( int(it->_mu.getGBData() ) ).c_str()));
297 
298  //std::cout << int(it->_level) << int(it->_region) << int(it->_hsHalf)
299  // << " " << int(it->_index)
300  // << " " << it->_mu.printDebugInfo(2) << std::endl;
301 
302  it = m_muons.erase(it);
303 
304  } // muons iter
305  } // be iter
306  } //half iteration
307  } // lvl iteration
308 
309  if (m_muons.size()!=0) {
310  throw cms::Exception("RPCMuonsGrabber") << " There are still some muons in muons vec" << std::endl;
311 
312  }
313 }
314 
315 
316 
318 
319  std::stringstream ss;
320  ss << i;
321 
322  return ss.str();
323 
324 }
325 
int i
Definition: DBlmapReader.cc:9
XERCES_CPP_NAMESPACE::DOMImplementation * m_dom
Definition: MuonsGrabber.h:80
const XMLCh * unicodeForm() const
Definition: MuonsGrabber.cc:39
int getPtCode() const
Definition: RPCMuon.cc:66
std::string IntToString(int i)
#define X(str)
Definition: MuonsGrabber.cc:48
virtual int getTowerNumOnTb(const RPCConst::l1RpcConeCrdnts &coneCrdnts)
void xercesInitialize()
Definition: Xerces.cc:17
XMLCh * fUnicodeForm
Definition: MuonsGrabber.cc:45
static MuonsGrabber & Instance()
Definition: MuonsGrabber.cc:58
static bool lvlCompare(const RPCMuonExtraStruct &a, const RPCMuonExtraStruct &b)
Definition: MuonsGrabber.h:48
void startNewEvent(int event, int bx)
RPCBasicTrigConfig * m_trigConfig
Definition: MuonsGrabber.h:76
XStr(const char *const toTranscode)
Definition: MuonsGrabber.cc:29
XERCES_CPP_NAMESPACE::DOMElement * m_rootElem
Definition: MuonsGrabber.h:82
const int mu
Definition: Constants.h:22
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
XERCES_CPP_NAMESPACE::DOMDocument * m_doc
Definition: MuonsGrabber.h:81
std::vector< RPCMuonExtraStruct > m_muons
Definition: MuonsGrabber.h:75
XERCES_CPP_NAMESPACE::DOMElement * m_currEvent
Definition: MuonsGrabber.h:83
void addMuon(RPCTBMuon &mu, int lvl, int region, int hs, int index)
virtual int getTBNum(const RPCConst::l1RpcConeCrdnts &coneCrdnts)
Returns the index of TB (in TC) that should run given LogCone.
virtual int getTCNum(const RPCConst::l1RpcConeCrdnts &coneCrdnts)
Returns the index of TC that should run given LogCone.
virtual ~MuonsGrabber()
tuple level
Definition: testEve_cfg.py:34
int m_currentEvent
Definition: MuonsGrabber.h:78
void writeDataForRelativeBX(int bx)