Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize CondCore/ESSources/test #36429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 22 additions & 23 deletions CondCore/ESSources/test/SiStripTest/noiseanalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,49 @@
#include <string>
#include <iostream>
#include <map>
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/EventSetup.h"

#include "CondFormats/Calibration/interface/mySiStripNoises.h"
#include "CondFormats/DataRecord/interface/mySiStripNoisesRcd.h"

#include "FWCore/Framework/interface/global/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"

using namespace std;

namespace edmtest {
class NoisesAnalyzer : public edm::EDAnalyzer {
class NoisesAnalyzer : public edm::global::EDAnalyzer<> {
public:
explicit NoisesAnalyzer(edm::ParameterSet const& p) { std::cout << "NoisesAnalyzer" << std::endl; }
explicit NoisesAnalyzer(int i) { std::cout << "NoisesAnalyzer " << i << std::endl; }
virtual ~NoisesAnalyzer() { std::cout << "~NoisesAnalyzer " << std::endl; }
virtual void analyze(const edm::Event& e, const edm::EventSetup& c);
explicit NoisesAnalyzer(edm::ParameterSet const& p) : theNoisesToken_(esConsumes()) {
edm::LogPrint("NoisesAnalyzer") << "NoisesAnalyzer";
}
explicit NoisesAnalyzer(int i) { edm::LogPrint("NoisesAnalyzer") << "NoisesAnalyzer " << i; }
virtual ~NoisesAnalyzer() { edm::LogPrint("NoisesAnalyzer") << "~NoisesAnalyzer "; }
void analyze(edm::StreamID, const edm::Event& e, const edm::EventSetup& c) const override;

private:
const edm::ESGetToken<mySiStripNoises, mySiStripNoisesRcd> theNoisesToken_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francescobrivio does this token ( and all the others added ) need to be initialise with esConsumes ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's initialized few lines before (line 19):

explicit NoisesAnalyzer(edm::ParameterSet const& p) : theNoisesToken_(esConsumes())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francescobrivio thanks, did not noticed...

};

void NoisesAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
void NoisesAnalyzer::analyze(edm::StreamID, const edm::Event& e, const edm::EventSetup& context) const {
using namespace edm::eventsetup;
// Context is not used.
std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
edm::LogPrint("NoisesAnalyzer") << " I AM IN RUN NUMBER " << e.id().run();
edm::LogPrint("NoisesAnalyzer") << " ---EVENT NUMBER " << e.id().event();
edm::eventsetup::EventSetupRecordKey recordKey(
edm::eventsetup::EventSetupRecordKey::TypeTag::findType("mySiStripNoisesRcd"));
if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
//record not found
std::cout << "Record \"mySiStripNoisesRcd"
<< "\" does not exist " << std::endl;
edm::LogPrint("NoisesAnalyzer") << "Record \"mySiStripNoisesRcd\" does not exist";
}
edm::ESHandle<mySiStripNoises> pNoises;
std::cout << "got eshandle" << std::endl;
context.get<mySiStripNoisesRcd>().get(pNoises);
std::cout << "got context" << std::endl;
const mySiStripNoises* mynoise = pNoises.product();
std::cout << "Noises* " << mynoise << std::endl;
edm::LogPrint("NoisesAnalyzer") << "got context";
auto const& mynoise = &context.getData(theNoisesToken_);
edm::LogPrint("NoisesAnalyzer") << "Noises* " << mynoise;
unsigned int a = mynoise->v_noises.size();
std::cout << "size a " << a << std::endl;
edm::LogPrint("NoisesAnalyzer") << "size a " << a;
unsigned int b = mynoise->indexes.size();
std::cout << "size b " << b << std::endl;
edm::LogPrint("NoisesAnalyzer") << "size b " << b;
/*for(std::vector<mySiStripNoises::DetRegistry>::const_iterator it=mynoise->indexes.begin(); it!=mynoise->indexes.end(); ++it){
std::cout << " detid " <<it->detid<< std::endl;
}*/
Expand Down
4 changes: 2 additions & 2 deletions CondCore/ESSources/test/TestConcurrentIOVsCondCore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ function die { echo $1: status $2 ; exit $2; }
pushd ${LOCAL_TMP_DIR}

echo cmsRun TestConcurrentIOVsCondCore_cfg.py
cmsRun --parameter-set ${LOCAL_TEST_DIR}/TestConcurrentIOVsCondCore_cfg.py > TestConcurrentIOVsCondCoreCout.log || die 'Failed in TestConcurrentIOVsCondCore_cfg.py' $?
grep TestConcurrentIOVsCondCore TestConcurrentIOVsCondCoreCout.log > TestConcurrentIOVsCondCore.log
cmsRun --parameter-set ${LOCAL_TEST_DIR}/TestConcurrentIOVsCondCore_cfg.py || die 'Failed in TestConcurrentIOVsCondCore_cfg.py' $?
grep "TestConcurrentIOVsCondCore: " TestConcurrentIOVsCondCoreCout.log > TestConcurrentIOVsCondCore.log
diff ${LOCAL_TEST_DIR}/unit_test_outputs/TestConcurrentIOVsCondCore.log TestConcurrentIOVsCondCore.log || die "comparing TestConcurrentIOVsCondCore.log" $?

popd
8 changes: 6 additions & 2 deletions CondCore/ESSources/test/TestConcurrentIOVsCondCore_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@
)

process.load("FWCore.MessageService.MessageLogger_cfi")
#process.MessageLogger.cerr.threshold = 'INFO'
#process.MessageLogger.cerr.INFO.limit = 1000000
process.MessageLogger = cms.Service("MessageLogger",
destinations = cms.untracked.vstring('TestConcurrentIOVsCondCoreCout','cout'),
TestConcurrentIOVsCondCoreCout = cms.untracked.PSet(
threshold = cms.untracked.string('WARNING')
)
)

process.source = cms.Source("EmptySource",
firstRun = cms.untracked.uint32(132598),
Expand Down
56 changes: 28 additions & 28 deletions CondCore/ESSources/test/stubs/EfficiencyByLabelAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,61 @@ Toy EDProducers and EDProducts for testing purposes only.
#include <iostream>
#include <map>
#include <typeinfo>
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"

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

#include "CondFormats/Calibration/interface/Efficiency.h"
#include "CondFormats/DataRecord/interface/ExEfficiency.h"

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

using namespace std;

namespace edmtest {
class EfficiencyByLabelAnalyzer : public edm::EDAnalyzer {
class EfficiencyByLabelAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit EfficiencyByLabelAnalyzer(edm::ParameterSet const& p) {
std::cout << "EfficiencyByLabelAnalyzer" << std::endl;
explicit EfficiencyByLabelAnalyzer(edm::ParameterSet const& p)
: theEffToken1_(esConsumes()), theEffToken2_(esConsumes()) {
edm::LogPrint("EfficiencyByLabelAnalyzer") << "EfficiencyByLabelAnalyzer";
}
explicit EfficiencyByLabelAnalyzer(int i) {
edm::LogPrint("EfficiencyByLabelAnalyzer") << "EfficiencyByLabelAnalyzer " << i;
}
virtual ~EfficiencyByLabelAnalyzer() {
edm::LogPrint("EfficiencyByLabelAnalyzer") << "~EfficiencyByLabelAnalyzer ";
}
explicit EfficiencyByLabelAnalyzer(int i) { std::cout << "EfficiencyByLabelAnalyzer " << i << std::endl; }
virtual ~EfficiencyByLabelAnalyzer() { std::cout << "~EfficiencyByLabelAnalyzer " << std::endl; }
virtual void analyze(const edm::Event& e, const edm::EventSetup& c);

private:
const edm::ESGetToken<condex::Efficiency, ExEfficiencyRcd> theEffToken1_, theEffToken2_;
};

void EfficiencyByLabelAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
using namespace edm::eventsetup;
// Context is not used.
std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
edm::LogPrint("EfficiencyByLabelAnalyzer") << " I AM IN RUN NUMBER " << e.id().run();
edm::LogPrint("EfficiencyByLabelAnalyzer") << " ---EVENT NUMBER " << e.id().event();
edm::eventsetup::EventSetupRecordKey recordKey(
edm::eventsetup::EventSetupRecordKey::TypeTag::findType("ExEfficiencyRcd"));
if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
//record not found
std::cout << "Record \"ExEfficiencyRcd"
<< "\" does not exist " << std::endl;
edm::LogPrint("EfficiencyByLabelAnalyzer") << "Record \"ExEfficiencyRcd\" does not exist";
}
edm::ESHandle<condex::Efficiency> hEff1;
edm::ESHandle<condex::Efficiency> hEff2;
std::cout << "got eshandle" << std::endl;
context.get<ExEfficiencyRcd>().get("vinEff1", hEff1);
context.get<ExEfficiencyRcd>().get("vinEff2", hEff2);
std::cout << "got context" << std::endl;
edm::LogPrint("EfficiencyByLabelAnalyzer") << "got context";
{
condex::Efficiency const& eff = *hEff2.product();
std::cout << "Efficiency*, type (2) " << (void*)(&eff) << " " << typeid(eff).name() << std::endl;
condex::Efficiency const& eff = context.getData(theEffToken2_);
edm::LogPrint("EfficiencyByLabelAnalyzer")
<< "Efficiency*, type (2) " << (void*)(&eff) << " " << typeid(eff).name();
}
condex::Efficiency const& eff = *hEff1.product();
std::cout << "Efficiency*, type " << (void*)(&eff) << " " << typeid(eff).name() << std::endl;
condex::Efficiency const& eff = context.getData(theEffToken1_);
edm::LogPrint("EfficiencyByLabelAnalyzer") << "Efficiency*, type " << (void*)(&eff) << " " << typeid(eff).name();
for (float pt = 0; pt < 10; pt += 2) {
std::cout << "\npt=" << pt << " :";
edm::LogPrint("EfficiencyByLabelAnalyzer") << "\npt=" << pt << " :";
for (float eta = -3; eta < 3; eta += 1)
std::cout << eff(pt, eta) << " ";
edm::LogPrint("EfficiencyByLabelAnalyzer") << eff(pt, eta) << " ";
}
std::cout << std::endl;
edm::LogPrint("EfficiencyByLabelAnalyzer");
}

DEFINE_FWK_MODULE(EfficiencyByLabelAnalyzer);
Expand Down
89 changes: 39 additions & 50 deletions CondCore/ESSources/test/stubs/KeyListAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,66 @@
#include <iostream>
#include <map>
#include <typeinfo>
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"

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

#include "CondFormats/DataRecord/interface/ExEfficiency.h"
#include "CondCore/IOVService/interface/KeyList.h"

#include "CondFormats/Calibration/interface/Conf.h"
#include "CondFormats/DataRecord/interface/ExEfficiency.h"

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

using namespace std;

namespace {

template<typename Conf>
void print(Conf const & c) {
std::cout << c.v << " " << c.key << " ; ";
template <typename Conf>
void print(Conf const& c) {
edm::LogPrint("KeyListAnalyzer") << c.v << " " << c.key << " ; ";
}

}

} // namespace

namespace edmtest
{
class KeyListAnalyzer : public edm::EDAnalyzer
{
namespace edmtest {
class KeyListAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit KeyListAnalyzer(edm::ParameterSet const& p)
{
std::cout<<"KeyListAnalyzer"<<std::endl;
}
explicit KeyListAnalyzer(int i)
{ std::cout<<"KeyListAnalyzer "<<i<<std::endl; }
virtual ~KeyListAnalyzer() {
std::cout<<"~KeyListAnalyzer "<<std::endl;
explicit KeyListAnalyzer(edm::ParameterSet const& p) : theKeyListToken_(esConsumes()) {
edm::LogPrint("KeyListAnalyzer") << "KeyListAnalyzer";
}
explicit KeyListAnalyzer(int i) { edm::LogPrint("KeyListAnalyzer") << "KeyListAnalyzer " << i; }
virtual ~KeyListAnalyzer() { edm::LogPrint("KeyListAnalyzer") << "~KeyListAnalyzer "; }
virtual void analyze(const edm::Event& e, const edm::EventSetup& c);

private:
const edm::ESGetToken<cond::KeyList, ExDwarfListRcd> theKeyListToken_;
};

void
KeyListAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context){

void KeyListAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
using namespace edm::eventsetup;
// Context is not used.
std::cout <<" I AM IN RUN NUMBER "<<e.id().run() <<std::endl;
std::cout <<" ---EVENT NUMBER "<<e.id().event() <<std::endl;
edm::eventsetup::EventSetupRecordKey
recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("ExDwarfListRcd"));
if( recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
edm::LogPrint("KeyListAnalyzer") << " I AM IN RUN NUMBER " << e.id().run();
edm::LogPrint("KeyListAnalyzer") << " ---EVENT NUMBER " << e.id().event();
edm::eventsetup::EventSetupRecordKey recordKey(
edm::eventsetup::EventSetupRecordKey::TypeTag::findType("ExDwarfListRcd"));
if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
//record not found
std::cout <<"Record \"ExDwarfListRcd "<<"\" does not exist "<<std::endl;
edm::LogPrint("KeyListAnalyzer") << "Record \"ExDwarfListRcd\" does not exist";
}
edm::ESHandle<cond::KeyList> klh;
std::cout<<"got eshandle"<<std::endl;
context.get<ExDwarfListRcd>().get(klh);
std::cout<<"got context"<<std::endl;
cond::KeyList const & kl= *klh.product();
int n=0;
for (int i=0; i<kl.size(); i++)
if (kl.elem(i)) {
n++;
if (0==i%2)
print(*kl.get<condex::ConfI>(i));
else
print(*kl.get<condex::ConfF>(i));
edm::LogPrint("KeyListAnalyzer") << "got context";
cond::KeyList const& kl = context.getData(theKeyListToken_);
int n = 0;
for (int i = 0; i < kl.size(); i++)
if (kl.elem(i)) {
n++;
if (0 == i % 2)
print(*kl.get<condex::ConfI>(i));
else
print(*kl.get<condex::ConfF>(i));
}
std::cout << "found " << n << " valid keyed confs" << std::endl;

std::cout << std::endl;
edm::LogPrint("KeyListAnalyzer") << "found " << n << " valid keyed confs" << std::endl;
}

DEFINE_FWK_MODULE(KeyListAnalyzer);
}
} // namespace edmtest
43 changes: 19 additions & 24 deletions CondCore/ESSources/test/stubs/LumiTestReadAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,43 @@ Toy EDProducers and EDProducts for testing purposes only.
#include <stdexcept>
#include <string>
#include <iostream>
//#include <map>
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include <fstream>

#include "CondCore/CondDB/interface/Time.h"

#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"

#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
//#include "CondFormats/DataRecord/interface/LumiTestPayloadRcd.h"
//#include "CondFormats/Common/interface/LumiTestPayload.h"
#include "CondCore/CondDB/interface/Time.h"
#include <fstream>

using namespace std;

namespace edmtest {
class LumiTestReadAnalyzer : public edm::EDAnalyzer {
class LumiTestReadAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit LumiTestReadAnalyzer(edm::ParameterSet const& p)
: m_processId(p.getUntrackedParameter<std::string>("processId")),
: theBSToken_(esConsumes()),
m_processId(p.getUntrackedParameter<std::string>("processId")),
m_pathForLastLumiFile(p.getUntrackedParameter<std::string>("lastLumiFile", "")),
m_pathForErrorFile("") {
std::string pathForErrorFolder = p.getUntrackedParameter<std::string>("pathForErrorFile");
m_pathForErrorFile = pathForErrorFolder + "/lumi_read_" + m_processId + ".txt";
}
explicit LumiTestReadAnalyzer(int i) {}
virtual ~LumiTestReadAnalyzer() {}
virtual void beginJob();
virtual void beginRun(const edm::Run&, const edm::EventSetup& context);
virtual ~LumiTestReadAnalyzer() = default;
virtual void analyze(const edm::Event& e, const edm::EventSetup& c);

private:
const edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> theBSToken_;
std::string m_processId;
std::string m_pathForLastLumiFile;
std::string m_pathForErrorFile;
};
void LumiTestReadAnalyzer::beginRun(const edm::Run&, const edm::EventSetup& context) {}
void LumiTestReadAnalyzer::beginJob() {}

void LumiTestReadAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
static constexpr const char* const MSGSOURCE = "LumiTestReadAnalyzer:";
edm::eventsetup::EventSetupRecordKey recordKey(
Expand All @@ -56,9 +53,7 @@ namespace edmtest {
//record not found
edm::LogError(MSGSOURCE) << "Record \"BeamSpotObjectsRcd\" does not exist ";
}
edm::ESHandle<BeamSpotObjects> ps;
context.get<BeamSpotObjectsRcd>().get(ps);
const BeamSpotObjects* payload = ps.product();
auto const& payload = &context.getData(theBSToken_);
edm::LogInfo(MSGSOURCE) << "Event " << e.id().event() << " Run " << e.id().run() << " Lumi "
<< e.id().luminosityBlock() << " Time " << e.time().value() << " LumiTestPayload id "
<< payload->GetBeamType() << std::endl;
Expand All @@ -71,15 +66,15 @@ namespace edmtest {
msg << "On time " << boost::posix_time::to_iso_extended_string(now) << " Target " << target << "; found "
<< found;
edm::LogWarning(MSGSOURCE) << msg.str();
std::cout << "ERROR ( process " << m_processId << " ) : " << msg.str() << std::endl;
std::cout << "### dumping in file " << m_pathForErrorFile << std::endl;
edm::LogPrint("LumiTestReadAnalyzer") << "ERROR ( process " << m_processId << " ) : " << msg.str();
edm::LogPrint("LumiTestReadAnalyzer") << "### dumping in file " << m_pathForErrorFile;
{
std::ofstream errorFile(m_pathForErrorFile, std::ios_base::app);
errorFile << msg.str() << std::endl;
}
//throw std::runtime_error( msg.str() );
} else {
std::cout << "Info: read was ok." << std::endl;
edm::LogPrint("LumiTestReadAnalyzer") << "Info: read was ok.";
}
}
DEFINE_FWK_MODULE(LumiTestReadAnalyzer);
Expand Down