SamplingInputFile.h
Go to the documentation of this file.
1 #ifndef art_Framework_Modules_detail_SamplingInputFile_h
2 #define art_Framework_Modules_detail_SamplingInputFile_h
3 
8 #include "canvas/Persistency/Provenance/Compatibility/BranchIDList.h"
19 #include "cetlib/exempt_ptr.h"
21 
22 #include "TFile.h"
23 #include "TTree.h"
24 
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 namespace art {
31  class BranchChildren;
32  class GroupSelectorRules;
33  class MasterProductRegistry;
34  class ModuleDescription;
35  struct ProcessConfiguration;
36 
37  namespace detail {
38 
40  public:
41  using EntriesForID_t = std::map<EventID, input::EntryNumbers>;
42  using InstanceForID_t = std::map<SubRunID, std::unique_ptr<EDProduct>>;
43  using ProductsForKey_t = std::map<BranchKey, InstanceForID_t>;
44 
45  explicit SamplingInputFile(std::string const& dataset,
46  std::string const& filename,
47  double weight,
48  double probability,
49  EventID const& firstEvent,
50  GroupSelectorRules const& groupSelectorRules,
51  bool dropDescendants,
52  unsigned int treeCacheSize,
53  int64_t treeMaxVirtualSize,
54  int64_t saveMemoryObjectThreshold,
55  BranchDescription const& sampledEventInfoDesc,
56  bool compactRangeSets,
57  std::map<BranchKey, BranchDescription>&
58  oldKeyToSampledProductDescription,
59  ModuleDescription const& moduleDescription,
60  bool readIncomingParameterSets,
62 
63  EventID nextEvent() const;
64  bool readyForNextEvent();
65 
68 
69  template <typename T>
71 
72  std::unique_ptr<EventPrincipal> readEvent(
73  EventID const& eventID,
74  ProcessConfigurations const& sampled_pcs,
75  ProcessConfiguration const& current_pc);
76 
77  private:
78  void dropOnInput_(GroupSelectorRules const& rules,
79  BranchChildren const& children,
80  bool dropDescendants,
81  ProductList& productList);
83  input::EntryNumber& entry) const;
84  TTree* treeForBranchType_(BranchType bt) const;
87 
89  std::unique_ptr<TFile> file_;
90  double const weight_;
91  double const probability_;
93  cet::sqlite::Connection sqliteDB_{}; // Start with invalid connection.
100  TTree* runTree_{nullptr};
101  TTree* subRunTree_{nullptr};
102  TTree* eventTree_{nullptr};
103  TTree* eventMetaTree_{nullptr};
104  TBranch* auxBranch_{nullptr};
105  TBranch* productProvenanceBranch_{nullptr};
106  TTree* eventHistoryTree_{nullptr};
112  std::unique_ptr<BranchIDLists> branchIDLists_{
113  nullptr}; // Only used for maintaining backwards compatibility
114  };
115 
116  template <typename T>
117  T id_for(EventID const& id);
118 
119  template <>
120  inline RunID
122  {
123  return id.runID();
124  }
125 
126  template <>
127  inline SubRunID
129  {
130  return id.subRunID();
131  }
132 
133  template <typename T>
136  {
137  // We use a set because it is okay for multiple entries of the
138  // same (sub)run to be present in the FileIndex--these correspond
139  // to (sub)run fragments. However, we do not want these to appear
140  // as separate entries in the SampledInfo object.
141  std::set<T> ids;
142  for (auto const& pr : entries) {
143  auto const& invalid_event_id = pr.first;
144  ids.insert(id_for<T>(invalid_event_id));
145  }
146 
147  return SampledInfo<T>{
148  weight_, probability_, std::vector<T>(cbegin(ids), cend(ids))};
149  }
150 
151  }
152 }
153 
154 #endif /* art_Framework_Modules_detail_SamplingInputFile_h */
155 
156 // Local Variables:
157 // mode: c++
158 // End:
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
bool updateEventEntry_(FileIndex::const_iterator &iter, input::EntryNumber &entry) const
TTree * treeForBranchType_(BranchType bt) const
EventAuxiliary auxiliaryForEntry_(input::EntryNumber entry)
const_iterator cbegin() const
Definition: FileIndex.h:107
const Var weight
SampledInfo< T > sampledInfoFor(EntriesForID_t const &entries)
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductList.h:15
Int_t eventID
Definition: plot.C:81
string filename
Definition: shutoffs.py:106
T id_for(EventID const &id)
std::map< EventID, input::EntryNumbers > EntriesForID_t
cet::sqlite::Connection sqliteDB_
FileIndex::const_iterator fiEnd_
FileIndex::const_iterator fiIter_
std::unique_ptr< BranchIDLists > branchIDLists_
History historyForEntry_(input::EntryNumber entry)
std::unique_ptr< TFile > file_
SubRunID id_for< SubRunID >(EventID const &id)
RunID id_for< RunID >(EventID const &id)
std::map< SubRunID, std::unique_ptr< EDProduct >> InstanceForID_t
EntriesForID_t treeEntries(BranchType)
const_iterator cend() const
Definition: FileIndex.h:123
std::map< BranchKey const, BranchInfo > BranchMap
Definition: Inputfwd.h:46
FileFormatVersion fileFormatVersion_
SamplingInputFile(std::string const &dataset, std::string const &filename, double weight, double probability, EventID const &firstEvent, GroupSelectorRules const &groupSelectorRules, bool dropDescendants, unsigned int treeCacheSize, int64_t treeMaxVirtualSize, int64_t saveMemoryObjectThreshold, BranchDescription const &sampledEventInfoDesc, bool compactRangeSets, std::map< BranchKey, BranchDescription > &oldKeyToSampledProductDescription, ModuleDescription const &moduleDescription, bool readIncomingParameterSets, MasterProductRegistry &mpr)
Long64_t EntryNumber
Definition: Inputfwd.h:47
input::EntryNumber currentEventEntry_
std::vector< ProcessConfiguration > ProcessConfigurations
void dropOnInput_(GroupSelectorRules const &rules, BranchChildren const &children, bool dropDescendants, ProductList &productList)
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:76
BranchType
Definition: BranchType.h:18
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
double T
Definition: Xdiff_gwt.C:5
std::unique_ptr< EventPrincipal > readEvent(EventID const &eventID, ProcessConfigurations const &sampled_pcs, ProcessConfiguration const &current_pc)
def entry(str)
Definition: HTMLTools.py:26
ProductsForKey_t productsFor(EntriesForID_t const &entries, BranchType)
std::map< BranchKey, InstanceForID_t > ProductsForKey_t
BranchDescription const & sampledEventInfoDesc_
enum BeamMode string