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;
181 temp.push_back(std::make_pair(
item.association(), &
item));
185 [](std::pair<BranchID, ThinnedAssociationBranches const*>
const&
x,
186 std::pair<BranchID, ThinnedAssociationBranches const*>
const& y) {
return x.first < y.first; });
191 std::vector<BranchDescription const*>
const& associationDescriptions,
192 std::set<BranchID>
const& keptProductsInEvent,
193 std::map<BranchID, bool>& keepAssociation)
const {
194 keepAssociation.clear();
197 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
associationToBranches();
202 keepAssociation.insert(std::make_pair(
association->branchID(),
false));
204 std::set<BranchID> branchesInRecursion;
206 association->branchID(), assocToBranches, branchesInRecursion, keptProductsInEvent, keepAssociation);
213 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>>
const& associationToBranches,
214 std::set<BranchID>& branchesInRecursion,
215 std::set<BranchID>
const& keptProductsInEvent,
216 std::map<BranchID, bool>& keepAssociation)
const {
220 if (decision != keepAssociation.end()) {
221 return decision->second;
226 if (!branchesInRecursion.insert(
association).second) {
234 std::make_pair(
association, static_cast<ThinnedAssociationBranches const*>(
nullptr)),
235 [](std::pair<BranchID, ThinnedAssociationBranches const*>
const&
x,
236 std::pair<BranchID, ThinnedAssociationBranches const*>
const& y) {
return x.first < y.first; });
240 "ThinnedAssociationHelper::shouldKeepAssociation could not find branches information, " 241 "contact Framework developers");
244 if (keptProductsInEvent.find(thinnedCollection) != keptProductsInEvent.end()) {
245 keepAssociation.insert(std::make_pair(
association,
true));
251 auto iterEnd =
parentEnd(thinnedCollection);
255 keepAssociation.insert(std::make_pair(
association,
true));
260 keepAssociation.insert(std::make_pair(
association,
false));
265 bool foundMatch =
false;
275 "ThinnedAssociationHelper::requireMatch, Illegal attempt to merge files with different ThinnedAssociations");
284 std::vector<ThinnedAssociationBranches>
const& inputData =
helper.data();
285 for (
auto const& inputEntry : inputData) {
291 std::vector<BranchID>
const& associationsFromSecondary) {
292 if (associationsFromSecondary.empty())
295 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
296 helper.associationToBranches();
300 assocToBranches.begin(),
301 assocToBranches.end(),
302 std::make_pair(
association, static_cast<ThinnedAssociationBranches const*>(
nullptr)),
303 [](std::pair<BranchID, ThinnedAssociationBranches const*>
const&
x,
304 std::pair<BranchID, ThinnedAssociationBranches const*>
const& y) {
return x.first < y.first; });
306 if (branches == assocToBranches.end() || branches->first !=
association) {
308 "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches " 309 "information, contact Framework developers");
317 std::map<BranchID, bool>
const& keepAssociation,
318 std::map<BranchID::value_type, BranchID::value_type>
const& droppedBranchIDToKeptBranchID) {
320 for (
auto const& associationBranches : parentThinnedAssociationsHelper.
data()) {
321 auto keep = keepAssociation.find(associationBranches.association());
322 if (
keep != keepAssociation.end() &&
keep->second) {
324 auto iter = droppedBranchIDToKeptBranchID.find(
parent.id());
325 if (iter != droppedBranchIDToKeptBranchID.end()) {
328 BranchID thinned = associationBranches.thinned();
329 iter = droppedBranchIDToKeptBranchID.find(thinned.
id());
330 if (iter != droppedBranchIDToKeptBranchID.end()) {
333 addAssociation(
parent, associationBranches.association(), thinned, associationBranches.isSlimmed());
340 if (associationsFromSecondary.empty())
343 std::vector<std::pair<BranchID, ThinnedAssociationBranches const*>> assocToBranches =
348 assocToBranches.begin(),
349 assocToBranches.end(),
350 std::make_pair(
association, static_cast<ThinnedAssociationBranches const*>(
nullptr)),
351 [](std::pair<BranchID, ThinnedAssociationBranches const*>
const&
x,
352 std::pair<BranchID, ThinnedAssociationBranches const*>
const& y) {
return x.first < y.first; });
354 if (branches == assocToBranches.end() || branches->first !=
association) {
356 "ThinnedAssociationHelper::initAssociationsFromSecondary could not find branches " 357 "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 &)
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
static std::string const input
void ensureSlimmingConstraints() const
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)