CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
CollectionMerger< T1, T2 > Class Template Reference

#include <CollectionMerger.h>

Inheritance diagram for CollectionMerger< T1, T2 >:
edm::stream::EDProducer<>

Public Member Functions

 CollectionMerger (const edm::ParameterSet &)
 
 ~CollectionMerger () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Types

typedef T2 BaseHit
 
typedef T1 MergeCollection
 

Private Member Functions

void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
template<>
void fill_output_obj (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
void fill_output_obj_calo (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
void fill_output_obj_muonchamber (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
 
void fill_output_obj_tracker (std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections, bool print_pixel=false)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::map< std::string, std::vector< edm::EDGetTokenT< MergeCollection > > > inputs_
 

Additional Inherited Members

- 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
 

Detailed Description

template<typename T1, typename T2>
class CollectionMerger< T1, T2 >

Author
Stefan Wayand; Christian Veelken, LLR

Definition at line 43 of file CollectionMerger.h.

Member Typedef Documentation

template<typename T1 , typename T2 >
typedef T2 CollectionMerger< T1, T2 >::BaseHit
private

Definition at line 53 of file CollectionMerger.h.

template<typename T1 , typename T2 >
typedef T1 CollectionMerger< T1, T2 >::MergeCollection
private

Definition at line 52 of file CollectionMerger.h.

Constructor & Destructor Documentation

template<typename T1 , typename T2 >
CollectionMerger< T1, T2 >::CollectionMerger ( const edm::ParameterSet iConfig)
explicit

Definition at line 68 of file CollectionMerger.h.

References edm::ParameterSet::getParameter(), and CollectionMerger< T1, T2 >::inputs_.

69 {
70  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("mergCollections");
71  for (auto const & inCollection : inCollections){
72  inputs_[inCollection.instance()].push_back(consumes<MergeCollection >(inCollection));
73  }
74  for (auto toproduce : inputs_){
75  // std::cout<<toproduce.first<<"\t"<<toproduce.second.size()<<std::endl;
76  produces<MergeCollection>(toproduce.first);
77 
78  }
79 }
T getParameter(std::string const &) const
std::map< std::string, std::vector< edm::EDGetTokenT< MergeCollection > > > inputs_
template<typename T1 , typename T2 >
CollectionMerger< T1, T2 >::~CollectionMerger ( )
override

Definition at line 82 of file CollectionMerger.h.

83 {
84 // nothing to be done yet...
85 }

Member Function Documentation

template<typename T1 , typename T2 >
void CollectionMerger< T1, T2 >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 118 of file CollectionMerger.cc.

Referenced by CollectionMerger< T1, T2 >::produce().

119 {
120  assert(0); // CV: make sure general function never gets called;
121  // always use template specializations
122 }
template<>
void CollectionMerger< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 126 of file CollectionMerger.cc.

127 {
128  fill_output_obj_tracker(output,inputCollections,true);
129 
130 }
void fill_output_obj_tracker(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections, bool print_pixel=false)
template<>
void CollectionMerger< edmNew::DetSetVector< SiStripCluster >, SiStripCluster >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 134 of file CollectionMerger.cc.

135 {
136  fill_output_obj_tracker(output,inputCollections);
137 }
void fill_output_obj_tracker(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections, bool print_pixel=false)
template<>
void CollectionMerger< edm::SortedCollection< EcalRecHit >, EcalRecHit >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 142 of file CollectionMerger.cc.

143 {
144  fill_output_obj_calo(output,inputCollections);
145 }
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::SortedCollection< HBHERecHit >, HBHERecHit >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 149 of file CollectionMerger.cc.

150 {
151  fill_output_obj_calo(output,inputCollections);
152 }
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::SortedCollection< HFRecHit >, HFRecHit >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 155 of file CollectionMerger.cc.

156 {
157  fill_output_obj_calo(output,inputCollections);
158 }
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::SortedCollection< HORecHit >, HORecHit >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 161 of file CollectionMerger.cc.

162 {
163  fill_output_obj_calo(output,inputCollections);
164 }
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::SortedCollection< CastorRecHit >, CastorRecHit >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 167 of file CollectionMerger.cc.

168 {
169  fill_output_obj_calo(output,inputCollections);
170 }
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::SortedCollection< ZDCRecHit >, ZDCRecHit >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 174 of file CollectionMerger.cc.

175 {
176  fill_output_obj_calo(output,inputCollections);
177 }
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::RangeMap< DTLayerId, edm::OwnVector< DTRecHit1DPair > >, DTRecHit1DPair >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 183 of file CollectionMerger.cc.

184 {
185  fill_output_obj_muonchamber(output,inputCollections);
186 }
void fill_output_obj_muonchamber(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::RangeMap< CSCDetId, edm::OwnVector< CSCRecHit2D > >, CSCRecHit2D >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 189 of file CollectionMerger.cc.

190 {
191  fill_output_obj_muonchamber(output,inputCollections);
192 }
void fill_output_obj_muonchamber(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<>
void CollectionMerger< edm::RangeMap< RPCDetId, edm::OwnVector< RPCRecHit > >, RPCRecHit >::fill_output_obj ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 196 of file CollectionMerger.cc.

References DEFINE_FWK_MODULE.

197 {
198  fill_output_obj_muonchamber(output,inputCollections);
199 }
void fill_output_obj_muonchamber(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
template<typename T1 , typename T2 >
void CollectionMerger< T1, T2 >::fill_output_obj_calo ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 72 of file CollectionMerger.cc.

References genParticles_cff::inputCollection, and rpcPointValidation_cfi::recHit.

73 {
74  std::map<uint32_t, BaseHit > output_map;
75  // First merge the two collections again
76  for (auto const & inputCollection : inputCollections){
77  for ( typename MergeCollection::const_iterator recHit = inputCollection->begin(); recHit!= inputCollection->end(); ++recHit ) {
78  DetId detIdObject( recHit->detid().rawId() );
79  T2 *akt_calo_obj = &output_map[detIdObject.rawId()];
80  float new_energy = akt_calo_obj->energy() + recHit->energy();
81  T2 newRecHit(*recHit);
82  newRecHit.setEnergy(new_energy);
83  *akt_calo_obj = newRecHit;
84  }
85  }
86  // Now save it into the standard CMSSW format
87  for (typename std::map<uint32_t, BaseHit >::const_iterator outHits = output_map.begin(); outHits != output_map.end(); ++outHits ) {
88  output->push_back(outHits->second);
89  }
90  output->sort(); //Do a sort for this collection
91 }
Definition: DetId.h:18
template<typename T1 , typename T2 >
void CollectionMerger< T1, T2 >::fill_output_obj_muonchamber ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections 
)
private

Definition at line 97 of file CollectionMerger.cc.

References genParticles_cff::inputCollection, genParticles_cff::map, and rpcPointValidation_cfi::recHit.

98 {
99  std::map<uint32_t, std::vector<BaseHit> > output_map;
100  // First merge the collections with the help of the output map
101  for (auto const & inputCollection : inputCollections){
102  for ( typename MergeCollection::const_iterator recHit = inputCollection->begin(); recHit!= inputCollection->end(); ++recHit ) {
103  DetId detIdObject( recHit->geographicalId() );
104  output_map[detIdObject].push_back(*recHit);
105  }
106  }
107  // Now save it into the standard CMSSW format, with the standard Filler
108  for (typename std::map<uint32_t, std::vector<BaseHit> >::const_iterator outHits = output_map.begin(); outHits != output_map.end(); ++outHits ) {
109  output->put((typename T1::id_iterator::value_type) outHits->first , outHits->second.begin(), outHits->second.end()); // The DTLayerId misses the automatic type cast
110  }
111 }
Definition: DetId.h:18
template<typename T1 , typename T2 >
void CollectionMerger< T1, T2 >::fill_output_obj_tracker ( std::unique_ptr< MergeCollection > &  output,
std::vector< edm::Handle< MergeCollection > > &  inputCollections,
bool  print_pixel = false 
)
private

Definition at line 44 of file CollectionMerger.cc.

References genParticles_cff::inputCollection, and genParticles_cff::map.

45 {
46 
47  std::map<uint32_t, std::vector<BaseHit> > output_map;
48  // First merge the collections with the help of the output map
49  for (auto const & inputCollection : inputCollections){
50  for ( typename MergeCollection::const_iterator clustSet = inputCollection->begin(); clustSet!= inputCollection->end(); ++clustSet ) {
51  DetId detIdObject( clustSet->detId() );
52  for (typename edmNew::DetSet<BaseHit>::const_iterator clustIt = clustSet->begin(); clustIt != clustSet->end(); ++clustIt ) {
53  output_map[detIdObject.rawId()].push_back(*clustIt);
54  }
55  }
56  }
57  // Now save it into the standard CMSSW format, with the standard Filler
58  for (typename std::map<uint32_t, std::vector<BaseHit> >::const_iterator outHits = output_map.begin(); outHits != output_map.end(); ++outHits ) {
59  DetId detIdObject(outHits->first);
60  typename MergeCollection::FastFiller spc(*output, detIdObject);
61  for (auto Hit : outHits->second){
62  spc.push_back(Hit);
63  }
64  }
65 
66 }
data_type const * const_iterator
Definition: DetSetNew.h:30
Definition: DetId.h:18
template<typename T1 , typename T2 >
void CollectionMerger< T1, T2 >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 89 of file CollectionMerger.h.

References CollectionMerger< T1, T2 >::fill_output_obj(), edm::Event::getByToken(), CollectionMerger< T1, T2 >::inputs_, eostools::move(), convertSQLitetoXML_cfg::output, and edm::Event::put().

90 {
91 
92  for (auto input_ : inputs_){
93  std::unique_ptr<MergeCollection > output(new MergeCollection());
94  std::vector<edm::Handle<MergeCollection> > inputCollections;
95  inputCollections.resize(input_.second.size());
96  for (unsigned id = 0; id<input_.second.size(); id++){
97  iEvent.getByToken(input_.second[id], inputCollections[id]);
98  }
99  fill_output_obj(output,inputCollections);
100  iEvent.put(std::move(output),input_.first);
101 
102  }
103 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::map< std::string, std::vector< edm::EDGetTokenT< MergeCollection > > > inputs_
void fill_output_obj(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

template<typename T1 , typename T2 >
std::map<std::string, std::vector<edm::EDGetTokenT<MergeCollection > > > CollectionMerger< T1, T2 >::inputs_
private