CMS 3D CMS Logo

ValueMapTraslator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ValueMapTraslator
4 // Class: ValueMapTraslator
5 //
13 //
14 // Original Author: Shervin Nourbakhsh,32 4-C03,+41227672087,
15 // Created: Sat Jul 13 15:40:56 CEST 2013
16 // $Id$
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
28 
31 
33 
36 
37 //#define DEBUG
38 //
39 // class declaration
40 //
41 
43  typedef double value_t;
45 
46  public:
47  explicit ValueMapTraslator(const edm::ParameterSet&);
48  ~ValueMapTraslator() override;
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52  private:
53  void produce(edm::Event&, const edm::EventSetup&) override;
54 
55  // ----------member data ---------------------------
59 
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78  referenceCollectionTAG(iConfig.getParameter<edm::InputTag>("referenceCollection")),
79  oldreferenceCollectionTAG(iConfig.getParameter<edm::InputTag>("oldreferenceCollection")),
80  inputCollectionTAG(iConfig.getParameter<edm::InputTag>("inputCollection")),
81  outputCollectionName(iConfig.getParameter<std::string>("outputCollection"))
82 {
83  //now do what ever other initialization is needed
84  referenceToken_ = consumes<reco::GsfElectronCollection>(referenceCollectionTAG);
85  oldreferenceToken_ = consumes<reco::GsfElectronCollection>(oldreferenceCollectionTAG);
86  inputToken_ = consumes< Map_t >(inputCollectionTAG);
88  produces< Map_t >(outputCollectionName);
89 
90 }
91 
92 
94 {
95 
96  // do anything here that needs to be done at desctruction time
97  // (e.g. close files, deallocate resources etc.)
98 
99 }
100 
101 
102 //
103 // member functions
104 //
105 
106 // ------------ method called to produce the data ------------
107 void
109 {
110  using namespace edm;
111  std::vector<value_t> valueVector;
112  auto valueVectorPtr = std::make_unique<Map_t>();
113 
114  //------------------------------
116  Handle< reco::GsfElectronCollection > oldreferenceHandle;
117  Handle< Map_t > inputHandle;
118 
119  iEvent.getByToken( referenceToken_, referenceHandle);
120  iEvent.getByToken( oldreferenceToken_, oldreferenceHandle);
121  iEvent.getByToken( inputToken_, inputHandle);
122 
123  for(Map_t::const_iterator valueMap_itr = inputHandle->begin();
124  valueMap_itr != inputHandle->end();
125  valueMap_itr++){
126  for(unsigned int i = 0; i < valueMap_itr.size(); i++){
127 #ifdef DEBUG
128  std::cout << valueMap_itr[i] << std::endl;
129 #endif
130  // valueVector.push_back((valueMap_itr[i])); //valueMap_itr-inputHandle->begin()]));
131  }
132  break;
133  }
134 
135 #ifdef DEBUG
136  std::cout << "Size: " << referenceHandle->size() << "\t" << oldreferenceHandle->size() << "\t" << inputHandle->size() << "\t" << valueVector.size() << std::endl;
137 #endif
138  for(reco::GsfElectronCollection::const_iterator electronNew = referenceHandle->begin();
139  electronNew!= referenceHandle->end();
140  electronNew++){
141 
142  for(reco::GsfElectronCollection::const_iterator electron = oldreferenceHandle->begin();
143  electron!= oldreferenceHandle->end();
144  electron++){
145  //if(electronNew->GsfTrackF
146  if(electron->gsfTrack() != electronNew->gsfTrack()) continue;
147  //if(fabs(electronNew->eta() - electron->eta())>0.0001) continue;
148  //if(fabs(electronNew->phi() - electron->phi())>0.0001) continue;
149 
150  reco::GsfElectronRef eleRef(oldreferenceHandle, electron-oldreferenceHandle->begin());
151  reco::GsfElectronRef eleRef2(referenceHandle, electronNew-referenceHandle->begin());
152 
153 #ifdef DEBUG
154  std::cout << eleRef->eta() << "\t" << eleRef2->eta() << "\t"
155  << eleRef->phi() << "\t" << eleRef2->phi() << "\t"
156  << eleRef->energy() << "\t" << eleRef2->energy() << "\t"
157  << (eleRef->gsfTrack() == eleRef2->gsfTrack()) << "\t"
158  << (eleRef == eleRef2) << "\t"
159  << (*inputHandle)[eleRef] << std::endl;
160 #endif
161  valueVector.push_back((*inputHandle)[eleRef]); //valueMap_itr-inputHandle->begin()]));
162  }
163  }
164  //#endif
165  Map_t::Filler filler(*valueVectorPtr);
166  filler.insert(referenceHandle, valueVector.begin(), valueVector.end());
167  filler.fill();
168 
169  iEvent.put(std::move(valueVectorPtr));
170 
171 }
172 
173 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
174 void
176  //The following says we do not know what parameters are allowed so do no validation
177  // Please change this to state exactly what you do use, even if it is no parameters
179  desc.setUnknown();
180  descriptions.addDefault(desc);
181 }
182 
183 //define this as a plug-in
ValueMapTraslator(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
~ValueMapTraslator() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void valueVector(const std::map< K, V > &extract, std::vector< V > &output)
Definition: Operators.h:43
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::ValueMap< value_t > Map_t
std::string outputCollectionName
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
edm::InputTag inputCollectionTAG
edm::InputTag oldreferenceCollectionTAG
edm::EDGetTokenT< reco::GsfElectronCollection > referenceToken_
edm::EDGetTokenT< reco::GsfElectronCollection > oldreferenceToken_
edm::EDGetTokenT< Map_t > inputToken_
HLT enums.
edm::InputTag referenceCollectionTAG
def move(src, dest)
Definition: eostools.py:510