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 &)
 
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
 
void sort ()
 
 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

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 35 of file ThinnedAssociationsHelper.h.

Constructor & Destructor Documentation

◆ ThinnedAssociationsHelper()

edm::ThinnedAssociationsHelper::ThinnedAssociationsHelper ( )

Definition at line 15 of file ThinnedAssociationsHelper.cc.

15 {}

Member Function Documentation

◆ addAssociation() [1/2]

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

◆ addAssociation() [2/2]

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

Definition at line 62 of file ThinnedAssociationsHelper.cc.

62  {
63  vThinnedAssociationBranches_.push_back(branches);
64  }

References vThinnedAssociationBranches_.

◆ associationToBranches()

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

Definition at line 67 of file ThinnedAssociationsHelper.cc.

67  {
68  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > temp;
69  for (auto const& item : vThinnedAssociationBranches_) {
70  temp.push_back(std::make_pair(item.association(), &item));
71  }
72  std::sort(temp.begin(),
73  temp.end(),
74  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
75  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
76  return temp;
77  }

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

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

◆ begin()

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

Definition at line 17 of file ThinnedAssociationsHelper.cc.

17  {
18  return vThinnedAssociationBranches_.begin();
19  }

References vThinnedAssociationBranches_.

◆ clear()

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

◆ data()

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

Definition at line 57 of file ThinnedAssociationsHelper.h.

References vThinnedAssociationBranches_.

Referenced by updateFromParentProcess().

◆ end()

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

Definition at line 21 of file ThinnedAssociationsHelper.cc.

21  {
22  return vThinnedAssociationBranches_.end();
23  }

References vThinnedAssociationBranches_.

Referenced by Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

◆ initAssociationsFromSecondary()

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

Definition at line 228 of file ThinnedAssociationsHelper.cc.

229  {
230  if (associationsFromSecondary.empty())
231  return;
232 
233  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > assocToBranches =
234  fileAssociationsHelper.associationToBranches();
235 
236  for (BranchID const& association : associationsFromSecondary) {
237  auto branches = std::lower_bound(
238  assocToBranches.begin(),
239  assocToBranches.end(),
240  std::make_pair(association, static_cast<ThinnedAssociationBranches const*>(nullptr)),
241  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
242  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
243  // This should never happen
244  if (branches == assocToBranches.end() || branches->first != association) {
246  "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches "
247  "information, contact Framework developers");
248  }
249  addAssociation(*(branches->second));
250  }
251  sort();
252  }

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

◆ parentBegin()

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

Definition at line 25 of file ThinnedAssociationsHelper.cc.

26  {
27  ThinnedAssociationBranches target(parent, BranchID(), BranchID());
30  target,
31  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
32  return x.parent() < y.parent();
33  });
34  }

References cuda_std::lower_bound(), class-composition::parent, filterCSVwithJSON::target, and vThinnedAssociationBranches_.

Referenced by BareRootProductGetter::getThinnedProduct(), fwlite::DataGetterHelper::getThinnedProduct(), BareRootProductGetter::getThinnedProducts(), fwlite::DataGetterHelper::getThinnedProducts(), requireMatch(), and shouldKeepAssociation().

◆ parentEnd()

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

Definition at line 36 of file ThinnedAssociationsHelper.cc.

37  {
38  ThinnedAssociationBranches target(parent, BranchID(), BranchID());
41  target,
42  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
43  return x.parent() < y.parent();
44  });
45  }

References class-composition::parent, filterCSVwithJSON::target, cuda_std::upper_bound(), and vThinnedAssociationBranches_.

Referenced by BareRootProductGetter::getThinnedProduct(), fwlite::DataGetterHelper::getThinnedProduct(), BareRootProductGetter::getThinnedProducts(), fwlite::DataGetterHelper::getThinnedProducts(), requireMatch(), and shouldKeepAssociation().

◆ requireMatch()

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

Definition at line 153 of file ThinnedAssociationsHelper.cc.

153  {
154  bool foundMatch = false;
155  for (auto entry = parentBegin(input.parent()), iEnd = parentEnd(input.parent()); entry != iEnd; ++entry) {
156  if (entry->association() == input.association() && entry->thinned() == input.thinned()) {
157  foundMatch = true;
158  break;
159  }
160  }
161  if (!foundMatch) {
162  throw edm::Exception(
164  "ThinnedAssociationHelper::requireMatch, Illegal attempt to merge files with different ThinnedAssociations");
165  }
166  }

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

82  {
83  keepAssociation.clear();
84  // Copy the elements in vThinnedAssociationBranches_ into a vector sorted on
85  // the association BranchID so we can do searches on that BranchID faster.
86  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > assocToBranches = associationToBranches();
87 
88  for (auto association : associationDescriptions) {
89  if (association
90  ->isAlias()) { // There is no reason to configure an association product with an EDAlias (ignore and drop them if they exist)
91  keepAssociation.insert(std::make_pair(association->branchID(), false));
92  } else {
93  std::set<BranchID> branchesInRecursion;
95  association->branchID(), assocToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation);
96  }
97  }
98  }

References TrackValidation_cff::association, 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 100 of file ThinnedAssociationsHelper.cc.

105  {
106  // If we already decided to keep or drop this one, then
107  // return the same decision.
108  auto decision = keepAssociation.find(association);
109  if (decision != keepAssociation.end()) {
110  return decision->second;
111  }
112 
113  // Be careful not to fall into an infinite loop because
114  // of a circular recursion.
115  if (!branchesInRecursion.insert(association).second) {
116  return false;
117  }
118 
119  // If the thinned collection is being kept then keep the association
120  auto branches = std::lower_bound(
121  associationToBranches.begin(),
122  associationToBranches.end(),
123  std::make_pair(association, static_cast<ThinnedAssociationBranches const*>(nullptr)),
124  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
125  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
126  // This should never happen
127  if (branches == associationToBranches.end() || branches->first != association) {
129  "ThinnedAssociationHelper::shouldKeepAssociation could not find branches information, "
130  "contact Framework developers");
131  }
132  BranchID const& thinnedCollection = branches->second->thinned();
133  if (keptProductsInEvent.find(thinnedCollection) != keptProductsInEvent.end()) {
134  keepAssociation.insert(std::make_pair(association, true));
135  return true;
136  }
137  // otherwise loop over any associations where the thinned collection
138  // is also a parent collection and recursively examine those to see
139  // if their thinned collections are being kept.
140  auto iterEnd = parentEnd(thinnedCollection);
141  for (auto match = parentBegin(thinnedCollection); match != iterEnd; ++match) {
143  match->association(), associationToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation)) {
144  keepAssociation.insert(std::make_pair(association, true));
145  return true;
146  }
147  }
148  // drop the association
149  keepAssociation.insert(std::make_pair(association, false));
150  return false;
151  }

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

Referenced by selectAssociationProducts().

◆ sort()

void edm::ThinnedAssociationsHelper::sort ( )

Definition at line 47 of file ThinnedAssociationsHelper.cc.

47  {
48  std::sort(vThinnedAssociationBranches_.begin(),
50  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
51  return x.parent() < y.parent() ? true
52  : y.parent() < x.parent() ? false : x.association() < y.association();
53  });
54  }

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

Referenced by initAssociationsFromSecondary(), and updateFromParentProcess().

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

207  {
208  clear();
209  for (auto const& associationBranches : parentThinnedAssociationsHelper.data()) {
210  auto keep = keepAssociation.find(associationBranches.association());
211  if (keep != keepAssociation.end() && keep->second) {
212  BranchID parent = associationBranches.parent();
213  auto iter = droppedBranchIDToKeptBranchID.find(parent.id());
214  if (iter != droppedBranchIDToKeptBranchID.end()) {
215  parent = BranchID(iter->second);
216  }
217  BranchID thinned = associationBranches.thinned();
218  iter = droppedBranchIDToKeptBranchID.find(thinned.id());
219  if (iter != droppedBranchIDToKeptBranchID.end()) {
220  thinned = BranchID(iter->second);
221  }
222  addAssociation(parent, associationBranches.association(), thinned);
223  }
224  }
225  sort();
226  }

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

◆ updateFromPrimaryInput()

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

Definition at line 168 of file ThinnedAssociationsHelper.cc.

168  {
169  if (vThinnedAssociationBranches_.empty()) {
171  return;
172  }
173  std::vector<ThinnedAssociationBranches> const& inputData = helper.data();
174  for (auto const& inputEntry : inputData) {
175  requireMatch(inputEntry);
176  }
177  }

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

180  {
181  if (associationsFromSecondary.empty())
182  return;
183 
184  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > assocToBranches =
185  helper.associationToBranches();
186 
187  for (BranchID const& association : associationsFromSecondary) {
188  auto branches = std::lower_bound(
189  assocToBranches.begin(),
190  assocToBranches.end(),
191  std::make_pair(association, static_cast<ThinnedAssociationBranches const*>(nullptr)),
192  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
193  std::pair<BranchID, ThinnedAssociationBranches const*> const& y) { return x.first < y.first; });
194  // This should never happen
195  if (branches == assocToBranches.end() || branches->first != association) {
197  "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches "
198  "information, contact Framework developers");
199  }
200  requireMatch(*(branches->second));
201  }
202  }

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

Member Data Documentation

◆ vThinnedAssociationBranches_

std::vector<ThinnedAssociationBranches> edm::ThinnedAssociationsHelper::vThinnedAssociationBranches_
private
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:34
edm::errors::LogicError
Definition: EDMException.h:37
mps_splice.entry
entry
Definition: mps_splice.py:68
edm::ThinnedAssociationsHelper::clear
void clear()
Definition: ThinnedAssociationsHelper.h:51
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:100
edm::ThinnedAssociationsHelper::parentEnd
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
Definition: ThinnedAssociationsHelper.cc:36
DDAxes::x
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
cuda_std::upper_bound
__host__ constexpr __device__ RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:45
edm::ThinnedAssociationsHelper::requireMatch
void requireMatch(ThinnedAssociationBranches const &input) const
Definition: ThinnedAssociationsHelper.cc:153
edm::ThinnedAssociationsHelper::vThinnedAssociationBranches_
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
Definition: ThinnedAssociationsHelper.h:81
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
funct::true
true
Definition: Factorize.h:173
helper
Definition: helper.py:1
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
TrackValidation_cff.association
association
Definition: TrackValidation_cff.py:286
edm::match
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
Definition: BranchDescription.cc:351
edm::ThinnedAssociationsHelper::parentBegin
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
Definition: ThinnedAssociationsHelper.cc:25
Exception
Definition: hltDiff.cc:246
edm::ThinnedAssociationsHelper::sort
void sort()
Definition: ThinnedAssociationsHelper.cc:47
filterCSVwithJSON.target
target
Definition: filterCSVwithJSON.py:32
edm::ThinnedAssociationsHelper::associationToBranches
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
Definition: ThinnedAssociationsHelper.cc:67
keep
const int keep
Definition: GenParticlePruner.cc:48
class-composition.parent
parent
Definition: class-composition.py:88
edm::ThinnedAssociationsHelper::addAssociation
void addAssociation(BranchID const &, BranchID const &, BranchID const &)
Definition: ThinnedAssociationsHelper.cc:56