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

edm::ThinnedAssociationsHelper::ThinnedAssociationsHelper ( )

Definition at line 15 of file ThinnedAssociationsHelper.cc.

15 {}

Member Function Documentation

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

Definition at line 62 of file ThinnedAssociationsHelper.cc.

62  {
63  vThinnedAssociationBranches_.push_back(branches);
64  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > edm::ThinnedAssociationsHelper::associationToBranches ( ) const

Definition at line 67 of file ThinnedAssociationsHelper.cc.

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

Referenced by initAssociationsFromSecondary(), and updateFromSecondaryInput().

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  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::begin ( void  ) const

Definition at line 17 of file ThinnedAssociationsHelper.cc.

17  {
18  return vThinnedAssociationBranches_.begin();
19  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::clear ( void  )
inline
std::vector<ThinnedAssociationBranches> const& edm::ThinnedAssociationsHelper::data ( ) const
inline

Definition at line 57 of file ThinnedAssociationsHelper.h.

References edm::ThinnedAssociationBranches::association(), and input.

Referenced by updateFromParentProcess(), and updateFromPrimaryInput().

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

Definition at line 21 of file ThinnedAssociationsHelper.cc.

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

21  {
22  return vThinnedAssociationBranches_.end();
23  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::initAssociationsFromSecondary ( std::vector< BranchID > const &  associationsFromSecondary,
ThinnedAssociationsHelper const &  fileAssociationsHelper 
)

Definition at line 228 of file ThinnedAssociationsHelper.cc.

References edm::ThinnedAssociationBranches::association(), associationToBranches(), Exception, and edm::errors::LogicError.

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  }
void addAssociation(BranchID const &, BranchID const &, BranchID const &)
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::parentBegin ( BranchID const &  parent) const

Definition at line 25 of file ThinnedAssociationsHelper.cc.

References filterCSVwithJSON::target.

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

26  {
27  ThinnedAssociationBranches target(parent, BranchID(), BranchID());
28  return std::lower_bound(vThinnedAssociationBranches_.begin(),
30  target,
31  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
32  return x.parent() < y.parent();
33  });
34  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::parentEnd ( BranchID const &  parent) const

Definition at line 36 of file ThinnedAssociationsHelper.cc.

References filterCSVwithJSON::target.

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

37  {
38  ThinnedAssociationBranches target(parent, BranchID(), BranchID());
39  return std::upper_bound(vThinnedAssociationBranches_.begin(),
41  target,
42  [](ThinnedAssociationBranches const& x, ThinnedAssociationBranches const& y) {
43  return x.parent() < y.parent();
44  });
45  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::requireMatch ( ThinnedAssociationBranches const &  input) const

Definition at line 153 of file ThinnedAssociationsHelper.cc.

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

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

References edm::ThinnedAssociationBranches::association().

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

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  }
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() 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
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.

References edm::ThinnedAssociationBranches::association(), Exception, edm::errors::LogicError, and edm::match().

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  }
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) 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
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
void edm::ThinnedAssociationsHelper::sort ( )

Definition at line 47 of file ThinnedAssociationsHelper.cc.

References edm::ThinnedAssociationBranches::association(), and edm::ThinnedAssociationBranches::parent().

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  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
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.

References hitfit::clear(), data(), edm::BranchID::id(), keep, edm::ThinnedAssociationBranches::parent(), and edm::ThinnedAssociationBranches::thinned().

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

Definition at line 168 of file ThinnedAssociationsHelper.cc.

References data().

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

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  }
Definition: helper.py:1
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 179 of file ThinnedAssociationsHelper.cc.

References edm::ThinnedAssociationBranches::association(), associationToBranches(), Exception, and edm::errors::LogicError.

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  }
Definition: helper.py:1
void requireMatch(ThinnedAssociationBranches const &input) const

Member Data Documentation

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

Definition at line 81 of file ThinnedAssociationsHelper.h.