18 return vThinnedAssociationBranches_.begin();
22 return vThinnedAssociationBranches_.end();
28 return std::lower_bound(vThinnedAssociationBranches_.begin(),
29 vThinnedAssociationBranches_.end(),
32 return x.parent() < y.parent();
39 return std::upper_bound(vThinnedAssociationBranches_.begin(),
40 vThinnedAssociationBranches_.end(),
43 return x.parent() < y.parent();
48 std::sort(vThinnedAssociationBranches_.begin(),
49 vThinnedAssociationBranches_.end(),
51 return x.
parent() < y.parent() ?
true 63 vThinnedAssociationBranches_.push_back(branches);
66 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> >
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));
72 std::sort(temp.begin(),
74 [](std::pair<BranchID, ThinnedAssociationBranches const*>
const& x,
75 std::pair<BranchID, ThinnedAssociationBranches const*>
const& y) {
return x.first < y.first; });
80 std::vector<BranchDescription const*>
const& associationDescriptions,
81 std::set<BranchID>
const& keptProductsInEvent,
82 std::map<BranchID, bool>& keepAssociation)
const {
83 keepAssociation.clear();
86 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > assocToBranches = associationToBranches();
91 keepAssociation.insert(std::make_pair(
association->branchID(),
false));
93 std::set<BranchID> branchesInRecursion;
94 shouldKeepAssociation(
95 association->branchID(), assocToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation);
102 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> >
const& associationToBranches,
103 std::set<BranchID>& branchesInRecursion,
104 std::set<BranchID>
const& keptProductsInEvent,
105 std::map<BranchID, bool>& keepAssociation)
const {
108 auto decision = keepAssociation.find(association);
109 if (decision != keepAssociation.end()) {
110 return decision->second;
115 if (!branchesInRecursion.insert(association).second) {
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; });
127 if (branches == associationToBranches.end() || branches->first !=
association) {
129 "ThinnedAssociationHelper::shouldKeepAssociation could not find branches information, " 130 "contact Framework developers");
132 BranchID const& thinnedCollection = branches->second->thinned();
133 if (keptProductsInEvent.find(thinnedCollection) != keptProductsInEvent.end()) {
134 keepAssociation.insert(std::make_pair(association,
true));
140 auto iterEnd = parentEnd(thinnedCollection);
141 for (
auto match = parentBegin(thinnedCollection);
match != iterEnd; ++
match) {
142 if (shouldKeepAssociation(
143 match->association(), associationToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation)) {
144 keepAssociation.insert(std::make_pair(association,
true));
149 keepAssociation.insert(std::make_pair(association,
false));
154 bool foundMatch =
false;
164 "ThinnedAssociationHelper::requireMatch, Illegal attempt to merge files with different ThinnedAssociations");
169 if (vThinnedAssociationBranches_.empty()) {
170 vThinnedAssociationBranches_ = helper.
data();
173 std::vector<ThinnedAssociationBranches>
const& inputData = helper.
data();
174 for (
auto const& inputEntry : inputData) {
175 requireMatch(inputEntry);
180 std::vector<BranchID>
const& associationsFromSecondary) {
181 if (associationsFromSecondary.empty())
184 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > assocToBranches =
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; });
195 if (branches == assocToBranches.end() || branches->first !=
association) {
197 "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches " 198 "information, contact Framework developers");
200 requireMatch(*(branches->second));
206 std::map<BranchID, bool>
const& keepAssociation,
207 std::map<BranchID::value_type, BranchID::value_type>
const& droppedBranchIDToKeptBranchID) {
209 for (
auto const& associationBranches : parentThinnedAssociationsHelper.
data()) {
210 auto keep = keepAssociation.find(associationBranches.association());
211 if (
keep != keepAssociation.end() &&
keep->second) {
213 auto iter = droppedBranchIDToKeptBranchID.find(parent.
id());
214 if (iter != droppedBranchIDToKeptBranchID.end()) {
218 iter = droppedBranchIDToKeptBranchID.find(thinned.
id());
219 if (iter != droppedBranchIDToKeptBranchID.end()) {
222 addAssociation(parent, associationBranches.association(),
thinned);
230 if (associationsFromSecondary.empty())
233 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > assocToBranches =
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; });
244 if (branches == assocToBranches.end() || branches->first !=
association) {
246 "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches " 247 "information, contact Framework developers");
249 addAssociation(*(branches->second));
void initAssociationsFromSecondary(std::vector< BranchID > const &, ThinnedAssociationsHelper const &)
std::vector< ThinnedAssociationBranches > const & data() const
void addAssociation(BranchID const &, BranchID const &, BranchID const &)
void requireMatch(ThinnedAssociationBranches const &input) const
BranchID const & parent() const
ThinnedAssociationBranches()
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
void updateFromPrimaryInput(ThinnedAssociationsHelper const &)
std::vector< ThinnedAssociationBranches >::const_iterator end() const
static std::string const input
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
void selectAssociationProducts(std::vector< BranchDescription const * > const &associationDescriptions, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const
BranchID const & association() const
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
void updateFromSecondaryInput(ThinnedAssociationsHelper const &, std::vector< BranchID > const &associationsFromSecondary)
std::vector< ThinnedAssociationBranches >::const_iterator begin() const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
void updateFromParentProcess(ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, std::map< BranchID, bool > const &keepAssociation, std::map< BranchID::value_type, BranchID::value_type > const &droppedBranchIDToKeptBranchID)
ThinnedAssociationsHelper()
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
BranchID const & thinned() const
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)