Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:31

0001 #ifndef DataFormats_Provenance_ThinnedAssociationsHelper_h
0002 #define DataFormats_Provenance_ThinnedAssociationsHelper_h
0003 
0004 /** \class edm::ThinnedAssociationsHelper
0005 \author W. David Dagenhart, created 11 June 2014
0006 */
0007 
0008 #include "DataFormats/Provenance/interface/BranchID.h"
0009 
0010 #include <map>
0011 #include <set>
0012 #include <vector>
0013 
0014 namespace edm {
0015 
0016   class BranchDescription;
0017 
0018   class ThinnedAssociationBranches {
0019   public:
0020     ThinnedAssociationBranches();
0021     ThinnedAssociationBranches(BranchID const&, BranchID const&, BranchID const&, bool slimmed);
0022 
0023     BranchID const& parent() const { return parent_; }
0024     BranchID const& association() const { return association_; }
0025     BranchID const& thinned() const { return thinned_; }
0026     bool isSlimmed() const { return slimmed_; }
0027 
0028     bool operator<(ThinnedAssociationBranches const& rhs) const { return parent_ < rhs.parent_; }
0029 
0030   private:
0031     BranchID parent_;
0032     BranchID association_;
0033     BranchID thinned_;
0034     bool slimmed_ = false;
0035   };
0036 
0037   class ThinnedAssociationsHelper {
0038   public:
0039     ThinnedAssociationsHelper();
0040 
0041     std::vector<ThinnedAssociationBranches>::const_iterator begin() const;
0042     std::vector<ThinnedAssociationBranches>::const_iterator end() const;
0043 
0044     std::vector<ThinnedAssociationBranches>::const_iterator parentBegin(BranchID const&) const;
0045     std::vector<ThinnedAssociationBranches>::const_iterator parentEnd(BranchID const&) const;
0046 
0047     void addAssociation(BranchID const&, BranchID const&, BranchID const&, bool slimmed);
0048     void addAssociation(ThinnedAssociationBranches const&);
0049 
0050     std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > associationToBranches() const;
0051 
0052     void clear() { vThinnedAssociationBranches_.clear(); }
0053 
0054     void selectAssociationProducts(std::vector<BranchDescription const*> const& associationDescriptions,
0055                                    std::set<BranchID> const& keptProductsInEvent,
0056                                    std::map<BranchID, bool>& keepAssociation) const;
0057 
0058     std::vector<ThinnedAssociationBranches> const& data() const { return vThinnedAssociationBranches_; }
0059 
0060     void requireMatch(ThinnedAssociationBranches const& input) const;
0061 
0062     void updateFromPrimaryInput(ThinnedAssociationsHelper const&);
0063 
0064     void updateFromSecondaryInput(ThinnedAssociationsHelper const&,
0065                                   std::vector<BranchID> const& associationsFromSecondary);
0066 
0067     void updateFromParentProcess(
0068         ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
0069         std::map<BranchID, bool> const& keepAssociation,
0070         std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID);
0071 
0072     void initAssociationsFromSecondary(std::vector<BranchID> const&, ThinnedAssociationsHelper const&);
0073 
0074   private:
0075     bool shouldKeepAssociation(
0076         BranchID const& association,
0077         std::vector<std::pair<BranchID, ThinnedAssociationBranches const*> > const& associationToBranches,
0078         std::set<BranchID>& branchesInRecursion,
0079         std::set<BranchID> const& keptProductsInEvent,
0080         std::map<BranchID, bool>& keepAssociation) const;
0081     std::vector<ThinnedAssociationBranches>::const_iterator lower_bound(
0082         ThinnedAssociationBranches const& branches) const;
0083 
0084     void ensureSlimmingConstraints() const;
0085 
0086     std::vector<ThinnedAssociationBranches> vThinnedAssociationBranches_;
0087   };
0088 }  // namespace edm
0089 #endif