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 //
43 // constants, enums and typedefs
44 //
45 
46 //
47 // static data member definitions
48 //
49 
50 //
51 // constructors and destructor
52 //
53 template< class PhysicsObjectPtr , class SelectorType >
56  constexpr char bitmap_label[] = "Bitmap";
57 
58  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
59 
60  physicsObjectSrc_ =
61  consumes<Collection>(iConfig.getParameter<edm::InputTag>("physicsObjectSrc"));
62 
63  const std::vector<edm::ParameterSet>& ids =
64  iConfig.getParameterSetVector("physicsObjectIDs");
65  for(const auto& id : ids ) {
66  const std::string& idMD5 =
67  id.getParameter<std::string>("idMD5");
68  const edm::ParameterSet& the_id =
69  id.getParameterSet("idDefinition");
70  const std::string& idname =
71  the_id.getParameter<std::string>("idName");
72  std::string calculated_md5;
73  ids_.emplace_back( new SelectorType(the_id) );
74  calculated_md5 = ids_.back()->md5String();
75  ids_.back()->setConsumes(consumesCollector());
76  if( ids_.back()->cutFlowSize() == 0 ) {
77  throw cms::Exception("InvalidCutFlow")
78  << "Post-processing cutflow size is zero! You may have configured"
79  << " the python incorrectly!";
80  }
81 
82  if( idMD5 != calculated_md5 ) {
83  edm::LogError("IdConfigurationNotValidated")
84  << "ID: " << ids_.back()->name() << "\n"
85  << "The expected md5: " << idMD5 << " does not match the md5\n"
86  << "calculated by the ID: " << calculated_md5 << " please\n"
87  << "update your python configuration or determine the source\n"
88  << "of transcription error!";
89  }
90 
91  std::stringstream idmsg;
92 
93  // dump whatever information about the ID we have
94  idmsg << "Instantiated ID: " << idname << std::endl
95  << "with MD5 hash: " << idMD5 << std::endl;
96  const bool isPOGApproved =
97  id.getUntrackedParameter<bool>("isPOGApproved",false);
98  if( isPOGApproved ) {
99  idmsg << "This ID is POG approved!" << std::endl;
100  } else {
101  idmsg << "This ID is not POG approved and likely under development!!!\n"
102  << "Please make sure to report your progress with this ID "
103  << "at the next relevant POG meeting." << std::endl;
104  }
105 
106  if( !isPOGApproved ) {
107  edm::LogWarning("IdInformation")
108  << idmsg.str();
109  } else {
110  edm::LogInfo("IdInformation")
111  << idmsg.str();
112  }
113 
114  produces<std::string>(idname);
115  produces<edm::ValueMap<bool> >(idname);
116  produces<edm::ValueMap<float> >(idname); // for PAT
117  produces<edm::ValueMap<unsigned> >(idname);
118  produces<edm::ValueMap<unsigned> >(idname+std::string(bitmap_label));
119  }
120 }
121 
122 template< class PhysicsObjectPtr , class SelectorType >
125  constexpr char bitmap_label[] = "Bitmap";
126 
127  edm::Handle<Collection> physicsObjectsHandle;
128  iEvent.getByToken(physicsObjectSrc_,physicsObjectsHandle);
129 
130  const Collection& physicsobjects = *physicsObjectsHandle;
131 
132  for( const auto& id : ids_ ) {
133  std::auto_ptr<edm::ValueMap<bool> > outPass(new edm::ValueMap<bool>() );
134  std::auto_ptr<edm::ValueMap<float> > outPassf(new edm::ValueMap<float>() );
135  std::auto_ptr<edm::ValueMap<unsigned> > outHowFar(new edm::ValueMap<unsigned>() );
136  std::auto_ptr<edm::ValueMap<unsigned> > outBitmap(new edm::ValueMap<unsigned>() );
137  std::vector<bool> passfail;
138  std::vector<float> passfailf;
139  std::vector<unsigned> howfar;
140  std::vector<unsigned> bitmap;
141  for(size_t i = 0; i < physicsobjects.size(); ++i) {
142  auto po = physicsobjects.ptrAt(i);
143  passfail.push_back((*id)(po,iEvent));
144  passfailf.push_back(passfail.back());
145  howfar.push_back(id->howFarInCutFlow());
146  bitmap.push_back(id->bitMap());
147  }
148 
149  edm::ValueMap<bool>::Filler fillerpassfail(*outPass);
150  fillerpassfail.insert(physicsObjectsHandle, passfail.begin(), passfail.end());
151  fillerpassfail.fill();
152 
153  edm::ValueMap<float>::Filler fillerpassfailf(*outPassf);
154  fillerpassfailf.insert(physicsObjectsHandle, passfailf.begin(), passfailf.end());
155  fillerpassfailf.fill();
156 
157  edm::ValueMap<unsigned>::Filler fillerhowfar(*outHowFar);
158  fillerhowfar.insert(physicsObjectsHandle, howfar.begin(), howfar.end() );
159  fillerhowfar.fill();
160 
161  edm::ValueMap<unsigned>::Filler fillerbitmap(*outBitmap);
162  fillerbitmap.insert(physicsObjectsHandle, bitmap.begin(), bitmap.end() );
163  fillerbitmap.fill();
164 
165  iEvent.put(outPass,id->name());
166  iEvent.put(outPassf,id->name());
167  iEvent.put(outHowFar,id->name());
168  iEvent.put(outBitmap,id->name()+std::string(bitmap_label));
169  iEvent.put(std::auto_ptr<std::string>(new std::string(id->md5String())),
170  id->name());
171 
172  }
173 }
174 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
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:449
Ptr< value_type > ptrAt(size_type i) const
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
size_type size() const
#define constexpr
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