Skip to content

Commit

Permalink
add SiPhase2OuterTrackerLorentzAngleReader and use it in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Oct 19, 2021
1 parent d68381f commit 6a27c62
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// user include files
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "CondFormats/DataRecord/interface/SiPhase2OuterTrackerLorentzAngleRcd.h"
#include "CondFormats/SiPhase2TrackerObjects/interface/SiPhase2OuterTrackerLorentzAngle.h"

//
//
// class decleration
//
class SiPhase2OuterTrackerLorentzAngleReader : public edm::one::EDAnalyzer<> {
public:
explicit SiPhase2OuterTrackerLorentzAngleReader(const edm::ParameterSet&);
~SiPhase2OuterTrackerLorentzAngleReader() override = default;
void analyze(const edm::Event&, const edm::EventSetup&) override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
uint32_t printdebug_;
std::string label_;
edm::ESGetToken<SiPhase2OuterTrackerLorentzAngle, SiPhase2OuterTrackerLorentzAngleRcd> laToken_;
};

SiPhase2OuterTrackerLorentzAngleReader::SiPhase2OuterTrackerLorentzAngleReader(const edm::ParameterSet& iConfig)
: printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 5)),
label_(iConfig.getUntrackedParameter<std::string>("label", "")),
laToken_(esConsumes(edm::ESInputTag{"", label_})) {}

void SiPhase2OuterTrackerLorentzAngleReader::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
const auto& lorentzAngles = iSetup.getData(laToken_);
edm::LogInfo("SiPhase2OuterTrackerLorentzAngleReader")
<< "[SiPhase2OuterTrackerLorentzAngleReader::analyze] End Reading SiPhase2OuterTrackerLorentzAngle with label " << label_ << std::endl;

const auto& detid_la = lorentzAngles.getLorentzAngles();
std::unordered_map<unsigned int, float>::const_iterator it;
size_t count = 0;
for (it = detid_la.begin(); it != detid_la.end() && count < printdebug_; it++) {
edm::LogInfo("SiPhase2OuterTrackerLorentzAngleReader") << "detid " << it->first << " \t"
<< " Lorentz angle " << it->second;
count++;
}
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void SiPhase2OuterTrackerLorentzAngleReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.setComment("Module to read SiPhase2OuterTrackerLorentzAngle Payloads");
desc.addUntracked<uint32_t>("printDebug",5)->setComment("maximum amount of print-outs");
desc.addUntracked<std::string>("label", "")->setComment("label from which to read the payload");
descriptions.addWithDefaultLabel(desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(SiPhase2OuterTrackerLorentzAngleReader);
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#! /usr/bin/env cmsRun
# Author: Marco Musich (October 2021)
import FWCore.ParameterSet.Config as cms
process = cms.Process("TEST")

###################################################################
# Messages
###################################################################
process.load('FWCore.MessageService.MessageLogger_cfi')
process.MessageLogger.cerr.enable = False
process.MessageLogger.SiPhase2OuterTrackerLorentzAngleReader=dict()
process.MessageLogger.SiPhase2OuterTrackerLorentzAngle=dict()
process.MessageLogger.cout = cms.untracked.PSet(
enable = cms.untracked.bool(True),
enableStatistics = cms.untracked.bool(True),
threshold = cms.untracked.string("INFO"),
default = cms.untracked.PSet(limit = cms.untracked.int32(0)),
FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
reportEvery = cms.untracked.int32(1000)
),
SiPhase2OuterTrackerLorentzAngleReader = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
SiPhase2OuterTrackerLorentzAngle = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
)

###################################################################
# Input data
###################################################################
tag = 'SiPhase2OuterTrackerLorentzAngle_T15'
suffix = 'v0'
inFile = tag+'_'+suffix+'.db'
inDB = 'sqlite_file:'+inFile

process.load("CondCore.CondDB.CondDB_cfi")
# input database (in this case the local sqlite file)
process.CondDB.connect = inDB

process.PoolDBESSource = cms.ESSource("PoolDBESSource",
process.CondDB,
DumpStat=cms.untracked.bool(True),
toGet = cms.VPSet(cms.PSet(record = cms.string(''),
tag = cms.string(tag))
)
)

###################################################################
# check the ES data getter
###################################################################
process.get = cms.EDAnalyzer("EventSetupRecordDataGetter",
toGet = cms.VPSet(cms.PSet(
record = cms.string(' SiPhase2OuterTrackerLorentzAngleRcd'),
data = cms.vstring('SiPhase2OuterTrackerLorentzAngle')
)),
verbose = cms.untracked.bool(True)
)

###################################################################
# Payload reader
###################################################################
import CondTools.SiPhase2Tracker.siPhase2OuterTrackerLorentzAngleReader_cfi.py as _mod
process.LAPayloadReader = _mod.siPhase2OuterTrackerLorentzAngleReader.clone(printDebug = 10,
label = "")

###################################################################
# Path
###################################################################
process.p = cms.Path(process.LAPayloadReader)

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
TEST_DIR=$CMSSW_BASE/src/CondTools/SiPhase2Tracker/test
echo "test dir: $TEST_DIR"

printf "testing writing Phase2 Lorentz Angle \n\n"
## need to be in order (don't read before writing)
cmsRun ${TEST_DIR}/SiPhase2OuterTrackerLorentzAngleWriter_cfg.py
cmsRun ${TEST_DIR}/SiPhase2OuterTrackerLorentzAngleReader_cfg.py

printf "testing writing Phase2 Tracker Cabling Map (test) \n\n"
## need to be in order (don't read before writing)
cmsRun ${TEST_DIR}/DTCCablingMapTestProducer_write.py
cmsRun ${TEST_DIR}/DTCCablingMapTestProducer_retrieve.py
cmsRun ${TEST_DIR}/DTCCablingMapTestProducer_dump.py

printf "testing writing Phase2 Tracker Cabling Map \n\n"
## need to be in order (don't read before writing)
cmsRun ${TEST_DIR}/DTCCablingMapProducer_write.py
cmsRun ${TEST_DIR}/DTCCablingMapProducer_retrieve.py
Expand Down

0 comments on commit 6a27c62

Please sign in to comment.