CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/CondTools/L1Trigger/plugins/L1CondDBPayloadWriter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    L1CondDBPayloadWriter
00004 // Class:      L1CondDBPayloadWriter
00005 // 
00013 //
00014 // Original Author:  Werner Man-Li Sun
00015 //         Created:  Sun Mar  2 07:05:15 CET 2008
00016 // $Id: L1CondDBPayloadWriter.cc,v 1.18 2010/02/16 21:59:24 wsun Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 
00023 // user include files
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 
00026 #include "CondTools/L1Trigger/plugins/L1CondDBPayloadWriter.h"
00027 
00028 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
00029 #include "CondFormats/DataRecord/interface/L1TriggerKeyRcd.h"
00030 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
00031 #include "CondFormats/DataRecord/interface/L1TriggerKeyListRcd.h"
00032 
00033 //
00034 // class declaration
00035 //
00036 
00037 //
00038 // constants, enums and typedefs
00039 //
00040 
00041 //
00042 // static data member definitions
00043 //
00044 
00045 //
00046 // constructors and destructor
00047 //
00048 L1CondDBPayloadWriter::L1CondDBPayloadWriter(const edm::ParameterSet& iConfig)
00049    : m_writeL1TriggerKey( iConfig.getParameter< bool >( "writeL1TriggerKey" )),
00050      m_writeConfigData( iConfig.getParameter< bool >( "writeConfigData" ) ),
00051      m_overwriteKeys( iConfig.getParameter< bool >( "overwriteKeys" ) ),
00052      m_logTransactions( iConfig.getParameter<bool>( "logTransactions" ) ),
00053      m_newL1TriggerKeyList( iConfig.getParameter< bool >( "newL1TriggerKeyList" ) )
00054 {
00055    //now do what ever initialization is needed
00056 
00057 }
00058 
00059 
00060 L1CondDBPayloadWriter::~L1CondDBPayloadWriter()
00061 {
00062  
00063    // do anything here that needs to be done at desctruction time
00064    // (e.g. close files, deallocate resources etc.)
00065 
00066 }
00067 
00068 
00069 //
00070 // member functions
00071 //
00072 
00073 // ------------ method called to for each event  ------------
00074 void
00075 L1CondDBPayloadWriter::analyze(const edm::Event& iEvent,
00076                                const edm::EventSetup& iSetup)
00077 {
00078    using namespace edm;
00079 
00080    // Get L1TriggerKeyList and make a copy
00081    L1TriggerKeyList oldKeyList ;
00082 
00083    if( !m_newL1TriggerKeyList )
00084      {
00085        if( !m_writer.fillLastTriggerKeyList( oldKeyList ) )
00086          {
00087            edm::LogError( "L1-O2O" )
00088              << "Problem getting last L1TriggerKeyList" ;
00089          }
00090      }
00091 
00092    L1TriggerKeyList* keyList = 0 ;
00093 
00094    // Write L1TriggerKey to ORCON with no IOV
00095    std::string token ;
00096    ESHandle< L1TriggerKey > key ;
00097 
00098    // Before calling writePayload(), check if TSC key is already in
00099    // L1TriggerKeyList.  writePayload() will not catch this situation in
00100    // the case of dummy configurations.
00101    bool triggerKeyOK = true ;
00102    try
00103      {
00104        // Get L1TriggerKey
00105        iSetup.get< L1TriggerKeyRcd >().get( key ) ;
00106 
00107        if( !m_overwriteKeys )
00108          {
00109            triggerKeyOK = oldKeyList.token( key->tscKey() ) == "" ;
00110          }
00111      }
00112    catch( l1t::DataAlreadyPresentException& ex )
00113      {
00114        triggerKeyOK = false ;
00115        edm::LogVerbatim( "L1-O2O" ) << ex.what() ;
00116      }
00117 
00118    if( triggerKeyOK && m_writeL1TriggerKey )
00119      {
00120        edm::LogVerbatim( "L1-O2O" )
00121          << "Object key for L1TriggerKeyRcd@L1TriggerKey: "
00122          << key->tscKey() ;
00123        token = m_writer.writePayload( iSetup,
00124                                       "L1TriggerKeyRcd@L1TriggerKey" ) ;
00125      }
00126 
00127    // If L1TriggerKey is invalid, then all configuration data is already in DB
00128    bool throwException = false ;
00129 
00130    if( !token.empty() || !m_writeL1TriggerKey )
00131    {
00132       // Record token in L1TriggerKeyList
00133       if( m_writeL1TriggerKey )
00134         {
00135           keyList = new L1TriggerKeyList( oldKeyList ) ;
00136           if( !( keyList->addKey( key->tscKey(),
00137                                   token,
00138                                   m_overwriteKeys ) ) )
00139             {
00140               throw cond::Exception( "L1CondDBPayloadWriter: TSC key "
00141                                      + key->tscKey()
00142                                      + " already in L1TriggerKeyList" ) ;
00143             }
00144         }
00145 
00146       if( m_writeConfigData )
00147         {
00148           // Loop over record@type in L1TriggerKey
00149           L1TriggerKey::RecordToKey::const_iterator it =
00150             key->recordToKeyMap().begin() ;
00151           L1TriggerKey::RecordToKey::const_iterator end =
00152             key->recordToKeyMap().end() ;
00153 
00154           for( ; it != end ; ++it )
00155             {
00156               // Do nothing if object key is null.
00157               if( it->second == L1TriggerKey::kNullKey )
00158                 {
00159                   edm::LogVerbatim( "L1-O2O" )
00160                     << "L1CondDBPayloadWriter: null object key for "
00161                     << it->first << "; skipping this record." ;
00162                 }
00163               else
00164                 {
00165                   // Check key is new before writing
00166                   if( oldKeyList.token( it->first, it->second ) == "" ||
00167                       m_overwriteKeys )
00168                     {
00169                       // Write data to ORCON with no IOV
00170                       if( oldKeyList.token( it->first, it->second ) != "" )
00171                         {
00172                           edm::LogVerbatim( "L1-O2O" )
00173                             << "*** Overwriting payload: object key for "
00174                             << it->first << ": " << it->second ;
00175                         }
00176                       else
00177                         {
00178                           edm::LogVerbatim( "L1-O2O" )
00179                             << "object key for "
00180                             << it->first << ": " << it->second ;
00181                         }
00182 
00183                       try
00184                         {
00185                           token = m_writer.writePayload( iSetup, it->first ) ;
00186                         }
00187                       catch( l1t::DataInvalidException& ex )
00188                         {
00189                           edm::LogVerbatim( "L1-O2O" )
00190                             << ex.what()
00191                             << " Skipping to next record." ;
00192 
00193                           throwException = true ;
00194 
00195                           continue ;
00196                         }
00197 
00198                       if( !token.empty() )
00199                         {
00200                           // Record token in L1TriggerKeyList
00201                           if( !keyList )
00202                             {
00203                               keyList = new L1TriggerKeyList( oldKeyList ) ;
00204                             }
00205 
00206                           if( !( keyList->addKey( it->first,
00207                                                   it->second,
00208                                                   token,
00209                                                   m_overwriteKeys ) ) )
00210                             {
00211                               // This should never happen because of the check
00212                               // above, but just in case....
00213                               throw cond::Exception(
00214                                 "L1CondDBPayloadWriter: subsystem key "
00215                                 + it->second + " for " + it->first
00216                                 + " already in L1TriggerKeyList" ) ;
00217                             }
00218                         }
00219                     }
00220                   else
00221                     {
00222                       edm::LogVerbatim( "L1-O2O" )
00223                         << "L1CondDBPayloadWriter: object key "
00224                         << it->second << " for " << it->first
00225                         << " already in L1TriggerKeyList" ;
00226                     }
00227                 }
00228             }
00229         }
00230    }
00231 
00232    if( keyList )
00233    {
00234       // Write L1TriggerKeyList to ORCON
00235       m_writer.writeKeyList( keyList, 0, m_logTransactions ) ;
00236    }
00237 
00238    if( throwException )
00239      {
00240        throw l1t::DataInvalidException( "Payload problem found." ) ;
00241      }
00242 }
00243 
00244 
00245 // ------------ method called once each job just before starting event loop  ------------
00246 void 
00247 L1CondDBPayloadWriter::beginJob()
00248 {
00249 }
00250 
00251 // ------------ method called once each job just after ending the event loop  ------------
00252 void 
00253 L1CondDBPayloadWriter::endJob() {
00254 }
00255 
00256 //define this as a plug-in
00257 //DEFINE_FWK_MODULE(L1CondDBPayloadWriter);