Skip to content

Commit

Permalink
Merge pull request #21883 from rovere/DQMEDAnalyserSkeleton
Browse files Browse the repository at this point in the history
DQMEDAnalyzer skeleton
  • Loading branch information
cmsbuild committed Jan 26, 2018
2 parents 8f94a93 + 9851a36 commit 375030f
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 55 deletions.
17 changes: 17 additions & 0 deletions FWCore/Skeletons/python/cms.py
Expand Up @@ -48,6 +48,23 @@ def config(tmpl, pkg_help, tmpl_dir):
kwds['tmpl_etags'] = etags
return kwds

def config_with_parser(tmpl, args, tmpl_dir):
"""
Inject arguments parsed upstream into mk-scripts.
The arguments are parsed by the different front-ends(binaries)
and passed here via the args object.
"""

kwds = {'author': '', 'tmpl': tmpl,
'args': {}, 'debug': False, 'tmpl_dir': tmpl_dir}
etags = []
kwds['pname'] = args.subpackage_name
if args.author: kwds['author'] = args.author
if args.debug: kwds['debug'] = True
if args.example: etags.append('@%s' % args.example)
kwds['tmpl_etags'] = etags
return kwds

def cms_error():
"Standard CMS error message"
msg = "\nPackages must be created in a 'subsystem'."
Expand Down
22 changes: 10 additions & 12 deletions FWCore/Skeletons/python/pkg.py
Expand Up @@ -48,7 +48,7 @@ def __init__(self, config=None):
self.author = user_info(self.config.get('author', None))
self.date = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
self.not_in_dir = self.config.get('not_in_dir', [])

def tmpl_etags(self):
"Scan template files and return example tags"
keys = []
Expand Down Expand Up @@ -94,22 +94,19 @@ def print_tags(self):

def parse_etags(self, line):
"""
Determine either skip or keep given line based on class tags
Determine either skip or keep given line based on class tags
meta-strings
"""
tmpl_etags = self.tmpl_etags()
keep_etags = self.config.get('tmpl_etags', [])
for tag in tmpl_etags:
if keep_etags:
for valid_tag in keep_etags:
if line.find(valid_tag) != -1:
line = line.replace(valid_tag, '')
return line
else:
if line.find(tag) != -1:
line = line.replace(tag, '')
line = ''
return line
for valid_tag in keep_etags:
if line.find(valid_tag) != -1:
line = line.replace(valid_tag, '')
return line
if line.find(tag) != -1:
line = ''
return line
return line

def write(self, fname, tmpl_name, kwds):
Expand Down Expand Up @@ -146,6 +143,7 @@ def get_kwds(self):
'__user__': os.getlogin(),
'__date__': self.date,
'__class__': self.pname,
'__class_lowercase__': self.pname.lower(),
'__name__': self.pname,
'__subsys__': self.config.get('subsystem', 'Subsystem')}
args = self.config.get('args', None)
Expand Down
@@ -0,0 +1,5 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ParameterSet"/>
<use name="DQMServices/Core" />
<flags EDM_PLUGIN="1"/>
143 changes: 143 additions & 0 deletions FWCore/Skeletons/scripts/mkTemplates/DQMEDAnalyzer/DQMEDAnalyzer.cc
@@ -0,0 +1,143 @@
// -*- 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__
//
//

#include <string>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
@example_stream#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
@example_global#include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"

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

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

@example_stream#include "DQMServices/Core/interface/MonitorElement.h"

//
// class declaration
//

@example_globalstruct Histograms___class__ {
@example_global ConcurrentMonitorElement histo_;
@example_global};

@example_streamclass __class__ : public DQMEDAnalyzer {
@example_globalclass __class__ : public DQMGlobalEDAnalyzer<Histograms___class__> {
public:
explicit __class__(const edm::ParameterSet&);
~__class__();

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


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

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

// ----------member data ---------------------------
std::string folder_;
@example_stream MonitorElement * example_;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
__class__::__class__(const edm::ParameterSet& iConfig)
: folder_(iConfig.getUntrackedParameter<std::string>("folder"))
{
//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.)
}


//
// member functions
//

// ------------ method called for each event ------------
@example_streamvoid
@example_stream__class__::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
@example_stream{
@example_stream using namespace edm;
@example_stream}
@example_stream
@example_streamvoid
@example_stream__class__::bookHistograms(DQMStore::IBooker & ibook,
@example_stream edm::Run const& run,
@example_stream edm::EventSetup const & iSetup)
@example_stream{
@example_stream ibook.setCurrentFolder(folder_);
@example_stream
@example_stream ibook.book1D("EXAMPLE", "EXAMPLE", 10, 0., 10.);
@example_stream}

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

@example_globalvoid
@example_global__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{
@example_global ibook.setCurrentFolder(folder_);
@example_global histos.histo_ = ibook.book1D("EXAMPLE", "EXAMPLE", 10, 0., 10.);
@example_global}

// ------------ 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.add<std::string>("folder", "MY_FOLDER");
descriptions.add("__class_lowercase__", desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(__class__);
5 changes: 5 additions & 0 deletions FWCore/Skeletons/scripts/mkTemplates/DQMEDAnalyzer/Driver.dir
@@ -0,0 +1,5 @@
plugins/BuildFile.xml
plugins/DQMEDAnalyzer.cc
python/ExampleConfig_cfg.py
test
doc
@@ -0,0 +1,19 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("Demo")

process.load("FWCore.MessageService.MessageLogger_cfi")

process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) )

process.source = cms.Source("PoolSource",
# replace 'myfile.root' with the source file you want to use
fileNames = cms.untracked.vstring(
'file:myfile.root'
)
)

process.load("__subsys__.__pkgname__.__class_lowercase___cfi")
process.DQMStore = cms.Service("DQMStore")

process.p = cms.Path(process.__class_lowercase__)
@@ -1,6 +1,6 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ParameterSet"/>
<use name="DataFormats/TrackReco"/>
<flags EDM_PLUGIN="1"/>
@example_track <use name="DataFormats/TrackReco"/>
@example_histo <use name="CommonTools/UtilAlgos"/>
@@ -1,5 +1,5 @@
import FWCore.ParameterSet.Config as cms

demo = cms.EDAnalyzer('__class__'
@example_track ,tracks = cms.untracked.InputTag('ctfWithMaterialTracks')
,tracks = cms.untracked.InputTag('ctfWithMaterialTracks')
)
Expand Up @@ -14,11 +14,11 @@
)

process.demo = cms.EDAnalyzer('__class__'
@example_track , tracks = cms.untracked.InputTag('ctfWithMaterialTracks')
, tracks = cms.untracked.InputTag('ctfWithMaterialTracks')
)

@example_histo process.TFileService = cms.Service("TFileService",
@example_histo fileName = cms.string('histo.root')
@example_histo )
@example_histoprocess.TFileService = cms.Service("TFileService",
@example_histo fileName = cms.string('histo.root')
@example_histo)

process.p = cms.Path(process.demo)

0 comments on commit 375030f

Please sign in to comment.