CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VersionedIdProducer.h
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
12 
14 
16 
17 #include <memory>
18 #include <sstream>
19 
20 template< class PhysicsObjectPtr , class SelectorType=VersionedSelector<PhysicsObjectPtr> >
22 public:
24 
27 
28  explicit VersionedIdProducer(const edm::ParameterSet&);
30 
31  virtual void produce(edm::Event&, const edm::EventSetup&) override;
32 
33 private:
34  // ----------member data ---------------------------
35  bool verbose_;
37 
38  std::vector<std::unique_ptr<SelectorType> > ids_;
39 };
40 
41 //
42 // constants, enums and typedefs
43 //
44 
45 //
46 // static data member definitions
47 //
48 
49 //
50 // constructors and destructor
51 //
52 template< class PhysicsObjectPtr , class SelectorType >
55  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
56 
57  physicsObjectSrc_ =
58  consumes<Collection>(iConfig.getParameter<edm::InputTag>("physicsObjectSrc"));
59 
60  const std::vector<edm::ParameterSet>& ids =
61  iConfig.getParameterSetVector("physicsObjectIDs");
62  for(const auto& id : ids ) {
63  const std::string& idMD5 =
64  id.getParameter<std::string>("idMD5");
65  const edm::ParameterSet& the_id =
66  id.getParameterSet("idDefinition");
67  const std::string& idname =
68  the_id.getParameter<std::string>("idName");
69  std::string calculated_md5;
70  ids_.emplace_back( new SelectorType(the_id) );
71  calculated_md5 = ids_.back()->md5String();
72  ids_.back()->setConsumes(consumesCollector());
73  if( ids_.back()->cutFlowSize() == 0 ) {
74  throw cms::Exception("InvalidCutFlow")
75  << "Post-processing cutflow size is zero! You may have configured"
76  << " the python incorrectly!";
77  }
78 
79  if( idMD5 != calculated_md5 ) {
80  edm::LogError("IdConfigurationNotValidated")
81  << "The expected md5: " << idMD5 << " does not match the md5\n"
82  << "calculated by the ID: " << calculated_md5 << " please\n"
83  << "update your python configuration or determine the source\n"
84  << "of transcription error!";
85  }
86 
87  std::stringstream idmsg;
88 
89  // dump whatever information about the ID we have
90  idmsg << "Instantiated ID: " << idname << std::endl
91  << "with MD5 hash: " << idMD5 << std::endl;
92  const bool isPOGApproved =
93  id.getUntrackedParameter<bool>("isPOGApproved",false);
94  if( isPOGApproved ) {
95  idmsg << "This ID is POG approved!" << std::endl;
96  } else {
97  idmsg << "This ID is not POG approved and likely under development!!!\n"
98  << "Please make sure to report your progress with this ID "
99  << "at the next relevant POG meeting." << std::endl;
100  }
101 
102  edm::LogWarning("IdInformation")
103  << idmsg.str();
104 
105  produces<std::string>(idname);
106  produces<edm::ValueMap<bool> >(idname);
107  produces<edm::ValueMap<float> >(idname); // for PAT
108  produces<edm::ValueMap<unsigned> >(idname);
109  }
110 }
111 
112 template< class PhysicsObjectPtr , class SelectorType >
115  edm::Handle<Collection> physicsObjectsHandle;
116  iEvent.getByToken(physicsObjectSrc_,physicsObjectsHandle);
117 
118  const Collection& physicsobjects = *physicsObjectsHandle;
119 
120  for( const auto& id : ids_ ) {
121  std::auto_ptr<edm::ValueMap<bool> > outPass(new edm::ValueMap<bool>() );
122  std::auto_ptr<edm::ValueMap<float> > outPassf(new edm::ValueMap<float>() );
123  std::auto_ptr<edm::ValueMap<unsigned> > outHowFar(new edm::ValueMap<unsigned>() );
124  std::vector<bool> passfail;
125  std::vector<float> passfailf;
126  std::vector<unsigned> howfar;
127  for(const auto& po : physicsobjects.ptrVector()) {
128  passfail.push_back((*id)(po,iEvent));
129  passfailf.push_back(passfail.back());
130  howfar.push_back(id->howFarInCutFlow());
131  }
132 
133  edm::ValueMap<bool>::Filler fillerpassfail(*outPass);
134  fillerpassfail.insert(physicsObjectsHandle, passfail.begin(), passfail.end());
135  fillerpassfail.fill();
136 
137  edm::ValueMap<float>::Filler fillerpassfailf(*outPassf);
138  fillerpassfailf.insert(physicsObjectsHandle, passfailf.begin(), passfailf.end());
139  fillerpassfailf.fill();
140 
141  edm::ValueMap<unsigned>::Filler fillerhowfar(*outHowFar);
142  fillerhowfar.insert(physicsObjectsHandle, howfar.begin(), howfar.end() );
143  fillerhowfar.fill();
144 
145  iEvent.put(outPass,id->name());
146  iEvent.put(outPassf,id->name());
147  iEvent.put(outHowFar,id->name());
148  iEvent.put(std::auto_ptr<std::string>(new std::string(id->md5String())),
149  id->name());
150  }
151 }
152 
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_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
PtrVector< T > const & ptrVector() const
Definition: View.h:125
typename PhysicsObjectPtr::value_type PhysicsObjectType
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
virtual void produce(edm::Event &, const edm::EventSetup &) override
Container::value_type value_type
VersionedIdProducer(const edm::ParameterSet &)
ParameterSet const & getParameterSet(std::string const &) const