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,
95 int slimmingChildren = countSlimmingChildren(helper, branches.
thinned(),
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) {
131 if (pos != counts.end() && pos->parent ==
parent) {
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);
162 counts.begin(), counts.end(), iItem->parent(), [](SlimmedCount
const&
c,
BranchID const&
b) {
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));
182 std::sort(temp.begin(),
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 {
218 auto decision = keepAssociation.find(association);
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 =
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) {
322 BranchID parent = associationBranches.parent();
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");
std::vector< ThinnedAssociationBranches >::const_iterator lower_bound(ThinnedAssociationBranches const &branches) const
void initAssociationsFromSecondary(std::vector< BranchID > const &, ThinnedAssociationsHelper const &)
std::vector< ThinnedAssociationBranches > const & data() const
const edm::EventSetup & c
void requireMatch(ThinnedAssociationBranches const &input) const
__host__ __device__ constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
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
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
BranchID const & association() const
void addAdditionalInfo(std::string const &info)
void addAssociation(BranchID const &, BranchID const &, BranchID const &, bool slimmed)
void updateFromSecondaryInput(ThinnedAssociationsHelper const &, std::vector< BranchID > const &associationsFromSecondary)
std::vector< ThinnedAssociationBranches > vThinnedAssociationBranches_
void addContext(std::string const &context)
std::vector< ThinnedAssociationBranches >::const_iterator begin() const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
void ensureSlimmingConstraints() const
void updateFromParentProcess(ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, std::map< BranchID, bool > const &keepAssociation, std::map< BranchID::value_type, BranchID::value_type > const &droppedBranchIDToKeptBranchID)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
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)