Skip to content

Commit

Permalink
Move leftover PoolDBOutputService modules to use kSharedResource
Browse files Browse the repository at this point in the history
  • Loading branch information
tvami committed Mar 18, 2023
1 parent 42b93b9 commit 43aa1d7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 77 deletions.
Expand Up @@ -2,21 +2,20 @@
#define CalibTracker_SiStripESProducer_DummyCondDBWriter_h

// user include files
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include <string>

#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"

#include "FWCore/Utilities/interface/Exception.h"

#include <string>

template <typename TObject, typename TObjectO, typename TRecord>
class DummyCondDBWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
class DummyCondDBWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
public:
explicit DummyCondDBWriter(const edm::ParameterSet& iConfig);
~DummyCondDBWriter() override;
Expand All @@ -35,22 +34,23 @@ DummyCondDBWriter<TObject, TObjectO, TRecord>::DummyCondDBWriter(const edm::Para
: iConfig_(iConfig),
token_(esConsumes<edm::Transition::EndRun>(
edm::ESInputTag{"", iConfig.getUntrackedParameter<std::string>("label", "")})) {
usesResource(cond::service::PoolDBOutputService::kSharedResource);
edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter constructor for typename " << typeid(TObject).name()
<< " and record " << typeid(TRecord).name() << std::endl;
<< " and record " << typeid(TRecord).name();
}

template <typename TObject, typename TObjectO, typename TRecord>
DummyCondDBWriter<TObject, TObjectO, TRecord>::~DummyCondDBWriter() {
edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter::~DummyCondDBWriter()" << std::endl;
edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter::~DummyCondDBWriter()";
}

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");

if (!watcher_.check(es)) {
edm::LogInfo("DummyCondDBWriter") << "not needed to store objects with Record " << rcdName << " at run "
<< run.run() << std::endl;
edm::LogInfo("DummyCondDBWriter") << "Not needed to store objects with Record " << rcdName << " at run "
<< run.run();
return;
}

Expand All @@ -70,7 +70,7 @@ void DummyCondDBWriter<TObject, TObjectO, TRecord>::endRun(const edm::Run& run,

dbservice->writeOneIOV(*obj, Time_, rcdName);
} else {
edm::LogError("SiStripFedCablingBuilder") << "Service is unavailable" << std::endl;
edm::LogError("DummyCondDBWriter") << "Service is unavailable";
}
}

Expand Down
100 changes: 46 additions & 54 deletions CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h
Expand Up @@ -129,22 +129,19 @@
#include <cstdlib>

// user include files
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Exception.h"
//#include "FWCore/Framework/interface/EventSetup.h"

#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"

template <class T>
class ConditionDBWriter
Expand All @@ -161,7 +158,7 @@ class ConditionDBWriter
setSinceTime_(false),
firstRun_(true) {
usesResource(cond::service::PoolDBOutputService::kSharedResource);
edm::LogInfo("ConditionDBWriter::ConditionDBWriter()") << std::endl;
edm::LogInfo("ConditionDBWriter") << "ConditionDBWriter()";
SinceAppendMode_ = iConfig.getParameter<bool>("SinceAppendMode");
std::string IOVMode = iConfig.getParameter<std::string>("IOVMode");
if (IOVMode == std::string("Job"))
Expand All @@ -173,20 +170,19 @@ class ConditionDBWriter
else if (IOVMode == std::string("AlgoDriven"))
AlgoDrivenMode_ = true;
else
edm::LogError(
"ConditionDBWriter::ConditionDBWriter(): ERROR - unknown IOV interval write mode...will not store anything "
"on the DB")
<< std::endl;
edm::LogError("ConditionDBWriter")
<< "ConditionDBWriter(): ERROR - unknown IOV interval write mode...will not store anything "
"on the DB";
Record_ = iConfig.getParameter<std::string>("Record");
doStore_ = iConfig.getParameter<bool>("doStoreOnDB");
timeFromEndRun_ = iConfig.getUntrackedParameter<bool>("TimeFromEndRun", false);
timeFromStartOfRunRange_ = iConfig.getUntrackedParameter<bool>("TimeFromStartOfRunRange", false);

if (!SinceAppendMode_)
edm::LogError("ConditionDBWriter::endJob(): ERROR - only SinceAppendMode support!!!!");
edm::LogError("ConditionDBWriter") << "endJob(): ERROR - only SinceAppendMode support!!!!";
}

~ConditionDBWriter() override { edm::LogInfo("ConditionDBWriter::~ConditionDBWriter()") << std::endl; }
~ConditionDBWriter() override { edm::LogInfo("ConditionDBWriter") << "~ConditionDBWriter()"; }

// utility method to validate configurations of inherited classes
static void fillPSetDescription(edm::ParameterSetDescription &desc) {
Expand Down Expand Up @@ -222,7 +218,7 @@ class ConditionDBWriter

void beginRun(const edm::Run &run, const edm::EventSetup &es) override {
if (firstRun_) {
edm::LogInfo("ConditionDBWriter::beginJob") << std::endl;
edm::LogInfo("ConditionDBWriter") << "beginJob";
if ((JobMode_ || AlgoDrivenMode_) && SinceAppendMode_)
setSinceTime_ = true;
algoBeginJob(es);
Expand All @@ -234,14 +230,14 @@ class ConditionDBWriter
if (run.id().run() > maxRunRange_)
maxRunRange_ = run.id().run();

edm::LogInfo("ConditionDBWriter::beginRun") << std::endl;
edm::LogInfo("ConditionDBWriter") << "beginRun";
if (RunMode_ && SinceAppendMode_)
setSinceTime_ = true;
algoBeginRun(run, es);
}

void beginLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup) override {
edm::LogInfo("ConditionDBWriter::beginLuminosityBlock") << std::endl;
edm::LogInfo("ConditionDBWriter") << "beginLuminosityBlock";
if (LumiBlockMode_ && SinceAppendMode_)
setSinceTime_ = true;
algoBeginLuminosityBlock(lumiBlock, iSetup);
Expand All @@ -256,7 +252,7 @@ class ConditionDBWriter
}

void endLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &es) override {
edm::LogInfo("ConditionDBWriter::endLuminosityBlock") << std::endl;
edm::LogInfo("ConditionDBWriter") << "endLuminosityBlock";
algoEndLuminosityBlock(lumiBlock, es);

if (LumiBlockMode_) {
Expand All @@ -265,18 +261,17 @@ class ConditionDBWriter
if (objPointer) {
storeOnDb(objPointer);
} else {
edm::LogError(
"ConditionDBWriter::endLuminosityblock(): ERROR - requested to store on DB on a Lumi Block based interval, "
"but received null pointer...will not store anything on the DB")
<< std::endl;
edm::LogError("ConditionDBWriter")
<< "endLuminosityblock(): ERROR - requested to store on DB on a Lumi Block based interval, "
"but received null pointer...will not store anything on the DB";
}
}
}

virtual void algoEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &){};

void endRun(const edm::Run &run, const edm::EventSetup &es) override {
edm::LogInfo("ConditionDBWriter::endRun") << std::endl;
edm::LogInfo("ConditionDBWriter") << "endRun";

algoEndRun(run, es);

Expand All @@ -288,16 +283,15 @@ class ConditionDBWriter
Time_ = run.id().run();
storeOnDb(objPointer);
} else {
edm::LogError(
"ConditionDBWriter::endRun(): ERROR - requested to store on DB on a Run based interval, but received null "
"pointer...will not store anything on the DB")
<< std::endl;
edm::LogError("ConditionDBWriter")
<< "endRun(): ERROR - requested to store on DB on a Run based interval, but received null "
"pointer...will not store anything on the DB";
}
}
}

void endJob() override {
edm::LogInfo("ConditionDBWriter::endJob") << std::endl;
edm::LogInfo("ConditionDBWriter") << "endJob";

algoEndJob();

Expand All @@ -309,16 +303,17 @@ class ConditionDBWriter
}

else {
edm::LogError(
"ConditionDBWriter::endJob(): ERROR - requested to store on DB on a Job based interval, but received null "
"pointer...will not store anything on the DB")
<< std::endl;
edm::LogError("ConditionDBWriter") << endJob()
: ERROR - requested to store on DB on a Job based interval,
but received null
"
"pointer...will not store anything on the DB";
}
}
}
void storeOnDb(std::unique_ptr<T> &objPointer) {
edm::LogInfo("ConditionDBWriter::storeOnDb ") << std::endl;
edm::LogInfo("ConditionDBWriter)") << "storeOnDb ";
setSinceTime_ = true;
Expand All @@ -332,7 +327,7 @@ class ConditionDBWriter
return;
edm::Service<cond::service::PoolDBOutputService> mydbservice;
if (!mydbservice.isAvailable()) {
edm::LogError("ConditionDBWriter") << "PoolDBOutputService is unavailable" << std::endl;
edm::LogError("ConditionDBWriter") << "PoolDBOutputService is unavailable";
return;
}
Expand All @@ -343,7 +338,7 @@ class ConditionDBWriter
if (timeFromStartOfRunRange_)
since = minRunRange_;
edm::LogInfo("ConditionDBWriter") << "appending a new object to tag " << Record_ << " in since mode " << std::endl;
edm::LogInfo("ConditionDBWriter") << "appending a new object to tag " << Record_ << " in since mode ";
mydbservice->writeOneIOV<T>(*objPointer, since, Record_);
}
Expand All @@ -353,10 +348,9 @@ class ConditionDBWriter
if (mydbservice.isAvailable()) {
Time_ = mydbservice->currentTime();
edm::LogInfo("ConditionDBWriter::setTime: time set to ") << Time_ << std::endl;
edm::LogInfo("ConditionDBWriter") << "setTime: time set to " << Time_;
} else {
edm::LogError("ConditionDBWriter::setTime(): PoolDBOutputService is not available...cannot set current time")
<< std::endl;
edm::LogError("ConditionDBWriter") << "setTime(): PoolDBOutputService is not available...cannot set current time";
}
}
Expand All @@ -370,21 +364,19 @@ class ConditionDBWriter
std::unique_ptr<T> objPointer = getNewObject();
if (!objPointer) {
edm::LogError(
"ConditionDBWriter::storeOnDbNow: ERROR - requested to store on DB a new object (module configuration is "
"algo driven based IOV), but received NULL pointer...will not store anything on the DB")
<< std::endl;
edm::LogError("ConditionDBWriter")
<< "storeOnDbNow: ERROR - requested to store on DB a new object (module configuration is "
"algo driven based IOV), but received NULL pointer...will not store anything on the DB";
return;
} else {
storeOnDb(objPointer);
}
} else {
edm::LogError(
"ConditionDBWriter::storeOnDbNow(): ERROR - received a direct request from concrete algorithm to store on DB "
"a new object, but module configuration is not to store on DB on an algo driven based interval...will not "
"store anything on the DB")
<< std::endl;
edm::LogError("ConditionDBWriter")
<< "storeOnDbNow(): ERROR - received a direct request from concrete algorithm to store on DB "
"a new object, but module configuration is not to store on DB on an algo driven based interval...will not "
"store anything on the DB";
return;
}
}
Expand All @@ -403,14 +395,14 @@ class ConditionDBWriter
bool SinceAppendMode_; // till or since append mode
bool LumiBlockMode_; //LumiBlock since/till time
bool RunMode_; //
bool RunMode_;
bool JobMode_;
bool AlgoDrivenMode_;
bool doStore_;
std::string Record_;
cond::Time_t
Time_; //time until which the DB object is valid. It is taken from the time of the first event analyzed. The end of the validity is infinity. However as soon as a new DB object with a later start time is inserted, the end time of this one becomes the start time of the new one.
//time until which the DB object is valid. It is taken from the time of the first event analyzed. The end of the validity is infinity. However as soon as a new DB object with a later start time is inserted, the end time of this one becomes the start time of the new one.
cond::Time_t Time_;
bool setSinceTime_;
Expand Down
18 changes: 8 additions & 10 deletions CondTools/Hcal/interface/BoostIODBWriter.h
Expand Up @@ -24,24 +24,20 @@
#include <memory>
#include <cassert>

#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "CondFormats/Serialization/interface/eos/portable_iarchive.hpp"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"

#include "FWCore/Utilities/interface/Exception.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Exception.h"

//
// class declaration
//
template <class DataType>
class BoostIODBWriter : public edm::one::EDAnalyzer<> {
class BoostIODBWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
typedef DataType data_type;

Expand All @@ -57,7 +53,9 @@ class BoostIODBWriter : public edm::one::EDAnalyzer<> {

template <class DataType>
BoostIODBWriter<DataType>::BoostIODBWriter(const edm::ParameterSet& ps)
: inputFile_(ps.getParameter<std::string>("inputFile")), record_(ps.getParameter<std::string>("record")) {}
: inputFile_(ps.getParameter<std::string>("inputFile")), record_(ps.getParameter<std::string>("record")) {
usesResource(cond::service::PoolDBOutputService::kSharedResource);
}

template <class DataType>
void BoostIODBWriter<DataType>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
Expand Down

0 comments on commit 43aa1d7

Please sign in to comment.