CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 &)
 
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 updateFromInput (ThinnedAssociationsHelper const &, bool isSecondaryFile, std::vector< BranchID > const &associationsFromSecondary)
 
void updateFromParentProcess (ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, std::map< BranchID, bool > const &keepAssociation, std::map< BranchID::value_type, BranchID::value_type > const &droppedBranchIDToKeptBranchID)
 

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
< ThinnedAssociationBranches
vThinnedAssociationBranches_
 

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

18  {
19  }

Member Function Documentation

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

Definition at line 56 of file ThinnedAssociationsHelper.cc.

References vThinnedAssociationBranches_.

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

58  {
59  vThinnedAssociationBranches_.push_back(ThinnedAssociationBranches(parent, association, thinned));
60  }
list parent
Definition: dbtoconf.py:74
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::addAssociation ( ThinnedAssociationBranches const &  branches)

Definition at line 62 of file ThinnedAssociationsHelper.cc.

References vThinnedAssociationBranches_.

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 python.multivaluedict::sort(), groupFilesInBlocks::temp, vThinnedAssociationBranches_, and x().

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

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(), temp.end(), [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
73  std::pair<BranchID, ThinnedAssociationBranches const*> const& y)
74  { return x.first < y.first; });
75  return temp;
76  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::begin ( void  ) const

Definition at line 22 of file ThinnedAssociationsHelper.cc.

References vThinnedAssociationBranches_.

22  {
23  return vThinnedAssociationBranches_.begin();
24  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::clear ( void  )
inline
std::vector<ThinnedAssociationBranches> const& edm::ThinnedAssociationsHelper::data ( ) const
inline

Definition at line 58 of file ThinnedAssociationsHelper.h.

References vThinnedAssociationBranches_.

Referenced by cuy.FindIssue::__init__(), updateFromInput(), and updateFromParentProcess().

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

Definition at line 27 of file ThinnedAssociationsHelper.cc.

References vThinnedAssociationBranches_.

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

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

Definition at line 232 of file ThinnedAssociationsHelper.cc.

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

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

Definition at line 32 of file ThinnedAssociationsHelper.cc.

References filterCSVwithJSON::target, vThinnedAssociationBranches_, and x().

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

32  {
33  ThinnedAssociationBranches target(parent, BranchID(), BranchID());
34  return std::lower_bound(vThinnedAssociationBranches_.begin(), vThinnedAssociationBranches_.end(), target,
35  [](ThinnedAssociationBranches const& x,
36  ThinnedAssociationBranches const& y)
37  { return x.parent() < y.parent(); });
38  }
list parent
Definition: dbtoconf.py:74
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
std::vector< ThinnedAssociationBranches >::const_iterator edm::ThinnedAssociationsHelper::parentEnd ( BranchID const &  parent) const

Definition at line 41 of file ThinnedAssociationsHelper.cc.

References filterCSVwithJSON::target, vThinnedAssociationBranches_, and x().

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

41  {
42  ThinnedAssociationBranches target(parent, BranchID(), BranchID());
43  return std::upper_bound(vThinnedAssociationBranches_.begin(), vThinnedAssociationBranches_.end(), target,
44  [](ThinnedAssociationBranches const& x,
45  ThinnedAssociationBranches const& y)
46  { return x.parent() < y.parent(); });
47  }
list parent
Definition: dbtoconf.py:74
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::requireMatch ( ThinnedAssociationBranches const &  input) const

Definition at line 158 of file ThinnedAssociationsHelper.cc.

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

Referenced by updateFromInput().

158  {
159  bool foundMatch = false;
160  for(auto entry = parentBegin(input.parent()), iEnd = parentEnd(input.parent());
161  entry != iEnd; ++entry) {
162  if(entry->association() == input.association() &&
163  entry->thinned() == input.thinned()) {
164  foundMatch = true;
165  break;
166  }
167  }
168  if(!foundMatch) {
169  throw edm::Exception(errors::MismatchedInputFiles, "ThinnedAssociationHelper::requireMatch, Illegal attempt to merge files with different ThinnedAssociations");
170  }
171  }
static std::string const input
Definition: EdmProvDump.cc:43
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 80 of file ThinnedAssociationsHelper.cc.

References associationToBranches(), and shouldKeepAssociation().

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

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

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

Referenced by selectAssociationProducts().

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

References edm::ThinnedAssociationBranches::association(), edm::ThinnedAssociationBranches::parent(), python.multivaluedict::sort(), vThinnedAssociationBranches_, and x().

Referenced by initAssociationsFromSecondary(), and updateFromParentProcess().

49  {
51  [](ThinnedAssociationBranches const& x,
52  ThinnedAssociationBranches const& y)
53  { return x.parent() < y.parent() ? true : y.parent() < x.parent() ? false : x.association() < y.association(); });
54  }
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void edm::ThinnedAssociationsHelper::updateFromInput ( ThinnedAssociationsHelper const &  helper,
bool  isSecondaryFile,
std::vector< BranchID > const &  associationsFromSecondary 
)

Definition at line 173 of file ThinnedAssociationsHelper.cc.

References associationToBranches(), data(), Exception, idDealer::inputData, edm::errors::LogicError, requireMatch(), vThinnedAssociationBranches_, and x().

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

174  {
175  if(!isSecondaryFile) {
176  if(vThinnedAssociationBranches_.empty()) {
177  vThinnedAssociationBranches_ = helper.data();
178  return;
179  }
180  std::vector<ThinnedAssociationBranches> const& inputData = helper.data();
181  for (auto const& inputEntry : inputData) {
182  requireMatch(inputEntry);
183  }
184  } else { // Input is from a secondary file
185 
186  if(associationsFromSecondary.empty()) return;
187 
188  std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > assocToBranches = helper.associationToBranches();
189 
190  for(BranchID const& association : associationsFromSecondary) {
191 
192  auto branches = std::lower_bound(assocToBranches.begin(), assocToBranches.end(),
193  std::make_pair(association, static_cast<ThinnedAssociationBranches const*>(nullptr)),
194  [](std::pair<BranchID, ThinnedAssociationBranches const*> const& x,
195  std::pair<BranchID, ThinnedAssociationBranches const*> const& y)
196  { return x.first < y.first; });
197  // This should never happen
198  if(branches == assocToBranches.end() || branches->first != association) {
200  "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches information, contact Framework developers");
201  }
202  requireMatch(*(branches->second));
203  }
204  }
205  }
void requireMatch(ThinnedAssociationBranches const &input) const
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
tuple inputData
Definition: idDealer.py:72
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 208 of file ThinnedAssociationsHelper.cc.

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

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

Member Data Documentation

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