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 
)

◆ addAssociation() [2/2]

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

Definition at line 68 of file ThinnedAssociationsHelper.cc.

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  }

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

◆ associationToBranches()

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

Definition at line 176 of file ThinnedAssociationsHelper.cc.

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

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

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

◆ begin()

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

◆ clear()

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

◆ data()

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

Definition at line 58 of file ThinnedAssociationsHelper.h.

References vThinnedAssociationBranches_.

Referenced by updateFromParentProcess().

◆ 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.

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  }

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

Referenced by addAssociation().

◆ initAssociationsFromSecondary()

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

Definition at line 337 of file ThinnedAssociationsHelper.cc.

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

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

◆ lower_bound()

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

Definition at line 50 of file ThinnedAssociationsHelper.cc.

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  }

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

Referenced by addAssociation().

◆ parentBegin()

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

Definition at line 28 of file ThinnedAssociationsHelper.cc.

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  }

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

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

◆ parentEnd()

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

Definition at line 39 of file ThinnedAssociationsHelper.cc.

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  }

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

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

◆ requireMatch()

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

Definition at line 263 of file ThinnedAssociationsHelper.cc.

263  {
264  bool foundMatch = false;
265  for (auto entry = parentBegin(input.parent()), iEnd = parentEnd(input.parent()); entry != iEnd; ++entry) {
266  if (entry->association() == input.association() && entry->thinned() == input.thinned()) {
267  foundMatch = true;
268  break;
269  }
270  }
271  if (!foundMatch) {
272  throw edm::Exception(
274  "ThinnedAssociationHelper::requireMatch, Illegal attempt to merge files with different ThinnedAssociations");
275  }
276  }

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

Referenced by updateFromPrimaryInput(), and updateFromSecondaryInput().

◆ 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 189 of file ThinnedAssociationsHelper.cc.

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

References associationToBranches(), and shouldKeepAssociation().

Referenced by edm::SubProcess::selectProducts(), edm::global::OutputModuleBase::selectProducts(), edm::limited::OutputModuleBase::selectProducts(), and edm::one::OutputModuleBase::selectProducts().

◆ 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 210 of file ThinnedAssociationsHelper.cc.

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

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

Referenced by selectAssociationProducts().

◆ 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 314 of file ThinnedAssociationsHelper.cc.

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

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

◆ updateFromPrimaryInput()

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

Definition at line 278 of file ThinnedAssociationsHelper.cc.

278  {
279  if (vThinnedAssociationBranches_.empty()) {
281  return;
282  }
283  std::vector<ThinnedAssociationBranches> const& inputData = helper.data();
284  for (auto const& inputEntry : inputData) {
285  requireMatch(inputEntry);
286  }
287  }

References requireMatch(), and vThinnedAssociationBranches_.

Referenced by edm::StreamerInputSource::mergeIntoRegistry().

◆ updateFromSecondaryInput()

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

Definition at line 289 of file ThinnedAssociationsHelper.cc.

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

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

Member Data Documentation

◆ vThinnedAssociationBranches_

std::vector<ThinnedAssociationBranches> edm::ThinnedAssociationsHelper::vThinnedAssociationBranches_
private
pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
DDAxes::y
edm::errors::MismatchedInputFiles
Definition: EDMException.h:52
input
static const std::string input
Definition: EdmProvDump.cc:48
funct::false
false
Definition: Factorize.h:29
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
edm::errors::LogicError
Definition: EDMException.h:37
mps_splice.entry
entry
Definition: mps_splice.py:68
edm::ThinnedAssociationsHelper::clear
void clear()
Definition: ThinnedAssociationsHelper.h:52
edm::ThinnedAssociationsHelper::shouldKeepAssociation
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
Definition: ThinnedAssociationsHelper.cc:210
edm::ThinnedAssociationsHelper::parentEnd
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
Definition: ThinnedAssociationsHelper.cc:39
DDAxes::x
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::Exception
Definition: EDMException.h:77
dqm-mbProfile.format
format
Definition: dqm-mbProfile.py:16
edm::ThinnedAssociationsHelper::ensureSlimmingConstraints
void ensureSlimmingConstraints() const
Definition: ThinnedAssociationsHelper.cc:144
b
double b
Definition: hdecay.h:118
edm::ThinnedAssociationsHelper::requireMatch
void requireMatch(ThinnedAssociationBranches const &input) const
Definition: ThinnedAssociationsHelper.cc:263
edm::ThinnedAssociationsHelper::vThinnedAssociationBranches_
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
Definition: ThinnedAssociationsHelper.h:86
funct::true
true
Definition: Factorize.h:173
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::ThinnedAssociationsHelper::addAssociation
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)
Definition: ThinnedAssociationsHelper.cc:61
cms::Exception::addAdditionalInfo
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:169
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
helper
Definition: helper.py:1
edm::ThinnedAssociationsHelper::end
std::vector< ThinnedAssociationBranches >::const_iterator end() const
Definition: ThinnedAssociationsHelper.cc:24
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::match
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
Definition: BranchDescription.cc:351
hgcal::association
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Definition: LayerClusterAssociatorByEnergyScoreImpl.h:44
edm::ThinnedAssociationsHelper::parentBegin
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
Definition: ThinnedAssociationsHelper.cc:28
Exception
Definition: hltDiff.cc:245
dqmiodumpmetadata.counts
counts
Definition: dqmiodumpmetadata.py:25
filterCSVwithJSON.target
target
Definition: filterCSVwithJSON.py:32
edm::ThinnedAssociationsHelper::lower_bound
std::vector< ThinnedAssociationBranches >::const_iterator lower_bound(ThinnedAssociationBranches const &branches) const
Definition: ThinnedAssociationsHelper.cc:50
edm::ThinnedAssociationsHelper::associationToBranches
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
Definition: ThinnedAssociationsHelper.cc:176
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
keep
const int keep
Definition: GenParticlePruner.cc:48
class-composition.parent
parent
Definition: class-composition.py:88
edm::ThinnedAssociationsHelper::begin
std::vector< ThinnedAssociationBranches >::const_iterator begin() const
Definition: ThinnedAssociationsHelper.cc:20