9 #include <openssl/sha.h> 13 #include "RelationalAccess/ITransaction.h" 14 #include "RelationalAccess/ISessionProxy.h" 15 #include "RelationalAccess/ISchema.h" 16 #include "RelationalAccess/ITable.h" 17 #include "RelationalAccess/IQuery.h" 18 #include "RelationalAccess/ICursor.h" 19 #include "RelationalAccess/ITableDataEditor.h" 20 #include "CoralBase/Attribute.h" 21 #include "CoralBase/AttributeList.h" 22 #include "CoralBase/TimeStamp.h" 26 template <
typename SiStripPayload>
54 template<
typename SiStripPayload>
62 m_since( iConfig.getParameter< uint32_t >(
"since") ),
63 p_type(
cond::demangledName(typeid(SiStripPayload)) ),
69 template<
typename SiStripPayload>
73 template<
typename SiStripPayload>
84 std::shared_ptr<SiStripPayload> payloadToUpload;
89 bool mapUpToDate =
false;
91 if ( !mappedPayloadHash.empty() ){
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.";
103 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 104 <<
"NO mapping payload hash found. Will run the long O2O. ";
105 SiStripPayload *
obj =
nullptr;
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.";
115 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 127 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 128 <<
"Payload " << thePayloadHash <<
" inserted to sqlite with IOV " <<
m_since;
136 if (last_hash == thePayloadHash){
137 std::cout <<
"@@@[PayloadChange:false]@@@" << last_hash << std::endl;
139 std::cout <<
"@@@[PayloadChange:true]@@@" << last_hash <<
" -> " << thePayloadHash << std::endl;
144 template<
typename SiStripPayload>
148 template<
typename SiStripPayload>
151 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 152 <<
"Convert config string to SHA-1 hash for " <<
p_type 158 if( !SHA1_Init( &ctx ) ){
161 if( !SHA1_Update( &ctx,
p_type.c_str(),
p_type.size() ) ){
164 if( !SHA1_Update( &ctx, p_cfgstr.c_str(), p_cfgstr.size() ) ){
167 unsigned char hash[SHA_DIGEST_LENGTH];
168 if( !SHA1_Final(hash, &ctx) ){
172 char tmp[SHA_DIGEST_LENGTH*2+1];
174 for (
unsigned int i = 0;
i < SHA_DIGEST_LENGTH;
i++) {
175 ::sprintf(&tmp[
i * 2],
"%02x", hash[i]);
177 tmp[SHA_DIGEST_LENGTH*2] = 0;
179 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 185 template<
typename SiStripPayload>
187 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 188 <<
"Query " <<
m_configMapDb <<
" to see if the payload is already in DB.";
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>() );
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;
204 whereData.begin()->data<
std::string >() = configHash;
205 query->setCondition( whereClause, whereData );
206 coral::ICursor& cursor =
query->execute();
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();
217 cmDbSession->transaction().commit();
222 template<
typename SiStripPayload>
224 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 225 <<
"Updating the config to payload hash map to " <<
m_cfgMapDbFile;
229 cmSQLiteSession->transaction().start(
false );
230 coral::ITable& cmTable = cmSQLiteSession->nominalSchema().tableHandle(
"STRIP_CONFIG_TO_PAYLOAD_MAP" );
231 coral::AttributeList insertData;
237 insertData.extend<coral::TimeStamp>(
"INSERTION_TIME" );
238 insertData[
"CONFIG_HASH"].data<
std::string>() = configHash;
239 insertData[
"PAYLOAD_HASH"].data<
std::string>() = payloadHash;
243 cmTable.dataEditor().insertRow( insertData );
244 cmSQLiteSession->transaction().commit();
245 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 246 <<
"Updated with mapping (configHash : payloadHash)" << configHash <<
" : " << payloadHash;
T getParameter(std::string const &) const
edm::Service< SiStripCondObjBuilderFromDb > condObjBuilder
SiStripPayloadHandler< SiStripNoises > SiStripO2ONoises
SiStripPayloadHandler< SiStripFedCabling > SiStripO2OFedCabling
std::string queryConfigMap(std::string configHash)
#define DEFINE_FWK_MODULE(type)
void start(bool readOnly=true)
void updateConfigMap(std::string configHash, std::string payloadHash)
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
void setDescription(const std::string &description)
virtual ~SiStripPayloadHandler()
Transaction & transaction()
def query(query_str, verbose=False)
SiStripPayloadHandler< SiStripPedestals > SiStripO2OPedestals
void setParameters(const edm::ParameterSet &connectionPset)
IOVProxy readIov(const std::string &tag, bool full=false)
SiStripPayloadHandler< SiStripBadStrip > SiStripO2OBadStrip
unsigned long long Time_t
SiStripPayloadHandler< SiStripApvGain > SiStripO2OApvGain
void getValue(SiStripFedCabling *&val)
Session createSession(const std::string &connectionString, bool writeCapable=false)
std::string m_cfgMapDbFile
cond::persistency::ConnectionPool m_connectionPool
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
SiStripPayloadHandler(const edm::ParameterSet &iConfig)
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
std::vector< std::vector< double > > tmp
std::string m_localCondDbFile
virtual void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup)
std::string m_configMapDb
SiStripPayloadHandler< SiStripThreshold > SiStripO2OThreshold
SiStripPayloadHandler< SiStripLatency > SiStripO2OLatency
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
std::string makeConfigHash()
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)