CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SiStripPayloadHandler< SiStripPayload > Class Template Reference
Inheritance diagram for SiStripPayloadHandler< SiStripPayload >:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

virtual void analyze (const edm::Event &evt, const edm::EventSetup &evtSetup)
 
virtual void endJob ()
 
 SiStripPayloadHandler (const edm::ParameterSet &iConfig)
 
virtual ~SiStripPayloadHandler ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

std::string makeConfigHash ()
 
std::string queryConfigMap (std::string configHash)
 
void updateConfigMap (std::string configHash, std::string payloadHash)
 

Private Attributes

edm::Service< SiStripCondObjBuilderFromDbcondObjBuilder
 
std::string m_cfgMapDbFile
 
std::string m_condDb
 
std::string m_configMapDb
 
cond::persistency::ConnectionPool m_connectionPool
 
std::string m_localCondDbFile
 
cond::Time_t m_since
 
std::string m_targetTag
 
std::string p_cfgstr
 
std::string p_type
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

template<typename SiStripPayload>
class SiStripPayloadHandler< SiStripPayload >

Definition at line 27 of file SiStripPayloadHandler.cc.

Constructor & Destructor Documentation

template<typename SiStripPayload >
SiStripPayloadHandler< SiStripPayload >::SiStripPayloadHandler ( const edm::ParameterSet iConfig)
explicit

Definition at line 55 of file SiStripPayloadHandler.cc.

References cond::persistency::ConnectionPool::configure(), edm::ParameterSet::getParameter(), SiStripPayloadHandler< SiStripPayload >::m_connectionPool, and cond::persistency::ConnectionPool::setParameters().

55  :
57  m_configMapDb( iConfig.getParameter< std::string >("configMapDatabase") ),
58  m_condDb( iConfig.getParameter< std::string >("conditionDatabase") ),
59  m_cfgMapDbFile( iConfig.getParameter< std::string >("cfgMapDbFile") ),
60  m_localCondDbFile( iConfig.getParameter< std::string >("condDbFile") ),
61  m_targetTag( iConfig.getParameter< std::string >("targetTag") ),
62  m_since( iConfig.getParameter< uint32_t >("since") ),
63  p_type( cond::demangledName(typeid(SiStripPayload)) ),
64  p_cfgstr( condObjBuilder->getConfigString(typeid(SiStripPayload)) ){
67 }
T getParameter(std::string const &) const
edm::Service< SiStripCondObjBuilderFromDb > condObjBuilder
void setParameters(const edm::ParameterSet &connectionPset)
cond::persistency::ConnectionPool m_connectionPool
std::string getConfigString(const std::type_info &typeInfo)
template<typename SiStripPayload >
SiStripPayloadHandler< SiStripPayload >::~SiStripPayloadHandler ( )
virtual

Definition at line 70 of file SiStripPayloadHandler.cc.

70  {
71 }

Member Function Documentation

template<typename SiStripPayload >
void SiStripPayloadHandler< SiStripPayload >::analyze ( const edm::Event evt,
const edm::EventSetup evtSetup 
)
virtual

Definition at line 74 of file SiStripPayloadHandler.cc.

References cond::persistency::Transaction::commit(), SiStripPayloadHandler< SiStripPayload >::condObjBuilder, gather_cfg::cout, cond::persistency::Session::createIov(), cond::persistency::ConnectionPool::createSession(), cond::persistency::Session::fetchPayload(), cond::persistency::IOVEditor::flush(), cond::persistency::IOVProxy::getLast(), SiStripCondObjBuilderFromDb::getValue(), cond::persistency::IOVEditor::insert(), SiStripPayloadHandler< SiStripPayload >::m_condDb, SiStripPayloadHandler< SiStripPayload >::m_connectionPool, SiStripPayloadHandler< SiStripPayload >::m_localCondDbFile, SiStripPayloadHandler< SiStripPayload >::m_since, SiStripPayloadHandler< SiStripPayload >::m_targetTag, SiStripPayloadHandler< SiStripPayload >::makeConfigHash(), MuonAssociatorByHits_cfi::obj, cond::Iov_t::payloadId, SiStripPayloadHandler< SiStripPayload >::queryConfigMap(), cond::persistency::Session::readIov(), cond::runnumber, cond::persistency::IOVEditor::setDescription(), cond::persistency::Transaction::start(), cond::persistency::Session::storePayload(), AlCaHLTBitMon_QueryRunRegistry::string, cond::persistency::Session::transaction(), and SiStripPayloadHandler< SiStripPayload >::updateConfigMap().

74  {
75 
76  // some extra work: Getting the payload hash of the last IOV from condDb
77  // Will be compared with the new payload and reported
79  condDbSession.transaction().start( true );
80  cond::persistency::IOVProxy iovProxy = condDbSession.readIov( m_targetTag );
81  cond::Hash last_hash = iovProxy.getLast().payloadId;
82 
83  // that's the final goal: obtain the payload to store into the sqlite file for the upload into the DB
84  std::shared_ptr<SiStripPayload> payloadToUpload;
85  // first compute the hash of the configuration
86  std::string configHash = makeConfigHash();
87  // query the configMap DB to find the corresponding payload hash
88  std::string mappedPayloadHash = queryConfigMap(configHash);
89  bool mapUpToDate = false;
90 
91  if ( !mappedPayloadHash.empty() ){
92  // the payload has been found ( fast O2O case )
93  // copy the payload from condtition database
94  mapUpToDate = true;
95  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
96  << "Try retrieving payload from " << m_condDb;
97  payloadToUpload = condDbSession.fetchPayload<SiStripPayload>( mappedPayloadHash );
98  std::cout << "@@@[FastO2O:true]@@@" << std::endl;
99  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
100  << " ... Payload is copied from offline condition database.";
101  }else {
102  // start the long O2O...
103  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
104  << "NO mapping payload hash found. Will run the long O2O. ";
105  SiStripPayload *obj = nullptr;
106  condObjBuilder->getValue(obj);
107  payloadToUpload = std::shared_ptr<SiStripPayload>(obj);
108  std::cout << "@@@[FastO2O:false]@@@" << std::endl;
109  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
110  << " ... New payload has been created.";
111  }
112  condDbSession.transaction().commit();
113 
114  // write payload and iov in the local file
115  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
116  << "Write payload to local sqlite file: " << m_localCondDbFile;
117  cond::persistency::Session localFileSession = m_connectionPool.createSession( m_localCondDbFile, true );
118  localFileSession.transaction().start( false );
119  // write the payload
120  cond::Hash thePayloadHash = localFileSession.storePayload<SiStripPayload>( *payloadToUpload );
121  cond::persistency::IOVEditor iovEditor = localFileSession.createIov<SiStripPayload>( m_targetTag, cond::runnumber );
122  iovEditor.setDescription( "New IOV" );
123  // inserting the iov
124  iovEditor.insert( m_since, thePayloadHash );
125  iovEditor.flush();
126  localFileSession.transaction().commit();
127  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
128  << "Payload " << thePayloadHash << " inserted to sqlite with IOV " << m_since;
129 
130  // last step, update the configMap if required
131  if( !mapUpToDate ){
132  updateConfigMap(configHash, thePayloadHash);
133  }
134 
135  // finish the extra work: Compare the new payload with last IOV
136  if (last_hash == thePayloadHash){
137  std::cout << "@@@[PayloadChange:false]@@@" << last_hash << std::endl;
138  }else {
139  std::cout << "@@@[PayloadChange:true]@@@" << last_hash << " -> " << thePayloadHash << std::endl;
140  }
141 
142 }
edm::Service< SiStripCondObjBuilderFromDb > condObjBuilder
std::string queryConfigMap(std::string configHash)
void start(bool readOnly=true)
Definition: Session.cc:22
void updateConfigMap(std::string configHash, std::string payloadHash)
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:180
void setDescription(const std::string &description)
Definition: IOVEditor.cc:128
Transaction & transaction()
Definition: Session.cc:66
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
void getValue(SiStripFedCabling *&val)
Hash payloadId
Definition: Types.h:57
Session createSession(const std::string &connectionString, bool writeCapable=false)
std::string Hash
Definition: Types.h:45
cond::persistency::ConnectionPool m_connectionPool
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:152
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:184
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:197
template<typename SiStripPayload >
void SiStripPayloadHandler< SiStripPayload >::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 145 of file SiStripPayloadHandler.cc.

145  {
146 }
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::makeConfigHash ( )
private

Definition at line 149 of file SiStripPayloadHandler.cc.

References Exception, cond::hash, i, SiStripPayloadHandler< SiStripPayload >::p_cfgstr, SiStripPayloadHandler< SiStripPayload >::p_type, and tmp.

Referenced by SiStripPayloadHandler< SiStripPayload >::analyze().

149  {
150 
151  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
152  << "Convert config string to SHA-1 hash for " << p_type
153  << "\n... config: " << p_cfgstr;
154 
155  // calcuate SHA-1 hash using openssl
156  // adapted from cond::persistency::makeHash() in CondCore/CondDB/src/IOVSchema.cc
157  SHA_CTX ctx;
158  if( !SHA1_Init( &ctx ) ){
159  throw cms::Exception("SHA1 initialization error.");
160  }
161  if( !SHA1_Update( &ctx, p_type.c_str(), p_type.size() ) ){
162  throw cms::Exception("SHA1 processing error (1).");
163  }
164  if( !SHA1_Update( &ctx, p_cfgstr.c_str(), p_cfgstr.size() ) ){
165  throw cms::Exception("SHA1 processing error (2).");
166  }
167  unsigned char hash[SHA_DIGEST_LENGTH];
168  if( !SHA1_Final(hash, &ctx) ){
169  throw cms::Exception("SHA1 finalization error.");
170  }
171 
172  char tmp[SHA_DIGEST_LENGTH*2+1];
173  // re-write bytes in hex
174  for (unsigned int i = 0; i < SHA_DIGEST_LENGTH; i++) {
175  ::sprintf(&tmp[i * 2], "%02x", hash[i]);
176  }
177  tmp[SHA_DIGEST_LENGTH*2] = 0;
178 
179  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
180  "... hash: " << tmp;
181  return tmp;
182 
183 }
int i
Definition: DBlmapReader.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::queryConfigMap ( std::string  configHash)
private

Definition at line 186 of file SiStripPayloadHandler.cc.

References cond::persistency::ConnectionPool::createCoralSession(), SiStripPayloadHandler< SiStripPayload >::m_configMapDb, SiStripPayloadHandler< SiStripPayload >::m_connectionPool, das::query(), AlCaHLTBitMon_QueryRunRegistry::string, and toolbox::toString().

Referenced by SiStripPayloadHandler< SiStripPayload >::analyze().

186  {
187  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
188  << "Query " << m_configMapDb << " to see if the payload is already in DB.";
189 
190  auto cmDbSession = m_connectionPool.createCoralSession( m_configMapDb );
191  // query the STRIP_CONFIG_TO_PAYLOAD_MAP table
192  cmDbSession->transaction().start( true );
193  coral::ITable& cmTable = cmDbSession->nominalSchema().tableHandle( "STRIP_CONFIG_TO_PAYLOAD_MAP" );
194  std::unique_ptr<coral::IQuery> query( cmTable.newQuery() );
195  query->addToOutputList( "PAYLOAD_HASH" );
196  query->defineOutputType( "PAYLOAD_HASH", coral::AttributeSpecification::typeNameForType<std::string>() );
197  // also print these for debugging
198  query->addToOutputList( "PAYLOAD_TYPE" );
199  query->addToOutputList( "CONFIG_STRING" );
200  query->addToOutputList( "INSERTION_TIME" );
201  std::string whereClause( "CONFIG_HASH = :CONFIG_HASH" );
202  coral::AttributeList whereData;
203  whereData.extend<std::string>( "CONFIG_HASH" );
204  whereData.begin()->data< std::string >() = configHash;
205  query->setCondition( whereClause, whereData );
206  coral::ICursor& cursor = query->execute();
207  std::string p_hash;
208  if( cursor.next() ){
209  // the payload has been found ( fast O2O case )
210  p_hash = cursor.currentRow()["PAYLOAD_HASH"].data<std::string>();
211  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
212  << "Found associated payload hash " << p_hash
213  << "\n... type=" << cursor.currentRow()["PAYLOAD_TYPE"].data<std::string>()
214  << "\n... config=" << cursor.currentRow()["CONFIG_STRING"].data<std::string>()
215  << "\n... insertion_time=" << cursor.currentRow()["INSERTION_TIME"].data<coral::TimeStamp>().toString();
216  }
217  cmDbSession->transaction().commit();
218 
219  return p_hash;
220 }
def query(query_str, verbose=False)
Definition: das.py:5
Definition: query.py:1
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
cond::persistency::ConnectionPool m_connectionPool
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
template<typename SiStripPayload >
void SiStripPayloadHandler< SiStripPayload >::updateConfigMap ( std::string  configHash,
std::string  payloadHash 
)
private

Definition at line 223 of file SiStripPayloadHandler.cc.

References cond::persistency::ConnectionPool::createCoralSession(), SiStripPayloadHandler< SiStripPayload >::m_cfgMapDbFile, SiStripPayloadHandler< SiStripPayload >::m_connectionPool, cmsPerfSuiteHarvest::now, SiStripPayloadHandler< SiStripPayload >::p_cfgstr, SiStripPayloadHandler< SiStripPayload >::p_type, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by SiStripPayloadHandler< SiStripPayload >::analyze().

223  {
224  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
225  << "Updating the config to payload hash map to " << m_cfgMapDbFile;
226 
227  // create a writable transaction
228  auto cmSQLiteSession = m_connectionPool.createCoralSession( m_cfgMapDbFile, true );
229  cmSQLiteSession->transaction().start( false );
230  coral::ITable& cmTable = cmSQLiteSession->nominalSchema().tableHandle( "STRIP_CONFIG_TO_PAYLOAD_MAP" );
231  coral::AttributeList insertData;
232  insertData.extend<std::string>( "CONFIG_HASH" );
233  insertData.extend<std::string>( "PAYLOAD_HASH" );
234  // also insert these for bookkeeping
235  insertData.extend<std::string>( "PAYLOAD_TYPE" );
236  insertData.extend<std::string>( "CONFIG_STRING" );
237  insertData.extend<coral::TimeStamp>( "INSERTION_TIME" );
238  insertData["CONFIG_HASH"].data<std::string>() = configHash;
239  insertData["PAYLOAD_HASH"].data<std::string>() = payloadHash;
240  insertData["PAYLOAD_TYPE"].data<std::string>() = p_type;
241  insertData["CONFIG_STRING"].data<std::string>() = p_cfgstr;
242  insertData["INSERTION_TIME"].data<coral::TimeStamp>() = coral::TimeStamp::now(); // UTC time
243  cmTable.dataEditor().insertRow( insertData );
244  cmSQLiteSession->transaction().commit();
245  edm::LogInfo("SiStripPayloadHandler") << "[SiStripPayloadHandler::" << __func__ << "] "
246  << "Updated with mapping (configHash : payloadHash)" << configHash << " : " << payloadHash;
247 }
cond::persistency::ConnectionPool m_connectionPool
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)

Member Data Documentation

template<typename SiStripPayload >
edm::Service<SiStripCondObjBuilderFromDb> SiStripPayloadHandler< SiStripPayload >::condObjBuilder
private
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::m_cfgMapDbFile
private
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::m_condDb
private
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::m_configMapDb
private
template<typename SiStripPayload >
cond::persistency::ConnectionPool SiStripPayloadHandler< SiStripPayload >::m_connectionPool
private
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::m_localCondDbFile
private
template<typename SiStripPayload >
cond::Time_t SiStripPayloadHandler< SiStripPayload >::m_since
private
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::m_targetTag
private
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::p_cfgstr
private
template<typename SiStripPayload >
std::string SiStripPayloadHandler< SiStripPayload >::p_type
private