Skip to content

Commit

Permalink
Merge pull request #2910 from venturia/apvcyle_fromDB-71x
Browse files Browse the repository at this point in the history
Tracking -- Added the possibility to configure APVCyclePhaseProducerFromL1TS with a DB object
  • Loading branch information
ktf committed Mar 25, 2014
2 parents d1670c9 + 2ec8296 commit 290e2d4
Show file tree
Hide file tree
Showing 19 changed files with 405 additions and 20 deletions.
Expand Up @@ -48,14 +48,15 @@ template< typename TObject , typename TObjectO ,typename TRecord >
void DummyCondDBWriter<TObject,TObjectO,TRecord>::endRun(const edm::Run & run, const edm::EventSetup & es){

std::string rcdName=iConfig_.getParameter<std::string>("record");
std::string labelName=iConfig_.getUntrackedParameter<std::string>("label","");

if( cacheID == es.get<TRecord>().cacheIdentifier()){
edm::LogInfo("DummyCondDBWriter") << "not needed to store objects with Record "<< rcdName << " at run " << run.run() << std::endl; return;
}
cacheID = es.get<TRecord>().cacheIdentifier();

edm::ESHandle<TObject> esobj;
es.get<TRecord>().get( esobj );
es.get<TRecord>().get( labelName, esobj );
TObjectO *obj= new TObjectO(*(esobj.product()));
cond::Time_t Time_;

Expand Down
Expand Up @@ -24,9 +24,18 @@ SiStripConfObject* SiStripConfObjectGenerator::createObject()
else if( parIt->getParameter<std::string>("ParameterType") == "double" ) {
obj->put(parIt->getParameter<std::string>("ParameterName"), parIt->getParameter<double>("ParameterValue"));
}
if( parIt->getParameter<std::string>("ParameterType") == "string" ) {
else if( parIt->getParameter<std::string>("ParameterType") == "string" ) {
obj->put(parIt->getParameter<std::string>("ParameterName"), parIt->getParameter<std::string>("ParameterValue"));
}
else if( parIt->getParameter<std::string>("ParameterType") == "bool" ) {
obj->put(parIt->getParameter<std::string>("ParameterName"), parIt->getParameter<bool>("ParameterValue"));
}
else if( parIt->getParameter<std::string>("ParameterType") == "vint32" ) {
obj->put(parIt->getParameter<std::string>("ParameterName"), parIt->getParameter<std::vector<int> >("ParameterValue"));
}
else if( parIt->getParameter<std::string>("ParameterType") == "vstring" ) {
obj->put(parIt->getParameter<std::string>("ParameterName"), parIt->getParameter<std::vector<std::string> >("ParameterValue"));
}
}
return obj;
}
16 changes: 16 additions & 0 deletions CondFormats/SiStripObjects/interface/SiStripConfObject.h
Expand Up @@ -38,6 +38,7 @@ class SiStripConfObject
return false;
}


/// Updating the value stored as 'name' with 'inputValue'.
/// False if parameter 'name' does not exist (and nothing is done then - use put(..) instead!),
/// otherwise true.
Expand Down Expand Up @@ -73,6 +74,7 @@ class SiStripConfObject
return returnValue;
}


bool isParameter( const std::string & name ) const
{
return( parameters.find(name) != parameters.end() );
Expand All @@ -88,4 +90,18 @@ class SiStripConfObject
parMap parameters;
};

template <>
bool SiStripConfObject::put<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue );
template <>
bool SiStripConfObject::update<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue );
template <>
std::vector<int> SiStripConfObject::get<std::vector<int> >( const std::string & name ) const;
template <>
bool SiStripConfObject::put<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue );
template <>
bool SiStripConfObject::update<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue );
template <>
std::vector<std::string> SiStripConfObject::get<std::vector<std::string> >( const std::string & name ) const;


#endif
93 changes: 93 additions & 0 deletions CondFormats/SiStripObjects/src/SiStripConfObject.cc
@@ -1,5 +1,98 @@
#include "CondFormats/SiStripObjects/interface/SiStripConfObject.h"

template <>
bool SiStripConfObject::put<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue )
{
std::stringstream ss;
for(std::vector<int>::const_iterator elem=inputValue.begin();elem!=inputValue.end();++elem) {
ss << *elem << " ";
}
if( parameters.insert(std::make_pair(name, ss.str())).second ) return true;
return false;
}

template <>
bool SiStripConfObject::update<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue )
{
parMap::iterator it = parameters.find(name);
if (it == parameters.end()) {
std::cout << "WARNING in SiStripConfObject::update: parameter " << name << " not found, "
<< "so cannot be updated to the vector of int of size'" << inputValue.size() << "'." << std::endl;
return false;
} else {
std::stringstream ss;
for(std::vector<int>::const_iterator elem=inputValue.begin();elem!=inputValue.end();++elem) {
ss << *elem << " ";
}
it->second = ss.str();
return true;
}
}

template <>
std::vector<int> SiStripConfObject::get<std::vector<int> >( const std::string & name ) const
{
std::vector<int> returnValue;
parMap::const_iterator it = parameters.find(name);
std::stringstream ss;
if( it != parameters.end() ) {
ss << it->second;
int elem;
while(ss >> elem) returnValue.push_back(elem);
}
else {
std::cout << "WARNING: parameter " << name << " not found. Returning default value" << std::endl;
}
return returnValue;
}

template <>
bool SiStripConfObject::put<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue )
{
std::stringstream ss;
for(std::vector<std::string>::const_iterator elem=inputValue.begin();elem!=inputValue.end();++elem) {
ss << *elem << " ";
}
if( parameters.insert(std::make_pair(name, ss.str())).second ) return true;
return false;
}

template <>
bool SiStripConfObject::update<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue )
{
parMap::iterator it = parameters.find(name);
if (it == parameters.end()) {
std::cout << "WARNING in SiStripConfObject::update: parameter " << name << " not found, "
<< "so cannot be updated to the vector of std::string of size'" << inputValue.size() << "'." << std::endl;
return false;
} else {
std::stringstream ss;
for(std::vector<std::string>::const_iterator elem=inputValue.begin();elem!=inputValue.end();++elem) {
ss << *elem << " ";
}
it->second = ss.str();
return true;
}
}

template <>
std::vector<std::string> SiStripConfObject::get<std::vector<std::string> >( const std::string & name ) const
{
std::vector<std::string> returnValue;
parMap::const_iterator it = parameters.find(name);
std::stringstream ss;
if( it != parameters.end() ) {
ss << it->second;
std::string elem;
while(ss >> elem) returnValue.push_back(elem);
}
else {
std::cout << "WARNING: parameter " << name << " not found. Returning default value" << std::endl;
}
return returnValue;
}


void SiStripConfObject::printSummary(std::stringstream & ss) const
{
parMap::const_iterator it = parameters.begin();
Expand Down
73 changes: 67 additions & 6 deletions DPGAnalysis/SiStripTools/plugins/APVCyclePhaseProducerFromL1TS.cc
Expand Up @@ -28,6 +28,10 @@
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/EventSetup.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "FWCore/Utilities/interface/InputTag.h"
Expand All @@ -39,10 +43,14 @@
#include <vector>
#include <utility>
#include <string>
#include <iostream>

#include "TH1F.h"
#include "TProfile.h"

#include "CondFormats/SiStripObjects/interface/SiStripConfObject.h"
#include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"

#include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
#include "DPGAnalysis/SiStripTools/interface/APVCyclePhaseCollection.h"

Expand All @@ -62,15 +70,20 @@ class APVCyclePhaseProducerFromL1TS : public edm::EDProducer {
virtual void produce(edm::Event&, const edm::EventSetup&) override;

bool isBadRun(const unsigned int) const;
void printConfiguration(std::stringstream& ss) const;

// ----------member data ---------------------------

edm::ESWatcher<SiStripConfObjectRcd> m_eswatcher;
const edm::InputTag _l1tscollection;
const std::vector<std::string> _defpartnames;
const std::vector<int> _defphases;
const bool m_ignoreDB;
const std::string m_rcdLabel;
std::vector<std::string> _defpartnames;
std::vector<int> _defphases;
const bool _wantHistos;
const bool _useEC0;
const int _magicOffset;
bool _useEC0;
int _magicOffset;
bool m_badRun;
const unsigned int m_maxLS;
const unsigned int m_LSfrac;

Expand Down Expand Up @@ -112,12 +125,16 @@ class APVCyclePhaseProducerFromL1TS : public edm::EDProducer {
// constructors and destructor
//
APVCyclePhaseProducerFromL1TS::APVCyclePhaseProducerFromL1TS(const edm::ParameterSet& iConfig):
m_eswatcher(),
_l1tscollection(iConfig.getParameter<edm::InputTag>("l1TSCollection")),
m_ignoreDB(iConfig.getUntrackedParameter<bool>("ignoreDB",false)),
m_rcdLabel(iConfig.getUntrackedParameter<std::string>("recordLabel","apvphaseoffsets")),
_defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
_defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
_wantHistos(iConfig.getUntrackedParameter<bool>("wantHistos",false)),
_useEC0(iConfig.getUntrackedParameter<bool>("useEC0",false)),
_magicOffset(iConfig.getUntrackedParameter<int>("magicOffset",8)),
m_badRun(false),
m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin",250)),
m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction",16)),
m_rhm(),
Expand All @@ -127,6 +144,11 @@ APVCyclePhaseProducerFromL1TS::APVCyclePhaseProducerFromL1TS(const edm::Paramete
_lastEventCounter0(-1),_lastOrbitCounter0(-1),_lastTestEnable(-1)
{

std::stringstream ss;
printConfiguration(ss);
edm::LogInfo("ConfigurationAtConstruction") << ss.str();


produces<APVCyclePhaseCollection,edm::InEvent>();

m_badruns.push_back(std::pair<unsigned int, unsigned int>(0,131767));
Expand Down Expand Up @@ -171,7 +193,28 @@ APVCyclePhaseProducerFromL1TS::beginRun(const edm::Run& iRun, const edm::EventSe

{

// reset offset vector
// update the parameters from DB

if(!m_ignoreDB && m_eswatcher.check(iSetup)) {
edm::ESHandle<SiStripConfObject> confObj;
iSetup.get<SiStripConfObjectRcd>().get(m_rcdLabel,confObj);

std::stringstream summary;
confObj->printDebug(summary);
LogDebug("SiStripConfObjectSummary") << summary.str();

_defpartnames = confObj->get<std::vector<std::string> >("defaultPartitionNames");
_defphases = confObj->get<std::vector<int> >("defaultPhases");
_useEC0 = confObj->get<bool>("useEC0");
m_badRun = confObj->get<bool>("badRun");
_magicOffset = confObj->get<int>("magicOffset");

std::stringstream ss;
printConfiguration(ss);
edm::LogInfo("UpdatedConfiguration") << ss.str();


}

if(_wantHistos) {

Expand Down Expand Up @@ -329,9 +372,27 @@ APVCyclePhaseProducerFromL1TS::isBadRun(const unsigned int run) const {
if( run >= runpair->first && run <= runpair->second) return true;
}

return false;
return m_badRun;

}

void
APVCyclePhaseProducerFromL1TS::printConfiguration(std::stringstream& ss) const {

ss << _defpartnames.size() << " default partition names: ";
for(std::vector<std::string>::const_iterator part=_defpartnames.begin();part!=_defpartnames.end();++part) {
ss << *part << " ";
}
ss << std::endl;
ss << _defphases.size() << " default phases: ";
for(std::vector<int>::const_iterator phase=_defphases.begin();phase!=_defphases.end();++phase) {
ss << *phase << " ";
}
ss << std::endl;
ss << " Magic offset: " << _magicOffset << std::endl;
ss << " use ECO: " << _useEC0 << std::endl;
ss << " bad run: " << m_badRun << std::endl;

}
//define this as a plug-in
DEFINE_FWK_MODULE(APVCyclePhaseProducerFromL1TS);
2 changes: 2 additions & 0 deletions DPGAnalysis/SiStripTools/plugins/BuildFile.xml
Expand Up @@ -8,6 +8,8 @@
<use name="FWCore/Utilities"/>
<use name="CommonTools/Utils"/>
<use name="CommonTools/UtilAlgos"/>
<use name="CondFormats/SiStripObjects"/>
<use name="CondFormats/DataRecords"/>
<use name="DataFormats/SiStripDigi"/>
<use name="DataFormats/SiStripCluster"/>
<use name="DataFormats/SiPixelCluster"/>
Expand Down
@@ -0,0 +1,38 @@
import FWCore.ParameterSet.Config as cms

from CalibTracker.SiStripESProducers.services.SiStripConfObjectGeneratorService_cfi import *

SiStripConfObjectGenerator.Parameters = cms.VPSet(
cms.PSet(
ParameterName = cms.string("defaultPartitionNames"),
ParameterType = cms.string("vstring"),
ParameterValue = cms.vstring("TI","TO","TP","TM"),
),
cms.PSet(
ParameterName = cms.string("defaultPhases"),
ParameterType = cms.string("vint32"),
ParameterValue = cms.vint32(48,48,48,48),
),
cms.PSet(
ParameterName = cms.string("useEC0"),
ParameterType = cms.string("bool"),
ParameterValue = cms.bool(False),
),
cms.PSet(
ParameterName = cms.string("badRun"),
ParameterType = cms.string("bool"),
ParameterValue = cms.bool(False),
),
cms.PSet(
ParameterName = cms.string("magicOffset"),
ParameterType = cms.string("int"),
ParameterValue = cms.int32(11),
),
)

siStripConfObjectAPVPhaseOffsetsFakeESSource = cms.ESSource("SiStripConfObjectFakeESSource",
appendToDataLabel = cms.string('apvphaseoffsets')
)



@@ -1,6 +1,7 @@
import FWCore.ParameterSet.Config as cms

APVPhases = cms.EDProducer('APVCyclePhaseProducerFromL1TS',
ignoreDB = cms.untracked.bool(True),
defaultPartitionNames = cms.vstring("TI",
"TO",
"TP",
Expand Down
@@ -1,6 +1,7 @@
import FWCore.ParameterSet.Config as cms

APVPhases = cms.EDProducer('APVCyclePhaseProducerFromL1TS',
ignoreDB = cms.untracked.bool(True),
defaultPartitionNames = cms.vstring("TI",
"TO",
"TP",
Expand Down
@@ -1,6 +1,7 @@
import FWCore.ParameterSet.Config as cms

APVPhases = cms.EDProducer('APVCyclePhaseProducerFromL1TS',
ignoreDB = cms.untracked.bool(True),
defaultPartitionNames = cms.vstring("TI",
"TO",
"TP",
Expand Down
@@ -0,0 +1,12 @@
import FWCore.ParameterSet.Config as cms

APVPhases = cms.EDProducer('APVCyclePhaseProducerFromL1TS',
defaultPartitionNames = cms.vstring("TI",
"TO",
"TP",
"TM"
),
defaultPhases = cms.vint32(30,30,30,30),
l1TSCollection = cms.InputTag("scalersRawToDigi"),
)

0 comments on commit 290e2d4

Please sign in to comment.