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

Fix and modernize Skeleton template scripts #29840

Merged
merged 18 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,17 @@

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


private:
@example_stream void bookHistograms(DQMStore::IBooker &,
@example_stream edm::Run const&,
@example_stream edm::EventSetup const&) override;
@example_global void bookHistograms(DQMStore::ConcurrentBooker &,
@example_global edm::Run const&,
@example_global edm::EventSetup const&,
@example_global Histograms___class__&) const override;
@example_stream void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
@example_global void bookHistograms(DQMStore::ConcurrentBooker&,
@example_global edm::Run const&,
@example_global edm::EventSetup const&,
@example_global Histograms___class__&) const override;

@example_stream void analyze(const edm::Event&, const edm::EventSetup&) override;
@example_global void dqmAnalyze(edm::Event const&,
@example_global edm::EventSetup const&,
@example_global Histograms___class__ const&) const override;
@example_global void dqmAnalyze(edm::Event const&, edm::EventSetup const&, Histograms___class__ const&) const override;

// ------------ member data ------------
// ------------ member data ------------
std::string folder_;
@example_stream MonitorElement* example_;
@example_stream MonitorElement* example2D_;
Expand All @@ -84,16 +79,14 @@
//
__class__::__class__(const edm::ParameterSet& iConfig)
: folder_(iConfig.getParameter<std::string>("folder")) {
// now do what ever initialization is needed
// now do what ever initialization is needed
}


__class__::~__class__() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}


//
// member functions
//
Expand All @@ -111,27 +104,27 @@ __class__::~__class__() {
@example_stream exampleTProfile2D_->Fill(eventCount_ / 10, eventCount_ / 10, eventCount_ / 10.f);
@example_stream}
@example_stream
@example_streamvoid __class__::bookHistograms(DQMStore::IBooker & ibook,
@example_stream edm::Run const& run,
@example_stream edm::EventSetup const & iSetup) {
@example_streamvoid __class__::bookHistograms(DQMStore::IBooker& ibook, edm::Run const& run, edm::EventSetup const& iSetup) {
@example_stream ibook.setCurrentFolder(folder_);
@example_stream
@example_stream example_ = ibook.book1D("EXAMPLE", "Example 1D", 20, 0., 10.);
@example_stream example2D_ = ibook.book2D("EXAMPLE_2D", "Example 2D", 20, 0, 20, 15, 0, 15);
@example_stream example3D_ = ibook.book3D("EXAMPLE_3D", "Example 3D", 20, 0, 20, 15, 0, 15, 25, 0, 25);
@example_stream exampleTProfile_ = ibook.bookProfile("EXAMPLE_TPROFILE", "Example TProfile", 20, 0, 20, 15, 0, 15);
@example_stream exampleTProfile2D_ =ibook.bookProfile2D("EXAMPLE_TPROFILE2D", "Example TProfile 2D", 20, 0, 20, 15, 0, 15, 0, 100);
@example_stream exampleTProfile2D_ = ibook.bookProfile2D("EXAMPLE_TPROFILE2D", "Example TProfile 2D", 20, 0, 20, 15, 0, 15, 0, 100);
@example_stream}

@example_globalvoid __class__::dqmAnalyze(edm::Event const& iEvent, edm::EventSetup const& iSetup,
@example_global Histograms___class__ const & histos) const {
@example_globalvoid __class__::dqmAnalyze(edm::Event const& iEvent,
@example_global edm::EventSetup const& iSetup,
@example_global Histograms___class__ const& histos) const {
@example_global foo();
@example_global}
@example_global

@example_globalvoid __class__::bookHistograms(DQMStore::ConcurrentBooker & ibook,
@example_global edm::Run const & run,
@example_global edm::EventSetup const & iSetup,
@example_global Histograms___class__ & histos) const {
@example_globalvoid __class__::bookHistograms(DQMStore::ConcurrentBooker& ibook,
@example_global edm::Run const& run,
@example_global edm::EventSetup const& iSetup,
@example_global Histograms___class__& histos) const {
@example_global ibook.setCurrentFolder(folder_);
@example_global histos.histo_ = ibook.book1D("EXAMPLE", "EXAMPLE", 10, 0., 10.);
@example_global}
Expand Down
5 changes: 5 additions & 0 deletions FWCore/Skeletons/mkTemplates/DataPkg/classes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "DataFormats/Common/interface/Wrapper.h"

//Add includes for your classes here
#include "__subsys__/__pkgname__/interface/YOUR_CLASS_GOES_HERE.h"
#include <vector>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@example_histo<use name="CommonTools/UtilAlgos"/>
<use name="DataFormats/TrackReco"/>
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ParameterSet"/>
<use name="DataFormats/TrackReco"/>
<use name="FWCore/PluginManager"/>
<flags EDM_PLUGIN="1"/>
@example_histo <use name="CommonTools/UtilAlgos"/>
144 changes: 144 additions & 0 deletions FWCore/Skeletons/mkTemplates/EDAnalyzer/EDAnalyzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// -*- C++ -*-
//
// Package: __subsys__/__pkgname__
// Class: __class__
//
/**\class __class__ __class__.cc __subsys__/__pkgname__/plugins/__class__.cc

Description: [one line class summary]

Implementation:
[Notes on implementation]
*/
//
// Original Author: __author__
// Created: __date__
//
//

// system include files
#include <memory>

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

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
@example_histo#include "FWCore/ServiceRegistry/interface/Service.h"
@example_histo#include "CommonTools/UtilAlgos/interface/TFileService.h"
@example_histo#include "TH1.h"
//
// class declaration
//

// If the analyzer does not use TFileService, please remove
// the template argument to the base class so the class inherits
// from edm::one::EDAnalyzer<>
// This will improve performance in multithreaded jobs.

using reco::TrackCollection;

class __class__ : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit __class__(const edm::ParameterSet&);
~__class__();

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

private:
void beginJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;

// ----------member data ---------------------------
edm::EDGetTokenT<TrackCollection> tracksToken_; //used to select what tracks to read from configuration file
#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
edm::ESGetToken<SetupData, SetupRecord> setupToken_;
#endif
@example_histo TH1I* histo;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
__class__::__class__(const edm::ParameterSet& iConfig)
: tracksToken_(consumes<TrackCollection>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))) {
#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
setupDataToken_ = esConsumes<SetupData, SetupRecord>();
#endif
//now do what ever initialization is needed
@example_histo usesResource("TFileService");
@example_histo edm::Service<TFileService> fs;
@example_histo histo = fs->make<TH1I>("charge", "Charges", 2, -1, 1);
}

__class__::~__class__() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
//
// please remove this method altogether if it would be left empty
}

//
// member functions
//

// ------------ method called for each event ------------
void __class__::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;

for (const auto& track : iEvent.get(tracksToken_)) {
// do something with track parameters, e.g, plot the charge.
// int charge = track.charge();
@example_histo histo->Fill(track.charge());
}

#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
// if the SetupData is always needed
auto setup = iSetup.getData(setupToken_);
// if need the ESHandle to check if the SetupData was there or not
auto pSetup = iSetup.getHandle(setupToken_);
#endif
}

// ------------ method called once each job just before starting event loop ------------
void __class__::beginJob() {
// please remove this method if not needed
}

// ------------ method called once each job just after ending the event loop ------------
void __class__::endJob() {
// please remove this method if not needed
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void __class__::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.addDefault(desc);

//Specify that only 'tracks' is allowed
//To use, remove the default given above and uncomment below
//ParameterSetDescription desc;
//desc.addUntracked<edm::InputTag>("tracks","ctfWithMaterialTracks");
//descriptions.addDefault(desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(__class__);
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,42 @@ static constexpr auto s_tag = "[__class__]";

TEST_CASE("Standard checks of __class__", s_tag) {
const std::string baseConfig{
R"_(from FWCore.TestProcessor.TestProcess import *
R"_(from FWCore.TestProcessor.TestProcess import *
process = TestProcess()
process.toTest = cms.EDProducer("__class__"
#necessary configuration parameters
)
process.moduleToTest(process.toTest)
)_"
};

edm::test::TestProcessor::Config config{ baseConfig };
SECTION("base configuration is OK") {
REQUIRE_NOTHROW(edm::test::TestProcessor(config));
}

)_"};

edm::test::TestProcessor::Config config{baseConfig};
SECTION("base configuration is OK") { REQUIRE_NOTHROW(edm::test::TestProcessor(config)); }

SECTION("No event data") {
edm::test::TestProcessor tester(config);

REQUIRE_THROWS_AS(tester.test(), cms::Exception);
//If the module does not throw when given no data, substitute
//If the module does not throw when given no data, substitute
//REQUIRE_NOTHROW for REQUIRE_THROWS_AS
}

SECTION("beginJob and endJob only") {
edm::test::TestProcessor tester(config);

REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly());
}

SECTION("Run with no LuminosityBlocks") {
edm::test::TestProcessor tester(config);

REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks());
}

SECTION("LuminosityBlock with no Events") {
edm::test::TestProcessor tester(config);

REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents());
}

}

//Add additional TEST_CASEs to exercise the modules capabilities
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/PluginManager"/>
<flags EDM_PLUGIN="1"/>