From 15b17e470398ed37d6fc3c5183b3917803207a51 Mon Sep 17 00:00:00 2001 From: Marta Date: Mon, 2 Nov 2015 10:02:41 +0100 Subject: [PATCH 1/4] Bug fix for compatible mode in UETableProducer. Don't overwrite python files in make_db.sh --- RecoHI/HiJetAlgos/plugins/UETableProducer.cc | 6 +++--- RecoHI/HiJetAlgos/test/make_db.sh | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc index 9b6007e177aa4..574e87486c766 100644 --- a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc +++ b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc @@ -204,10 +204,10 @@ UETableProducer::endJob() { jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter); - if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){ - pool->createNewIOV( jme_payload, pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" ); + if( pool->isNewTagRequest( "JetCorrectionsRecord" ) ){ + pool->createNewIOV( jme_payload, pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord" ); }else{ - pool->appendSinceTime( jme_payload, pool->currentTime(), "HeavyIonUERcd" ); + pool->appendSinceTime( jme_payload, pool->currentTime(), "JetCorrectionsRecord" ); } } else { diff --git a/RecoHI/HiJetAlgos/test/make_db.sh b/RecoHI/HiJetAlgos/test/make_db.sh index d2c9e6bc44149..80d470147684a 100755 --- a/RecoHI/HiJetAlgos/test/make_db.sh +++ b/RecoHI/HiJetAlgos/test/make_db.sh @@ -1,8 +1,8 @@ #!/bin/sh -py=`mktemp --tmpdir=. make_db_XXXXXXXXXX.py` +#py=`mktemp --tmpdir=. make_db_XXXXXXXXXX.py` -trap "rm -f \"$py\"" 1 2 3 15 +#trap "rm -f \"$py\"" 1 2 3 15 o="./output.db" v="00" @@ -10,6 +10,8 @@ v="00" #eval `scramv1 runtime -sh` rm -f "$o" for f in ue_calibrations_pf_mc.txt ue_calibrations_calo_mc.txt ue_calibrations_pf_data.txt ue_calibrations_calo_data.txt; do + py=`mktemp --tmpdir=. make_db_XXXXXXXXXX.py` + trap "rm -f \"$py\"" 1 2 3 15 e="unknown" d="unknown" case "$f" in From 5c46cd17c4af07a198c3bb9650e871a49890a6e9 Mon Sep 17 00:00:00 2001 From: Marta Date: Wed, 4 Nov 2015 18:47:46 +0100 Subject: [PATCH 2/4] make UETableProducer multi-thread safe --- RecoHI/HiJetAlgos/plugins/UETableProducer.cc | 143 ++++++++++--------- 1 file changed, 74 insertions(+), 69 deletions(-) diff --git a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc index 574e87486c766..6c7860e7f17a6 100644 --- a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc +++ b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc @@ -32,36 +32,39 @@ using namespace std; // class decleration // -class UETableProducer : public edm::EDAnalyzer { -public: - explicit UETableProducer(const edm::ParameterSet&); - ~UETableProducer(); +namespace { + class UETableProducer : public edm::one::EDAnalyzer<> { + public: + explicit UETableProducer(const edm::ParameterSet&); + ~UETableProducer(); -private: - virtual void beginRun(const edm::EventSetup&) ; - virtual void analyze(const edm::Event&, const edm::EventSetup&); - virtual void endJob() ; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginJob() override {} + virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void endJob(); - // ----------member data --------------------------- + // ----------member data --------------------------- - bool debug_; - bool jetCorrectorFormat_; + bool debug_; + bool jetCorrectorFormat_; - string calibrationFile_; - unsigned int runnum_; + string calibrationFile_; + unsigned int runnum_; - unsigned int index = 0, - np[5], - ni0[2], - ni1[2], - ni2[2]; + unsigned int index = 0, + np[5], + ni0[2], + ni1[2], + ni2[2]; - // ue_interpolation_pf0[15][344], - // ue_interpolation_pf1[15][344], - // ue_interpolation_pf2[15][82]; - -}; + // ue_interpolation_pf0[15][344], + // ue_interpolation_pf1[15][344], + // ue_interpolation_pf2[15][82]; + }; +} // // constants, enums and typedefs // @@ -118,12 +121,6 @@ UETableProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup } -// ------------ method called once each job just before starting event loop ------------ -void -UETableProducer::beginRun(const edm::EventSetup& iSetup) -{ -} - // ------------ method called once each job just after ending the event loop ------------ void UETableProducer::endJob() { @@ -134,7 +131,7 @@ UETableProducer::endJob() { UETable *ue_predictor_pf = NULL; if (!jetCorrectorFormat_) { - ue_predictor_pf = new UETable(); + ue_predictor_pf = new UETable(); } // unsigned int Nnp_full = np[0] * np[1] * np[2] * np[3] * np[4]; unsigned int Nnp = np[0] * np[1] * (1 + (np[2] - 1) * np[3]) * np[4]; @@ -143,23 +140,23 @@ UETableProducer::endJob() { unsigned int Nni2 = ni2[0]*ni2[1]; if (!jetCorrectorFormat_) { - ue_predictor_pf->np.resize(5); - ue_predictor_pf->ni0.resize(2); - ue_predictor_pf->ni1.resize(2); - ue_predictor_pf->ni2.resize(2); - - std::copy(np, np + 5, ue_predictor_pf->np.begin()); - std::copy(ni0, ni0 + 2, ue_predictor_pf->ni0.begin()); - std::copy(ni1, ni1 + 2, ue_predictor_pf->ni1.begin()); - std::copy(ni2, ni2 + 2, ue_predictor_pf->ni2.begin()); - - static const float edge_pseudorapidity[16] = { - -5.191, -2.650, -2.043, -1.740, -1.479, -1.131, -0.783, -0.522, 0.522, 0.783, 1.131, 1.479, 1.740, 2.043, 2.650, 5.191 - }; + ue_predictor_pf->np.resize(5); + ue_predictor_pf->ni0.resize(2); + ue_predictor_pf->ni1.resize(2); + ue_predictor_pf->ni2.resize(2); - ue_predictor_pf->edgeEta.resize(16); + std::copy(np, np + 5, ue_predictor_pf->np.begin()); + std::copy(ni0, ni0 + 2, ue_predictor_pf->ni0.begin()); + std::copy(ni1, ni1 + 2, ue_predictor_pf->ni1.begin()); + std::copy(ni2, ni2 + 2, ue_predictor_pf->ni2.begin()); - std::copy(edge_pseudorapidity, edge_pseudorapidity + 16, ue_predictor_pf->edgeEta.begin()); + static const float edge_pseudorapidity[16] = { + -5.191, -2.650, -2.043, -1.740, -1.479, -1.131, -0.783, -0.522, 0.522, 0.783, 1.131, 1.479, 1.740, 2.043, 2.650, 5.191 + }; + + ue_predictor_pf->edgeEta.resize(16); + + std::copy(edge_pseudorapidity, edge_pseudorapidity + 16, ue_predictor_pf->edgeEta.begin()); } @@ -175,16 +172,16 @@ UETableProducer::endJob() { int bin0, bin1, bin2, bin3, bin4; if(index < Nnp){ linestream>>bin0>>bin1>>bin2>>bin3>>bin4>>val; - ue_vec.push_back(val); + ue_vec.push_back(val); }else if(index < Nnp + Nni0){ linestream>>bin0>>bin1>>val; - ue_vec.push_back(val); + ue_vec.push_back(val); }else if(index < Nnp + Nni0 + Nni1){ linestream>>bin0>>bin1>>val; - ue_vec.push_back(val); + ue_vec.push_back(val); }else if(index < Nnp + Nni0 + Nni1 + Nni2){ linestream>>bin0>>bin1>>val; - ue_vec.push_back(val); + ue_vec.push_back(val); } ++index; @@ -194,32 +191,40 @@ UETableProducer::endJob() { if( pool.isAvailable() ){ - if (jetCorrectorFormat_) { - // A minimal dummy line that satisfies the JME # token >= 6 requirement, and has the correct key type - JetCorrectorParameters::Definitions definition("1 0 0 0 Correction L1Offset"); - std::vector record(1, JetCorrectorParameters::Record(ue_vec.size(), std::vector(ue_vec.size(), 0), std::vector(ue_vec.size(), 0), ue_vec)); - JetCorrectorParameters parameter(definition, record); + if (jetCorrectorFormat_) { + // A minimal dummy line that satisfies the JME # token >= 6 requirement, and has the correct key type + JetCorrectorParameters::Definitions definition("1 0 0 0 Correction L1Offset"); + std::vector record(1, JetCorrectorParameters::Record(ue_vec.size(), std::vector(ue_vec.size(), 0), std::vector(ue_vec.size(), 0), ue_vec)); + JetCorrectorParameters parameter(definition, record); - JetCorrectorParametersCollection *jme_payload = new JetCorrectorParametersCollection(); + JetCorrectorParametersCollection *jme_payload = new JetCorrectorParametersCollection(); - jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter); + jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter); - if( pool->isNewTagRequest( "JetCorrectionsRecord" ) ){ - pool->createNewIOV( jme_payload, pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord" ); - }else{ - pool->appendSinceTime( jme_payload, pool->currentTime(), "JetCorrectionsRecord" ); + if( pool->isNewTagRequest( "JetCorrectionsRecord" ) ){ + pool->createNewIOV( jme_payload, pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord" ); + }else{ + pool->appendSinceTime( jme_payload, pool->currentTime(), "JetCorrectionsRecord" ); + } } - } - else { - ue_predictor_pf->values = ue_vec; - - if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){ - pool->createNewIOV( ue_predictor_pf, pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" ); - }else{ - pool->appendSinceTime( ue_predictor_pf, pool->currentTime(), "HeavyIonUERcd" ); + else { + ue_predictor_pf->values = ue_vec; + + if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){ + pool->createNewIOV( ue_predictor_pf, pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" ); + }else{ + pool->appendSinceTime( ue_predictor_pf, pool->currentTime(), "HeavyIonUERcd" ); + } } } - } +} + +void UETableProducer::fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("algorithm", 1); + desc.add("ptCut", 20.0); + desc.addUntracked("debugLevel", 1U); + descriptions.add("produceUETable", desc); } From e2835b5b28da44e3f019e842936cf75332f71821 Mon Sep 17 00:00:00 2001 From: Marta Date: Wed, 4 Nov 2015 18:56:59 +0100 Subject: [PATCH 3/4] sensible info in fillDescription --- RecoHI/HiJetAlgos/plugins/UETableProducer.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc index 6c7860e7f17a6..594dbb01fb6e9 100644 --- a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc +++ b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc @@ -221,12 +221,11 @@ UETableProducer::endJob() { void UETableProducer::fillDescriptions(edm::ConfigurationDescriptions & descriptions) { edm::ParameterSetDescription desc; - desc.add("algorithm", 1); - desc.add("ptCut", 20.0); - desc.addUntracked("debugLevel", 1U); + desc.add("txtFile", "example"); + desc.addUntracked("debug", false); + desc.addUntracked("jetCorrectorFormat", false); descriptions.add("produceUETable", desc); } - //define this as a plug-in DEFINE_FWK_MODULE(UETableProducer); From 8550b00fa56a7a284b2597b20d0905511bcecdd6 Mon Sep 17 00:00:00 2001 From: Marta Date: Wed, 4 Nov 2015 19:36:42 +0100 Subject: [PATCH 4/4] fix potential memory leak + add override to analyze and endJob --- RecoHI/HiJetAlgos/plugins/UETableProducer.cc | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc index 594dbb01fb6e9..b4d9fccaa27d3 100644 --- a/RecoHI/HiJetAlgos/plugins/UETableProducer.cc +++ b/RecoHI/HiJetAlgos/plugins/UETableProducer.cc @@ -42,8 +42,8 @@ namespace { private: virtual void beginJob() override {} - virtual void analyze(const edm::Event&, const edm::EventSetup&); - virtual void endJob(); + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; // ----------member data --------------------------- @@ -128,10 +128,10 @@ UETableProducer::endJob() { std::ifstream textTable_(qpDataName.c_str()); std::vector ue_vec; - UETable *ue_predictor_pf = NULL; - + std::unique_ptr ue_predictor_pf; + if (!jetCorrectorFormat_) { - ue_predictor_pf = new UETable(); + ue_predictor_pf = std::make_unique(); } // unsigned int Nnp_full = np[0] * np[1] * np[2] * np[3] * np[4]; unsigned int Nnp = np[0] * np[1] * (1 + (np[2] - 1) * np[3]) * np[4]; @@ -197,23 +197,23 @@ UETableProducer::endJob() { std::vector record(1, JetCorrectorParameters::Record(ue_vec.size(), std::vector(ue_vec.size(), 0), std::vector(ue_vec.size(), 0), ue_vec)); JetCorrectorParameters parameter(definition, record); - JetCorrectorParametersCollection *jme_payload = new JetCorrectorParametersCollection(); - + std::unique_ptr jme_payload = std::make_unique(); + jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter); if( pool->isNewTagRequest( "JetCorrectionsRecord" ) ){ - pool->createNewIOV( jme_payload, pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord" ); + pool->createNewIOV( jme_payload.get(), pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord" ); }else{ - pool->appendSinceTime( jme_payload, pool->currentTime(), "JetCorrectionsRecord" ); + pool->appendSinceTime( jme_payload.get(), pool->currentTime(), "JetCorrectionsRecord" ); } } else { ue_predictor_pf->values = ue_vec; if( pool->isNewTagRequest( "HeavyIonUERcd" ) ){ - pool->createNewIOV( ue_predictor_pf, pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" ); + pool->createNewIOV( ue_predictor_pf.get(), pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd" ); }else{ - pool->appendSinceTime( ue_predictor_pf, pool->currentTime(), "HeavyIonUERcd" ); + pool->appendSinceTime( ue_predictor_pf.get(), pool->currentTime(), "HeavyIonUERcd" ); } } }