10 #include <openssl/sha.h> 14 #include "RelationalAccess/ITransaction.h" 15 #include "RelationalAccess/ISessionProxy.h" 16 #include "RelationalAccess/ISchema.h" 17 #include "RelationalAccess/ITable.h" 18 #include "RelationalAccess/IQuery.h" 19 #include "RelationalAccess/ICursor.h" 20 #include "RelationalAccess/ITableDataEditor.h" 21 #include "RelationalAccess/TableDescription.h" 22 #include "CoralBase/Attribute.h" 23 #include "CoralBase/AttributeList.h" 24 #include "CoralBase/TimeStamp.h" 28 template <
typename SiStripPayload>
58 template<
typename SiStripPayload>
66 m_since( iConfig.getParameter< uint32_t >(
"since") ),
67 p_type(
cond::demangledName(typeid(SiStripPayload)) ),
70 if (iConfig.
exists(
"configMapDatabase"))
72 if (iConfig.
exists(
"cfgMapDbFile"))
78 template<
typename SiStripPayload>
82 template<
typename SiStripPayload>
93 std::shared_ptr<SiStripPayload> payloadToUpload;
98 bool mapUpToDate =
false;
100 if ( !mappedPayloadHash.empty() ){
104 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 105 <<
"Try retrieving payload from " <<
m_condDb;
106 payloadToUpload = condDbSession.
fetchPayload<SiStripPayload>( mappedPayloadHash );
107 std::cout <<
"@@@[FastO2O:true]@@@" << std::endl;
108 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 109 <<
" ... Payload is copied from offline condition database.";
112 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 113 <<
"NO mapping payload hash found. Will run the long O2O. ";
114 SiStripPayload *
obj =
nullptr;
120 payloadToUpload = std::shared_ptr<SiStripPayload>(
obj);
121 std::cout <<
"@@@[FastO2O:false]@@@" << std::endl;
122 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 123 <<
" ... New payload has been created.";
128 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 140 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 141 <<
"Payload " << thePayloadHash <<
" inserted to sqlite with IOV " <<
m_since;
149 if (last_hash == thePayloadHash){
150 std::cout <<
"@@@[PayloadChange:false]@@@" << last_hash << std::endl;
152 std::cout <<
"@@@[PayloadChange:true]@@@" << last_hash <<
" -> " << thePayloadHash << std::endl;
157 template<
typename SiStripPayload>
161 template<
typename SiStripPayload>
164 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 165 <<
"Convert config string to SHA-1 hash for " <<
p_type 171 if( !SHA1_Init( &ctx ) ){
174 if( !SHA1_Update( &ctx,
p_type.c_str(),
p_type.size() ) ){
177 if( !SHA1_Update( &ctx, p_cfgstr.c_str(), p_cfgstr.size() ) ){
180 unsigned char hash[SHA_DIGEST_LENGTH];
181 if( !SHA1_Final(hash, &ctx) ){
185 char tmp[SHA_DIGEST_LENGTH*2+1];
187 for (
unsigned int i = 0;
i < SHA_DIGEST_LENGTH;
i++) {
188 ::sprintf(&tmp[
i * 2],
"%02x", hash[i]);
190 tmp[SHA_DIGEST_LENGTH*2] = 0;
192 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 198 template<
typename SiStripPayload>
202 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 203 <<
"Query " <<
m_configMapDb <<
" to see if the payload is already in DB.";
207 cmDbSession->transaction().start(
true );
209 std::unique_ptr<coral::IQuery>
query( cmTable.newQuery() );
210 query->addToOutputList(
"PAYLOAD_HASH" );
211 query->defineOutputType(
"PAYLOAD_HASH", coral::AttributeSpecification::typeNameForType<std::string>() );
213 query->addToOutputList(
"PAYLOAD_TYPE" );
214 query->addToOutputList(
"CONFIG_STRING" );
215 query->addToOutputList(
"INSERTION_TIME" );
216 std::string whereClause(
"CONFIG_HASH = :CONFIG_HASH" );
217 coral::AttributeList whereData;
219 whereData.begin()->data<
std::string >() = configHash;
220 query->setCondition( whereClause, whereData );
221 coral::ICursor& cursor =
query->execute();
225 p_hash = cursor.currentRow()[
"PAYLOAD_HASH"].data<
std::string>();
226 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 227 <<
"Found associated payload hash " << p_hash
228 <<
"\n... type=" << cursor.currentRow()[
"PAYLOAD_TYPE"].data<
std::string>()
229 <<
"\n... config=" << cursor.currentRow()[
"CONFIG_STRING"].data<
std::string>()
230 <<
"\n... insertion_time=" << cursor.currentRow()[
"INSERTION_TIME"].data<coral::TimeStamp>().
toString();
232 cmDbSession->transaction().commit();
237 template<
typename SiStripPayload>
241 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 242 <<
"Updating the config to payload hash map to " <<
m_cfgMapDbFile;
246 cmSQLiteSession->transaction().start(
false );
250 coral::TableDescription mapTable;
252 mapTable.insertColumn(
"CONFIG_HASH", coral::AttributeSpecification::typeNameForType<std::string>());
253 mapTable.insertColumn(
"PAYLOAD_HASH", coral::AttributeSpecification::typeNameForType<std::string>());
254 mapTable.insertColumn(
"PAYLOAD_TYPE", coral::AttributeSpecification::typeNameForType<std::string>());
255 mapTable.insertColumn(
"CONFIG_STRING", coral::AttributeSpecification::typeNameForType<std::string>());
256 mapTable.insertColumn(
"INSERTION_TIME", coral::AttributeSpecification::typeNameForType<coral::TimeStamp>());
257 mapTable.setPrimaryKey(
"CONFIG_HASH");
258 mapTable.setNotNullConstraint(
"CONFIG_HASH");
259 mapTable.setNotNullConstraint(
"PAYLOAD_HASH");
260 mapTable.setNotNullConstraint(
"PAYLOAD_TYPE");
261 mapTable.setNotNullConstraint(
"CONFIG_STRING");
262 mapTable.setNotNullConstraint(
"INSERTION_TIME");
263 cmSQLiteSession->nominalSchema().createTable(mapTable);
266 coral::ITable& cmTable = cmSQLiteSession->nominalSchema().tableHandle(
m_cfgMapTableName );
267 coral::AttributeList insertData;
273 insertData.extend<coral::TimeStamp>(
"INSERTION_TIME" );
274 insertData[
"CONFIG_HASH"].data<
std::string>() = configHash;
275 insertData[
"PAYLOAD_HASH"].data<
std::string>() = payloadHash;
279 cmTable.dataEditor().insertRow( insertData );
280 cmSQLiteSession->transaction().commit();
281 edm::LogInfo(
"SiStripPayloadHandler") <<
"[SiStripPayloadHandler::" << __func__ <<
"] " 282 <<
"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)
std::string m_cfgMapTableName
void start(bool readOnly=true)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void updateConfigMap(std::string configHash, std::string payloadHash)
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
~SiStripPayloadHandler() override
void setDescription(const std::string &description)
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
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
#define DEFINE_FWK_MODULE(type)
unsigned long long Time_t
SiStripPayloadHandler< SiStripApvGain > SiStripO2OApvGain
void getValue(SiStripFedCabling *&val)
std::string m_cfgMapSchemaName
Session createSession(const std::string &connectionString, bool writeCapable=false)
void setLastIovGain(std::shared_ptr< SiStripApvGain > gain)
std::string m_cfgMapDbFile
std::string toString(const std::pair< T, T > &aT)
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
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()