CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <memory>
21 #include <sstream>
22 
23 // user include files
26 
31 
33 
38 
41 
42 //
43 // class decleration
44 //
45 
47 public:
48  explicit L1O2OTestAnalyzer(const edm::ParameterSet&);
49  ~L1O2OTestAnalyzer() override;
50 
51 private:
52  void beginJob() override;
53  void analyze(const edm::Event&, const edm::EventSetup&) override;
54  void endJob() override;
55 
56  // ----------member data ---------------------------
61  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
84 }
85 
87  // do anything here that needs to be done at desctruction time
88  // (e.g. close files, deallocate resources etc.)
89 }
90 
91 //
92 // member functions
93 //
94 
95 // ------------ method called to for each event ------------
97  using namespace edm;
98 
100  // ESHandle< L1TriggerKeyList > pList ;
101  // iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
102  L1TriggerKeyList pList;
103  l1t::DataWriter dataWriter;
104  if (!dataWriter.fillLastTriggerKeyList(pList)) {
105  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
106  }
107 
108  edm::LogInfo("L1-O2O") << "Found " << pList.tscKeyToTokenMap().size() << " TSC keys:" << std::endl;
109 
110  L1TriggerKeyList::KeyToToken::const_iterator iTSCKey = pList.tscKeyToTokenMap().begin();
111  L1TriggerKeyList::KeyToToken::const_iterator eTSCKey = pList.tscKeyToTokenMap().end();
112  for (; iTSCKey != eTSCKey; ++iTSCKey) {
113  edm::LogInfo("L1-O2O") << iTSCKey->first;
114  if (m_printPayloadTokens) {
115  edm::LogInfo("L1-O2O") << " " << iTSCKey->second;
116  }
117  edm::LogInfo("L1-O2O") << std::endl;
118  }
119  edm::LogInfo("L1-O2O") << std::endl;
120 
121  L1TriggerKeyList::RecordToKeyToToken::const_iterator iRec = pList.recordTypeToKeyToTokenMap().begin();
122  L1TriggerKeyList::RecordToKeyToToken::const_iterator eRec = pList.recordTypeToKeyToTokenMap().end();
123  for (; iRec != eRec; ++iRec) {
124  const L1TriggerKeyList::KeyToToken& keyTokenMap = iRec->second;
125  edm::LogInfo("L1-O2O") << "For record@type " << iRec->first << ", found " << keyTokenMap.size()
126  << " keys:" << std::endl;
127 
128  L1TriggerKeyList::KeyToToken::const_iterator iKey = keyTokenMap.begin();
129  L1TriggerKeyList::KeyToToken::const_iterator eKey = keyTokenMap.end();
130  for (; iKey != eKey; ++iKey) {
131  edm::LogInfo("L1-O2O") << iKey->first;
132  if (m_printPayloadTokens) {
133  edm::LogInfo("L1-O2O") << " " << iKey->second;
134  }
135  edm::LogInfo("L1-O2O") << std::endl;
136  }
137  edm::LogInfo("L1-O2O") << std::endl;
138  }
139  }
140 
141  if (m_printL1TriggerKey) {
142  try {
143  auto pKey = iSetup.getHandle(l1TriggerKeyToken_);
144 
145  edm::LogInfo("L1-O2O") << std::endl;
146  edm::LogInfo("L1-O2O") << "Current TSC key = " << pKey->tscKey() << std::endl << std::endl;
147 
148  edm::LogInfo("L1-O2O") << "Current subsystem keys:" << std::endl;
149  edm::LogInfo("L1-O2O") << "CSCTF " << pKey->subsystemKey(L1TriggerKey::kCSCTF) << std::endl;
150  edm::LogInfo("L1-O2O") << "DTTF " << pKey->subsystemKey(L1TriggerKey::kDTTF) << std::endl;
151  edm::LogInfo("L1-O2O") << "RPC " << pKey->subsystemKey(L1TriggerKey::kRPC) << std::endl;
152  edm::LogInfo("L1-O2O") << "GMT " << pKey->subsystemKey(L1TriggerKey::kGMT) << std::endl;
153  edm::LogInfo("L1-O2O") << "RCT " << pKey->subsystemKey(L1TriggerKey::kRCT) << std::endl;
154  edm::LogInfo("L1-O2O") << "GCT " << pKey->subsystemKey(L1TriggerKey::kGCT) << std::endl;
155  edm::LogInfo("L1-O2O") << "GT " << pKey->subsystemKey(L1TriggerKey::kGT) << std::endl;
156  edm::LogInfo("L1-O2O") << "TSP0 " << pKey->subsystemKey(L1TriggerKey::kTSP0) << std::endl << std::endl;
157 
158  edm::LogInfo("L1-O2O") << "Object keys:" << std::endl;
159  const L1TriggerKey::RecordToKey& recKeyMap = pKey->recordToKeyMap();
160  L1TriggerKey::RecordToKey::const_iterator iRec = recKeyMap.begin();
161  L1TriggerKey::RecordToKey::const_iterator eRec = recKeyMap.end();
162  for (; iRec != eRec; ++iRec) {
163  edm::LogInfo("L1-O2O") << iRec->first << " " << iRec->second << std::endl;
164  }
165  } catch (cms::Exception& ex) {
166  edm::LogError("L1-O2O") << "No L1TriggerKey found." << std::endl;
167  }
168  }
169 
170  if (m_printESRecords) {
171  // ESHandle< L1TriggerKeyList > pList ;
172  // iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
173 
174  L1TriggerKeyList pList;
175  l1t::DataWriter dataWriter;
176  if (!dataWriter.fillLastTriggerKeyList(pList)) {
177  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
178  }
179 
180  // Start log string, convert run number into string
181  unsigned long long run = iEvent.id().run();
182  std::stringstream ss;
183  ss << run;
184  std::string log = "runNumber=" + ss.str();
185 
186  l1t::DataWriter writer;
187 
188  edm::LogInfo("L1-O2O") << std::endl << "Run Settings keys:" << std::endl;
189 
190  std::vector<std::string>::const_iterator iRec = m_recordsToPrint.begin();
191  std::vector<std::string>::const_iterator iEnd = m_recordsToPrint.end();
192  for (; iRec != iEnd; ++iRec) {
193  std::string payloadToken = writer.payloadToken(*iRec, iEvent.id().run());
195 
196  if (*iRec == "L1TriggerKeyRcd") {
197  key = pList.tscKey(payloadToken);
198  } else {
199  key = pList.objectKey(*iRec, payloadToken);
200  }
201 
202  edm::LogInfo("L1-O2O") << *iRec << " " << key;
203  if (m_printPayloadTokens) {
204  edm::LogInfo("L1-O2O") << " " << payloadToken;
205  }
206  edm::LogInfo("L1-O2O") << std::endl;
207 
208  // Replace spaces in key with ?s. Do reverse substitution when
209  // making L1TriggerKey.
210  replace(key.begin(), key.end(), ' ', '?');
211  log += " " + *iRec + "Key=" + key;
212  }
213 
214  edm::LogInfo("L1-O2O") << std::endl << log << std::endl;
215  }
216 }
217 
218 // ------------ method called once each job just before starting event loop ------------
220 
221 // ------------ method called once each job just after ending the event loop ------------
223 
224 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
static std::vector< std::string > checklist log
std::map< std::string, std::string > RecordToKey
Definition: L1TriggerKey.h:25
~L1O2OTestAnalyzer() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< std::string, std::string > KeyToToken
Log< level::Error, false > LogError
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
void beginJob() override
tuple key
prepare the HTCondor submission files and eventually submit them
std::vector< std::string > m_recordsToPrint
edm::ESGetToken< L1TriggerKey, L1TriggerKeyRcd > l1TriggerKeyToken_
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
Log< level::Info, false > LogInfo
const KeyToToken & tscKeyToTokenMap() const
void endJob() override
edm::EventID id() const
Definition: EventBase.h:59
L1O2OTestAnalyzer(const edm::ParameterSet &)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157