CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondTools/L1Trigger/plugins/L1O2OTestAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    L1O2OTestAnalyzer
00004 // Class:      L1O2OTestAnalyzer
00005 // 
00013 //
00014 // Original Author:  Werner Man-Li Sun
00015 //         Created:  Thu Nov  6 23:00:43 CET 2008
00016 // $Id: L1O2OTestAnalyzer.cc,v 1.7 2010/02/16 21:59:24 wsun Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <sstream>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 #include "FWCore/Framework/interface/EventSetup.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 
00036 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
00037 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
00038 #include "CondFormats/DataRecord/interface/L1TriggerKeyRcd.h"
00039 #include "CondFormats/DataRecord/interface/L1TriggerKeyListRcd.h"
00040 
00041 #include "CondTools/L1Trigger/interface/Exception.h"
00042 #include "CondTools/L1Trigger/interface/DataWriter.h"
00043 
00044 //
00045 // class decleration
00046 //
00047 
00048 class L1O2OTestAnalyzer : public edm::EDAnalyzer {
00049    public:
00050       explicit L1O2OTestAnalyzer(const edm::ParameterSet&);
00051       ~L1O2OTestAnalyzer();
00052 
00053 
00054    private:
00055       virtual void beginJob() ;
00056       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00057       virtual void endJob() ;
00058 
00059       // ----------member data ---------------------------
00060   bool m_printL1TriggerKey ;
00061   bool m_printL1TriggerKeyList ;
00062   bool m_printESRecords ;
00063   bool m_printPayloadTokens ;
00064   std::vector< std::string > m_recordsToPrint ;
00065 };
00066 
00067 //
00068 // constants, enums and typedefs
00069 //
00070 
00071 //
00072 // static data member definitions
00073 //
00074 
00075 //
00076 // constructors and destructor
00077 //
00078 L1O2OTestAnalyzer::L1O2OTestAnalyzer(const edm::ParameterSet& iConfig)
00079   : m_printL1TriggerKey( iConfig.getParameter<bool> ("printL1TriggerKey") ),
00080     m_printL1TriggerKeyList( iConfig.getParameter<bool> ("printL1TriggerKeyList") ),
00081     m_printESRecords( iConfig.getParameter<bool> ("printESRecords") ),
00082     m_printPayloadTokens( iConfig.getParameter<bool> ("printPayloadTokens") ),
00083     m_recordsToPrint( iConfig.getParameter< std::vector< std::string > >(
00084        "recordsToPrint" ) )
00085 {
00086    //now do what ever initialization is needed
00087 }
00088 
00089 
00090 L1O2OTestAnalyzer::~L1O2OTestAnalyzer()
00091 {
00092  
00093    // do anything here that needs to be done at desctruction time
00094    // (e.g. close files, deallocate resources etc.)
00095 
00096 }
00097 
00098 
00099 //
00100 // member functions
00101 //
00102 
00103 // ------------ method called to for each event  ------------
00104 void
00105 L1O2OTestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00106 {
00107    using namespace edm;
00108 
00109    if( m_printL1TriggerKeyList )
00110      {
00111 //        ESHandle< L1TriggerKeyList > pList ;
00112 //        iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
00113        L1TriggerKeyList pList ;
00114        l1t::DataWriter dataWriter ;
00115        if( !dataWriter.fillLastTriggerKeyList( pList ) )
00116          {
00117            edm::LogError( "L1-O2O" )
00118              << "Problem getting last L1TriggerKeyList" ;
00119          }
00120 
00121        std::cout << "Found " << pList.tscKeyToTokenMap().size() << " TSC keys:"
00122                  << std::endl ;
00123 
00124        L1TriggerKeyList::KeyToToken::const_iterator iTSCKey =
00125          pList.tscKeyToTokenMap().begin() ;
00126        L1TriggerKeyList::KeyToToken::const_iterator eTSCKey =
00127          pList.tscKeyToTokenMap().end() ;
00128        for( ; iTSCKey != eTSCKey ; ++iTSCKey )
00129          {
00130            std::cout << iTSCKey->first ;
00131            if( m_printPayloadTokens )
00132              {
00133                std::cout << " " << iTSCKey->second ;
00134              }
00135            std::cout << std::endl ;
00136          }
00137        std::cout << std::endl ;
00138 
00139        L1TriggerKeyList::RecordToKeyToToken::const_iterator iRec =
00140          pList.recordTypeToKeyToTokenMap().begin() ;
00141        L1TriggerKeyList::RecordToKeyToToken::const_iterator eRec =
00142          pList.recordTypeToKeyToTokenMap().end() ;
00143        for( ; iRec != eRec ; ++iRec )
00144          {
00145            const L1TriggerKeyList::KeyToToken& keyTokenMap = iRec->second ;
00146            std::cout << "For record@type " << iRec->first << ", found "
00147                      << keyTokenMap.size() << " keys:" << std::endl ;
00148 
00149            L1TriggerKeyList::KeyToToken::const_iterator iKey = keyTokenMap.begin();
00150            L1TriggerKeyList::KeyToToken::const_iterator eKey = keyTokenMap.end() ;
00151            for( ; iKey != eKey ; ++iKey )
00152              {
00153                std::cout << iKey->first ;
00154                if( m_printPayloadTokens )
00155                  {
00156                    std::cout << " " << iKey->second ;
00157                  }
00158                std::cout << std::endl ;
00159              }
00160            std::cout << std::endl ;
00161          }
00162      }
00163 
00164    if( m_printL1TriggerKey )
00165      {
00166        try
00167          {
00168            ESHandle< L1TriggerKey > pKey ;
00169            iSetup.get< L1TriggerKeyRcd >().get( pKey ) ;
00170 
00171            std::cout << std::endl ;
00172            std::cout << "Current TSC key = " << pKey->tscKey()
00173                      << std::endl << std::endl ;
00174 
00175            std::cout << "Current subsystem keys:" << std::endl ;
00176            std::cout << "CSCTF " << pKey->subsystemKey( L1TriggerKey::kCSCTF )
00177                      << std::endl ;
00178            std::cout << "DTTF " << pKey->subsystemKey( L1TriggerKey::kDTTF )
00179                      << std::endl ;
00180            std::cout << "RPC " << pKey->subsystemKey( L1TriggerKey::kRPC )
00181                      << std::endl ;
00182            std::cout << "GMT " << pKey->subsystemKey( L1TriggerKey::kGMT )
00183                      << std::endl ;
00184            std::cout << "RCT " << pKey->subsystemKey( L1TriggerKey::kRCT )
00185                      << std::endl ;
00186            std::cout << "GCT " << pKey->subsystemKey( L1TriggerKey::kGCT )
00187                      << std::endl ;
00188            std::cout << "GT " << pKey->subsystemKey( L1TriggerKey::kGT )
00189                      << std::endl ;
00190            std::cout << "TSP0 " << pKey->subsystemKey( L1TriggerKey::kTSP0 )
00191                      << std::endl << std::endl ;
00192 
00193            std::cout << "Object keys:" << std::endl ;
00194            const L1TriggerKey::RecordToKey& recKeyMap = pKey->recordToKeyMap() ;
00195            L1TriggerKey::RecordToKey::const_iterator iRec = recKeyMap.begin() ;
00196            L1TriggerKey::RecordToKey::const_iterator eRec = recKeyMap.end() ;
00197            for( ; iRec != eRec ; ++iRec )
00198              {
00199                std::cout << iRec->first << " " << iRec->second << std::endl ;
00200              }
00201          }
00202        catch( cms::Exception& ex )
00203          {
00204            std::cout << "No L1TriggerKey found." << std::endl ;
00205          }
00206      }
00207 
00208    if( m_printESRecords )
00209      {
00210 //        ESHandle< L1TriggerKeyList > pList ;
00211 //        iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
00212 
00213        L1TriggerKeyList pList ;
00214        l1t::DataWriter dataWriter ;
00215        if( !dataWriter.fillLastTriggerKeyList( pList ) )
00216          {
00217            edm::LogError( "L1-O2O" )
00218              << "Problem getting last L1TriggerKeyList" ;
00219          }
00220 
00221        // Start log string, convert run number into string
00222        unsigned long long run = iEvent.id().run() ;
00223        std::stringstream ss ;
00224        ss << run ;
00225        std::string log = "runNumber=" + ss.str() ;
00226 
00227        l1t::DataWriter writer ;
00228 
00229        std::cout << std::endl << "Run Settings keys:" << std::endl ;
00230 
00231        std::vector< std::string >::const_iterator iRec =
00232          m_recordsToPrint.begin() ;
00233        std::vector< std::string >::const_iterator iEnd =
00234          m_recordsToPrint.end() ;
00235        for( ; iRec != iEnd ; ++iRec )
00236          {
00237            std::string payloadToken = writer.payloadToken( *iRec,
00238                                                            iEvent.id().run() );
00239            std::string key ;
00240 
00241            if( *iRec == "L1TriggerKeyRcd" )
00242              {
00243                key = pList.tscKey( payloadToken ) ;
00244              }
00245            else
00246              {
00247                key = pList.objectKey( *iRec, payloadToken ) ;
00248              }
00249 
00250            std::cout << *iRec << " " << key ;
00251            if( m_printPayloadTokens )
00252              {
00253                std::cout << " " << payloadToken ;
00254              }
00255            std::cout << std::endl ;
00256 
00257            // Replace spaces in key with ?s.  Do reverse substitution when
00258            // making L1TriggerKey.
00259            replace( key.begin(), key.end(), ' ', '?' ) ;
00260            log += " " + *iRec + "Key=" + key ;
00261          }
00262 
00263        std::cout << std::endl << log << std::endl ;
00264      }
00265 }
00266 
00267 
00268 // ------------ method called once each job just before starting event loop  ------------
00269 void 
00270 L1O2OTestAnalyzer::beginJob()
00271 {
00272 }
00273 
00274 // ------------ method called once each job just after ending the event loop  ------------
00275 void 
00276 L1O2OTestAnalyzer::endJob() {
00277 }
00278 
00279 //define this as a plug-in
00280 DEFINE_FWK_MODULE(L1O2OTestAnalyzer);