UserUtils
PluginAlias.hpp
Go to the documentation of this file.
1
8#ifndef USERUTILS_EDMUTILS_PLUGINALIAS_HPP
9#define USERUTILS_EDMUTILS_PLUGINALIAS_HPP
10
11#include "FWCore/Framework/interface/Event.h"
12#include "FWCore/Framework/interface/MakerMacros.h"
13#include "FWCore/Framework/interface/one/EDAnalyzer.h"
14#include "FWCore/Framework/interface/one/EDFilter.h"
15#include "FWCore/ParameterSet/interface/ParameterSet.h"
16
17#include "TFile.h"
18#include "TObject.h"
19
20#include <string>
21
22namespace usr
23{
24
35template<typename EDMPLUGIN>
36class PluginAlias : public EDMPLUGIN
37{
38public:
43 PluginAlias( const edm::ParameterSet& config ) :
44 _config( config ){}
45 virtual ~PluginAlias(){}
46
47protected:
55 template<typename TYPE>
56 inline edm::EDGetToken
57 GetToken( const std::string& configtag )
58 {
59 return edm::EDConsumerBase::consumes<TYPE>(
60 _config.getParameter<edm::InputTag>( configtag ) );
61 }
62
63
68 template<typename TYPE>
69 inline edm::EDGetToken
70 GetRunToken( const std::string& configtag )
71 {
72 return edm::EDConsumerBase::consumes<TYPE, edm::InRun>(
73 _config.getParameter<edm::InputTag>( configtag ) );
74 }
75
76
80 template<typename TYPE>
81 inline edm::Handle<TYPE>
82 MakeHandle( const edm::Event& event, const edm::EDGetToken tok )
83 {
84 edm::Handle<TYPE> handle;
85 event.getByToken( tok, handle );
86 assert( handle.isValid() );
87 return handle;
88 }
89
90
95 inline TObject*GetFileObj( const std::string& filetag,
96 const std::string objtag )
97 { return GetFileObj( _config, filetag, objtag ); }
98
103 inline std::string GetFilePath( const std::string& filetag )
104 { return GetFilePath( _config, filetag ); }
105
110 static std::string
111 GetFilePath( const edm::ParameterSet& config,
112 const std::string& filetag )
113 {
114 return config.getParameter<edm::FileInPath>( filetag ).fullPath();
115 }
116
117
126 static TObject*
127 GetFileObj( const edm::ParameterSet& config,
128 const std::string& filetag,
129 const std::string& objtag )
130 {
131 const std::string filename = GetFilePath( config, filetag );
132 const std::string objname = config.getParameter<std::string>( objtag );
133 TFile* file = TFile::Open( filename.c_str() );
134 TObject* ans = file->Get( objname.c_str() )->Clone();
135
136 // ans->SetDirectory(0); // Detach object from parent directory.
137 file->Close();
138 return ans;
139 }
140
141private:
142 const edm::ParameterSet& _config;
143};
144
145typedef PluginAlias<edm::one::EDAnalyzer<edm::one::SharedResources> >
146 EDAnalyzer;
147typedef PluginAlias<edm::one::EDFilter<edm::one::SharedResources> >
148 EDFilter;
149
150}/* usr */
151
152#endif/* end of include guard: USERUTILS_EDMUTILS_PLUGINALIAS_HPP */
class for reducing the verbosity of the various edm plugin calls.
Definition: PluginAlias.hpp:37
edm::EDGetToken GetToken(const std::string &configtag)
template class for getting the EdmToken from the initializer configuration parameter set.
Definition: PluginAlias.hpp:57
static std::string GetFilePath(const edm::ParameterSet &config, const std::string &filetag)
returing the string to a path in the parameterset if an EDM::FileInPath was used.
Definition: PluginAlias.hpp:111
TObject * GetFileObj(const std::string &filetag, const std::string objtag)
getting a clone of an object described in a file. See static function for full documentation.
Definition: PluginAlias.hpp:95
std::string GetFilePath(const std::string &filetag)
getting the full path to a file. See static function for full documentation.
Definition: PluginAlias.hpp:103
PluginAlias(const edm::ParameterSet &config)
Definition: PluginAlias.hpp:43
edm::Handle< TYPE > MakeHandle(const edm::Event &event, const edm::EDGetToken tok)
Construction for a handle.
Definition: PluginAlias.hpp:82
edm::EDGetToken GetRunToken(const std::string &configtag)
Same template function as GetToken() except for getting Run level objects.
Definition: PluginAlias.hpp:70
static TObject * GetFileObj(const edm::ParameterSet &config, const std::string &filetag, const std::string &objtag)
Given a file path in the form of an EDM::FileInPath, and a object key as a parameter set string.
Definition: PluginAlias.hpp:127