CMS 3D CMS Logo

L1O2OTestAnalyzerExt.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <sstream>
4 
7 
12 
14 
21 
24 
25 //
26 // class decleration
27 //
28 
30  public:
31  explicit L1O2OTestAnalyzerExt(const edm::ParameterSet&);
32  ~L1O2OTestAnalyzerExt() override;
33 
34 
35  private:
36  void beginJob() override ;
37  void analyze(const edm::Event&, const edm::EventSetup&) override;
38  void endJob() override ;
39 
40  // ----------member data ---------------------------
45  std::vector< std::string > m_recordsToPrint ;
46 };
47 
49  : m_printL1TriggerKeyExt( iConfig.getParameter<bool> ("printL1TriggerKeyExt") ),
50  m_printL1TriggerKeyListExt( iConfig.getParameter<bool> ("printL1TriggerKeyListExt") ),
51  m_printESRecords( iConfig.getParameter<bool> ("printESRecords") ),
52  m_printPayloadTokens( iConfig.getParameter<bool> ("printPayloadTokens") ),
53  m_recordsToPrint( iConfig.getParameter< std::vector< std::string > >(
54  "recordsToPrint" ) )
55 {
56  //now do what ever initialization is needed
57 }
58 
59 
61 {
62 
63  // do anything here that needs to be done at desctruction time
64  // (e.g. close files, deallocate resources etc.)
65 
66 }
67 
68 
69 // ------------ method called to for each event ------------
70 void
72 {
73  using namespace edm;
74 
76  {
77 // ESHandle< L1TriggerKeyListExt > pList ;
78 // iSetup.get< L1TriggerKeyListExtRcd >().get( pList ) ;
79  L1TriggerKeyListExt pList ;
80  l1t::DataWriterExt dataWriter ;
81  if( !dataWriter.fillLastTriggerKeyList( pList ) )
82  {
83  edm::LogError( "L1-O2O" )
84  << "Problem getting last L1TriggerKeyListExt" ;
85  }
86 
87  std::cout << "Found " << pList.tscKeyToTokenMap().size() << " TSC keys:"
88  << std::endl ;
89 
90  L1TriggerKeyListExt::KeyToToken::const_iterator iTSCKey =
91  pList.tscKeyToTokenMap().begin() ;
92  L1TriggerKeyListExt::KeyToToken::const_iterator eTSCKey =
93  pList.tscKeyToTokenMap().end() ;
94  for( ; iTSCKey != eTSCKey ; ++iTSCKey )
95  {
96  std::cout << iTSCKey->first ;
98  {
99  std::cout << " " << iTSCKey->second ;
100  }
101  std::cout << std::endl ;
102  }
103  std::cout << std::endl ;
104 
105  L1TriggerKeyListExt::RecordToKeyToToken::const_iterator iRec =
106  pList.recordTypeToKeyToTokenMap().begin() ;
107  L1TriggerKeyListExt::RecordToKeyToToken::const_iterator eRec =
108  pList.recordTypeToKeyToTokenMap().end() ;
109  for( ; iRec != eRec ; ++iRec )
110  {
111  const L1TriggerKeyListExt::KeyToToken& keyTokenMap = iRec->second ;
112  std::cout << "For record@type " << iRec->first << ", found "
113  << keyTokenMap.size() << " keys:" << std::endl ;
114 
115  L1TriggerKeyListExt::KeyToToken::const_iterator iKey = keyTokenMap.begin();
116  L1TriggerKeyListExt::KeyToToken::const_iterator eKey = keyTokenMap.end() ;
117  for( ; iKey != eKey ; ++iKey )
118  {
119  std::cout << iKey->first ;
121  {
122  std::cout << " " << iKey->second ;
123  }
124  std::cout << std::endl ;
125  }
126  std::cout << std::endl ;
127  }
128  }
129 
131  {
132  try
133  {
135  iSetup.get< L1TriggerKeyExtRcd >().get( pKey ) ;
136 
137  std::cout << std::endl ;
138  std::cout << "Current TSC key = " << pKey->tscKey()
139  << std::endl << std::endl ;
140 
141  std::cout << "Current subsystem keys:" << std::endl ;
142  std::cout << "TSP0 " << pKey->subsystemKey( L1TriggerKeyExt::kuGT )
143  << std::endl << std::endl ;
144 
145  std::cout << "Object keys:" << std::endl ;
146  const L1TriggerKeyExt::RecordToKey& recKeyMap = pKey->recordToKeyMap() ;
147  L1TriggerKeyExt::RecordToKey::const_iterator iRec = recKeyMap.begin() ;
148  L1TriggerKeyExt::RecordToKey::const_iterator eRec = recKeyMap.end() ;
149  for( ; iRec != eRec ; ++iRec )
150  {
151  std::cout << iRec->first << " " << iRec->second << std::endl ;
152  }
153  }
154  catch( cms::Exception& ex )
155  {
156  std::cout << "No L1TriggerKeyExt found." << std::endl ;
157  }
158  }
159 
160  if( m_printESRecords )
161  {
162 // ESHandle< L1TriggerKeyListExt > pList ;
163 // iSetup.get< L1TriggerKeyListExtRcd >().get( pList ) ;
164 
165  L1TriggerKeyListExt pList ;
166  l1t::DataWriterExt dataWriter ;
167  if( !dataWriter.fillLastTriggerKeyList( pList ) )
168  {
169  edm::LogError( "L1-O2O" )
170  << "Problem getting last L1TriggerKeyListExt" ;
171  }
172 
173  // Start log string, convert run number into string
174  unsigned long long run = iEvent.id().run() ;
175  std::stringstream ss ;
176  ss << run ;
177  std::string log = "runNumber=" + ss.str() ;
178 
180 
181  std::cout << std::endl << "Run Settings keys:" << std::endl ;
182 
183  std::vector< std::string >::const_iterator iRec =
184  m_recordsToPrint.begin() ;
185  std::vector< std::string >::const_iterator iEnd =
186  m_recordsToPrint.end() ;
187  for( ; iRec != iEnd ; ++iRec )
188  {
189  std::string payloadToken = writer.payloadToken( *iRec,
190  iEvent.id().run() );
191  std::string key ;
192 
193  if( *iRec == "L1TriggerKeyExtRcd" )
194  {
195  key = pList.tscKey( payloadToken ) ;
196  }
197  else
198  {
199  key = pList.objectKey( *iRec, payloadToken ) ;
200  }
201 
202  std::cout << *iRec << " " << key ;
204  {
205  std::cout << " " << payloadToken ;
206  }
207  std::cout << std::endl ;
208 
209  // Replace spaces in key with ?s. Do reverse substitution when
210  // making L1TriggerKeyExt.
211  replace( key.begin(), key.end(), ' ', '?' ) ;
212  log += " " + *iRec + "Key=" + key ;
213  }
214 
215  std::cout << std::endl << log << std::endl ;
216  }
217 }
218 
219 
220 // ------------ method called once each job just before starting event loop ------------
221 void
223 {
224 }
225 
226 // ------------ method called once each job just after ending the event loop ------------
227 void
229 }
230 
231 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
def replace(string, replacements)
const KeyToToken & tscKeyToTokenMap() const
L1O2OTestAnalyzerExt(const edm::ParameterSet &)
const RecordToKey & recordToKeyMap() const
std::map< std::string, std::string > KeyToToken
int iEvent
Definition: GenABIO.cc:230
const std::string & subsystemKey(L1Subsystems subsystem) const
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
std::string tscKey(const std::string &triggerKeyPayloadToken) const
std::map< std::string, std::string > RecordToKey
std::vector< std::string > m_recordsToPrint
std::string objectKey(const std::string &recordName, const std::string &payloadToken) const
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
T get() const
Definition: EventSetup.h:62
const RecordToKeyToToken & recordTypeToKeyToTokenMap() const
const std::string & tscKey() const