1 #ifndef artdaq_ArtModules_RootDAQOutFile_h
2 #define artdaq_ArtModules_RootDAQOutFile_h
13 #include "art/Framework/Core/Frameworkfwd.h"
14 #include "art/Framework/Core/OutputModule.h"
15 #include "art/Framework/IO/FileStatsCollector.h"
16 #include "art/Framework/IO/Root/DropMetaData.h"
17 #include "art/Framework/IO/Root/RootOutputClosingCriteria.h"
18 #include "art/Framework/IO/Root/RootOutputTree.h"
19 #include "artdaq/ArtModules/RootDAQOutput/detail/DummyProductCache.h"
20 #include "art/Framework/Principal/RangeSetsSupported.h"
21 #if ART_HEX_VERSION >= 0x20703
22 # include "art/Persistency/Provenance/Selections.h"
23 # include "boost/filesystem.hpp"
24 # include "cetlib/sqlite/Connection.h"
26 # include "art/Persistency/Provenance/Selections.h"
27 # include "boost/filesystem.hpp"
29 #include "canvas/Persistency/Provenance/BranchDescription.h"
30 #include "canvas/Persistency/Provenance/BranchID.h"
31 #include "canvas/Persistency/Provenance/BranchType.h"
32 #include "canvas/Persistency/Provenance/FileIndex.h"
33 #include "canvas/Persistency/Provenance/ParameterSetBlob.h"
34 #include "canvas/Persistency/Provenance/ParameterSetMap.h"
35 #include "canvas/Persistency/Provenance/ProductProvenance.h"
36 #include "art/Persistency/RootDB/SQLite3Wrapper.h"
50 class ResultsPrincipal;
57 class SubRunAuxiliary;
59 class ResultsAuxiliary;
72 using RootOutputTreePtrArray = std::array<std::unique_ptr<RootOutputTree>, NumBranchTypes>;
76 BranchDescription
const* branchDescription_ {
nullptr};
77 mutable void const* product_ {
nullptr};
82 explicit Sorter(TTree* tree);
88 std::map<std::string, int> treeMap_;
93 explicit OutputItem(BranchDescription
const* bd)
94 : branchDescription_{bd}
97 BranchID branchID()
const
99 return branchDescription_->branchID();
102 std::string
const& branchName()
const
104 return branchDescription_->branchName();
107 bool operator<(OutputItem
const& rh)
const
109 return *branchDescription_ < *rh.branchDescription_;
114 using OutputItemList = std::vector<OutputItem>;
116 using OutputItemListArray = std::array<OutputItemList, NumBranchTypes>;
120 explicit RootDAQOutFile(OutputModule*,
121 std::string
const& fileName,
122 ClosingCriteria
const& fileSwitchCriteria,
123 int const compressionLevel,
124 int64_t
const saveMemoryObjectThreshold,
125 int64_t
const treeMaxVirtualSize,
126 int const splitLevel,
127 int const basketSize,
128 DropMetaData dropMetaData,
129 bool dropMetaDataForDroppedData,
132 #if ART_HEX_VERSION >= 0x20703
135 void writeOne(EventPrincipal
const&);
136 void writeSubRun(SubRunPrincipal
const&);
137 void writeRun(RunPrincipal
const&);
138 void writeFileFormatVersion();
139 void writeFileIndex();
140 void writeEventHistory();
141 void writeProcessConfigurationRegistry();
142 void writeProcessHistoryRegistry();
143 void writeParameterSetRegistry();
144 void writeProductDescriptionRegistry();
145 void writeParentageRegistry();
146 void writeBranchIDListRegistry();
147 void writeProductDependencies();
148 void writeFileCatalogMetadata(FileStatsCollector
const& stats,
149 FileCatalogMetadata::collection_type
const&,
150 FileCatalogMetadata::collection_type
const&);
151 void writeResults(ResultsPrincipal & resp);
152 void setRunAuxiliaryRangeSetID(RangeSet
const&);
153 void setSubRunAuxiliaryRangeSetID(RangeSet
const&);
154 void finishEndFile();
155 void beginInputFile(FileBlock
const&,
bool fastClone);
156 void incrementInputFileNumber();
157 void respondToCloseInputFile(FileBlock
const&);
158 bool requestsToCloseFile();
159 void setFileStatus(OutputFileStatus
const ofs) { status_ = ofs; }
161 void selectProducts(FileBlock
const&);
163 std::string
const& currentFileName()
const {
return file_; }
165 bool maxEventsPerFileReached(FileIndex::EntryNumber_t
const maxEventsPerFile)
const;
166 bool maxSizeReached(
unsigned const maxFileSize)
const;
170 void createDatabaseTables();
172 template <BranchType>
173 void fillBranches(Principal
const&,
174 std::vector<ProductProvenance>*);
176 template <BranchType BT>
177 std::enable_if_t<!detail::RangeSetsSupported<BT>::value, art::EDProduct
const*>
178 getProduct(OutputHandle
const&,
179 RangeSet
const& productRS,
180 std::string
const& wrappedName);
182 template <BranchType BT>
183 std::enable_if_t<detail::RangeSetsSupported<BT>::value, art::EDProduct
const*>
184 getProduct(OutputHandle
const&,
185 RangeSet
const& productRS,
186 std::string
const& wrappedName);
190 OutputModule
const* om_;
192 ClosingCriteria fileSwitchCriteria_;
193 OutputFileStatus status_ {OutputFileStatus::Closed};
194 int const compressionLevel_;
195 int64_t
const saveMemoryObjectThreshold_;
196 int64_t
const treeMaxVirtualSize_;
197 int const splitLevel_;
198 int const basketSize_;
199 DropMetaData dropMetaData_;
200 bool dropMetaDataForDroppedData_;
202 bool currentlyFastCloning_ {
true};
203 std::unique_ptr<TFile> filePtr_;
204 FileIndex fileIndex_ {};
205 FileProperties fp_ {};
206 TTree* metaDataTree_ {
nullptr};
207 TTree* fileIndexTree_ {
nullptr};
208 TTree* parentageTree_ {
nullptr};
209 TTree* eventHistoryTree_ {
nullptr};
210 EventAuxiliary
const* pEventAux_ {
nullptr};
211 SubRunAuxiliary
const* pSubRunAux_ {
nullptr};
212 RunAuxiliary
const* pRunAux_ {
nullptr};
213 ResultsAuxiliary
const *pResultsAux_ {
nullptr};
214 ProductProvenances eventProductProvenanceVector_ {};
215 ProductProvenances subRunProductProvenanceVector_ {};
216 ProductProvenances runProductProvenanceVector_ {};
217 ProductProvenances resultsProductProvenanceVector_ {};
218 ProductProvenances* pEventProductProvenanceVector_ {&eventProductProvenanceVector_};
219 ProductProvenances* pSubRunProductProvenanceVector_ {&subRunProductProvenanceVector_};
220 ProductProvenances* pRunProductProvenanceVector_ {&runProductProvenanceVector_};
221 ProductProvenances* pResultsProductProvenanceVector_ {&resultsProductProvenanceVector_};
222 History
const* pHistory_ {
nullptr};
223 RootOutputTreePtrArray treePointers_;
224 bool dataTypeReported_ {
false};
225 std::set<BranchID> branchesWithStoredHistory_ {};
226 # if ART_HEX_VERSION >= 0x20703
227 cet::sqlite::Connection rootFileDB_;
229 SQLite3Wrapper rootFileDB_;
231 OutputItemListArray selectedOutputItemList_ {{}};
232 detail::DummyProductCache dummyProductCache_ {};
233 unsigned subRunRSID_ {-1u};
234 unsigned runRSID_ {-1u};
235 std::chrono::steady_clock::time_point beginTime_ {std::chrono::steady_clock::now()};
An output module which allows specifying the output filename exactly. Used for testing (file -> /dev/...
ClosureRequestMode
Possible modes for when to close a file