CMS 3D CMS Logo

L1O2OTestAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1O2OTestAnalyzer
4 // Class: L1O2OTestAnalyzer
5 //
13 //
14 // Original Author: Werner Man-Li Sun
15 // Created: Thu Nov 6 23:00:43 CET 2008
16 //
17 //
18 
19 // system include files
20 #include <iostream>
21 #include <memory>
22 #include <sstream>
23 
24 // user include files
27 
32 
34 
39 
42 
43 //
44 // class decleration
45 //
46 
48 public:
49  explicit L1O2OTestAnalyzer(const edm::ParameterSet&);
50  ~L1O2OTestAnalyzer() override;
51 
52 private:
53  void beginJob() override;
54  void analyze(const edm::Event&, const edm::EventSetup&) override;
55  void endJob() override;
56 
57  // ----------member data ---------------------------
62  std::vector<std::string> m_recordsToPrint;
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77  : m_printL1TriggerKey(iConfig.getParameter<bool>("printL1TriggerKey")),
78  m_printL1TriggerKeyList(iConfig.getParameter<bool>("printL1TriggerKeyList")),
79  m_printESRecords(iConfig.getParameter<bool>("printESRecords")),
80  m_printPayloadTokens(iConfig.getParameter<bool>("printPayloadTokens")),
81  m_recordsToPrint(iConfig.getParameter<std::vector<std::string> >("recordsToPrint")) {
82  //now do what ever initialization is needed
83 }
84 
86  // do anything here that needs to be done at desctruction time
87  // (e.g. close files, deallocate resources etc.)
88 }
89 
90 //
91 // member functions
92 //
93 
94 // ------------ method called to for each event ------------
96  using namespace edm;
97 
99  // ESHandle< L1TriggerKeyList > pList ;
100  // iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
101  L1TriggerKeyList pList;
102  l1t::DataWriter dataWriter;
103  if (!dataWriter.fillLastTriggerKeyList(pList)) {
104  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
105  }
106 
107  std::cout << "Found " << pList.tscKeyToTokenMap().size() << " TSC keys:" << std::endl;
108 
109  L1TriggerKeyList::KeyToToken::const_iterator iTSCKey = pList.tscKeyToTokenMap().begin();
110  L1TriggerKeyList::KeyToToken::const_iterator eTSCKey = pList.tscKeyToTokenMap().end();
111  for (; iTSCKey != eTSCKey; ++iTSCKey) {
112  std::cout << iTSCKey->first;
113  if (m_printPayloadTokens) {
114  std::cout << " " << iTSCKey->second;
115  }
116  std::cout << std::endl;
117  }
118  std::cout << std::endl;
119 
120  L1TriggerKeyList::RecordToKeyToToken::const_iterator iRec = pList.recordTypeToKeyToTokenMap().begin();
121  L1TriggerKeyList::RecordToKeyToToken::const_iterator eRec = pList.recordTypeToKeyToTokenMap().end();
122  for (; iRec != eRec; ++iRec) {
123  const L1TriggerKeyList::KeyToToken& keyTokenMap = iRec->second;
124  std::cout << "For record@type " << iRec->first << ", found " << keyTokenMap.size() << " keys:" << std::endl;
125 
126  L1TriggerKeyList::KeyToToken::const_iterator iKey = keyTokenMap.begin();
127  L1TriggerKeyList::KeyToToken::const_iterator eKey = keyTokenMap.end();
128  for (; iKey != eKey; ++iKey) {
129  std::cout << iKey->first;
130  if (m_printPayloadTokens) {
131  std::cout << " " << iKey->second;
132  }
133  std::cout << std::endl;
134  }
135  std::cout << std::endl;
136  }
137  }
138 
139  if (m_printL1TriggerKey) {
140  try {
142  iSetup.get<L1TriggerKeyRcd>().get(pKey);
143 
144  std::cout << std::endl;
145  std::cout << "Current TSC key = " << pKey->tscKey() << std::endl << std::endl;
146 
147  std::cout << "Current subsystem keys:" << std::endl;
148  std::cout << "CSCTF " << pKey->subsystemKey(L1TriggerKey::kCSCTF) << std::endl;
149  std::cout << "DTTF " << pKey->subsystemKey(L1TriggerKey::kDTTF) << std::endl;
150  std::cout << "RPC " << pKey->subsystemKey(L1TriggerKey::kRPC) << std::endl;
151  std::cout << "GMT " << pKey->subsystemKey(L1TriggerKey::kGMT) << std::endl;
152  std::cout << "RCT " << pKey->subsystemKey(L1TriggerKey::kRCT) << std::endl;
153  std::cout << "GCT " << pKey->subsystemKey(L1TriggerKey::kGCT) << std::endl;
154  std::cout << "GT " << pKey->subsystemKey(L1TriggerKey::kGT) << std::endl;
155  std::cout << "TSP0 " << pKey->subsystemKey(L1TriggerKey::kTSP0) << std::endl << std::endl;
156 
157  std::cout << "Object keys:" << std::endl;
158  const L1TriggerKey::RecordToKey& recKeyMap = pKey->recordToKeyMap();
159  L1TriggerKey::RecordToKey::const_iterator iRec = recKeyMap.begin();
160  L1TriggerKey::RecordToKey::const_iterator eRec = recKeyMap.end();
161  for (; iRec != eRec; ++iRec) {
162  std::cout << iRec->first << " " << iRec->second << std::endl;
163  }
164  } catch (cms::Exception& ex) {
165  std::cout << "No L1TriggerKey found." << std::endl;
166  }
167  }
168 
169  if (m_printESRecords) {
170  // ESHandle< L1TriggerKeyList > pList ;
171  // iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
172 
173  L1TriggerKeyList pList;
174  l1t::DataWriter dataWriter;
175  if (!dataWriter.fillLastTriggerKeyList(pList)) {
176  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
177  }
178 
179  // Start log string, convert run number into string
180  unsigned long long run = iEvent.id().run();
181  std::stringstream ss;
182  ss << run;
183  std::string log = "runNumber=" + ss.str();
184 
186 
187  std::cout << std::endl << "Run Settings keys:" << std::endl;
188 
189  std::vector<std::string>::const_iterator iRec = m_recordsToPrint.begin();
190  std::vector<std::string>::const_iterator iEnd = m_recordsToPrint.end();
191  for (; iRec != iEnd; ++iRec) {
192  std::string payloadToken = writer.payloadToken(*iRec, iEvent.id().run());
194 
195  if (*iRec == "L1TriggerKeyRcd") {
196  key = pList.tscKey(payloadToken);
197  } else {
198  key = pList.objectKey(*iRec, payloadToken);
199  }
200 
201  std::cout << *iRec << " " << key;
202  if (m_printPayloadTokens) {
203  std::cout << " " << payloadToken;
204  }
205  std::cout << std::endl;
206 
207  // Replace spaces in key with ?s. Do reverse substitution when
208  // making L1TriggerKey.
209  replace(key.begin(), key.end(), ' ', '?');
210  log += " " + *iRec + "Key=" + key;
211  }
212 
213  std::cout << std::endl << log << std::endl;
214  }
215 }
216 
217 // ------------ method called once each job just before starting event loop ------------
219 
220 // ------------ method called once each job just after ending the event loop ------------
222 
223 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
std::map< std::string, std::string > RecordToKey
Definition: L1TriggerKey.h:25
~L1O2OTestAnalyzer() override
def replace(string, replacements)
std::map< std::string, std::string > KeyToToken
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:113
std::string tscKey(const std::string &triggerKeyPayloadToken) const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginJob() override
const RecordToKey & recordToKeyMap() const
Definition: L1TriggerKey.h:76
std::vector< std::string > m_recordsToPrint
const RecordToKeyToToken & recordTypeToKeyToTokenMap() const
std::string objectKey(const std::string &recordName, const std::string &payloadToken) const
void analyze(const edm::Event &, const edm::EventSetup &) override
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:147
const KeyToToken & tscKeyToTokenMap() const
const std::string & tscKey() const
Definition: L1TriggerKey.h:69
void endJob() override
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
T get() const
Definition: EventSetup.h:73
L1O2OTestAnalyzer(const edm::ParameterSet &)
const std::string & subsystemKey(L1Subsystems subsystem) const
Definition: L1TriggerKey.h:71