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