CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
< ThinnedAssociationBranches
vThinnedAssociationBranches_
 

Detailed Description

Author
W. David Dagenhart, created 11 June 2014

Definition at line 37 of file ThinnedAssociationsHelper.h.

Constructor & Destructor Documentation

edm::ThinnedAssociationsHelper::ThinnedAssociationsHelper ( )

Definition at line 18 of file ThinnedAssociationsHelper.cc.

18 {}

Member Function Documentation

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

Definition at line 61 of file ThinnedAssociationsHelper.cc.

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)
void edm::ThinnedAssociationsHelper::addAssociation ( ThinnedAssociationBranches const &  branches)

Definition at line 68 of file ThinnedAssociationsHelper.cc.

References cms::Exception::addAdditionalInfo(), cms::Exception::addContext(), ensureSlimmingConstraints(), diffTreeTool::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:169
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void addContext(std::string const &context)
Definition: Exception.cc:165
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > edm::ThinnedAssociationsHelper::associationToBranches ( ) const

Definition at line 176 of file ThinnedAssociationsHelper.cc.

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

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

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  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
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_
void edm::ThinnedAssociationsHelper::clear ( void  )
inline

Definition at line 52 of file ThinnedAssociationsHelper.h.

References vThinnedAssociationBranches_.

Referenced by BeautifulSoup.Tag::setString(), and updateFromParentProcess().

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

Definition at line 58 of file ThinnedAssociationsHelper.h.

References vThinnedAssociationBranches_.

Referenced by updateFromParentProcess(), and updateFromPrimaryInput().

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

Definition at line 144 of file ThinnedAssociationsHelper.cc.

References b, begin(), c, dqmiodumpmetadata::counts, end(), and cuda_std::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  }
const edm::EventSetup & c
std::vector< ThinnedAssociationBranches >::const_iterator end() const
double b
Definition: hdecay.h:118
std::vector< ThinnedAssociationBranches >::const_iterator begin() const
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
void edm::ThinnedAssociationsHelper::initAssociationsFromSecondary ( std::vector< BranchID > const &  associationsFromSecondary,
ThinnedAssociationsHelper const &  fileAssociationsHelper 
)

Definition at line 337 of file ThinnedAssociationsHelper.cc.

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

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  }
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::lower_bound ( ThinnedAssociationBranches const &  branches) const
private

Definition at line 50 of file ThinnedAssociationsHelper.cc.

References cuda_std::lower_bound(), edm::ThinnedAssociationBranches::parent(), and vThinnedAssociationBranches_.

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_
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::parentBegin ( BranchID const &  parent) const

Definition at line 28 of file ThinnedAssociationsHelper.cc.

References cuda_std::lower_bound(), filterCSVwithJSON::target, and vThinnedAssociationBranches_.

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_
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::parentEnd ( BranchID const &  parent) const

Definition at line 39 of file ThinnedAssociationsHelper.cc.

References filterCSVwithJSON::target, cuda_std::upper_bound(), and vThinnedAssociationBranches_.

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  }
__host__ __device__ constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::requireMatch ( ThinnedAssociationBranches const &  input) const

Definition at line 263 of file ThinnedAssociationsHelper.cc.

References edm::ThinnedAssociationBranches::association(), mps_splice::entry, Exception, edm::errors::MismatchedInputFiles, edm::ThinnedAssociationBranches::parent(), parentBegin(), parentEnd(), and edm::ThinnedAssociationBranches::thinned().

Referenced by updateFromPrimaryInput(), and updateFromSecondaryInput().

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  }
static std::string const input
Definition: EdmProvDump.cc:47
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
list entry
Definition: mps_splice.py:68
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.

References associationToBranches(), and shouldKeepAssociation().

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

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

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

Referenced by selectAssociationProducts().

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  }
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
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::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
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.

References addAssociation(), clear(), data(), edm::BranchID::id(), and keep.

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  }
const int keep
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)
void edm::ThinnedAssociationsHelper::updateFromPrimaryInput ( ThinnedAssociationsHelper const &  helper)

Definition at line 278 of file ThinnedAssociationsHelper.cc.

References data(), requireMatch(), and vThinnedAssociationBranches_.

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

278  {
279  if (vThinnedAssociationBranches_.empty()) {
280  vThinnedAssociationBranches_ = helper.data();
281  return;
282  }
283  std::vector<ThinnedAssociationBranches> const& inputData = helper.data();
284  for (auto const& inputEntry : inputData) {
285  requireMatch(inputEntry);
286  }
287  }
void requireMatch(ThinnedAssociationBranches const &input) const
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::updateFromSecondaryInput ( ThinnedAssociationsHelper const &  helper,
std::vector< BranchID > const &  associationsFromSecondary 
)

Definition at line 289 of file ThinnedAssociationsHelper.cc.

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

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  }
void requireMatch(ThinnedAssociationBranches const &input) const
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})

Member Data Documentation

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