CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
edm::ThinnedAssociationsHelper Class Reference

#include <ThinnedAssociationsHelper.h>

Public Member Functions

void addAssociation (BranchID const &, BranchID const &, BranchID const &, bool slimmed)
 
void addAssociation (ThinnedAssociationBranches const &)
 
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches () const
 
std::vector< ThinnedAssociationBranches >::const_iterator begin () const
 
void clear ()
 
std::vector< ThinnedAssociationBranches > const & data () const
 
std::vector< ThinnedAssociationBranches >::const_iterator end () const
 
void initAssociationsFromSecondary (std::vector< BranchID > const &, ThinnedAssociationsHelper const &)
 
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin (BranchID const &) const
 
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd (BranchID const &) const
 
void requireMatch (ThinnedAssociationBranches const &input) const
 
void selectAssociationProducts (std::vector< BranchDescription const *> const &associationDescriptions, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const
 
 ThinnedAssociationsHelper ()
 
void updateFromParentProcess (ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, std::map< BranchID, bool > const &keepAssociation, std::map< BranchID::value_type, BranchID::value_type > const &droppedBranchIDToKeptBranchID)
 
void updateFromPrimaryInput (ThinnedAssociationsHelper const &)
 
void updateFromSecondaryInput (ThinnedAssociationsHelper const &, std::vector< BranchID > const &associationsFromSecondary)
 

Private Member Functions

void ensureSlimmingConstraints () const
 
std::vector< ThinnedAssociationBranches >::const_iterator lower_bound (ThinnedAssociationBranches const &branches) const
 
bool shouldKeepAssociation (BranchID const &association, std::vector< std::pair< BranchID, ThinnedAssociationBranches const *> > const &associationToBranches, std::set< BranchID > &branchesInRecursion, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const
 

Private Attributes

std::vector< ThinnedAssociationBranchesvThinnedAssociationBranches_
 

Detailed Description

Author
W. David Dagenhart, created 11 June 2014

Definition at line 37 of file ThinnedAssociationsHelper.h.

Constructor & Destructor Documentation

◆ ThinnedAssociationsHelper()

edm::ThinnedAssociationsHelper::ThinnedAssociationsHelper ( )

Definition at line 18 of file ThinnedAssociationsHelper.cc.

18 {}

Member Function Documentation

◆ addAssociation() [1/2]

void edm::ThinnedAssociationsHelper::addAssociation ( BranchID const &  parent,
BranchID const &  association,
BranchID const &  thinned,
bool  slimmed 
)

Definition at line 61 of file ThinnedAssociationsHelper.cc.

References class-composition::parent.

Referenced by initAssociationsFromSecondary(), edm::ThinningProducer< Collection, Selector >::registerThinnedAssociations(), and updateFromParentProcess().

64  {
65  addAssociation(ThinnedAssociationBranches(parent, association, thinned, slimmed));
66  }
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)

◆ addAssociation() [2/2]

void edm::ThinnedAssociationsHelper::addAssociation ( ThinnedAssociationBranches const &  branches)

Definition at line 68 of file ThinnedAssociationsHelper.cc.

References cms::Exception::addAdditionalInfo(), cms::Exception::addContext(), ensureSlimmingConstraints(), dqm-mbProfile::format, edm::BranchID::id(), edm::ThinnedAssociationBranches::isSlimmed(), lower_bound(), edm::ThinnedAssociationBranches::thinned(), and vThinnedAssociationBranches_.

68  {
69  vThinnedAssociationBranches_.insert(lower_bound(branches), branches);
70  if (branches.isSlimmed()) {
71  try {
73  } catch (edm::Exception& ex) {
74  ex.addContext("Calling ThinnedAssociationsHelper::addAssociation()");
75  ex.addAdditionalInfo(fmt::format("When adding a slimmed collection with BranchID {}", branches.thinned().id()));
76  throw ex;
77  }
78  }
79  }
std::vector< ThinnedAssociationBranches >::const_iterator lower_bound(ThinnedAssociationBranches const &branches) const
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:173
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void addContext(std::string const &context)
Definition: Exception.cc:169

◆ associationToBranches()

std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > edm::ThinnedAssociationsHelper::associationToBranches ( ) const

Definition at line 176 of file ThinnedAssociationsHelper.cc.

References B2GTnPMonitor_cfi::item, jetUpdater_cfi::sort, groupFilesInBlocks::temp, vThinnedAssociationBranches_, and x.

Referenced by initAssociationsFromSecondary(), selectAssociationProducts(), and shouldKeepAssociation().

177  {
178  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> temp;
179  temp.reserve(vThinnedAssociationBranches_.size());
180  for (auto const& item : vThinnedAssociationBranches_) {
181  temp.push_back(std::make_pair(item.association(), &item));
182  }
183  std::sort(temp.begin(),
184  temp.end(),
185  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
186  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
187  return temp;
188  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
float x

◆ begin()

std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::begin ( void  ) const

Definition at line 20 of file ThinnedAssociationsHelper.cc.

References vThinnedAssociationBranches_.

Referenced by ensureSlimmingConstraints(), and edm::detail::getThinnedKeyFrom_implementation().

20  {
21  return vThinnedAssociationBranches_.begin();
22  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_

◆ clear()

void edm::ThinnedAssociationsHelper::clear ( void  )
inline

Definition at line 52 of file ThinnedAssociationsHelper.h.

References vThinnedAssociationBranches_.

Referenced by updateFromParentProcess().

std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_

◆ data()

std::vector<ThinnedAssociationBranches> const& edm::ThinnedAssociationsHelper::data ( ) const
inline

Definition at line 58 of file ThinnedAssociationsHelper.h.

References vThinnedAssociationBranches_.

Referenced by updateFromParentProcess().

std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_

◆ end()

std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::end ( void  ) const

◆ ensureSlimmingConstraints()

void edm::ThinnedAssociationsHelper::ensureSlimmingConstraints ( ) const
private

Definition at line 144 of file ThinnedAssociationsHelper.cc.

References b, begin(), HltBtagPostValidation_cff::c, dqmiodumpmetadata::counts, end(), and pfDeepBoostedJetPreprocessParams_cfi::lower_bound.

Referenced by addAssociation().

144  {
145  // ThinnedAssociationBranches defines an edge between a parent and
146  // a thinned collection in the parentage tree of the thinned
147  // collections. It is required that for a given parentage tree
148  // there is at most one path from the root node to any leaf nodes
149  // that has slimming edges.
150 
151  std::vector<::SlimmedCount> counts;
152  BranchID prevParent;
153  std::vector<SlimmedCount>::iterator currentCount;
154  for (auto iItem = begin(), iEnd = end(); iItem != iEnd; ++iItem) {
155  if (iItem->parent() == BranchID()) {
156  continue;
157  }
158  if (iItem->parent() == prevParent) {
159  addSlimmingChildrenCount(*this, *iItem, counts, currentCount->slimmedChildrenCount);
160  } else {
161  currentCount = std::lower_bound(
162  counts.begin(), counts.end(), iItem->parent(), [](SlimmedCount const& c, BranchID const& b) {
163  return c.parent < b;
164  });
165  // has the tree with iItem->parent() as root node already been counted?
166  if (currentCount != counts.end() && currentCount->parent == iItem->parent()) {
167  continue;
168  }
169  currentCount = counts.insert(currentCount, ::SlimmedCount{iItem->parent(), 0});
170  addSlimmingChildrenCount(*this, *iItem, counts, currentCount->slimmedChildrenCount);
171  prevParent = iItem->parent();
172  }
173  }
174  }
std::vector< ThinnedAssociationBranches >::const_iterator begin() const
std::vector< ThinnedAssociationBranches >::const_iterator end() const
double b
Definition: hdecay.h:120

◆ initAssociationsFromSecondary()

void edm::ThinnedAssociationsHelper::initAssociationsFromSecondary ( std::vector< BranchID > const &  associationsFromSecondary,
ThinnedAssociationsHelper const &  fileAssociationsHelper 
)

Definition at line 338 of file ThinnedAssociationsHelper.cc.

References addAssociation(), associationToBranches(), Exception, edm::errors::LogicError, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, and x.

339  {
340  if (associationsFromSecondary.empty())
341  return;
342 
343  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
344  fileAssociationsHelper.associationToBranches();
345 
346  for (BranchID const& association : associationsFromSecondary) {
347  auto branches = std::lower_bound(
348  assocToBranches.begin(),
349  assocToBranches.end(),
350  std::make_pair(association, static_cast<ThinnedAssociationBranches const*>(nullptr)),
351  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
352  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
353  // This should never happen
354  if (branches == assocToBranches.end() || branches->first != association) {
356  "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches "
357  "information, contact Framework developers");
358  }
359  addAssociation(*(branches->second));
360  }
361  }
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)
float x

◆ lower_bound()

std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::lower_bound ( ThinnedAssociationBranches const &  branches) const
private

Definition at line 50 of file ThinnedAssociationsHelper.cc.

References funct::false, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, funct::true, vThinnedAssociationBranches_, and x.

Referenced by addAssociation().

51  {
52  return std::lower_bound(
55  branches,
56  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
57  return x.parent() < y.parent() ? true : y.parent() < x.parent() ? false : x.association() < y.association();
58  });
59  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
float x

◆ parentBegin()

std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::parentBegin ( BranchID const &  parent) const

Definition at line 28 of file ThinnedAssociationsHelper.cc.

References pfDeepBoostedJetPreprocessParams_cfi::lower_bound, class-composition::parent, filterCSVwithJSON::target, vThinnedAssociationBranches_, and x.

Referenced by edm::detail::getThinnedKeyFrom_implementation(), edm::detail::getThinnedProductOnSlimmingDepth(), edm::detail::getThinnedProductsOnSlimmingDepth(), requireMatch(), and shouldKeepAssociation().

29  {
30  ThinnedAssociationBranches target(parent, BranchID(), BranchID(), false);
33  target,
34  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
35  return x.parent() < y.parent();
36  });
37  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
float x

◆ parentEnd()

std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::parentEnd ( BranchID const &  parent) const

Definition at line 39 of file ThinnedAssociationsHelper.cc.

References class-composition::parent, filterCSVwithJSON::target, pfDeepBoostedJetPreprocessParams_cfi::upper_bound, vThinnedAssociationBranches_, and x.

Referenced by edm::detail::getThinnedKeyFrom_implementation(), edm::detail::getThinnedProductOnSlimmingDepth(), edm::detail::getThinnedProductsOnSlimmingDepth(), requireMatch(), and shouldKeepAssociation().

40  {
41  ThinnedAssociationBranches target(parent, BranchID(), BranchID(), false);
44  target,
45  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
46  return x.parent() < y.parent();
47  });
48  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
float x

◆ requireMatch()

void edm::ThinnedAssociationsHelper::requireMatch ( ThinnedAssociationBranches const &  input) const

Definition at line 264 of file ThinnedAssociationsHelper.cc.

References mps_splice::entry, Exception, input, edm::errors::MismatchedInputFiles, parentBegin(), and parentEnd().

Referenced by updateFromPrimaryInput(), and updateFromSecondaryInput().

264  {
265  bool foundMatch = false;
266  for (auto entry = parentBegin(input.parent()), iEnd = parentEnd(input.parent()); entry != iEnd; ++entry) {
267  if (entry->association() == input.association() && entry->thinned() == input.thinned()) {
268  foundMatch = true;
269  break;
270  }
271  }
272  if (!foundMatch) {
273  throw edm::Exception(
275  "ThinnedAssociationHelper::requireMatch, Illegal attempt to merge files with different ThinnedAssociations");
276  }
277  }
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
static std::string const input
Definition: EdmProvDump.cc:50
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const

◆ selectAssociationProducts()

void edm::ThinnedAssociationsHelper::selectAssociationProducts ( std::vector< BranchDescription const *> const &  associationDescriptions,
std::set< BranchID > const &  keptProductsInEvent,
std::map< BranchID, bool > &  keepAssociation 
) const

Definition at line 190 of file ThinnedAssociationsHelper.cc.

References associationToBranches(), and shouldKeepAssociation().

Referenced by edm::SubProcess::selectProducts(), and edm::core::OutputModuleCore::selectProducts().

193  {
194  keepAssociation.clear();
195  // Copy the elements in vThinnedAssociationBranches_ into a vector sorted on
196  // the association BranchID so we can do searches on that BranchID faster.
197  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches = associationToBranches();
198 
199  for (auto association : associationDescriptions) {
200  if (association
201  ->isAlias()) { // There is no reason to configure an association product with an EDAlias (ignore and drop them if they exist)
202  keepAssociation.insert(std::make_pair(association->branchID(), false));
203  } else {
204  std::set<BranchID> branchesInRecursion;
206  association->branchID(), assocToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation);
207  }
208  }
209  }
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
bool shouldKeepAssociation(BranchID const &association, std::vector< std::pair< BranchID, ThinnedAssociationBranches const *> > const &associationToBranches, std::set< BranchID > &branchesInRecursion, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const

◆ shouldKeepAssociation()

bool edm::ThinnedAssociationsHelper::shouldKeepAssociation ( BranchID const &  association,
std::vector< std::pair< BranchID, ThinnedAssociationBranches const *> > const &  associationToBranches,
std::set< BranchID > &  branchesInRecursion,
std::set< BranchID > const &  keptProductsInEvent,
std::map< BranchID, bool > &  keepAssociation 
) const
private

Definition at line 211 of file ThinnedAssociationsHelper.cc.

References associationToBranches(), Exception, edm::errors::LogicError, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, edm::match(), parentBegin(), parentEnd(), edm::ThinnedAssociationBranches::thinned(), and x.

Referenced by selectAssociationProducts().

216  {
217  // If we already decided to keep or drop this one, then
218  // return the same decision.
219  auto decision = keepAssociation.find(association);
220  if (decision != keepAssociation.end()) {
221  return decision->second;
222  }
223 
224  // Be careful not to fall into an infinite loop because
225  // of a circular recursion.
226  if (!branchesInRecursion.insert(association).second) {
227  return false;
228  }
229 
230  // If the thinned collection is being kept then keep the association
231  auto branches = std::lower_bound(
232  associationToBranches.begin(),
233  associationToBranches.end(),
234  std::make_pair(association, static_cast<ThinnedAssociationBranches const*>(nullptr)),
235  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
236  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
237  // This should never happen
238  if (branches == associationToBranches.end() || branches->first != association) {
240  "ThinnedAssociationHelper::shouldKeepAssociation could not find branches information, "
241  "contact Framework developers");
242  }
243  BranchID const& thinnedCollection = branches->second->thinned();
244  if (keptProductsInEvent.find(thinnedCollection) != keptProductsInEvent.end()) {
245  keepAssociation.insert(std::make_pair(association, true));
246  return true;
247  }
248  // otherwise loop over any associations where the thinned collection
249  // is also a parent collection and recursively examine those to see
250  // if their thinned collections are being kept.
251  auto iterEnd = parentEnd(thinnedCollection);
252  for (auto match = parentBegin(thinnedCollection); match != iterEnd; ++match) {
254  match->association(), associationToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation)) {
255  keepAssociation.insert(std::make_pair(association, true));
256  return true;
257  }
258  }
259  // drop the association
260  keepAssociation.insert(std::make_pair(association, false));
261  return false;
262  }
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
bool shouldKeepAssociation(BranchID const &association, std::vector< std::pair< BranchID, ThinnedAssociationBranches const *> > const &associationToBranches, std::set< BranchID > &branchesInRecursion, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
float x
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)

◆ updateFromParentProcess()

void edm::ThinnedAssociationsHelper::updateFromParentProcess ( ThinnedAssociationsHelper const &  parentThinnedAssociationsHelper,
std::map< BranchID, bool > const &  keepAssociation,
std::map< BranchID::value_type, BranchID::value_type > const &  droppedBranchIDToKeptBranchID 
)

Definition at line 315 of file ThinnedAssociationsHelper.cc.

References addAssociation(), clear(), data(), edm::BranchID::id(), runTheMatrix::keep, and class-composition::parent.

318  {
319  clear();
320  for (auto const& associationBranches : parentThinnedAssociationsHelper.data()) {
321  auto keep = keepAssociation.find(associationBranches.association());
322  if (keep != keepAssociation.end() && keep->second) {
323  BranchID parent = associationBranches.parent();
324  auto iter = droppedBranchIDToKeptBranchID.find(parent.id());
325  if (iter != droppedBranchIDToKeptBranchID.end()) {
326  parent = BranchID(iter->second);
327  }
328  BranchID thinned = associationBranches.thinned();
329  iter = droppedBranchIDToKeptBranchID.find(thinned.id());
330  if (iter != droppedBranchIDToKeptBranchID.end()) {
331  thinned = BranchID(iter->second);
332  }
333  addAssociation(parent, associationBranches.association(), thinned, associationBranches.isSlimmed());
334  }
335  }
336  }
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)

◆ updateFromPrimaryInput()

void edm::ThinnedAssociationsHelper::updateFromPrimaryInput ( ThinnedAssociationsHelper const &  helper)

Definition at line 279 of file ThinnedAssociationsHelper.cc.

References requireMatch(), and vThinnedAssociationBranches_.

279  {
280  if (vThinnedAssociationBranches_.empty()) {
282  return;
283  }
284  std::vector<ThinnedAssociationBranches> const& inputData = helper.data();
285  for (auto const& inputEntry : inputData) {
286  requireMatch(inputEntry);
287  }
288  }
Definition: helper.py:1
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void requireMatch(ThinnedAssociationBranches const &input) const

◆ updateFromSecondaryInput()

void edm::ThinnedAssociationsHelper::updateFromSecondaryInput ( ThinnedAssociationsHelper const &  helper,
std::vector< BranchID > const &  associationsFromSecondary 
)

Definition at line 290 of file ThinnedAssociationsHelper.cc.

References Exception, edm::errors::LogicError, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, requireMatch(), and x.

291  {
292  if (associationsFromSecondary.empty())
293  return;
294 
295  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
296  helper.associationToBranches();
297 
298  for (BranchID const& association : associationsFromSecondary) {
299  auto branches = std::lower_bound(
300  assocToBranches.begin(),
301  assocToBranches.end(),
302  std::make_pair(association, static_cast<ThinnedAssociationBranches const*>(nullptr)),
303  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
304  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
305  // This should never happen
306  if (branches == assocToBranches.end() || branches->first != association) {
308  "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches "
309  "information, contact Framework developers");
310  }
311  requireMatch(*(branches->second));
312  }
313  }
Definition: helper.py:1
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
void requireMatch(ThinnedAssociationBranches const &input) const
float x

Member Data Documentation

◆ vThinnedAssociationBranches_

std::vector<ThinnedAssociationBranches> edm::ThinnedAssociationsHelper::vThinnedAssociationBranches_
private