CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
VersionedIdProducer< PhysicsObjectPtr, SelectorType > Class Template Reference

#include <VersionedIdProducer.h>

Inheritance diagram for VersionedIdProducer< PhysicsObjectPtr, SelectorType >:
edm::stream::EDProducer<>

Public Types

using Collection = edm::View< PhysicsObjectType >
 
using PhysicsObjectType = typename PhysicsObjectPtr::value_type
 
using TokenType = edm::EDGetTokenT< Collection >
 
- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Public Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 
 VersionedIdProducer (const edm::ParameterSet &)
 
 ~VersionedIdProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Attributes

std::vector< std::unique_ptr< SelectorType > > ids_
 
TokenType physicsObjectSrc_
 
bool verbose_
 

Detailed Description

template<class PhysicsObjectPtr, class SelectorType = VersionedSelector<PhysicsObjectPtr>>
class VersionedIdProducer< PhysicsObjectPtr, SelectorType >

Definition at line 27 of file VersionedIdProducer.h.

Member Typedef Documentation

template<class PhysicsObjectPtr , class SelectorType = VersionedSelector<PhysicsObjectPtr>>
using VersionedIdProducer< PhysicsObjectPtr, SelectorType >::Collection = edm::View<PhysicsObjectType>

Definition at line 31 of file VersionedIdProducer.h.

template<class PhysicsObjectPtr , class SelectorType = VersionedSelector<PhysicsObjectPtr>>
using VersionedIdProducer< PhysicsObjectPtr, SelectorType >::PhysicsObjectType = typename PhysicsObjectPtr::value_type

Definition at line 29 of file VersionedIdProducer.h.

template<class PhysicsObjectPtr , class SelectorType = VersionedSelector<PhysicsObjectPtr>>
using VersionedIdProducer< PhysicsObjectPtr, SelectorType >::TokenType = edm::EDGetTokenT<Collection>

Definition at line 32 of file VersionedIdProducer.h.

Constructor & Destructor Documentation

template<class PhysicsObjectPtr , class SelectorType >
VersionedIdProducer< PhysicsObjectPtr, SelectorType >::VersionedIdProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 61 of file VersionedIdProducer.h.

References constexpr, Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), edm::ParameterSet::getParameterSetVector(), edm::ParameterSet::getUntrackedParameter(), egmPatElectronIDs_cfi::idMD5, photons_cff::ids, VersionedIdProducer< PhysicsObjectPtr, SelectorType >::ids_, cutBasedElectronHLTPreselecition_Summer16_V1_cff::isPOGApproved, VersionedIdProducer< PhysicsObjectPtr, SelectorType >::physicsObjectSrc_, VersionedIdProducer< PhysicsObjectPtr, SelectorType >::produce(), AlCaHLTBitMon_QueryRunRegistry::string, and VersionedIdProducer< PhysicsObjectPtr, SelectorType >::verbose_.

61  {
62  constexpr char bitmap_label[] = "Bitmap";
63 
64  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
65 
67  consumes<Collection>(iConfig.getParameter<edm::InputTag>("physicsObjectSrc"));
68 
69  const std::vector<edm::ParameterSet>& ids =
70  iConfig.getParameterSetVector("physicsObjectIDs");
71  for(const auto& id : ids ) {
72  const std::string& idMD5 =
73  id.getParameter<std::string>("idMD5");
74  const edm::ParameterSet& the_id =
75  id.getParameterSet("idDefinition");
76  const std::string& idname =
77  the_id.getParameter<std::string>("idName");
78  std::string calculated_md5;
79  ids_.emplace_back( new SelectorType(the_id) );
80  calculated_md5 = ids_.back()->md5String();
81  ids_.back()->setConsumes(consumesCollector());
82  if( ids_.back()->cutFlowSize() == 0 ) {
83  throw cms::Exception("InvalidCutFlow")
84  << "Post-processing cutflow size is zero! You may have configured"
85  << " the python incorrectly!";
86  }
87 
88  if( idMD5 != calculated_md5 ) {
89  edm::LogInfo("IdConfigurationNotValidated")
90  << "ID: " << ids_.back()->name() << "\n"
91  << "The expected md5: " << idMD5 << " does not match the md5\n"
92  << "calculated by the ID: " << calculated_md5 << " please\n"
93  << "update your python configuration or determine the source\n"
94  << "of transcription error!";
95  }
96 
97  std::stringstream idmsg;
98 
99  // dump whatever information about the ID we have
100  idmsg << "Instantiated ID: " << idname << std::endl
101  << "with MD5 hash: " << idMD5 << std::endl;
102  const bool isPOGApproved =
103  id.getUntrackedParameter<bool>("isPOGApproved",false);
104  if( isPOGApproved ) {
105  idmsg << "This ID is POG approved!" << std::endl;
106  } else {
107  idmsg << "This ID is not POG approved and likely under development!!!\n"
108  << "Please make sure to report your progress with this ID "
109  << "at the next relevant POG meeting." << std::endl;
110  }
111 
112  if( !isPOGApproved ) {
113  edm::LogWarning("IdInformation")
114  << idmsg.str();
115  } else {
116  edm::LogInfo("IdInformation")
117  << idmsg.str();
118  }
119 
120  produces<std::string>(idname);
121  produces<edm::ValueMap<bool> >(idname);
122  produces<edm::ValueMap<float> >(idname); // for PAT
123  produces<edm::ValueMap<unsigned> >(idname);
124  produces<edm::ValueMap<unsigned> >(idname+std::string(bitmap_label));
125  produces<edm::ValueMap<vid::CutFlowResult> >(idname);
126  produces<pat::UserDataCollection>(idname);
127  produces<edm::ValueMap<edm::Ptr<pat::UserData> > >(idname);
128  }
129 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
VParameterSet const & getParameterSetVector(std::string const &name) const
std::vector< std::unique_ptr< SelectorType > > ids_
#define constexpr
ParameterSet const & getParameterSet(std::string const &) const
template<class PhysicsObjectPtr , class SelectorType = VersionedSelector<PhysicsObjectPtr>>
VersionedIdProducer< PhysicsObjectPtr, SelectorType >::~VersionedIdProducer ( )
inlineoverride

Member Function Documentation

template<class PhysicsObjectPtr , class SelectorType >
void VersionedIdProducer< PhysicsObjectPtr, SelectorType >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 133 of file VersionedIdProducer.h.

References constexpr, edm::helper::Filler< Map >::fill(), edm::Event::getByToken(), mps_fire::i, triggerObjects_cff::id, VersionedIdProducer< PhysicsObjectPtr, SelectorType >::ids_, edm::helper::Filler< Map >::insert(), pat::UserData::make(), eostools::move(), VersionedIdProducer< PhysicsObjectPtr, SelectorType >::physicsObjectSrc_, edm::View< T >::ptrAt(), edm::Event::put(), edm::View< T >::size(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by VersionedIdProducer< PhysicsObjectPtr, SelectorType >::VersionedIdProducer(), and VersionedIdProducer< PhysicsObjectPtr, SelectorType >::~VersionedIdProducer().

133  {
134  constexpr char bitmap_label[] = "Bitmap";
135 
136  edm::Handle<Collection> physicsObjectsHandle;
137  iEvent.getByToken(physicsObjectSrc_,physicsObjectsHandle);
138 
139  const Collection& physicsobjects = *physicsObjectsHandle;
140 
141  for( const auto& id : ids_ ) {
142  auto outPass = std::make_unique<edm::ValueMap<bool>>();
143  auto outPassf = std::make_unique<edm::ValueMap<float>>();
144  auto outHowFar = std::make_unique<edm::ValueMap<unsigned>>();
145  auto outBitmap = std::make_unique<edm::ValueMap<unsigned>>();
146  auto out_cfrs = std::make_unique<edm::ValueMap<vid::CutFlowResult>>();
147  auto out_usrd = std::make_unique<pat::UserDataCollection>();
148 
149  std::vector<bool> passfail;
150  std::vector<float> passfailf;
151  std::vector<unsigned> howfar;
152  std::vector<unsigned> bitmap;
153  std::vector<vid::CutFlowResult> cfrs;
154 
155  for(size_t i = 0; i < physicsobjects.size(); ++i) {
156  auto po = physicsobjects.ptrAt(i);
157  passfail.push_back((*id)(po,iEvent));
158  passfailf.push_back(passfail.back());
159  howfar.push_back(id->howFarInCutFlow());
160  bitmap.push_back(id->bitMap());
161  cfrs.push_back(id->cutFlowResult());
162  out_usrd->push_back(pat::UserData::make(cfrs.back(),false));
163  }
164 
165  edm::ValueMap<bool>::Filler fillerpassfail(*outPass);
166  fillerpassfail.insert(physicsObjectsHandle, passfail.begin(), passfail.end());
167  fillerpassfail.fill();
168 
169  edm::ValueMap<float>::Filler fillerpassfailf(*outPassf);
170  fillerpassfailf.insert(physicsObjectsHandle, passfailf.begin(), passfailf.end());
171  fillerpassfailf.fill();
172 
173  edm::ValueMap<unsigned>::Filler fillerhowfar(*outHowFar);
174  fillerhowfar.insert(physicsObjectsHandle, howfar.begin(), howfar.end() );
175  fillerhowfar.fill();
176 
177  edm::ValueMap<unsigned>::Filler fillerbitmap(*outBitmap);
178  fillerbitmap.insert(physicsObjectsHandle, bitmap.begin(), bitmap.end() );
179  fillerbitmap.fill();
180 
181  edm::ValueMap<vid::CutFlowResult>::Filler fillercfr(*out_cfrs);
182  fillercfr.insert(physicsObjectsHandle, cfrs.begin(), cfrs.end() );
183  fillercfr.fill();
184 
185  iEvent.put(std::move(outPass),id->name());
186  iEvent.put(std::move(outPassf),id->name());
187  iEvent.put(std::move(outHowFar),id->name());
188  iEvent.put(std::move(outBitmap),id->name()+std::string(bitmap_label));
189  iEvent.put(std::move(out_cfrs),id->name());
190  iEvent.put(std::make_unique<std::string>(id->md5String()),
191  id->name());
192  auto usrd_handle = iEvent.put(std::move(out_usrd),id->name());
193  //now add the value map of ptrs to user datas
194  auto out_usrdptrs = std::make_unique<edm::ValueMap<edm::Ptr<pat::UserData>>>();
195  std::vector<edm::Ptr<pat::UserData> > usrdptrs;
196  for( unsigned i = 0; i < usrd_handle->size(); ++i ){
197  usrdptrs.push_back(edm::Ptr<pat::UserData>(usrd_handle,i));
198  }
199 
200  edm::ValueMap<edm::Ptr<pat::UserData> >::Filler fillerusrdptrs(*out_usrdptrs);
201  fillerusrdptrs.insert(physicsObjectsHandle, usrdptrs.begin(), usrdptrs.end());
202  fillerusrdptrs.fill();
203 
204  iEvent.put(std::move(out_usrdptrs),id->name());
205  }
206 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
std::vector< std::unique_ptr< SelectorType > > ids_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::View< PhysicsObjectType > Collection
#define constexpr
static std::unique_ptr< UserData > make(const T &value, bool transientOnly=false)
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

template<class PhysicsObjectPtr , class SelectorType = VersionedSelector<PhysicsObjectPtr>>
std::vector<std::unique_ptr<SelectorType> > VersionedIdProducer< PhysicsObjectPtr, SelectorType >::ids_
private
template<class PhysicsObjectPtr , class SelectorType = VersionedSelector<PhysicsObjectPtr>>
TokenType VersionedIdProducer< PhysicsObjectPtr, SelectorType >::physicsObjectSrc_
private
template<class PhysicsObjectPtr , class SelectorType = VersionedSelector<PhysicsObjectPtr>>
bool VersionedIdProducer< PhysicsObjectPtr, SelectorType >::verbose_
private