Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced synchronization types according to the new policy. #11959

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions CondCore/CondDB/interface/Session.h
Expand Up @@ -104,11 +104,11 @@ namespace cond {
template <typename T>
IOVEditor createIov( const std::string& tag,
cond::TimeType timeType,
cond::SynchronizationType synchronizationType=cond::OFFLINE );
cond::SynchronizationType synchronizationType=cond::SYNCH_ANY );
IOVEditor createIov( const std::string& payloadType,
const std::string& tag,
cond::TimeType timeType,
cond::SynchronizationType synchronizationType=cond::OFFLINE );
cond::SynchronizationType synchronizationType=cond::SYNCH_ANY );

IOVEditor createIov( const std::string& payloadType,
const std::string& tag,
Expand All @@ -118,7 +118,7 @@ namespace cond {

IOVEditor createIovForPayload( const Hash& payloadHash,
const std::string& tag, cond::TimeType timeType,
cond::SynchronizationType synchronizationType=cond::OFFLINE );
cond::SynchronizationType synchronizationType=cond::SYNCH_ANY );

void clearIov( const std::string& tag );

Expand Down
14 changes: 9 additions & 5 deletions CondCore/CondDB/interface/Types.h
Expand Up @@ -29,11 +29,15 @@ namespace cond {
"Validated" };

typedef enum {
SYNCHRONIZATION_UNKNOWN = -1,
OFFLINE=0,
HLT,
PROMPT,
PCL
SYNCH_ANY = 0,
SYNCH_VALIDATION,
SYNCH_OFFLINE,
SYNCH_MC,
SYNCH_RUNMC,
SYNCH_HLT,
SYNCH_EXPRESS,
SYNCH_PROMPT,
SYNCH_PCL
} SynchronizationType;

std::string synchronizationTypeNames( SynchronizationType type );
Expand Down
26 changes: 23 additions & 3 deletions CondCore/CondDB/src/IOVEditor.cc
Expand Up @@ -13,14 +13,14 @@ namespace cond {
tag( "" ),
timeType( cond::invalid ),
payloadType(""),
synchronizationType( cond::OFFLINE ),
synchronizationType( cond::SYNCH_ANY ),
description(""),
iovBuffer(){
}
std::string tag;
cond::TimeType timeType;
std::string payloadType;
cond::SynchronizationType synchronizationType = cond::OFFLINE;
cond::SynchronizationType synchronizationType;
std::string description;
cond::Time_t endOfValidity = cond::time::MAX_VAL;
cond::Time_t lastValidatedTime = cond::time::MIN_VAL;
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace cond {
}

cond::SynchronizationType IOVEditor::synchronizationType() const {
return m_data.get()? m_data->synchronizationType : cond::SYNCHRONIZATION_UNKNOWN ;
return m_data.get()? m_data->synchronizationType : cond::SYNCH_ANY ;
}

cond::Time_t IOVEditor::endOfValidity() const {
Expand Down Expand Up @@ -146,6 +146,10 @@ namespace cond {
m_data->iovBuffer.push_back( std::tie( since, payloadHash, insertionTime ) );
}
}

bool iovSorter( const std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime>& f, const std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime>& s ){
return std::get<0>(f) < std::get<0>(s);
}

bool IOVEditor::flush( const boost::posix_time::ptime& operationTime ){
bool ret = false;
Expand All @@ -167,6 +171,22 @@ namespace cond {
m_data->change = false;
}
if( m_data->iovBuffer.size() ) {

std::sort(m_data->iovBuffer.begin(),m_data->iovBuffer.end(),iovSorter);
cond::Time_t l = std::get<0>(m_data->iovBuffer.front());
if( m_data->synchronizationType != cond::SYNCH_ANY && m_data->synchronizationType != cond::SYNCH_VALIDATION ){
// retrieve the last since
cond::Time_t last = 0;
cond::Hash h;
m_session->iovSchema().iovTable().getLastIov( m_data->tag, last, h );
// check if the min iov is greater then the last since
if( l <= last ){
std::stringstream msg;
msg << "Can't insert iov since "<<l<<" on the tag "<< m_data->tag<<": last since is "<<last<<
" and synchronization is \""<<cond::synchronizationTypeNames( m_data->synchronizationType )<<"\"";
throwException( msg.str(),"IOVEditor::flush");
}
}

// insert the new iovs
m_session->iovSchema().iovTable().insertMany( m_data->tag, m_data->iovBuffer );
Expand Down
4 changes: 2 additions & 2 deletions CondCore/CondDB/src/IOVProxy.cc
Expand Up @@ -19,7 +19,7 @@ namespace cond {
boost::posix_time::ptime snapshotTime;
cond::TimeType timeType;
std::string payloadType;
cond::SynchronizationType synchronizationType = cond::OFFLINE;
cond::SynchronizationType synchronizationType;
cond::Time_t endOfValidity;
cond::Time_t lastValidatedTime;
// iov data
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace cond {
}

cond::SynchronizationType IOVProxy::synchronizationType() const {
return m_data.get() ? m_data->synchronizationType : cond::SYNCHRONIZATION_UNKNOWN;
return m_data.get() ? m_data->synchronizationType : cond::SYNCH_ANY;
}

cond::Time_t IOVProxy::endOfValidity() const {
Expand Down
17 changes: 11 additions & 6 deletions CondCore/CondDB/src/Types.cc
Expand Up @@ -29,18 +29,23 @@ namespace cond {
lastValidatedTime = time::MIN_VAL;
}

static std::pair<const char *, SynchronizationType> s_synchronizationTypeArray[] = { std::make_pair("Offline", OFFLINE),
std::make_pair("HLT", HLT),
std::make_pair("Prompt", PROMPT),
std::make_pair("PCL", PCL) };
static std::pair<const char *, SynchronizationType> s_synchronizationTypeArray[] = { std::make_pair("any", SYNCH_ANY),
std::make_pair("validation", SYNCH_VALIDATION),
std::make_pair("offline", SYNCH_OFFLINE),
std::make_pair("mc", SYNCH_MC),
std::make_pair("runmc", SYNCH_RUNMC),
std::make_pair("hlt", SYNCH_HLT),
std::make_pair("express", SYNCH_EXPRESS),
std::make_pair("prompt", SYNCH_PROMPT),
std::make_pair("pcl", SYNCH_PCL) };

std::string synchronizationTypeNames(SynchronizationType type) {
return s_synchronizationTypeArray[type].first;
}

SynchronizationType synchronizationTypeFromName( const std::string& name ){
for (auto const &i : s_synchronizationTypeArray)
if (name.compare(i.first))
return i.second;
if (name.compare(i.first)==0) return i.second;
throwException( "SynchronizationType \""+name+"\" is unknown.","synchronizationTypeFromName");
}

Expand Down
2 changes: 2 additions & 0 deletions CondCore/CondDB/test/BuildFile.xml
Expand Up @@ -11,6 +11,8 @@
<bin file="testReadWritePayloads.cpp" name="testReadWritePayloads">
</bin>

<bin file="testConditionDatabase_0.cpp" name="testConditionDatabase_0">
</bin>
<bin file="testConditionDatabase_1.cpp" name="testConditionDatabase_1">
</bin>

Expand Down
28 changes: 27 additions & 1 deletion CondCore/CondDB/test/testConditionDatabase_0.cpp
Expand Up @@ -37,7 +37,7 @@ int run( const std::string& connectionString ){

IOVEditor editor;
if( !session.existsIov( "MyNewIOV" ) ){
editor = session.createIov<MyTestData>( "MyNewIOV", cond::runnumber );
editor = session.createIov<MyTestData>( "MyNewIOV", cond::runnumber, cond::SYNCH_OFFLINE );
editor.setDescription("Test with MyTestData class");
editor.insert( 1, p0 );
editor.insert( 100, p1 );
Expand All @@ -54,8 +54,34 @@ int run( const std::string& connectionString ){
editor.flush();
}

bool isOra = session.isOraSession();
session.transaction().commit();
std::cout <<"> iov changes committed!..."<<std::endl;

if ( !isOra ){
session.transaction().start( false );
std::cout <<"## now trying to insert in the past..."<<std::endl;
try{
editor = session.editIov( "MyNewIOV" );
editor.insert( 200, p1 );
editor.insert( 300, p1 );
editor.insert( 50, p1 );
editor.flush();
std::cout <<"ERROR: forbidden insertion."<<std::endl;
session.transaction().commit();
} catch ( const cond::persistency::Exception& e ){
std::cout <<"Expected error: "<<e.what()<<std::endl;
session.transaction().rollback();
}
session.transaction().start( false );
editor = session.editIov( "StringData" );
editor.insert( 3000000, p3 );
editor.insert( 4000000, p3 );
editor.insert( 1500000, p3);
editor.flush();
std::cout <<"Insertion in the past completed."<<std::endl;
session.transaction().commit();
}
::sleep(2);
session.transaction().start();

Expand Down
4 changes: 2 additions & 2 deletions CondCore/DBOutputService/src/PoolDBOutputService.cc
Expand Up @@ -222,7 +222,7 @@ cond::service::PoolDBOutputService::createNewIOV( const std::string& firstPayloa

try{
// FIX ME: synchronization type and description have to be passed as the other parameters?
cond::persistency::IOVEditor editor = m_session.createIov( payloadType, myrecord.m_tag, myrecord.m_timetype, cond::OFFLINE );
cond::persistency::IOVEditor editor = m_session.createIov( payloadType, myrecord.m_tag, myrecord.m_timetype, cond::SYNCH_ANY );
editor.setDescription( "New Tag" );
editor.insert( firstSinceTime, firstPayloadId );
editor.flush();
Expand Down Expand Up @@ -264,7 +264,7 @@ cond::service::PoolDBOutputService::createNewIOV( const std::string& firstPayloa
std::string payloadType("");
try{
// FIX ME: synchronization type and description have to be passed as the other parameters?
cond::persistency::IOVEditor editor = m_session.createIovForPayload( firstPayloadId, myrecord.m_tag, myrecord.m_timetype, cond::OFFLINE );
cond::persistency::IOVEditor editor = m_session.createIovForPayload( firstPayloadId, myrecord.m_tag, myrecord.m_timetype, cond::SYNCH_ANY );
editor.setDescription( "New Tag" );
payloadType = editor.payloadType();
editor.insert( firstSinceTime, firstPayloadId );
Expand Down