Skip to content

Commit

Permalink
Merge pull request cms-sw#23589 from ggovi/lhcinfo-o2o-1-10_2_X
Browse files Browse the repository at this point in the history
Changes for LHCInfo O2O
  • Loading branch information
cmsbuild committed Jun 19, 2018
2 parents 051c89e + 81b86e2 commit 84df0b0
Show file tree
Hide file tree
Showing 7 changed files with 854 additions and 466 deletions.
19 changes: 12 additions & 7 deletions CondFormats/RunInfo/interface/LHCInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class LHCInfo {

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, 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 TimeParamIndex { CREATE_TIME = 0, BEGIN_TIME = 1, END_TIME = 2, TSIZE =3};
enum StringParamIndex { INJECTION_SCHEME = 0, LHC_STATE = 1, LHC_COMMENT = 2, CTPPS_STATUS = 3, SSIZE =4};

typedef FillType FillTypeId;
typedef ParticleType ParticleTypeId;
LHCInfo();
LHCInfo( unsigned short const & lhcFill, bool const & fromData = true );
LHCInfo( const LHCInfo& rhs );
~LHCInfo();

LHCInfo* cloneFill() const;
Expand All @@ -33,14 +33,11 @@ class LHCInfo {
//constant static unsigned integer hosting the available number of LHC bunch slots
static size_t const availableBunchSlots = 2808;

//reset instance
void setFill( unsigned short const & lhcFill, bool const & fromData );
void setFillNumber( unsigned short lhcFill );

//getters
unsigned short const fillNumber() const;

bool const isData() const;

unsigned short const bunchesInBeam1() const;

unsigned short const bunchesInBeam2() const;
Expand Down Expand Up @@ -99,6 +96,14 @@ class LHCInfo {

std::vector<float> const & beam2RF() const;

std::vector<float>& beam1VC();

std::vector<float>& beam2VC();

std::vector<float>& beam1RF();

std::vector<float>& beam2RF();

//returns a boolean, true if the injection scheme has a leading 25ns
//TODO: parse the circulating bunch configuration, instead of the string.
bool is25nsBunchSpacing() const;
Expand Down Expand Up @@ -221,7 +226,7 @@ class LHCInfo {
void setBunchBitsetForBeam2( std::bitset<bunchSlots+1> const & bunchConfiguration );

private:
bool m_isData;
bool m_isData = false;
std::vector<std::vector<unsigned int> > m_intParams;
std::vector<std::vector<float> > m_floatParams;
std::vector<std::vector<unsigned long long> > m_timeParams;
Expand Down
86 changes: 49 additions & 37 deletions CondFormats/RunInfo/src/LHCInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,26 @@ static std::string particleTypeToString( LHCInfo::ParticleTypeId const & particl
return s_particleType;
}

LHCInfo::LHCInfo(): m_intParams( ISIZE )
, m_floatParams( FSIZE )
, m_timeParams( TSIZE )
, m_stringParams( SSIZE )
{
setFill(0, false);
LHCInfo::LHCInfo(){
m_intParams.resize( ISIZE, std::vector<unsigned int>(1,0) );
m_floatParams.resize( FSIZE, std::vector<float>(1, 0.) );
m_floatParams[ LUMI_PER_B ] = std::vector<float>();
m_floatParams[ BEAM1_VC ] = std::vector<float>();
m_floatParams[ BEAM2_VC ] = std::vector<float>();
m_floatParams[ BEAM1_RF ] = std::vector<float>();
m_floatParams[ BEAM2_RF ] = std::vector<float>();
m_timeParams.resize( TSIZE, std::vector<unsigned long long>(1,0ULL) );
m_stringParams.resize( SSIZE, std::vector<std::string>(1, "") );
m_stringParams[ INJECTION_SCHEME ].push_back( std::string("None") );
}

LHCInfo::LHCInfo( unsigned short const & lhcFill, bool const & fromData ): m_intParams( ISIZE )
, m_floatParams( FSIZE )
, m_timeParams( TSIZE )
, m_stringParams( SSIZE )
{
setFill(lhcFill, fromData);
LHCInfo::LHCInfo( const LHCInfo& rhs ):
m_intParams( rhs.m_intParams ),
m_floatParams( rhs.m_floatParams ),
m_timeParams( rhs.m_timeParams ),
m_stringParams( rhs.m_stringParams ),
m_bunchConfiguration1( rhs.m_bunchConfiguration1),
m_bunchConfiguration2( rhs.m_bunchConfiguration2){
}

LHCInfo::~LHCInfo() {
Expand All @@ -95,40 +101,30 @@ LHCInfo* LHCInfo::cloneFill() const {
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];
ret->m_floatParams[LUMI_PER_B] = m_floatParams[LUMI_PER_B];
for(size_t i=0;i<TSIZE; i++) ret->m_timeParams[i]=m_timeParams[i];
for(size_t i=0;i<LHC_STATE; i++) ret->m_stringParams[i]=m_stringParams[i];
ret->m_bunchConfiguration1=m_bunchConfiguration1;
ret->m_bunchConfiguration2=m_bunchConfiguration2;
}
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 ] = 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.);
m_floatParams[ BEAM2_VC ] = std::vector<float>(1, 0.);
m_floatParams[ BEAM1_RF ] = std::vector<float>(1, 0.);
m_floatParams[ BEAM2_RF ] = std::vector<float>(1, 0.);
m_timeParams.resize( TSIZE, std::vector<unsigned long long>(1,0ULL) );
m_stringParams.resize( SSIZE, std::vector<std::string>(1, "") );
m_stringParams[ INJECTION_SCHEME ].push_back( std::string("None") );
m_bunchConfiguration1.reset();
m_bunchConfiguration2.reset();
}

namespace LHCInfoImpl {
template <typename T> const T& getParams( const std::vector<T>& params, size_t index ){
if( index >= params.size() ) throw std::out_of_range("Parameter with index "+std::to_string(index)+" is out of range.");
return params[index];
}

template <typename T> T& accessParams( std::vector<T>& params, size_t index ){
if( index >= params.size() ) throw std::out_of_range("Parameter with index "+std::to_string(index)+" is out of range.");
return params[index];
}

template <typename T> const T& getOneParam( const std::vector< std::vector<T> >& params, size_t index ){
if( index >= params.size() ) throw std::out_of_range("Parameter with index "+std::to_string(index)+" is out of range.");
const std::vector<T>& inner = params[index];
if( inner.empty() ) throw std::out_of_range("Parameter with index "+std::to_string(index)+" has no value stored.");
if( inner.empty() ) throw std::out_of_range("Parameter with index "+std::to_string(index)+" type="+typeid(T).name()+" has no value stored.");
return inner[ 0 ];
}

Expand All @@ -149,10 +145,6 @@ unsigned short const LHCInfo::fillNumber() const {
return LHCInfoImpl::getOneParam( m_intParams, LHC_FILL );
}

bool const LHCInfo::isData() const {
return m_isData;
}

unsigned short const LHCInfo::bunchesInBeam1() const {
return LHCInfoImpl::getOneParam( m_intParams, BUNCHES_1 );
}
Expand Down Expand Up @@ -269,6 +261,22 @@ std::vector<float> const & LHCInfo::beam2RF() const {
return LHCInfoImpl::getParams(m_floatParams, BEAM2_RF );
}

std::vector<float>& LHCInfo::beam1VC(){
return LHCInfoImpl::accessParams(m_floatParams, BEAM1_VC );
}

std::vector<float>& LHCInfo::beam2VC(){
return LHCInfoImpl::accessParams(m_floatParams, BEAM2_VC );
}

std::vector<float>& LHCInfo::beam1RF(){
return LHCInfoImpl::accessParams(m_floatParams, BEAM1_RF );
}

std::vector<float>& LHCInfo::beam2RF(){
return LHCInfoImpl::accessParams(m_floatParams, BEAM2_RF );
}

//returns a boolean, true if the injection scheme has a leading 25ns
//TODO: parse the circulating bunch configuration, instead of the string.
bool LHCInfo::is25nsBunchSpacing() const {
Expand Down Expand Up @@ -298,6 +306,10 @@ std::vector<unsigned short> LHCInfo::bunchConfigurationForBeam2() const {
return bitsetToVector( m_bunchConfiguration2 );
}

void LHCInfo::setFillNumber( unsigned short lhcFill ) {
LHCInfoImpl::setOneParam( m_intParams, LHC_FILL, static_cast<unsigned int>(lhcFill) );
}

//setters
void LHCInfo::setBunchesInBeam1( unsigned short const & bunches ) {
LHCInfoImpl::setOneParam( m_intParams, BUNCHES_1, static_cast<unsigned int>(bunches) );
Expand Down Expand Up @@ -505,7 +517,7 @@ void LHCInfo::print( std::stringstream & ss ) const {
<< "LHC State: " << this->lhcState() << std::endl
<< "LHC Comments: " << this->lhcComment() << std::endl
<< "CTPPS Status: " << this->ctppsStatus() << std::endl
<< "Lumi sections: " << this->lumiSection() << std::endl;
<< "Lumi section: " << this->lumiSection() << std::endl;

ss << "Luminosity per bunch (total " << this->lumiPerBX().size() << "): ";
std::copy( this->lumiPerBX().begin(), this->lumiPerBX().end(), std::ostream_iterator<float>( ss, ", " ) );
Expand Down
22 changes: 12 additions & 10 deletions CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfo>{
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 );
void addEmptyPayload( cond::Time_t iov );
bool getNextFillData( cond::persistency::Session& session, const boost::posix_time::ptime& targetTime, bool ended );
bool getFillData( cond::persistency::Session& session, unsigned short fillId );
size_t getLumiData( cond::persistency::Session& session, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime );
bool getDipData( cond::persistency::Session& session, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime );
bool getCTTPSData( cond::persistency::Session& session, const boost::posix_time::ptime& beginFillTime, const boost::posix_time::ptime& endFillTime );
bool getEcalData( cond::persistency::Session& session, const boost::posix_time::ptime& lowerTime, const boost::posix_time::ptime& upperTime, bool update );

private:
bool m_debug;
Expand All @@ -31,11 +29,15 @@ class LHCInfoPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfo>{
boost::posix_time::ptime m_endTime;
// sampling interval in seconds
unsigned int m_samplingInterval;
bool m_endFill = true;
std::string m_name;
//for reading from relational database source
std::string m_connectionString, m_ecalConnectionString;
std::string m_dipSchema, m_authpath;
std::vector<std::unique_ptr<LHCInfo> > m_payloadBuffer;
std::unique_ptr<LHCInfo> m_fillPayload;
std::shared_ptr<LHCInfo> m_prevPayload;
std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > > m_tmpBuffer;
std::vector<std::shared_ptr<LHCInfo> > m_payloadBuffer;
bool m_lastPayloadEmpty = false;
};

Expand Down
6 changes: 3 additions & 3 deletions CondTools/RunInfo/python/LHCInfoPopConAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
record = cms.string('LHCInfoRcd'),
name = cms.untracked.string('LHCInfo'),
Source = cms.PSet(fill = cms.untracked.uint32(6417),
startTime = cms.untracked.string('2018-04-01 00:00:00.000'),
#endTime = cms.untracked.string('2018-03-25 05:00:00.000'),
startTime = cms.untracked.string('2018-05-31 00:00:00.000'),
#endTime = cms.untracked.string('2018-05-31 20:13:59.000'),
samplingInterval = cms.untracked.uint32( 600 ),
endFill = cms.untracked.bool(True),
connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"),
ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"),
DIPSchema = cms.untracked.string("CMS_BEAM_COND"),
#authenticationPath = cms.untracked.string("."),
debug=cms.untracked.bool(False)
),
loggingOn = cms.untracked.bool(True),
Expand Down
86 changes: 86 additions & 0 deletions CondTools/RunInfo/python/LHCInfoPopConAnalyzerEndFill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import socket
import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing
process = cms.Process("LHCInfoPopulator")
from CondCore.CondDB.CondDB_cfi import *
#process.load("CondCore.DBCommon.CondDBCommon_cfi")
#process.CondDBCommon.connect = 'sqlite_file:lhcinfo_pop_test.db'
#process.CondDBCommon.DBParameters.authenticationPath = '.'
#process.CondDBCommon.DBParameters.messageLevel=cms.untracked.int32(1)

sourceConnection = 'oracle://cms_omds_adg/CMS_RUNINFO_R'
if socket.getfqdn().find('.cms') != -1:
sourceConnection = 'oracle://cms_omds_lb/CMS_RUNINFO_R'

options = VarParsing.VarParsing()
options.register( 'destinationConnection'
, 'sqlite_file:lhcinfo_pop_test.db' #default value
, VarParsing.VarParsing.multiplicity.singleton
, VarParsing.VarParsing.varType.string
, "Connection string to the DB where payloads will be possibly written."
)
options.register( 'targetConnection'
, '' #default value
, VarParsing.VarParsing.multiplicity.singleton
, VarParsing.VarParsing.varType.string
, """Connection string to the target DB:
if not empty (default), this provides the latest IOV and payloads to compare;
it is the DB where payloads should be finally uploaded."""
)
options.register( 'tag'
, 'LHCInfo_PopCon_test'
, VarParsing.VarParsing.multiplicity.singleton
, VarParsing.VarParsing.varType.string
, "Tag written in destinationConnection and finally appended in targetConnection."
)
options.register( 'messageLevel'
, 0 #default value
, VarParsing.VarParsing.multiplicity.singleton
, VarParsing.VarParsing.varType.int
, "Message level; default to 0"
)
options.parseArguments()

CondDBConnection = CondDB.clone( connect = cms.string( options.destinationConnection ) )
CondDBConnection.DBParameters.messageLevel = cms.untracked.int32( options.messageLevel )

process.MessageLogger = cms.Service("MessageLogger",
cout = cms.untracked.PSet(threshold = cms.untracked.string('INFO')),
destinations = cms.untracked.vstring('cout')
)

process.source = cms.Source("EmptyIOVSource",
lastValue = cms.uint64(1),
timetype = cms.string('runnumber'),
firstValue = cms.uint64(1),
interval = cms.uint64(1)
)

process.PoolDBOutputService = cms.Service("PoolDBOutputService",
CondDBConnection,
timetype = cms.untracked.string('timestamp'),
toPut = cms.VPSet(cms.PSet(record = cms.string('LHCInfoRcd'),
tag = cms.string( options.tag )
)
)
)

process.Test1 = cms.EDAnalyzer("LHCInfoPopConAnalyzer",
SinceAppendMode = cms.bool(True),
record = cms.string('LHCInfoRcd'),
name = cms.untracked.string('LHCInfo'),
Source = cms.PSet(fill = cms.untracked.uint32(6417),
startTime = cms.untracked.string('2018-05-31 00:00:00.000'),
#endTime = cms.untracked.string('2018-05-31 20:13:59.000'),
samplingInterval = cms.untracked.uint32( 600 ),
endFill = cms.untracked.bool(True),
connectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_RUNTIME_LOGGER"),
ecalConnectionString = cms.untracked.string("oracle://cms_orcon_adg/CMS_DCS_ENV_PVSS_COND"),
DIPSchema = cms.untracked.string("CMS_BEAM_COND"),
debug=cms.untracked.bool(False)
),
loggingOn = cms.untracked.bool(True),
IsDestDbCheckedInQueryLog = cms.untracked.bool(False)
)

process.p = cms.Path(process.Test1)
Loading

0 comments on commit 84df0b0

Please sign in to comment.