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

Enabling time-based sampling in LHCInfo O2O #23068

Merged
merged 2 commits into from May 2, 2018
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
21 changes: 18 additions & 3 deletions CondFormats/RunInfo/interface/LHCInfo.h
Expand Up @@ -15,7 +15,7 @@ class LHCInfo {
enum ParticleType { NONE = 0, PROTON = 1, PB82 = 2, AR18 = 3, D = 4, XE54 = 5 };

enum IntParamIndex { LHC_FILL = 0, BUNCHES_1 = 1, BUNCHES_2 = 2, COLLIDING_BUNCHES = 3, TARGET_BUNCHES = 4, FILL_TYPE = 5, PARTICLES_1 = 6, PARTICLES_2 = 7, LUMI_SECTION = 8, ISIZE = 9 };
enum FloatParamIndex { CROSSING_ANGLE = 0, BETA_STAR = 1, INTENSITY_1 = 2, INTENSITY_2 = 3, ENERGY = 4, DELIV_LUMI = 5, REC_LUMI = 7, LUMI_PER_B = 8, BEAM1_VC = 9, BEAM2_VC = 10, BEAM1_RF = 11, BEAM2_RF = 12, FSIZE = 13};
enum FloatParamIndex { CROSSING_ANGLE = 0, BETA_STAR = 1, INTENSITY_1 = 2, INTENSITY_2 = 3, ENERGY = 4, DELIV_LUMI = 5, REC_LUMI = 7, LUMI_PER_B = 8, BEAM1_VC = 9, BEAM2_VC = 10, BEAM1_RF = 11, BEAM2_RF = 12, INST_LUMI = 13, INST_LUMI_ERR = 14, FSIZE = 15};
enum TimeParamIndex { CREATE_TIME = 0, BEGIN_TIME = 1, END_TIME = 2, DIP_TIME = 3, TSIZE =4};
enum StringParamIndex { INJECTION_SCHEME = 0, LHC_STATE = 1, LHC_COMMENT = 2, CTPPS_STATUS = 3, SSIZE =4};

Expand All @@ -24,6 +24,8 @@ class LHCInfo {
LHCInfo();
LHCInfo( unsigned short const & lhcFill, bool const & fromData = true );
~LHCInfo();

LHCInfo* cloneFill() const;

//constant static unsigned integer hosting the maximum number of LHC bunch slots
static size_t const bunchSlots = 3564;
Expand Down Expand Up @@ -66,6 +68,10 @@ class LHCInfo {
float const delivLumi() const;

float const recLumi() const;

float const instLumi() const;

float const instLumiError() const;

cond::Time_t const createTime() const;

Expand Down Expand Up @@ -136,6 +142,10 @@ class LHCInfo {

void setRecLumi( float const & recLumi );

void setInstLumi( float const& instLumi );

void setInstLumiError( float const& instLumiError );

void setCreationTime( cond::Time_t const & createTime );

void setBeginTime( cond::Time_t const & beginTime );
Expand Down Expand Up @@ -177,6 +187,8 @@ class LHCInfo {
,float const & energy
,float const & delivLumi
,float const & recLumi
,float const & instLumi
,float const & instLumiError
,cond::Time_t const & createTime
,cond::Time_t const & beginTime
,cond::Time_t const & endTime
Expand All @@ -192,11 +204,14 @@ class LHCInfo {
,std::vector<float> const & beam2RF
,std::bitset<bunchSlots+1> const & bunchConf1
,std::bitset<bunchSlots+1> const & bunchConf2 );


bool equals( const LHCInfo& rhs ) const;

bool empty() const;

//dumping values on output stream
void print(std::stringstream & ss) const;

protected:
std::bitset<bunchSlots+1> const & bunchBitsetForBeam1() const;

std::bitset<bunchSlots+1> const & bunchBitsetForBeam2() const;
Expand Down
56 changes: 53 additions & 3 deletions CondFormats/RunInfo/src/LHCInfo.cc
Expand Up @@ -86,13 +86,26 @@ LHCInfo::LHCInfo( unsigned short const & lhcFill, bool const & fromData ): m_int
setFill(lhcFill, fromData);
}

LHCInfo::~LHCInfo() {}
LHCInfo::~LHCInfo() {
}

LHCInfo* LHCInfo::cloneFill() const {
LHCInfo* ret = new LHCInfo();
ret->m_isData = m_isData;
if( !m_intParams[0].empty()){
for(size_t i=0;i<LUMI_SECTION; i++) ret->m_intParams[i]=m_intParams[i];
for(size_t i=0;i<DELIV_LUMI; i++) ret->m_floatParams[i]=m_floatParams[i];
for(size_t i=0;i<DIP_TIME; i++) ret->m_timeParams[i]=m_timeParams[i];
for(size_t i=0;i<LHC_STATE; i++) ret->m_stringParams[i]=m_stringParams[i];
}
return ret;
}

//reset instance
void LHCInfo::setFill( unsigned short const & lhcFill, bool const & fromData ) {
m_isData = fromData;
m_intParams.resize( ISIZE, std::vector<unsigned int>(1,0) );
m_intParams[ LHC_FILL ].push_back( lhcFill );
m_intParams[ LHC_FILL ] = std::vector<unsigned int>(1,lhcFill);
m_floatParams.resize( FSIZE, std::vector<float>(1,0.));
m_floatParams[ LUMI_PER_B ] = std::vector<float>(1, 0.);
m_floatParams[ BEAM1_VC ] = std::vector<float>(1, 0.);
Expand Down Expand Up @@ -133,7 +146,7 @@ namespace LHCInfoImpl {

//getters
unsigned short const LHCInfo::fillNumber() const {
return LHCInfoImpl::getOneParam( m_intParams, LHC_FILL );
return LHCInfoImpl::getOneParam( m_intParams, LHC_FILL );
}

bool const LHCInfo::isData() const {
Expand Down Expand Up @@ -196,6 +209,14 @@ float const LHCInfo::recLumi() const {
return LHCInfoImpl::getOneParam( m_floatParams, REC_LUMI );
}

float const LHCInfo::instLumi() const {
return LHCInfoImpl::getOneParam( m_floatParams, INST_LUMI );
}

float const LHCInfo::instLumiError() const {
return LHCInfoImpl::getOneParam( m_floatParams, INST_LUMI_ERR );
}

cond::Time_t const LHCInfo::createTime() const {
return LHCInfoImpl::getOneParam( m_timeParams, CREATE_TIME );
}
Expand Down Expand Up @@ -334,6 +355,14 @@ void LHCInfo::setRecLumi( float const & recLumi ) {
LHCInfoImpl::setOneParam( m_floatParams, REC_LUMI, recLumi );
}

void LHCInfo::setInstLumi( float const & instLumi ) {
LHCInfoImpl::setOneParam( m_floatParams, INST_LUMI, instLumi );
}

void LHCInfo::setInstLumiError( float const & instLumiError ) {
LHCInfoImpl::setOneParam( m_floatParams, INST_LUMI_ERR, instLumiError );
}

void LHCInfo::setCreationTime( cond::Time_t const & createTime ) {
LHCInfoImpl::setOneParam( m_timeParams, CREATE_TIME, createTime );
}
Expand Down Expand Up @@ -401,6 +430,8 @@ void LHCInfo::setInfo( unsigned short const & bunches1
,float const & energy
,float const & delivLumi
,float const & recLumi
,float const & instLumi
,float const & instLumiError
,cond::Time_t const & createTime
,cond::Time_t const & beginTime
,cond::Time_t const & endTime
Expand Down Expand Up @@ -430,6 +461,8 @@ void LHCInfo::setInfo( unsigned short const & bunches1
this->setEnergy( energy );
this->setDelivLumi( delivLumi );
this->setRecLumi( recLumi );
this->setInstLumi( instLumi );
this->setInstLumiError( instLumiError );
this->setCreationTime( createTime );
this->setBeginTime( beginTime );
this->setEndTime( endTime );
Expand Down Expand Up @@ -463,6 +496,8 @@ void LHCInfo::print( std::stringstream & ss ) const {
<< "Energy (GeV): " << this->energy() << std::endl
<< "Delivered Luminosity (max): " << this->delivLumi() << std::endl
<< "Recorded Luminosity (max): " << this->recLumi() << std::endl
<< "Instantaneous Luminosity: " << this->instLumi() << std::endl
<< "Instantaneous Luminosity Error: " << this->instLumiError() << std::endl
<< "Creation time of the fill: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( this->createTime() ) ) << std::endl
<< "Begin time of Stable Beam flag: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( this->beginTime() ) ) << std::endl
<< "End time of the fill: " << boost::posix_time::to_iso_extended_string( cond::time::to_boost( this->endTime() ) ) << std::endl
Expand Down Expand Up @@ -526,3 +561,18 @@ std::ostream & operator<<( std::ostream & os, LHCInfo beamInfo ) {
os << ss.str();
return os;
}

bool LHCInfo::equals( const LHCInfo& rhs ) const {
if( m_isData != rhs.m_isData ) return false;
if( m_intParams != rhs.m_intParams ) return false;
if( m_floatParams != rhs.m_floatParams ) return false;
if( m_timeParams != rhs.m_timeParams ) return false;
if( m_stringParams != rhs.m_stringParams ) return false;
if( m_bunchConfiguration1 != rhs.m_bunchConfiguration1 ) return false;
if( m_bunchConfiguration2 != rhs.m_bunchConfiguration2 ) return false;
return true;
}

bool LHCInfo::empty() const {
return m_intParams[0].empty();
}
4 changes: 4 additions & 0 deletions CondTools/RunInfo/bin/BuildFile.xml
Expand Up @@ -4,3 +4,7 @@
<use name="CondCore/Utilities"/>
<use name="CondCore/CondDB"/>
</bin>
<bin file="conddb_dump_LHCInfo.cpp" name="conddb_dump_LHCInfo">
<use name="CondCore/Utilities"/>
<use name="CondCore/CondDB"/>
</bin>
97 changes: 97 additions & 0 deletions CondTools/RunInfo/bin/conddb_dump_LHCInfo.cpp
@@ -0,0 +1,97 @@
#include "CondCore/Utilities/interface/Utilities.h"
#include "CondCore/CondDB/interface/ConnectionPool.h"
#include "CondFormats/RunInfo/interface/LHCInfo.h"

//#include <boost/program_options.hpp>
#include <fstream>
#include <iostream>
#include <stdexcept>

namespace cond {
class Dump_LHCInfo : public Utilities {
public:
Dump_LHCInfo();
~Dump_LHCInfo() override;
int execute() override;
};
}

cond::Dump_LHCInfo::Dump_LHCInfo():Utilities("conddb_dump_LHCInfo"){
addConnectOption("connect","c","source connection string (optional, default=connect)");
addOption<std::string>("tag","t","the source tag");
addOption<std::string>("hash","i","the hash (id) of the payload to dump");
addOption<cond::Time_t>("since","s","since time of the iov");
}

cond::Dump_LHCInfo::~Dump_LHCInfo(){
}

namespace Dump_LHCInfo_impl {
void dump( const LHCInfo& payload, std::ostream& out ){
std::stringstream ss;
payload.print( ss );
out <<ss.str();
out <<std::endl;
}
}

int cond::Dump_LHCInfo::execute(){

std::string connect = getOptionValue<std::string>("connect");
std::string tag("");

cond::persistency::ConnectionPool connection;
connection.setMessageVerbosity( coral::Error );
connection.configure();

cond::Hash payloadHash("");
cond::Time_t since=0;
if(hasOptionValue("hash")) {
payloadHash = getOptionValue<std::string>("hash");
} else {
if(hasOptionValue("tag")){
tag = getOptionValue<std::string>("tag");
} else {
std::cout <<"Error: no tag provided to identify the payload."<<std::endl;
return 1;
}
if(hasOptionValue("since")){
since = getOptionValue<cond::Time_t>("since");
} else {
std::cout <<"Error: no IOV since provided to identify the payload."<<std::endl;
return 1;
}
}

cond::persistency::Session session = connection.createSession( connect, false );
session.transaction().start(true);

if( payloadHash.empty() ){
cond::persistency::IOVProxy iovSeq = session.readIov( tag );
auto it = iovSeq.find( since );
if( it == iovSeq.end() ){
std::cout <<"Could not find iov with since="<<since<<" in tag "<<tag<<std::endl;
session.transaction().commit();
return 2;
}
payloadHash = (*it).payloadId;
}

std::shared_ptr<LHCInfo> payload = session.fetchPayload<LHCInfo>( payloadHash );
session.transaction().commit();

std::cout <<"# *********************************************************** "<<std::endl;
std::cout <<"# Dumping payload id "<<payloadHash<<std::endl;
std::cout <<"# *********************************************************** "<<std::endl;

Dump_LHCInfo_impl::dump( *payload,std::cout );

std::cout <<"# *********************************************************** "<<std::endl;
return 0;
}

int main( int argc, char** argv ){

cond::Dump_LHCInfo utilities;
return utilities.run(argc,argv);
}
25 changes: 21 additions & 4 deletions CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h
Expand Up @@ -13,13 +13,30 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfo>{
~LHCInfoPopConSourceHandler() override;
void getNewObjects() override;
std::string id() const override;

private:
void addEmptyPayload( cond::Time_t iov );
void addPayload( LHCInfo& newPayload, cond::Time_t iov );
bool getFillData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, bool next, LHCInfo& payload );
bool getCurrentFillData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, LHCInfo& payload );
bool getNextFillData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, LHCInfo& payload );
bool getLumiData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, LHCInfo& payload );
bool getDipData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, LHCInfo& payload );
bool getCTTPSData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, LHCInfo& payload );
bool getEcalData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, LHCInfo& payload );

private:
bool m_debug;
unsigned short m_firstFill, m_lastFill;
// starting date for sampling
boost::posix_time::ptime m_startTime;
boost::posix_time::ptime m_endTime;
// sampling interval in seconds
unsigned int m_samplingInterval;
std::string m_name;
//for reading from relational database source
std::string m_connectionString, m_dipSchema, m_authpath;
};
std::string m_connectionString, m_ecalConnectionString;
std::string m_dipSchema, m_authpath;
std::vector<std::unique_ptr<LHCInfo> > m_payloadBuffer;
bool m_lastPayloadEmpty = false;
};

#endif