LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
RootOutputFile.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_RootOutputFile_h
2 #define art_Framework_IO_Root_RootOutputFile_h
3 // vim: set sw=2:
4 
14 #include "boost/filesystem.hpp"
22 #include "cetlib/sqlite/Connection.h"
23 
24 #include <array>
25 #include <map>
26 #include <memory>
27 #include <set>
28 #include <string>
29 #include <vector>
30 
31 #include "TFile.h"
32 #include "TROOT.h"
33 
34 class TTree;
35 
36 namespace art {
37  class RootOutputFile;
38 
39  class ResultsPrincipal;
40  class RootOutput;
41  class History;
42  class FileBlock;
43  class EventAuxiliary;
44  class SubRunAuxiliary;
45  class RunAuxiliary;
46  class ResultsAuxiliary;
47  class RootFileBlock;
48 }
49 
51 public: // TYPES
54  std::array<std::unique_ptr<RootOutputTree>, NumBranchTypes>;
55 
56  struct OutputItem {
57 
58  BranchDescription const* branchDescription_{nullptr};
59  mutable void const* product_{nullptr};
60 
61  explicit OutputItem(BranchDescription const* pd) : branchDescription_{pd} {}
62 
63  std::string const&
64  branchName() const
65  {
66  return branchDescription_->branchName();
67  }
68 
69  bool
70  operator<(OutputItem const& rh) const
71  {
72  return *branchDescription_ < *rh.branchDescription_;
73  }
74  };
75 
76  using OutputItemList = std::set<OutputItem>;
77  using OutputItemListArray = std::array<OutputItemList, NumBranchTypes>;
78 
79 public: // MEMBER FUNCTIONS
80  explicit RootOutputFile(OutputModule*,
81  std::string const& fileName,
82  ClosingCriteria const& fileSwitchCriteria,
83  int const compressionLevel,
84  int64_t const saveMemoryObjectThreshold,
85  int64_t const treeMaxVirtualSize,
86  int const splitLevel,
87  int const basketSize,
88  DropMetaData dropMetaData,
89  bool dropMetaDataForDroppedData,
90  bool fastCloningRequested);
91 
92  void writeTTrees();
93 
94  void writeOne(EventPrincipal const&);
95  void writeSubRun(SubRunPrincipal const&);
96  void writeRun(RunPrincipal const&);
98  void writeFileIndex();
99  void writeEventHistory();
104  void writeParentageRegistry();
109  void writeResults(ResultsPrincipal& resp);
110  void setRunAuxiliaryRangeSetID(RangeSet const&);
112  void beginInputFile(RootFileBlock const*, bool fastClone);
114  void respondToCloseInputFile(FileBlock const&);
115  bool requestsToCloseFile();
116  void
118  {
119  status_ = ofs;
120  }
121 
122  void selectProducts();
123 
124  std::string const&
126  {
127  return file_;
128  }
129 
131  FileIndex::EntryNumber_t const maxEventsPerFile) const;
132  bool maxSizeReached(unsigned const maxFileSize) const;
133 
134 private: // MEMBER FUNCTIONS
135  void createDatabaseTables();
136 
137  template <BranchType>
138  void fillBranches(Principal const&,
139  std::vector<ProductProvenance>*); // Defined in source.
140 
141  template <BranchType BT>
143  art::EDProduct const*>
144  getProduct(OutputHandle const&,
145  RangeSet const& productRS,
146  std::string const& wrappedName); // Defined in source.
147 
148  template <BranchType BT>
150  getProduct(OutputHandle const&,
151  RangeSet const& productRS,
152  std::string const& wrappedName); // Defined in source.
153 
154 private: // MEMBER DATA
156  std::string file_;
159  int const compressionLevel_;
161  int64_t const treeMaxVirtualSize_;
162  int const splitLevel_;
163  int const basketSize_;
167  bool wasFastCloned_{false};
168  std::unique_ptr<TFile> filePtr_; // File closed when d'tor called
171  TTree* metaDataTree_{nullptr};
172  TTree* fileIndexTree_{nullptr};
173  TTree* parentageTree_{nullptr};
174  TTree* eventHistoryTree_{nullptr};
175  EventAuxiliary const* pEventAux_{nullptr};
176  SubRunAuxiliary const* pSubRunAux_{nullptr};
177  RunAuxiliary const* pRunAux_{nullptr};
191  History const* pHistory_{nullptr};
193  bool dataTypeReported_{false};
194  std::set<ProductID> branchesWithStoredHistory_{};
195  cet::sqlite::Connection rootFileDB_; // Connection closed when d'tor
196  // called. DB written to file
197  // when sqlite3_close is
198  // called.
199  OutputItemListArray selectedOutputItemList_{{}}; // filled by aggregation
201  unsigned subRunRSID_{-1u};
202  unsigned runRSID_{-1u};
203  std::chrono::steady_clock::time_point beginTime_{
204  std::chrono::steady_clock::now()};
205 };
206 
207 // Local Variables:
208 // mode: c++
209 // End:
210 #endif /* art_Framework_IO_Root_RootOutputFile_h */
SubRunAuxiliary const * pSubRunAux_
EventAuxiliary const * pEventAux_
std::set< ProductID > branchesWithStoredHistory_
std::vector< std::pair< std::string, std::string >> collection_type
void setFileStatus(OutputFileStatus const ofs)
int const compressionLevel_
cet::sqlite::Connection rootFileDB_
bool fastCloningEnabledAtConstruction_
RootOutputFile(OutputModule *, std::string const &fileName, ClosingCriteria const &fileSwitchCriteria, int const compressionLevel, int64_t const saveMemoryObjectThreshold, int64_t const treeMaxVirtualSize, int const splitLevel, int const basketSize, DropMetaData dropMetaData, bool dropMetaDataForDroppedData, bool fastCloningRequested)
std::enable_if_t<!detail::RangeSetsSupported< BT >::value, art::EDProduct const * > getProduct(OutputHandle const &, RangeSet const &productRS, std::string const &wrappedName)
ProductProvenances * pRunProductProvenanceVector_
int64_t const treeMaxVirtualSize_
ProductProvenances resultsProductProvenanceVector_
std::chrono::steady_clock::time_point beginTime_
std::unique_ptr< TFile > filePtr_
void beginInputFile(RootFileBlock const *, bool fastClone)
DropMetaData dropMetaData_
ProductProvenances runProductProvenanceVector_
BranchDescription const * branchDescription_
void writeOne(EventPrincipal const &)
long long EntryNumber_t
Definition: FileIndex.h:43
void setRunAuxiliaryRangeSetID(RangeSet const &)
ProductProvenances eventProductProvenanceVector_
ProductProvenances * pResultsProductProvenanceVector_
void writeFileCatalogMetadata(FileStatsCollector const &stats, FileCatalogMetadata::collection_type const &, FileCatalogMetadata::collection_type const &)
OutputFileStatus status_
void setSubRunAuxiliaryRangeSetID(RangeSet const &)
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.h:44
ProductProvenances subRunProductProvenanceVector_
OutputFileStatus
FileProperties fp_
void writeSubRun(SubRunPrincipal const &)
detail::DummyProductCache dummyProductCache_
std::array< OutputItemList, NumBranchTypes > OutputItemListArray
void writeResults(ResultsPrincipal &resp)
RootOutputTreePtrArray treePointers_
void respondToCloseInputFile(FileBlock const &)
std::string const & branchName() const
ProductProvenances * pEventProductProvenanceVector_
bool maxSizeReached(unsigned const maxFileSize) const
void writeProductDescriptionRegistry()
std::string const & currentFileName() const
OutputItem(BranchDescription const *pd)
std::string value(boost::any const &)
bool maxEventsPerFileReached(FileIndex::EntryNumber_t const maxEventsPerFile) const
void writeProcessConfigurationRegistry()
OutputModule const * om_
int64_t const saveMemoryObjectThreshold_
void writeRun(RunPrincipal const &)
std::array< std::unique_ptr< RootOutputTree >, NumBranchTypes > RootOutputTreePtrArray
void writeProcessHistoryRegistry()
std::vector< ProductProvenance > ProductProvenances
HLT enums.
std::set< OutputItem > OutputItemList
ResultsAuxiliary const * pResultsAux_
ProductProvenances * pSubRunProductProvenanceVector_
RunAuxiliary const * pRunAux_
OutputItemListArray selectedOutputItemList_
History const * pHistory_
ClosingCriteria fileSwitchCriteria_
void fillBranches(Principal const &, std::vector< ProductProvenance > *)