Skip to content

Commit

Permalink
Made code-checks happy
Browse files Browse the repository at this point in the history
  • Loading branch information
ggovi committed Dec 7, 2021
1 parent c797340 commit 47c0881
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 96 deletions.
2 changes: 1 addition & 1 deletion CondCore/CondDB/interface/Time.h
Expand Up @@ -64,7 +64,7 @@ namespace cond {

edm::IOVSyncValue limitedIOVSyncValue(edm::IOVSyncValue const& time, TimeType timetype);

std::string transactionIdForLumiTime( Time_t time, unsigned int iovSize, const std::string& secretKey);
std::string transactionIdForLumiTime(Time_t time, unsigned int iovSize, const std::string& secretKey);

} // namespace time

Expand Down
16 changes: 8 additions & 8 deletions CondCore/CondDB/src/Time.cc
Expand Up @@ -135,20 +135,20 @@ namespace cond {
}
}

std::string transactionIdForLumiTime( Time_t time, unsigned int iovSize, const std::string& secretKey){
std::string transactionIdForLumiTime(Time_t time, unsigned int iovSize, const std::string& secretKey) {
auto unpackedTime = cond::time::unpack(time);
unsigned int offset = 1+iovSize;
unsigned int offset = 1 + iovSize;
cond::Time_t id = 0;
if( unpackedTime.second < offset ){
id = lumiTime(unpackedTime.first, 1);
if (unpackedTime.second < offset) {
id = lumiTime(unpackedTime.first, 1);
} else {
unsigned int res = (unpackedTime.second-offset) % iovSize;
id = lumiTime(unpackedTime.first, unpackedTime.second-res );
unsigned int res = (unpackedTime.second - offset) % iovSize;
id = lumiTime(unpackedTime.first, unpackedTime.second - res);
}
std::stringstream transId;
transId << id;
if(!secretKey.empty()){
transId << "_" << secretKey;
if (!secretKey.empty()) {
transId << "_" << secretKey;
}
return transId.str();
}
Expand Down
11 changes: 6 additions & 5 deletions CondCore/DBOutputService/interface/OnlineDBOutputService.h
Expand Up @@ -35,14 +35,15 @@ namespace cond {

template <typename PayloadType>
cond::Time_t writeIOVForNextLumisection(const PayloadType& payload, const std::string& recordName) {
auto& rec = PoolDBOutputService::lookUpRecord( recordName );
auto& rec = PoolDBOutputService::lookUpRecord(recordName);
cond::Time_t lastTime = getLastLumiProcessed();
auto unpkLastTime = cond::time::unpack( lastTime );
cond::Time_t targetTime = cond::time::lumiTime( unpkLastTime.first, unpkLastTime.second+m_latencyInLumisections);
auto unpkLastTime = cond::time::unpack(lastTime);
cond::Time_t targetTime =
cond::time::lumiTime(unpkLastTime.first, unpkLastTime.second + m_latencyInLumisections);
auto t0 = std::chrono::high_resolution_clock::now();
logger().logInfo() << "Updating lumisection " << targetTime;
cond::Hash payloadId = PoolDBOutputService::writeOneIOV<PayloadType>(payload, targetTime, recordName);
PoolDBOutputService::commitTransaction();
PoolDBOutputService::commitTransaction();
if (payloadId.empty()) {
return 0;
}
Expand All @@ -65,7 +66,7 @@ namespace cond {
<< usedIov.since << "). A revert is required.";
PoolDBOutputService::eraseSinceTime(payloadId, targetTime, recordName);
PoolDBOutputService::commitTransaction();
targetTime = 0;
targetTime = 0;
}
auto t4 = std::chrono::high_resolution_clock::now();
auto t_lat = std::chrono::duration_cast<std::chrono::microseconds>(t4 - t0).count();
Expand Down
35 changes: 17 additions & 18 deletions CondCore/DBOutputService/interface/PoolDBOutputService.h
Expand Up @@ -172,11 +172,11 @@ namespace cond {
doStartTransaction();
cond::persistency::TransactionScope scope(m_session.transaction());
try {
this->initDB();
auto& myrecord = this->getRecord(recordName);
if (!myrecord.m_isNewTag) {
cond::throwException(myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
}
this->initDB();
auto& myrecord = this->getRecord(recordName);
if (!myrecord.m_isNewTag) {
cond::throwException(myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
}
Hash payloadId = m_session.storePayload(payload);
createNewIOV(payloadId, cond::demangledName(typeid(payload)), firstSinceTime, myrecord);
if (m_autoCommit) {
Expand All @@ -203,16 +203,16 @@ namespace cond {
doStartTransaction();
cond::persistency::TransactionScope scope(m_session.transaction());
try {
bool dbexists = this->initDB( true );
if(!dbexists){
cond::throwException(std::string("Target database does not exist."),
"PoolDBOutputService::appendSinceTime");
}
auto& myrecord = this->lookUpRecord(recordName);
if (myrecord.m_isNewTag) {
cond::throwException(std::string("Cannot append to non-existing tag ") + myrecord.m_tag,
"PoolDBOutputService::appendSinceTime");
}
bool dbexists = this->initDB(true);
if (!dbexists) {
cond::throwException(std::string("Target database does not exist."),
"PoolDBOutputService::appendSinceTime");
}
auto& myrecord = this->lookUpRecord(recordName);
if (myrecord.m_isNewTag) {
cond::throwException(std::string("Cannot append to non-existing tag ") + myrecord.m_tag,
"PoolDBOutputService::appendSinceTime");
}
appendSinceTime(m_session.storePayload(payload), sinceTime, myrecord);
if (m_autoCommit) {
doCommitTransaction();
Expand Down Expand Up @@ -278,14 +278,13 @@ namespace cond {
bool m_isNewTag;
std::string m_idName;
cond::TimeType m_timetype;
unsigned int m_refreshTime = 0;
unsigned int m_refreshTime = 0;
bool m_onlyAppendUpdatePolicy;
};

const Record& lookUpRecord(const std::string& recordName);

private:

//
void doStartTransaction();
void doCommitTransaction();
Expand Down Expand Up @@ -314,7 +313,7 @@ namespace cond {

void fillRecord(edm::ParameterSet& pset, const std::string& gTimeTypeStr);

bool initDB( bool readOnly=false );
bool initDB(bool readOnly = false);

Record& getRecord(const std::string& recordName);

Expand Down
6 changes: 3 additions & 3 deletions CondCore/DBOutputService/src/OnlineDBOutputService.cc
Expand Up @@ -114,8 +114,9 @@ cond::Time_t cond::service::OnlineDBOutputService::getLastLumiProcessed() {
return lastLumiProcessed;
}

cond::Iov_t cond::service::OnlineDBOutputService::preLoadIov(const PoolDBOutputService::Record& record, cond::Time_t targetTime) {
auto transId = cond::time::transactionIdForLumiTime( targetTime, record.m_refreshTime, m_frontierKey );
cond::Iov_t cond::service::OnlineDBOutputService::preLoadIov(const PoolDBOutputService::Record& record,
cond::Time_t targetTime) {
auto transId = cond::time::transactionIdForLumiTime(targetTime, record.m_refreshTime, m_frontierKey);
cond::persistency::Session session = PoolDBOutputService::newReadOnlySession(m_preLoadConnectionString, transId);
cond::persistency::TransactionScope transaction(session.transaction());
transaction.start(true);
Expand All @@ -124,4 +125,3 @@ cond::Iov_t cond::service::OnlineDBOutputService::preLoadIov(const PoolDBOutputS
transaction.commit();
return iov;
}

62 changes: 32 additions & 30 deletions CondCore/DBOutputService/src/PoolDBOutputService.cc
Expand Up @@ -28,7 +28,7 @@ void cond::service::PoolDBOutputService::fillRecord(edm::ParameterSet& recordPse

thisrecord.m_onlyAppendUpdatePolicy = recordPset.getUntrackedParameter<bool>("onlyAppendUpdatePolicy", false);

thisrecord.m_refreshTime = recordPset.getUntrackedParameter<unsigned int>("refreshTime",1);
thisrecord.m_refreshTime = recordPset.getUntrackedParameter<unsigned int>("refreshTime", 1);

m_records.insert(std::make_pair(thisrecord.m_idName, thisrecord));

Expand Down Expand Up @@ -144,8 +144,10 @@ bool cond::service::PoolDBOutputService::isNewTagRequest(const std::string& reco
} catch (const std::exception& er) {
cond::throwException(std::string(er.what()), "PoolDBOutputService::isNewTagRequest");
}
if( doCommit ) m_session.transaction().commit();
if(!dbexists) return true;
if (doCommit)
m_session.transaction().commit();
if (!dbexists)
return true;
auto& myrecord = this->lookUpRecord(recordName);
return myrecord.m_isNewTag;
}
Expand Down Expand Up @@ -178,25 +180,26 @@ void cond::service::PoolDBOutputService::commitTransaction() {
doCommitTransaction();
}

bool cond::service::PoolDBOutputService::initDB( bool readOnly ) {
bool cond::service::PoolDBOutputService::initDB(bool readOnly) {
if (!m_dbInitialised) {
if (!m_session.existsDatabase()){
if(readOnly) return false;
if (!m_session.existsDatabase()) {
if (readOnly)
return false;
m_session.createDatabase();
}
else {
} else {
for (auto& iR : m_records) {
if (m_session.existsIov(iR.second.m_tag)){
if (m_session.existsIov(iR.second.m_tag)) {
iR.second.m_isNewTag = false;
}
}
}
}
m_dbInitialised = true;
}
return m_dbInitialised;
}

cond::service::PoolDBOutputService::Record& cond::service::PoolDBOutputService::getRecord(const std::string& recordName){
cond::service::PoolDBOutputService::Record& cond::service::PoolDBOutputService::getRecord(
const std::string& recordName) {
std::map<std::string, Record>::iterator it = m_records.find(recordName);
if (it == m_records.end()) {
cond::throwException("The record \"" + recordName + "\" has not been registered.",
Expand Down Expand Up @@ -272,7 +275,7 @@ void cond::service::PoolDBOutputService::createNewIOV(const std::string& firstPa
cond::throwException(myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
}
m_logger.logInfo() << "Creating new tag " << myrecord.m_tag << ", adding iov with since " << firstSinceTime
<< " pointing to payload id " << firstPayloadId;
<< " pointing to payload id " << firstPayloadId;
cond::persistency::IOVEditor editor =
m_session.createIovForPayload(firstPayloadId, myrecord.m_tag, myrecord.m_timetype, cond::SYNCH_ANY);
editor.setDescription("New Tag");
Expand Down Expand Up @@ -315,14 +318,13 @@ bool cond::service::PoolDBOutputService::appendSinceTime(const std::string& payl
cond::persistency::TransactionScope scope(m_session.transaction());
try {
bool dbexists = this->initDB();
if(!dbexists){
cond::throwException(std::string("Target database does not exist."),
"PoolDBOutputService::appendSinceTime");
if (!dbexists) {
cond::throwException(std::string("Target database does not exist."), "PoolDBOutputService::appendSinceTime");
}
auto& myrecord = this->lookUpRecord(recordName);
if (myrecord.m_isNewTag) {
cond::throwException(std::string("Cannot append to non-existing tag ") + myrecord.m_tag,
"PoolDBOutputService::appendSinceTime");
"PoolDBOutputService::appendSinceTime");
}
ret = appendSinceTime(payloadId, time, myrecord);
if (m_autoCommit) {
Expand Down Expand Up @@ -359,17 +361,16 @@ void cond::service::PoolDBOutputService::eraseSinceTime(const std::string& paylo
cond::persistency::TransactionScope scope(m_session.transaction());
try {
bool dbexists = this->initDB();
if(!dbexists){
cond::throwException(std::string("Target database does not exist."),
"PoolDBOutputService::eraseSinceTime");
if (!dbexists) {
cond::throwException(std::string("Target database does not exist."), "PoolDBOutputService::eraseSinceTime");
}
auto& myrecord = this->lookUpRecord(recordName);
if (myrecord.m_isNewTag) {
cond::throwException(std::string("Cannot delete from non-existing tag ") + myrecord.m_tag,
"PoolDBOutputService::appendSinceTime");
"PoolDBOutputService::appendSinceTime");
}
m_logger.logInfo() << "Updating existing tag " << myrecord.m_tag << ", removing iov with since " << sinceTime
<< " pointing to payload id " << payloadId;
<< " pointing to payload id " << payloadId;
cond::persistency::IOVEditor editor = m_session.editIov(myrecord.m_tag);
editor.erase(sinceTime, payloadId);
cond::UserLogInfo a = this->lookUpUserLogInfo(recordName);
Expand All @@ -383,7 +384,8 @@ void cond::service::PoolDBOutputService::eraseSinceTime(const std::string& paylo
scope.close();
}

const cond::service::PoolDBOutputService::Record& cond::service::PoolDBOutputService::lookUpRecord(const std::string& recordName) {
const cond::service::PoolDBOutputService::Record& cond::service::PoolDBOutputService::lookUpRecord(
const std::string& recordName) {
std::map<std::string, Record>::const_iterator it = m_records.find(recordName);
if (it == m_records.end()) {
cond::throwException("The record \"" + recordName + "\" has not been registered.",
Expand All @@ -404,16 +406,15 @@ void cond::service::PoolDBOutputService::closeIOV(Time_t lastTill, const std::st
std::lock_guard<std::recursive_mutex> lock(m_mutex);
doStartTransaction();
cond::persistency::TransactionScope scope(m_session.transaction());
try{
try {
bool dbexists = this->initDB();
if(!dbexists){
cond::throwException(std::string("Target database does not exist."),
"PoolDBOutputService::closeIOV");
}
if (!dbexists) {
cond::throwException(std::string("Target database does not exist."), "PoolDBOutputService::closeIOV");
}
auto& myrecord = lookUpRecord(recordName);
if (myrecord.m_isNewTag) {
cond::throwException(std::string("Cannot close non-existing tag ") + myrecord.m_tag,
"PoolDBOutputService::closeIOV");
"PoolDBOutputService::closeIOV");
}
m_logger.logInfo() << "Updating existing tag " << myrecord.m_tag << ", closing with end of validity " << lastTill;
cond::persistency::IOVEditor editor = m_session.editIov(myrecord.m_tag);
Expand Down Expand Up @@ -464,13 +465,14 @@ bool cond::service::PoolDBOutputService::tagInfo(const std::string& recordName,
cond::persistency::TransactionScope scope(m_session.transaction());
try {
dbexists = initDB(true);
if(dbexists){
if (dbexists) {
ret = getTagInfo(recordName, result);
}
} catch (const std::exception& er) {
cond::throwException(std::string(er.what()), "PoolDBOutputService::tagInfo");
}
if( doCommit ) m_session.transaction().commit();
if (doCommit)
m_session.transaction().commit();
scope.close();
return ret;
}
13 changes: 7 additions & 6 deletions CondCore/DBOutputService/test/stubs/IOVPayloadAnalyzer.cc
Expand Up @@ -55,21 +55,22 @@ void IOVPayloadAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& e
std::cout << myped.m_pedestals[1].m_mean << std::endl;

std::cout << "currentTime " << mydbservice->currentTime() << std::endl;
if(mydbservice->isNewTagRequest(m_record)){
if (mydbservice->isNewTagRequest(m_record)) {
mydbservice->createOneIOV(myped, mydbservice->currentTime(), m_record);
} else {
mydbservice->appendOneIOV(myped, mydbservice->currentTime(), m_record);
}
mydbservice->startTransaction();
auto iov = mydbservice->currentTime()+100;
auto iov = mydbservice->currentTime() + 100;
auto hash = mydbservice->writeOneIOV(myped, iov, m_record);
mydbservice->commitTransaction();
cond::TagInfo_t tinfo;
mydbservice->tagInfo(m_record,tinfo);
if(tinfo.lastInterval.payloadId == hash && tinfo.lastInterval.since == iov ){
std::cout <<"Last IOV stored is the expected one..."<<std::endl;
mydbservice->tagInfo(m_record, tinfo);
if (tinfo.lastInterval.payloadId == hash && tinfo.lastInterval.since == iov) {
std::cout << "Last IOV stored is the expected one..." << std::endl;
} else {
std::cout <<"Last IOV hash = "<<tinfo.lastInterval.payloadId<<" (expected: "<<hash<<") since = "<<tinfo.lastInterval.since<<" (expected: "<<iov<<")"<<std::endl;
std::cout << "Last IOV hash = " << tinfo.lastInterval.payloadId << " (expected: " << hash
<< ") since = " << tinfo.lastInterval.since << " (expected: " << iov << ")" << std::endl;
}
mydbservice->eraseSinceTime(hash, iov, m_record);
}
Expand Down

0 comments on commit 47c0881

Please sign in to comment.