CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes

L1ConfigOnlineProdBase< TRcd, TData > Class Template Reference

#include <CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h>

Inheritance diagram for L1ConfigOnlineProdBase< TRcd, TData >:
edm::ESProducer edm::ESProxyFactoryProducer edm::eventsetup::DataProxyProvider

List of all members.

Public Member Functions

 L1ConfigOnlineProdBase (const edm::ParameterSet &)
virtual boost::shared_ptr< TData > newObject (const std::string &objectKey)=0
boost::shared_ptr< TData > produce (const TRcd &iRecord)
 ~L1ConfigOnlineProdBase ()

Protected Member Functions

bool getObjectKey (const TRcd &record, boost::shared_ptr< TData > data, std::string &objectKey)

Protected Attributes

bool m_copyFromCondDB
cond::DbConnection m_dbConnection
cond::DbSession m_dbSession
bool m_forceGeneration
l1t::OMDSReader m_omdsReader

Detailed Description

template<class TRcd, class TData>
class L1ConfigOnlineProdBase< TRcd, TData >

Description: Abstract templated base class for producers that reads OMDS to retrieve configuration data for a given key and generates the corresponding C++ objects.

Usage: <usage>

Definition at line 54 of file L1ConfigOnlineProdBase.h.


Constructor & Destructor Documentation

template<class TRcd , class TData >
L1ConfigOnlineProdBase< TRcd, TData >::L1ConfigOnlineProdBase ( const edm::ParameterSet iConfig)

Definition at line 87 of file L1ConfigOnlineProdBase.h.

References cond::DbConnection::configuration(), cond::DbConnection::configure(), l1t::OMDSReader::connect(), cond::DbConnection::createSession(), edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), L1ConfigOnlineProdBase< TRcd, TData >::m_copyFromCondDB, L1ConfigOnlineProdBase< TRcd, TData >::m_dbConnection, L1ConfigOnlineProdBase< TRcd, TData >::m_dbSession, L1ConfigOnlineProdBase< TRcd, TData >::m_omdsReader, cond::DbSession::open(), and edm::ESProducer::setWhatProduced().

   : m_omdsReader(),
     m_forceGeneration( iConfig.getParameter< bool >( "forceGeneration" ) ),
     m_dbConnection(),
     m_dbSession(),
     m_copyFromCondDB( false )
{
   //the following line is needed to tell the framework what
   // data is being produced
  setWhatProduced(this);

   //now do what ever other initialization is needed

  if( iConfig.exists( "copyFromCondDB" ) )
    {
      m_copyFromCondDB = iConfig.getParameter< bool >( "copyFromCondDB" ) ;

      if( m_copyFromCondDB )
        {
          // Connect DbSession
          m_dbConnection.configuration().setAuthenticationPath(
             iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
          m_dbConnection.configure() ;
          m_dbSession = m_dbConnection.createSession() ;
          m_dbSession.open(
                           iConfig.getParameter< std::string >( "onlineDB" ),
                           true ); // read-only
        }
    }
  else
    {
      m_omdsReader.connect(
        iConfig.getParameter< std::string >( "onlineDB" ),
        iConfig.getParameter< std::string >( "onlineAuthentication" ) ) ;
    }
}
template<class TRcd , class TData >
L1ConfigOnlineProdBase< TRcd, TData >::~L1ConfigOnlineProdBase ( )

Definition at line 125 of file L1ConfigOnlineProdBase.h.

{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)

}

Member Function Documentation

template<class TRcd, class TData>
bool L1ConfigOnlineProdBase< TRcd, TData >::getObjectKey ( const TRcd &  record,
boost::shared_ptr< TData >  data,
std::string &  objectKey 
) [protected]

Definition at line 204 of file L1ConfigOnlineProdBase.h.

References dtT0WireCalibration_cfg::dataType, funct::false, l1t::DataWriter::fillLastTriggerKeyList(), edm::eventsetup::EventSetupRecord::get(), combine::key, ecalTPGAnalyzer_cfg::recordName, and L1TriggerKeyList::token().

{
   // Get L1TriggerKey
   const L1TriggerKeyRcd& keyRcd =
      record.template getRecord< L1TriggerKeyRcd >() ;

   // Explanation of funny syntax: since record is dependent, we are not
   // expecting getRecord to be a template so the compiler parses it
   // as a non-template. https://gcc.gnu.org/ml/gcc-bugs/2005-11/msg03685.html

   // If L1TriggerKey is invalid, then all configuration objects are
   // already in ORCON.
   edm::ESHandle< L1TriggerKey > key ;
   try
   {
      keyRcd.get( key ) ;
   }
   catch( l1t::DataAlreadyPresentException& ex )
   {
      objectKey = std::string() ;
      return false ;      
   }

   // Get object key from L1TriggerKey
   std::string recordName = edm::typelookup::className<TRcd>();
   std::string dataType = edm::typelookup::className<TData>();

   objectKey = key->get( recordName, dataType ) ;

/*    edm::LogVerbatim( "L1-O2O" ) */
/*      << "L1ConfigOnlineProdBase record " << recordName */
/*      << " type " << dataType << " obj key " << objectKey ; */

   // Get L1TriggerKeyList
   L1TriggerKeyList keyList ;
   l1t::DataWriter dataWriter ;
   if( !dataWriter.fillLastTriggerKeyList( keyList ) )
     {
       edm::LogError( "L1-O2O" )
         << "Problem getting last L1TriggerKeyList" ;
     }

   // If L1TriggerKeyList does not contain object key, token is empty
   return
      keyList.token( recordName, dataType, objectKey ) == std::string() ;
}
template<class TRcd, class TData>
virtual boost::shared_ptr< TData > L1ConfigOnlineProdBase< TRcd, TData >::newObject ( const std::string &  objectKey) [pure virtual]
template<class TRcd, class TData >
boost::shared_ptr< TData > L1ConfigOnlineProdBase< TRcd, TData >::produce ( const TRcd &  iRecord)

Definition at line 135 of file L1ConfigOnlineProdBase.h.

References cond::DbScopedTransaction::commit(), dtT0WireCalibration_cfg::dataType, edm::eventsetup::EventSetupRecord::get(), combine::key, ecalTPGAnalyzer_cfg::recordName, and cond::DbScopedTransaction::start().

{
   using namespace edm::es;
   boost::shared_ptr< TData > pData ;

   // Get object key and check if already in ORCON
   std::string key ;
   if( getObjectKey( iRecord, pData, key ) || m_forceGeneration )
   {
     if( m_copyFromCondDB )
       {
         // Get L1TriggerKeyList from EventSetup
         const L1TriggerKeyListRcd& keyListRcd =
           iRecord.template getRecord< L1TriggerKeyListRcd >() ;
         edm::ESHandle< L1TriggerKeyList > keyList ;
         keyListRcd.get( keyList ) ;

         // Find payload token
         std::string recordName = edm::typelookup::className<TRcd>();
         std::string dataType = edm::typelookup::className<TData>();
         std::string payloadToken =
           keyList->token( recordName, dataType, key ) ;

         edm::LogVerbatim( "L1-O2O" )
           << "Copying payload for " << recordName
           << "@" << dataType << " obj key " << key
           << " from CondDB." ;
         edm::LogVerbatim( "L1-O2O" )
           << "TOKEN " << payloadToken ;

         // Get object from POOL
         // Copied from l1t::DataWriter::readObject()
         if( !payloadToken.empty() )
           {
             cond::DbScopedTransaction tr( m_dbSession ) ;
             tr.start( true ) ; 
             pData = m_dbSession.getTypedObject<TData>( payloadToken ) ;
             tr.commit ();
           }
       }
     else
       {
         pData = newObject( key ) ;
       }

     //     if( pData.get() == 0 )
     if( pData == boost::shared_ptr< TData >() )
       {
         std::string dataType = edm::typelookup::className<TData>();

         throw l1t::DataInvalidException( "Unable to generate " +
                                          dataType + " for key " + key +
                                          "." ) ;
       }
   }
   else
   {
     std::string dataType = edm::typelookup::className<TData>();

     throw l1t::DataAlreadyPresentException( dataType +
        " for key " + key + " already in CondDB." ) ;
   }

   return pData ;
}

Member Data Documentation

template<class TRcd, class TData>
bool L1ConfigOnlineProdBase< TRcd, TData >::m_copyFromCondDB [protected]
template<class TRcd, class TData>
cond::DbConnection L1ConfigOnlineProdBase< TRcd, TData >::m_dbConnection [protected]
template<class TRcd, class TData>
cond::DbSession L1ConfigOnlineProdBase< TRcd, TData >::m_dbSession [protected]
template<class TRcd, class TData>
bool L1ConfigOnlineProdBase< TRcd, TData >::m_forceGeneration [protected]

Definition at line 69 of file L1ConfigOnlineProdBase.h.

template<class TRcd, class TData>
l1t::OMDSReader L1ConfigOnlineProdBase< TRcd, TData >::m_omdsReader [protected]