Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New template analyzer for dealing with B ON/OFF transitions using Eve…
…ntSetup and PoolDBOutputService. An example is provided for EcalADCToGeVConstant.
- Loading branch information
Salvatore Di Guida
committed
Sep 28, 2016
1 parent
d79b60d
commit f0cc358
Showing
4 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef BTRANSITIONANALYZER_H | ||
#define BTRANSITIONANALYZER_H | ||
|
||
#include "FWCore/Framework/interface/one/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/Run.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/ServiceRegistry/interface/Service.h" | ||
#include "CondCore/CondDB/interface/Utils.h" | ||
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" | ||
#include "CondFormats/RunInfo/interface/RunInfo.h" | ||
#include "CondFormats/DataRecord/interface/RunSummaryRcd.h" | ||
|
||
namespace cond { | ||
template<class T, class R> | ||
class BTransitionAnalyzer: public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> { | ||
public: | ||
BTransitionAnalyzer( const edm::ParameterSet& pset ): | ||
m_currentThreshold( pset.getUntrackedParameter<double>( "currentThreshold", 18000. ) ) { | ||
usesResource( "PoolDBOutputService" ); | ||
} | ||
#ifdef __INTEL_COMPILER | ||
virtual ~BTransitionAnalyzer() = default; | ||
#endif | ||
// implicit copy constructor | ||
// implicit assignment operator | ||
// implicit destructor | ||
virtual void beginJob() final {}; | ||
virtual void beginRun(edm::Run const&, edm::EventSetup const&) final {}; | ||
virtual void analyze(edm::Event const&, edm::EventSetup const&) final {}; | ||
virtual void endRun(edm::Run const& run , edm::EventSetup const& eventSetup) final { | ||
edm::ESHandle<RunInfo> runInfoHandle; | ||
edm::ESHandle<T> payloadHandle, payloadRefHandle; | ||
eventSetup.get<RunInfoRcd>().get(runInfoHandle); | ||
double avg_current = (double)runInfoHandle->m_avg_current; | ||
double current_default = -1; | ||
std::string bOnLabel = std::string( "38T" ); | ||
std::string bOffLabel = std::string( "0T" ); | ||
std::string bFieldLabel = bOnLabel; | ||
LogDebug( "BTransitionAnalyzer" ) << "Comparing value of magnet current: " << avg_current << " A for run: " << run.run() | ||
<< " with the corresponding threshold: "<< m_currentThreshold << " A." << std::endl; | ||
if( avg_current != current_default && avg_current <= m_currentThreshold ) bFieldLabel = bOffLabel; | ||
edm::LogInfo( "BTransitionAnalyzer" ) << "The magnet was " | ||
<< ( bFieldLabel == bOnLabel ? "ON" : "OFF" ) << " during run " << run.run() | ||
<< ".\nLoading the product for the corrisponding label " << bFieldLabel << std::endl; | ||
eventSetup.get<R>().get( bFieldLabel, payloadHandle ); | ||
eventSetup.get<R>().get( payloadRefHandle ); | ||
edm::Service<cond::service::PoolDBOutputService> mydbservice; | ||
if( mydbservice.isAvailable() ) { | ||
if( !equalPayloads( payloadHandle, payloadRefHandle ) ) { | ||
edm::LogInfo( "BTransitionAnalyzer" ) << "Exporting payload corresponding to the calibrations for magnetic field " | ||
<< ( bFieldLabel == bOnLabel ? "ON" : "OFF" ) | ||
<< " starting from run number: " << run.run() << std::endl; | ||
mydbservice->writeOne( payloadHandle.product(), run.run(), demangledName( typeid(R) ) ); | ||
} else { | ||
edm::LogInfo( "BTransitionAnalyzer" ) << "The payload corresponding to the calibrations for magnetic field " | ||
<< ( bFieldLabel == bOnLabel ? "ON" : "OFF" ) | ||
<< " is still valid for run " << run.run() | ||
<< ".\nNo transfer needed." << std::endl; | ||
} | ||
} else { | ||
edm::LogError( "BTransitionAnalyzer" ) << "PoolDBOutputService unavailable"; | ||
} | ||
} | ||
virtual void endJob() final {}; | ||
virtual bool equalPayloads( edm::ESHandle<T> const & payloadHandle, edm::ESHandle<T> const & payloadRefHandle ) = 0; | ||
private: | ||
double m_currentThreshold; | ||
}; | ||
} //namespace cond | ||
#endif //BTRANSITIONANALYZER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
CondTools/Ecal/plugins/EcalADCToGeVConstantBTransitionAnalyzer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "CondCore/DBOutputService/interface/BTransitionAnalyzer.h" | ||
#include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h" | ||
#include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h" | ||
#include <sstream> | ||
|
||
class EcalADCToGeVConstantBTransitionAnalyzer: public cond::BTransitionAnalyzer<EcalADCToGeVConstant, EcalADCToGeVConstantRcd> { | ||
public: | ||
EcalADCToGeVConstantBTransitionAnalyzer( edm::ParameterSet const & pset ): | ||
cond::BTransitionAnalyzer<EcalADCToGeVConstant, EcalADCToGeVConstantRcd>( pset ) {} | ||
bool equalPayloads( edm::ESHandle<EcalADCToGeVConstant> const & payloadHandle, edm::ESHandle<EcalADCToGeVConstant> const & payloadRefHandle ) { | ||
bool areEquals = false; | ||
std::ostringstream os; | ||
os << "[" << "EcalADCToGeVConstantBTransitionAnalyzer::" << __func__ << "]: " << "Payload extracted starting from magnetic field value: "; | ||
payloadHandle->print( os ); | ||
os << "\nReference payload from the target tag: "; | ||
payloadRefHandle->print( os ); | ||
edm::LogInfo( "EcalADCToGeVConstantBTransitionAnalyzer" ) << os.str(); | ||
if( payloadHandle->getEBValue() == payloadRefHandle->getEBValue() && | ||
payloadHandle->getEEValue() == payloadRefHandle->getEEValue() ) areEquals = true; | ||
return areEquals; | ||
} | ||
}; | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(EcalADCToGeVConstantBTransitionAnalyzer); |
107 changes: 107 additions & 0 deletions
107
CondTools/Ecal/test/EcalADCToGeVConstantBTransitionAnalyzer_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import socket | ||
import time | ||
import FWCore.ParameterSet.Config as cms | ||
import FWCore.ParameterSet.VarParsing as VarParsing | ||
from CondCore.CondDB.CondDB_cfi import * | ||
from Configuration.AlCa.autoCond import autoCond | ||
|
||
options = VarParsing.VarParsing() | ||
options.register('connectionString', | ||
'frontier://FrontierProd/CMS_CONDITIONS', #default value | ||
VarParsing.VarParsing.multiplicity.singleton, | ||
VarParsing.VarParsing.varType.string, | ||
"GlobalTag Connection string") | ||
options.register('globalTag', | ||
autoCond['run2_data'], #default value | ||
VarParsing.VarParsing.multiplicity.singleton, | ||
VarParsing.VarParsing.varType.string, | ||
"GlobalTag") | ||
options.register( 'runNumber' | ||
, 1 #default value | ||
, VarParsing.VarParsing.multiplicity.singleton | ||
, VarParsing.VarParsing.varType.int | ||
, "Run number to be uploaded." | ||
) | ||
options.register( 'destinationConnection' | ||
, 'sqlite_file:EcalADCToGeVConstant_EDAnalyzer_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( 'tag' | ||
, 'EcalADCToGeVConstant_EDAnalyzer_test' | ||
, VarParsing.VarParsing.multiplicity.singleton | ||
, VarParsing.VarParsing.varType.string | ||
, "Tag written in destinationConnection and finally appended onto the tag in connectionString." | ||
) | ||
options.register( 'currentThreshold' | ||
, 18000. | ||
, VarParsing.VarParsing.multiplicity.singleton | ||
, VarParsing.VarParsing.varType.float | ||
, "The threshold on the magnet current for considering a switch of the magnetic field." | ||
) | ||
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.connectionString ) ) | ||
CondDBConnection.DBParameters.messageLevel = cms.untracked.int32( options.messageLevel ) | ||
DestConnection = CondDB.clone( connect = cms.string( options.destinationConnection ) ) | ||
DestConnection.DBParameters.messageLevel = cms.untracked.int32( options.messageLevel ) | ||
|
||
process = cms.Process( "EcalADCToGeVConstantWriter" ) | ||
|
||
process.MessageLogger = cms.Service( "MessageLogger" | ||
, destinations = cms.untracked.vstring( 'cout' ) | ||
, cout = cms.untracked.PSet( threshold = cms.untracked.string( 'INFO' ) ) | ||
) | ||
|
||
if options.messageLevel == 3: | ||
#enable LogDebug output: remember the USER_CXXFLAGS="-DEDM_ML_DEBUG" compilation flag! | ||
process.MessageLogger.cout = cms.untracked.PSet( threshold = cms.untracked.string( 'DEBUG' ) ) | ||
process.MessageLogger.debugModules = cms.untracked.vstring( '*' ) | ||
|
||
process.source = cms.Source( "EmptySource", | ||
firstRun = cms.untracked.uint32( options.runNumber ), | ||
firstTime = cms.untracked.uint64( ( long( time.time() ) - 24 * 3600 ) << 32 ), #24 hours ago in nanoseconds | ||
numberEventsInRun = cms.untracked.uint32( 1 ), | ||
numberEventsInLuminosityBlock = cms.untracked.uint32( 1 ) | ||
) | ||
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32( 1 ) ) | ||
|
||
process.GlobalTag = cms.ESSource( "PoolDBESSource", | ||
CondDBConnection, | ||
globaltag = cms.string( options.globalTag ), | ||
toGet = cms.VPSet() | ||
) | ||
process.GlobalTag.toGet.append( cms.PSet( record = cms.string( "EcalADCToGeVConstantRcd" ), | ||
label = cms.untracked.string( "0T" ), | ||
tag = cms.string( "EcalADCToGeVConstant_0T_test0" ), | ||
connect = cms.string( "frontier://FrontierPrep/CMS_CONDITIONS" ), | ||
) | ||
) | ||
process.GlobalTag.toGet.append( cms.PSet( record = cms.string( "EcalADCToGeVConstantRcd" ), | ||
label = cms.untracked.string( "38T" ), | ||
tag = cms.string( "EcalADCToGeVConstant_3.8T_test0" ), | ||
connect = cms.string( "frontier://FrontierPrep/CMS_CONDITIONS" ), | ||
) | ||
) | ||
|
||
process.PoolDBOutputService = cms.Service( "PoolDBOutputService" | ||
, DestConnection | ||
, timetype = cms.untracked.string( 'runnumber' ) | ||
, toPut = cms.VPSet( cms.PSet( record = cms.string( 'EcalADCToGeVConstantRcd' ) | ||
, tag = cms.string( options.tag ) | ||
) | ||
) | ||
) | ||
|
||
process.ecalADCToGeVConstantBTransition = cms.EDAnalyzer( "EcalADCToGeVConstantBTransitionAnalyzer" | ||
, currentThreshold = cms.untracked.double( options.currentThreshold ) | ||
) | ||
|
||
process.p = cms.Path( process.ecalADCToGeVConstantBTransition ) |