6 #include <fmt/format.h> 16 : parent_(
parent), association_(
association), thinned_(thinned), slimmed_(slimmed) {}
35 return x.parent() < y.parent();
46 return x.parent() < y.parent();
57 return x.parent() < y.parent() ?
true : y.parent() <
x.parent() ?
false :
x.association() < y.association();
74 ex.
addContext(
"Calling ThinnedAssociationsHelper::addAssociation()");
85 int slimmedChildrenCount;
90 std::vector<SlimmedCount>
const&
counts);
93 std::vector<SlimmedCount>
const&
counts,
96 if (slimmingChildren > 1) {
98 <<
"Encountered a parent collection with BranchID " << branches.
thinned().
id()
99 <<
" that has more than one thinned children that are either themselves slimmed, or have further thinned " 100 "children that are slimmed. This is not allowed, but this particular check should not fire (it should " 101 "have been caught earlier). Please contact framework developers.";
104 if (slimmingChildren == 0 and branches.
isSlimmed()) {
108 slimmedCount += slimmingChildren;
109 if (slimmedCount > 1) {
111 <<
"Encountered a parent collection with BranchID " << branches.
parent().
id()
112 <<
" that has more than one thinned children that are either themselves slimmed, or have further thinned " 113 "children that are slimmed. This is not allowed. In the thinning parentage tree, any parent may have " 114 "slimmed collections in at most one path to any leaf thinned collections of that parent.";
120 std::vector<SlimmedCount>
const&
counts) {
132 return pos->slimmedChildrenCount;
135 int slimmedCount = 0;
136 for (
auto iItem = begin; iItem !=
end; ++iItem) {
137 addSlimmingChildrenCount(
helper, *iItem,
counts, slimmedCount);
151 std::vector<::SlimmedCount>
counts;
153 std::vector<SlimmedCount>::iterator currentCount;
154 for (
auto iItem =
begin(), iEnd =
end(); iItem != iEnd; ++iItem) {
155 if (iItem->parent() ==
BranchID()) {
158 if (iItem->parent() == prevParent) {
159 addSlimmingChildrenCount(*
this, *iItem,
counts, currentCount->slimmedChildrenCount);
166 if (currentCount !=
counts.end() && currentCount->parent == iItem->parent()) {
169 currentCount =
counts.insert(currentCount, ::SlimmedCount{iItem->parent(), 0});
170 addSlimmingChildrenCount(*
this, *iItem,
counts, currentCount->slimmedChildrenCount);
171 prevParent = iItem->parent();
178 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>>
temp;
180 temp.push_back(std::make_pair(
item.association(), &
item));
184 [](std::pair<BranchID, ThinnedAssociationBranches const*>
const&
x,
185 std::pair<BranchID, ThinnedAssociationBranches const*>
const& y) {
return x.first < y.first; });
190 std::vector<BranchDescription const*>
const& associationDescriptions,
191 std::set<BranchID>
const& keptProductsInEvent,
192 std::map<BranchID, bool>& keepAssociation)
const {
193 keepAssociation.clear();
196 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
associationToBranches();
201 keepAssociation.insert(std::make_pair(
association->branchID(),
false));
203 std::set<BranchID> branchesInRecursion;
205 association->branchID(), assocToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation);
212 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>>
const& associationToBranches,
213 std::set<BranchID>& branchesInRecursion,
214 std::set<BranchID>
const& keptProductsInEvent,
215 std::map<BranchID, bool>& keepAssociation)
const {
219 if (decision != keepAssociation.end()) {
220 return decision->second;
225 if (!branchesInRecursion.insert(
association).second) {
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; });
239 "ThinnedAssociationHelper::shouldKeepAssociation could not find branches information, " 240 "contact Framework developers");
243 if (keptProductsInEvent.find(thinnedCollection) != keptProductsInEvent.end()) {
244 keepAssociation.insert(std::make_pair(
association,
true));
250 auto iterEnd =
parentEnd(thinnedCollection);
254 keepAssociation.insert(std::make_pair(
association,
true));
259 keepAssociation.insert(std::make_pair(
association,
false));
264 bool foundMatch =
false;
274 "ThinnedAssociationHelper::requireMatch, Illegal attempt to merge files with different ThinnedAssociations");
283 std::vector<ThinnedAssociationBranches>
const& inputData =
helper.data();
284 for (
auto const& inputEntry : inputData) {
290 std::vector<BranchID>
const& associationsFromSecondary) {
291 if (associationsFromSecondary.empty())
294 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
295 helper.associationToBranches();
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; });
305 if (branches == assocToBranches.end() || branches->first !=
association) {
307 "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches " 308 "information, contact Framework developers");
316 std::map<BranchID, bool>
const& keepAssociation,
317 std::map<BranchID::value_type, BranchID::value_type>
const& droppedBranchIDToKeptBranchID) {
319 for (
auto const& associationBranches : parentThinnedAssociationsHelper.
data()) {
320 auto keep = keepAssociation.find(associationBranches.association());
321 if (
keep != keepAssociation.end() &&
keep->second) {
323 auto iter = droppedBranchIDToKeptBranchID.find(
parent.id());
324 if (iter != droppedBranchIDToKeptBranchID.end()) {
327 BranchID thinned = associationBranches.thinned();
328 iter = droppedBranchIDToKeptBranchID.find(thinned.
id());
329 if (iter != droppedBranchIDToKeptBranchID.end()) {
332 addAssociation(
parent, associationBranches.association(), thinned, associationBranches.isSlimmed());
339 if (associationsFromSecondary.empty())
342 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
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; });
353 if (branches == assocToBranches.end() || branches->first !=
association) {
355 "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches " 356 "information, contact Framework developers");
void initAssociationsFromSecondary(std::vector< BranchID > const &, ThinnedAssociationsHelper const &)
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
std::vector< ThinnedAssociationBranches >::const_iterator lower_bound(ThinnedAssociationBranches const &branches) const
std::vector< std::pair< BranchID, ThinnedAssociationBranches const * > > associationToBranches() const
ThinnedAssociationBranches()
void updateFromPrimaryInput(ThinnedAssociationsHelper const &)
static std::string const input
void ensureSlimmingConstraints() const
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
std::vector< ThinnedAssociationBranches > const & data() const
BranchID const & parent() const
std::vector< ThinnedAssociationBranches >::const_iterator begin() const
void addAdditionalInfo(std::string const &info)
std::vector< ThinnedAssociationBranches >::const_iterator end() const
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)
void updateFromSecondaryInput(ThinnedAssociationsHelper const &, std::vector< BranchID > const &associationsFromSecondary)
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void requireMatch(ThinnedAssociationBranches const &input) 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
void addContext(std::string const &context)
BranchID const & thinned() 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)
void selectAssociationProducts(std::vector< BranchDescription const *> const &associationDescriptions, std::set< BranchID > const &keptProductsInEvent, std::map< BranchID, bool > &keepAssociation) const
ThinnedAssociationsHelper()
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)