CMS 3D CMS Logo

DoubleCollectionMerger.cc
Go to the documentation of this file.
3 
5 
10 
13 
18 
19 template <typename T1, typename T2, typename T3, typename T4>
21  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag>>("mergCollections");
22  for (auto const &inCollection : inCollections) {
23  inputs1_[inCollection.instance()].push_back(consumes<MergeCollection1>(inCollection));
24  inputs2_[inCollection.instance()].push_back(consumes<MergeCollection2>(inCollection));
25  }
26  for (const auto &toproduce : inputs1_) {
27  produces<MergeCollection1>(toproduce.first);
28  }
29  for (const auto &toproduce : inputs2_) {
30  produces<MergeCollection2>(toproduce.first);
31  }
32 }
33 
34 template <typename T1, typename T2, typename T3, typename T4>
36  // nothing to be done yet...
37 }
38 
39 template <typename T1, typename T2, typename T3, typename T4>
41  for (auto input_ : inputs1_) {
42  std::unique_ptr<MergeCollection1> output(new MergeCollection1());
43  std::vector<edm::Handle<MergeCollection1>> inputCollections;
44  inputCollections.resize(input_.second.size());
45  for (unsigned id = 0; id < input_.second.size(); id++) {
46  iEvent.getByToken(input_.second[id], inputCollections[id]);
47  }
48  fill_output_obj(output, inputCollections);
49  iEvent.put(std::move(output), input_.first);
50  }
51 
52  for (auto input_ : inputs2_) {
53  std::unique_ptr<MergeCollection2> output(new MergeCollection2());
54  std::vector<edm::Handle<MergeCollection2>> inputCollections;
55  inputCollections.resize(input_.second.size());
56  for (unsigned id = 0; id < input_.second.size(); id++) {
57  iEvent.getByToken(input_.second[id], inputCollections[id]);
58  }
59  fill_output_obj(output, inputCollections);
60  iEvent.put(std::move(output), input_.first);
61  }
62 }
63 
64 template <typename T1, typename T2, typename T3, typename T4>
66  std::unique_ptr<MergeCollection1> &output, std::vector<edm::Handle<MergeCollection1>> &inputCollections) {
67  assert(0);
68 }
69 
70 template <typename T1, typename T2, typename T3, typename T4>
72  std::unique_ptr<MergeCollection2> &output, std::vector<edm::Handle<MergeCollection2>> &inputCollections) {
73  assert(0);
74 }
75 
76 template <typename T1, typename T2, typename T3, typename T4>
78  std::unique_ptr<MergeCollection1> &output, std::vector<edm::Handle<MergeCollection1>> &inputCollections) {
79  std::map<uint32_t, BaseHit1> output_map;
80 
81  // First merge the two collections again
82  for (auto const &inputCollection : inputCollections) {
83  for (typename MergeCollection1::const_iterator obj = inputCollection->begin(); obj != inputCollection->end();
84  ++obj) {
85  DetId detIdObject(obj->id().rawId());
86 
87  std::map<uint32_t, EESrFlag>::iterator it = output_map.find(detIdObject.rawId());
88  if (it == output_map.end()) {
89  BaseHit1 *akt_flag_obj = &output_map[detIdObject.rawId()];
90  const T2 &newSrFlag(*obj);
91  *akt_flag_obj = newSrFlag;
92  } else {
93  // re-determine flag
94  BaseHit1 preFlag = it->second;
95  BaseHit1 *akt_flag_obj = &output_map[detIdObject.rawId()];
96  T2 newSrFlag(*obj);
97 
98  newSrFlag.setValue(std::max(obj->value(), preFlag.value()));
99  if (preFlag.value() == 3 or obj->value() == 3)
100  newSrFlag.setValue(3);
101  if (preFlag.value() == 7 or obj->value() == 7)
102  newSrFlag.setValue(7);
103 
104  *akt_flag_obj = newSrFlag;
105  }
106  }
107  }
108 
109  // Now save it into the standard CMSSW format
110  for (typename std::map<uint32_t, BaseHit1>::const_iterator outFlags = output_map.begin();
111  outFlags != output_map.end();
112  ++outFlags) {
113  BaseHit1 currFlag = outFlags->second;
114  output->push_back(outFlags->second);
115  }
116  output->sort(); // Do a sort for this collection
117 }
118 
119 template <typename T1, typename T2, typename T3, typename T4>
121  std::unique_ptr<MergeCollection2> &output, std::vector<edm::Handle<MergeCollection2>> &inputCollections) {
122  std::map<uint32_t, BaseHit2> output_map;
123 
124  // First merge the two collections again
125  for (auto const &inputCollection : inputCollections) {
126  for (typename MergeCollection2::const_iterator obj = inputCollection->begin(); obj != inputCollection->end();
127  ++obj) {
128  DetId detIdObject(obj->id().rawId());
129 
130  std::map<uint32_t, EBSrFlag>::iterator it = output_map.find(detIdObject.rawId());
131  if (it == output_map.end()) {
132  BaseHit2 *akt_flag_obj = &output_map[detIdObject.rawId()];
133  const T4 &newSrFlag(*obj);
134  *akt_flag_obj = newSrFlag;
135  } else {
136  // re-determine flag
137  BaseHit2 preFlag = it->second;
138  BaseHit2 *akt_flag_obj = &output_map[detIdObject.rawId()];
139  T4 newSrFlag(*obj);
140 
141  newSrFlag.setValue(std::max(obj->value(), preFlag.value()));
142  if (preFlag.value() == 3 or obj->value() == 3)
143  newSrFlag.setValue(3);
144  if (preFlag.value() == 7 or obj->value() == 7)
145  newSrFlag.setValue(7);
146 
147  *akt_flag_obj = newSrFlag;
148  }
149  }
150  }
151 
152  // Now save it into the standard CMSSW format
153  for (typename std::map<uint32_t, BaseHit2>::const_iterator outFlags = output_map.begin();
154  outFlags != output_map.end();
155  ++outFlags) {
156  BaseHit2 currFlag = outFlags->second;
157  output->push_back(outFlags->second);
158  }
159  output->sort(); // Do a sort for this collection
160 }
161 
162 template <typename T1, typename T2, typename T3, typename T4>
164  std::unique_ptr<MergeCollection1> &output, std::vector<edm::Handle<MergeCollection1>> &inputCollections) {
165  // TODO: implement proper merging, only skeleton for the time-being
166  return;
167 }
168 
169 template <typename T1, typename T2, typename T3, typename T4>
171  std::unique_ptr<MergeCollection2> &output, std::vector<edm::Handle<MergeCollection2>> &inputCollections) {
172  // TODO: implement proper merging, only skeleton for the time-being
173  return;
174 }
175 
176 template <>
178  fill_output_obj(std::unique_ptr<MergeCollection1> &output,
179  std::vector<edm::Handle<MergeCollection1>> &inputCollections) {
180  fill_output_obj_digiflag(output, inputCollections);
181 }
182 
183 template <>
185  fill_output_obj(std::unique_ptr<MergeCollection2> &output,
186  std::vector<edm::Handle<MergeCollection2>> &inputCollections) {
187  fill_output_obj_digiflag(output, inputCollections);
188 }
189 
190 template <>
192  fill_output_obj(std::unique_ptr<MergeCollection1> &output,
193  std::vector<edm::Handle<MergeCollection1>> &inputCollections) {
194  fill_output_obj_hcaldigi(output, inputCollections);
195 }
196 
197 template <>
199  fill_output_obj(std::unique_ptr<MergeCollection2> &output,
200  std::vector<edm::Handle<MergeCollection2>> &inputCollections) {
201  fill_output_obj_hcaldigi(output, inputCollections);
202 }
203 
void fill_output_obj(std::unique_ptr< MergeCollection1 > &output1, std::vector< edm::Handle< MergeCollection1 >> &inputCollections1)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void produce(edm::Event &, const edm::EventSetup &) override
DoubleCollectionMerger< HBHEDigiCollection, HBHEDataFrame, HcalCalibDigiCollection, HcalCalibDataFrame > HcalDigiColMerger
DoubleCollectionMerger< edm::SortedCollection< EESrFlag >, EESrFlag, edm::SortedCollection< EBSrFlag >, EBSrFlag > EcalSrFlagColMerger
void fill_output_obj_digiflag(std::unique_ptr< MergeCollection1 > &output, std::vector< edm::Handle< MergeCollection1 >> &inputCollections)
assert(be >=bs)
int iEvent
Definition: GenABIO.cc:224
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: DetId.h:17
DoubleCollectionMerger(const edm::ParameterSet &)
void fill_output_obj_hcaldigi(std::unique_ptr< MergeCollection1 > &output, std::vector< edm::Handle< MergeCollection1 >> &inputCollections)
Definition: output.py:1
def move(src, dest)
Definition: eostools.py:511