Skip to content

Commit

Permalink
Merge pull request #36180 from CTPPS/dbFixes
Browse files Browse the repository at this point in the history
PPS fixes in using DBOutputService followup
  • Loading branch information
cmsbuild authored Dec 7, 2021
2 parents 84856a9 + b0ab699 commit b5b1719
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 43 deletions.
5 changes: 2 additions & 3 deletions CondTools/CTPPS/plugins/PPSTimingCalibrationWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ class PPSTimingCalibrationWriter : public edm::one::EDAnalyzer<> {

void PPSTimingCalibrationWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
// get timing calibration parameters
edm::ESHandle<PPSTimingCalibration> hTimingCalib = iSetup.getHandle(tokenCalibration_);

const auto& hTimingCalib = iSetup.getData(tokenCalibration_);
// store the calibration into a DB object
edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (poolDbService.isAvailable())
poolDbService->writeOneIOV(*hTimingCalib.product(), poolDbService->currentTime(), "PPSTimingCalibrationRcd");
poolDbService->writeOneIOV(hTimingCalib, poolDbService->currentTime(), "PPSTimingCalibrationRcd");
else
throw cms::Exception("PPSTimingCalibrationWriter") << "PoolDBService required.";
}
Expand Down
9 changes: 2 additions & 7 deletions CondTools/CTPPS/plugins/WriteCTPPSBeamParameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ class WriteCTPPSBeamParameters : public edm::one::EDAnalyzer<> {
//---------------------------------------------------------------------------------------

void WriteCTPPSBeamParameters::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::ESHandle<CTPPSBeamParameters> bp = iSetup.getHandle(tokenBeamParameters_);

// Pointer for the conditions data object
const CTPPSBeamParameters* p = bp.product();

const auto& beamParam = iSetup.getData(tokenBeamParameters_);
// Using "lumiid" as IOV
const edm::LuminosityBlock& iLBlock = iEvent.getLuminosityBlock();
edm::LuminosityBlockID lu(iLBlock.run(), iLBlock.id().luminosityBlock());
Expand All @@ -67,8 +63,7 @@ void WriteCTPPSBeamParameters::analyze(const edm::Event& iEvent, const edm::Even
// Write to database or sqlite file
edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (poolDbService.isAvailable())
poolDbService->writeOneIOV(*p, ilumi, "CTPPSBeamParametersRcd");
// poolDbService->writeOne( p, poolDbService->currentTime(), "CTPPSBeamParametersRcd" );
poolDbService->writeOneIOV(beamParam, ilumi, "CTPPSBeamParametersRcd");
else
throw std::runtime_error("PoolDBService required.");
}
Expand Down
29 changes: 17 additions & 12 deletions CondTools/CTPPS/src/CTPPSRPAlignmentInfoAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,25 @@ CTPPSRPAlignmentInfoAnalyzer::CTPPSRPAlignmentInfoAnalyzer(const edm::ParameterS
//----------------------------------------------------------------------------------------------------

void CTPPSRPAlignmentInfoAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::ESHandle<CTPPSRPAlignmentCorrectionsData> alignments;
const auto alignments = [&r = record_,
&eS = iSetup,
&tAI = tokenAlignmentIdeal_,
&tAR = tokenAlignmentReal_,
&tAM = tokenAlignmentMisaligned_]() -> const CTPPSRPAlignmentCorrectionsData* {
if (r == "CTPPSRPAlignmentCorrectionsDataRcd") {
return &eS.getData(tAI);
} else if (r == "RPRealAlignmentRecord") {
return &eS.getData(tAR);
} else {
return &eS.getData(tAM);
}
}();

if (strcmp(record_.c_str(), "CTPPSRPAlignmentCorrectionsDataRcd") == 0) {
alignments = iSetup.getHandle(tokenAlignmentIdeal_);
} else if (strcmp(record_.c_str(), "RPRealAlignmentRecord") == 0) {
alignments = iSetup.getHandle(tokenAlignmentReal_);
} else {
alignments = iSetup.getHandle(tokenAlignmentMisaligned_);
}

const CTPPSRPAlignmentCorrectionsData* pCTPPSRPAlignmentCorrectionsData = alignments.product();
edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (poolDbService.isAvailable()) {
poolDbService->writeOneIOV(*pCTPPSRPAlignmentCorrectionsData, iov_, record_);
if (!poolDbService.isAvailable()) {
edm::LogError("CTPPSAlignmentInfoAnalyzer") << " DbService not available ";
} else {
poolDbService->writeOneIOV(alignments, iov_, record_);
}
}

Expand Down
10 changes: 5 additions & 5 deletions CondTools/CTPPS/src/WriteCTPPSPixGainCalibrations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ void WriteCTPPSPixGainCalibrations::getHistos() {
}

void WriteCTPPSPixGainCalibrations::fillDB() {
CTPPSPixelGainCalibrations* gainCalibsTest = new CTPPSPixelGainCalibrations();
CTPPSPixelGainCalibrations* gainCalibsTest1 = new CTPPSPixelGainCalibrations();
CTPPSPixelGainCalibrations gainCalibsTest;
CTPPSPixelGainCalibrations gainCalibsTest1;

// std::cout<<"Here! "<<std::endl;

Expand Down Expand Up @@ -225,9 +225,9 @@ void WriteCTPPSPixGainCalibrations::fillDB() {
setDummyFullPlane(orderedPeds, orderedGains, 6 * 52 * 80);
}

gainCalibsTest->setGainCalibration(tempdetid, orderedPeds, orderedGains);
gainCalibsTest.setGainCalibration(tempdetid, orderedPeds, orderedGains);
// std::cout << "Here detid = "<<tempdetid <<std::endl;
gainCalibsTest1->setGainCalibration(tempdetid, tempPGCalib);
gainCalibsTest1.setGainCalibration(tempdetid, tempPGCalib);
// std::cout << "Here again"<<std::endl;
}
// std::cout<<" Here 3!"<<std::endl;
Expand All @@ -236,7 +236,7 @@ void WriteCTPPSPixGainCalibrations::fillDB() {
edm::LogError("CTPPSPixGainsCalibrationWriter") << "Db Service Unavailable";
return;
}
mydbservice->writeOne(gainCalibsTest, mydbservice->currentTime(), m_record);
mydbservice->writeOneIOV(gainCalibsTest, mydbservice->currentTime(), m_record);
}

void WriteCTPPSPixGainCalibrations::setDummyFullPlane(std::vector<float>& peds,
Expand Down
8 changes: 3 additions & 5 deletions CondTools/CTPPS/src/WriteCTPPSPixelAnalysisMask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ WriteCTPPSPixelAnalysisMask::WriteCTPPSPixelAnalysisMask(const edm::ParameterSet
tokenAnalysisMask_(esConsumes<CTPPSPixelAnalysisMask, CTPPSPixelAnalysisMaskRcd>(edm::ESInputTag("", label_))) {}

void WriteCTPPSPixelAnalysisMask::analyze(const edm::Event &, edm::EventSetup const &es) {
// get analysis mask to mask channels
ESHandle<CTPPSPixelAnalysisMask> hAnalysisMask = es.getHandle(tokenAnalysisMask_);

/*// print analysisMask
printf("* mask\n");
for (const auto &p : analysisMask->analysisMask)
Expand All @@ -70,10 +67,11 @@ void WriteCTPPSPixelAnalysisMask::analyze(const edm::Event &, edm::EventSetup co
*/

// Write Analysis Mask to sqlite file:
const CTPPSPixelAnalysisMask *pCTPPSPixelAnalysisMask = hAnalysisMask.product(); // Analysis Mask

const auto &analysisMask = es.getData(tokenAnalysisMask_);
edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (poolDbService.isAvailable()) {
poolDbService->writeOneIOV(*pCTPPSPixelAnalysisMask, analysismaskiov_, /*m_record*/ record_);
poolDbService->writeOneIOV(analysisMask, analysismaskiov_, record_);
}
}

Expand Down
9 changes: 4 additions & 5 deletions CondTools/CTPPS/src/WriteCTPPSPixelDAQMapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,19 @@ WriteCTPPSPixelDAQMapping::WriteCTPPSPixelDAQMapping(const edm::ParameterSet &ps
tokenMapping_(esConsumes<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd>(edm::ESInputTag("", label_))) {}

void WriteCTPPSPixelDAQMapping::analyze(const edm::Event &, edm::EventSetup const &es) {
// get DAQ mapping
edm::ESHandle<CTPPSPixelDAQMapping> hMapping = es.getHandle(tokenMapping_);

// print mapping
/*printf("* DAQ mapping\n");
for (const auto &p : mapping->ROCMapping)
cout << " " << p.first << " -> " << p.second << endl;
*/

// Write DAQ Mapping to sqlite file:
const CTPPSPixelDAQMapping *pCTPPSPixelDAQMapping = hMapping.product(); // DAQ Mapping

const auto &mapping = es.getData(tokenMapping_);

edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (poolDbService.isAvailable()) {
poolDbService->writeOneIOV(*pCTPPSPixelDAQMapping, daqmappingiov_, /*m_record*/ record_);
poolDbService->writeOneIOV(mapping, daqmappingiov_, record_);
}
}

Expand Down
11 changes: 5 additions & 6 deletions CondTools/Geometry/plugins/PPSGeometryBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,19 @@ void PPSGeometryBuilder::analyze(const edm::Event& iEvent, const edm::EventSetup
}

// Build persistent geometry data from geometry
PDetGeomDesc* serializableData =
new PDetGeomDesc(); // cond::service::PoolDBOutputService::writeOne interface requires raw pointer.
PDetGeomDesc serializableData; // cond::service::PoolDBOutputService::writeOne interface requires raw pointer.
int counter = 0;
if (geoInfoRoot) {
buildSerializableDataFromGeoInfo(serializableData, geoInfoRoot.get(), counter);
buildSerializableDataFromGeoInfo(&serializableData, geoInfoRoot.get(), counter);
}

// Save geometry in the database
if (serializableData->container_.empty()) {
if (serializableData.container_.empty()) {
throw cms::Exception("PPSGeometryBuilder") << "PDetGeomDesc is empty, no geometry to save in the database.";
} else {
if (dbService_.isAvailable()) {
dbService_->writeOne(serializableData, dbService_->beginOfTime(), "VeryForwardIdealGeometryRecord");
edm::LogInfo("PPSGeometryBuilder") << "Successfully wrote DB, with " << serializableData->container_.size()
dbService_->writeOneIOV(serializableData, dbService_->beginOfTime(), "VeryForwardIdealGeometryRecord");
edm::LogInfo("PPSGeometryBuilder") << "Successfully wrote DB, with " << serializableData.container_.size()
<< " PDetGeomDesc items.";
} else {
throw cms::Exception("PPSGeometryBuilder") << "PoolDBService required.";
Expand Down

0 comments on commit b5b1719

Please sign in to comment.