Skip to content

Commit

Permalink
Merge pull request #26952 from cms-sw/code-format-alca-db-544901
Browse files Browse the repository at this point in the history
Running code-format for alca-db
  • Loading branch information
cmsbuild committed May 28, 2019
2 parents d9d1163 + da621e8 commit f7bfb79
Show file tree
Hide file tree
Showing 549 changed files with 2,070 additions and 2,087 deletions.
13 changes: 6 additions & 7 deletions CondCore/DBOutputService/interface/Exception.h
Expand Up @@ -2,13 +2,12 @@
#define CondCore_DBOutputService_Exception_h
#include "CondCore/CondDB/interface/Exception.h"
#include <string>
namespace cond{
class UnregisteredRecordException : public Exception{
namespace cond {
class UnregisteredRecordException : public Exception {
public:
UnregisteredRecordException( const std::string& recordName ) : Exception( std::string("PoolDBOutputService: unregistered record "+recordName) ){
}
~UnregisteredRecordException() throw() override{
}
UnregisteredRecordException(const std::string& recordName)
: Exception(std::string("PoolDBOutputService: unregistered record " + recordName)) {}
~UnregisteredRecordException() throw() override {}
};
}
} // namespace cond
#endif
39 changes: 15 additions & 24 deletions CondCore/DBOutputService/interface/KeyedElement.h
Expand Up @@ -3,39 +3,30 @@
#include "CondFormats/Common/interface/hash64.h"
#include <sstream>

namespace cond{
namespace cond {

/* encapsulate data to write a keyed element in an IOVSequence
*/
class KeyedElement {

public:
// constructor from int key
KeyedElement(BaseKeyed * obj, cond::Time_t key) :
m_obj(obj),
m_skey(""),
m_key(key) {
std::ostringstream ss; ss << key;
m_skey = ss.str();
(*obj).setKey(m_skey);
}
KeyedElement(BaseKeyed* obj, cond::Time_t key) : m_obj(obj), m_skey(""), m_key(key) {
std::ostringstream ss;
ss << key;
m_skey = ss.str();
(*obj).setKey(m_skey);
}

// constructor from ascii key
KeyedElement(BaseKeyed * obj, std::string key) :
m_obj(obj),
m_skey(key),
m_key(convert(key)) {
(*obj).setKey(m_skey);
}

static cond::Time_t convert(std::string key) {
return cond::hash64( (unsigned char*)(&key[0]),key.size(),0);
KeyedElement(BaseKeyed* obj, std::string key) : m_obj(obj), m_skey(key), m_key(convert(key)) {
(*obj).setKey(m_skey);
}

BaseKeyed * m_obj;
std::string m_skey;
static cond::Time_t convert(std::string key) { return cond::hash64((unsigned char*)(&key[0]), key.size(), 0); }

BaseKeyed* m_obj;
std::string m_skey;
cond::Time_t m_key;
};


}

} // namespace cond
230 changes: 111 additions & 119 deletions CondCore/DBOutputService/interface/PoolDBOutputService.h
Expand Up @@ -10,7 +10,7 @@
//
// Package: DBOutputService
// Class : PoolDBOutputService
//
//
/**\class PoolDBOutputService PoolDBOutputService.h CondCore/DBOutputService/interface/PoolDBOutputService.h
Description: edm service for writing conditions object to DB.
*/
Expand All @@ -19,142 +19,141 @@
// Fixes and other changes: Giacomo Govi
//

namespace edm{
namespace edm {
class Event;
class EventSetup;
class ParameterSet;
}
namespace cond{
inline std::string classNameForTypeId( const std::type_info& typeInfo ){
edm::TypeID type( typeInfo );
} // namespace edm
namespace cond {

inline std::string classNameForTypeId(const std::type_info& typeInfo) {
edm::TypeID type(typeInfo);
return type.className();
}

namespace service {

class PoolDBOutputService{
class PoolDBOutputService {
public:
PoolDBOutputService( const edm::ParameterSet & iConfig,
edm::ActivityRegistry & iAR );
PoolDBOutputService(const edm::ParameterSet& iConfig, edm::ActivityRegistry& iAR);
//use these to control connections
//void postBeginJob();
void postEndJob();
void postEndJob();

//
// return the database session in use ( GG: not sure this is still useful... )
//
cond::persistency::Session session() const;
//
std::string tag( const std::string& recordName );
bool isNewTagRequest( const std::string& recordName );

//
template<typename T>
void writeOne( T * payload, Time_t time, const std::string& recordName, bool withlogging=false ) {
if( !payload ) throwException( "Provided payload pointer is invalid.","PoolDBOutputService::writeOne");
std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (!m_dbstarted) this->initDB();
Hash payloadId = m_session.storePayload( *payload );
std::string payloadType = cond::demangledName(typeid(T));
if (isNewTagRequest(recordName) ){
createNewIOV(payloadId, payloadType, time, endOfTime(), recordName, withlogging);
std::string tag(const std::string& recordName);
bool isNewTagRequest(const std::string& recordName);

//
template <typename T>
void writeOne(T* payload, Time_t time, const std::string& recordName, bool withlogging = false) {
if (!payload)
throwException("Provided payload pointer is invalid.", "PoolDBOutputService::writeOne");
std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (!m_dbstarted)
this->initDB();
Hash payloadId = m_session.storePayload(*payload);
std::string payloadType = cond::demangledName(typeid(T));
if (isNewTagRequest(recordName)) {
createNewIOV(payloadId, payloadType, time, endOfTime(), recordName, withlogging);
} else {
appendSinceTime(payloadId, time, recordName, withlogging);
}
appendSinceTime(payloadId, time, recordName, withlogging);
}
}

// close the IOVSequence setting lastTill
void closeIOV(Time_t lastTill, const std::string& recordName,
bool withlogging=false);

//
template<typename T>
void createNewIOV( T* firstPayloadObj,
cond::Time_t firstSinceTime,
cond::Time_t firstTillTime,
const std::string& recordName,
bool withlogging=false){
if( !firstPayloadObj ) throwException( "Provided payload pointer is invalid.","PoolDBOutputService::createNewIOV");
std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (!m_dbstarted) this->initDB();
createNewIOV( m_session.storePayload( *firstPayloadObj ),
cond::demangledName(typeid(T)),
firstSinceTime,
firstTillTime,
recordName,
withlogging);
void closeIOV(Time_t lastTill, const std::string& recordName, bool withlogging = false);

//
template <typename T>
void createNewIOV(T* firstPayloadObj,
cond::Time_t firstSinceTime,
cond::Time_t firstTillTime,
const std::string& recordName,
bool withlogging = false) {
if (!firstPayloadObj)
throwException("Provided payload pointer is invalid.", "PoolDBOutputService::createNewIOV");
std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (!m_dbstarted)
this->initDB();
createNewIOV(m_session.storePayload(*firstPayloadObj),
cond::demangledName(typeid(T)),
firstSinceTime,
firstTillTime,
recordName,
withlogging);
}
void createNewIOV( const std::string& firstPayloadId,
const std::string payloadType,
cond::Time_t firstSinceTime,
cond::Time_t firstTillTime,
const std::string& recordName,
bool withlogging=false);

void createNewIOV(const std::string& firstPayloadId,
const std::string payloadType,
cond::Time_t firstSinceTime,
cond::Time_t firstTillTime,
const std::string& recordName,
bool withlogging = false);

// this one we need to avoid to adapt client code around... to be removed in the long term!
void createNewIOV( const std::string& firstPayloadId,
cond::Time_t firstSinceTime,
cond::Time_t firstTillTime,
const std::string& recordName,
bool withlogging=false);

//
template<typename T> void appendSinceTime( T* payloadObj,
cond::Time_t sinceTime,
const std::string& recordName,
bool withlogging=false){
if( !payloadObj ) throwException( "Provided payload pointer is invalid.","PoolDBOutputService::appendSinceTime");
appendSinceTime( m_session.storePayload( *payloadObj ),
sinceTime,
recordName,
withlogging);
void createNewIOV(const std::string& firstPayloadId,
cond::Time_t firstSinceTime,
cond::Time_t firstTillTime,
const std::string& recordName,
bool withlogging = false);

//
template <typename T>
void appendSinceTime(T* payloadObj,
cond::Time_t sinceTime,
const std::string& recordName,
bool withlogging = false) {
if (!payloadObj)
throwException("Provided payload pointer is invalid.", "PoolDBOutputService::appendSinceTime");
appendSinceTime(m_session.storePayload(*payloadObj), sinceTime, recordName, withlogging);
}

// Append the payload and its valid sinceTime into the database
// Note: the iov index appended to MUST pre-existing and the existing
// Note: the iov index appended to MUST pre-existing and the existing
// conditions data are retrieved from the DB
//
void appendSinceTime( const std::string& payloadId,
cond::Time_t sinceTime,
const std::string& recordName,
bool withlogging=false);
//
// Service time utility method
//
void appendSinceTime(const std::string& payloadId,
cond::Time_t sinceTime,
const std::string& recordName,
bool withlogging = false);

//
// Service time utility method
// return the infinity value according to the given timetype
//
cond::Time_t endOfTime() const;
//
// Service time utility method
// Service time utility method
// return beginning of time value according to the given timetype
//
cond::Time_t beginOfTime() const;
//
// Service time utility method
// return the time value of the current edm::Event according to the
// Service time utility method
// return the time value of the current edm::Event according to the
// given timetype
//
cond::Time_t currentTime() const;

// optional. User can inject additional information into the log associated with a given record
void setLogHeaderForRecord(const std::string& recordName,
const std::string& provenance,
const std::string& usertext);
const std::string& provenance,
const std::string& usertext);

//
//
// Retrieve tag information of the data
//
void tagInfo(const std::string& recordName,
cond::TagInfo_t& result );

virtual ~PoolDBOutputService();
//
void tagInfo(const std::string& recordName, cond::TagInfo_t& result);

virtual ~PoolDBOutputService();

void forceInit();

private:

private:
//
//use these to control transaction interval
//
Expand All @@ -164,48 +163,41 @@ namespace cond{
void preModuleEvent(edm::StreamContext const&, edm::ModuleCallingContext const&);
void postModuleEvent(edm::StreamContext const&, edm::ModuleCallingContext const&);

struct Record{
Record(): m_tag(),
m_isNewTag(false),
m_idName(),
m_timetype(cond::runnumber),
m_closeIOV(false)
{}

std::string timetypestr() const { return cond::timeTypeSpecs[m_timetype].name;}
std::string m_tag;
bool m_isNewTag;
std::string m_idName;
cond::TimeType m_timetype;
bool m_closeIOV;
};
struct Record {
Record() : m_tag(), m_isNewTag(false), m_idName(), m_timetype(cond::runnumber), m_closeIOV(false) {}

std::string timetypestr() const { return cond::timeTypeSpecs[m_timetype].name; }
std::string m_tag;
bool m_isNewTag;
std::string m_idName;
cond::TimeType m_timetype;
bool m_closeIOV;
};

void fillRecord(edm::ParameterSet& pset);

void fillRecord( edm::ParameterSet & pset);

void connect();
void connect();
void disconnect();
void initDB( bool dummy=false );
void initDB(bool dummy = false);

Record & lookUpRecord(const std::string& recordName);
Record& lookUpRecord(const std::string& recordName);
cond::UserLogInfo& lookUpUserLogInfo(const std::string& recordName);

private:
std::recursive_mutex m_mutex;
cond::TimeType m_timetype;
cond::TimeType m_timetype;
std::string m_timetypestr;
std::vector<cond::Time_t> m_currentTimes;

cond::persistency::Session m_session;
bool m_dbstarted;

std::map<std::string, Record> m_callbacks;
std::vector< std::pair<std::string,std::string> > m_newtags;
std::vector<std::pair<std::string, std::string> > m_newtags;
bool m_closeIOV;
std::map<std::string, cond::UserLogInfo> m_logheaders;

};//PoolDBOutputService
}//ns service
}//ns cond
}; //PoolDBOutputService
} // namespace service
} // namespace cond
#endif

0 comments on commit f7bfb79

Please sign in to comment.