21 #include "TBranchElement.h"
22 #include "TObjArray.h"
33 rootServiceChecker_(),
35 selectedOutputItemList_(),
36 fileName_(pset.getUntrackedParameter<std::
string>(
"fileName")),
37 logicalFileName_(pset.getUntrackedParameter<std::
string>(
"logicalFileName")),
38 catalog_(pset.getUntrackedParameter<std::
string>(
"catalog")),
39 maxFileSize_(pset.getUntrackedParameter<int>(
"maxSize")),
40 compressionLevel_(pset.getUntrackedParameter<int>(
"compressionLevel")),
41 compressionAlgorithm_(pset.getUntrackedParameter<std::
string>(
"compressionAlgorithm")),
42 basketSize_(pset.getUntrackedParameter<int>(
"basketSize")),
43 eventAutoFlushSize_(pset.getUntrackedParameter<int>(
"eventAutoFlushCompressedSize")),
44 splitLevel_(std::
min<int>(pset.getUntrackedParameter<int>(
"splitLevel") + 1, 99)),
45 basketOrder_(pset.getUntrackedParameter<std::
string>(
"sortBaskets")),
46 treeMaxVirtualSize_(pset.getUntrackedParameter<int>(
"treeMaxVirtualSize")),
47 whyNotFastClonable_(pset.getUntrackedParameter<bool>(
"fastCloning") ?
FileBlock::CanFastClone :
FileBlock::DisabledInConfigFile),
48 dropMetaData_(DropNone),
50 initializedFromInput_(
false),
54 numberOfDigitsInIndex_(0U),
57 overrideInputFileSplitLevels_(pset.getUntrackedParameter<bool>(
"overrideInputFileSplitLevels")),
62 std::ostringstream statusfilename;
75 << dropMetaData <<
".\n"
76 <<
"Legal values are 'NONE', 'DROPPED', 'PRIOR', and 'ALL'.\n";
100 branchDescription_(0),
107 branchDescription_(bd),
116 if(tree !=
nullptr) {
117 TObjArray* branches = tree->GetListOfBranches();
118 for(
int i = 0;
i < branches->GetEntries(); ++
i) {
119 TBranchElement*
br = (TBranchElement*)branches->At(
i);
129 if(treeMap_->empty())
return lh < rh;
132 std::map<std::string, int>::const_iterator lit = treeMap_->find(lstring);
133 std::map<std::string, int>::const_iterator rit = treeMap_->find(rstring);
134 bool lfound = (lit != treeMap_->end());
135 bool rfound = (rit != treeMap_->end());
136 if(lfound && rfound) {
137 return lit->second < rit->second;
165 for(
auto const& kept : keptVector) {
172 if(theBranch !=
nullptr) {
173 splitLevel = theBranch->GetSplitLevel();
174 basketSize = theBranch->GetBasketSize();
179 outputItemList.emplace_back(&prod, kept.second, splitLevel, basketSize);
204 TTree* theInputTree = (branchType ==
InEvent ? fb.
tree() :
221 while (iNumberOfChildren != 0) {
223 iNumberOfChildren /= 10;
238 statusFile << e.
id() <<
" time: " << std::setprecision(3) <<
TimeOfDay() <<
'\n';
290 std::pair<std::string, std::string>
294 <<
"Attempt to open output file before input file. "
295 <<
"Please report this to the core framework developers.\n";
299 bool ext = (offset ==
fileName().size() - suffix.size());
300 if(!ext) suffix.clear();
302 std::ostringstream ofilename;
303 std::ostringstream lfilename;
304 ofilename << fileBase;
321 return std::make_pair(ofilename.str(), lfilename.str());
333 for(
auto const& product : products) {
337 if(provenance !=
nullptr) {
340 it =
branchParents_.insert(std::make_pair(bid, std::set<ParentageID>())).first;
352 std::set<ParentageID>
const& eIds = branchParent.second;
353 for(
auto const& eId : eIds) {
357 for(
auto const&
parent : parents) {
368 desc.
setComment(
"Writes runs, lumis, and events into EDM/ROOT files.");
370 ->setComment(
"Name of output file.");
372 ->setComment(
"Passed to job report. Otherwise unused by module.");
374 ->setComment(
"Passed to job report. Otherwise unused by module.");
376 ->setComment(
"Maximum output file size, in kB.\n"
377 "If over maximum, new output file will be started at next input file transition.");
379 ->setComment(
"ROOT compression level of output file.");
381 ->setComment(
"Algorithm used to compress data in the ROOT output file, allowed values are ZLIB and LZMA");
383 ->setComment(
"Default ROOT basket size in output file.");
384 desc.
addUntracked<
int>(
"eventAutoFlushCompressedSize",-1)->setComment(
"Set ROOT auto flush stored data size (in bytes) for event TTree. The value sets how large the compressed buffer is allowed to get. The uncompressed buffer can be quite a bit larger than this depending on the average compression ratio. The value of -1 just uses ROOT's default value. The value of 0 turns off this feature.");
386 ->setComment(
"Default ROOT branch split level in output file.");
388 ->setComment(
"Legal values: 'sortbasketsbyoffset', 'sortbasketsbybranch', 'sortbasketsbyentry'.\n"
389 "Used by ROOT when fast copying. Affects performance.");
391 ->setComment(
"Size of ROOT TTree TBasket cache. Affects performance.");
393 ->setComment(
"True: Allow fast copying, if possible.\n"
394 "False: Disable fast copying.");
395 desc.
addUntracked<
bool>(
"overrideInputFileSplitLevels",
false)
396 ->setComment(
"False: Use branch split levels and basket sizes from input file, if possible.\n"
397 "True: Always use specified or default split levels and basket sizes.");
399 ->setComment(
"Write a status file. Intended for use by workflow management.");
401 ->setComment(
"Determines handling of per product per event metadata. Options are:\n"
402 "'NONE': Keep all of it.\n"
403 "'DROPPED': Keep it for products produced in current process and all kept products. Drop it for dropped products produced in prior processes.\n"
404 "'PRIOR': Keep it for products produced in current process. Drop it for products produced in prior processes.\n"
405 "'ALL': Drop all of it.");
409 ->setComment(
"PSet is only used by Data Operations and not by this module.");
418 descriptions.
add(
"edmOutput", desc);
void writeParentageRegistry()
virtual void openFile(FileBlock const &fb) override
virtual std::pair< std::string, std::string > physicalAndLogicalNameForNewFile()
T getUntrackedParameter(std::string const &, T const &) const
std::string const & branchName() const
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
BranchDescription const * branchDescription_
int const & basketSize() const
EventID const & id() const
bool wantAllEvents() const
virtual void write(EventForOutput const &e) override
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static const HistoName names[]
edm::propagate_const< std::unique_ptr< RootOutputFile > > rootOutputFile_
static int const invalidSplitLevel
void setAllowAnything()
allow any parameter label/value pairs
static int const invalidBasketSize
void updateBranchParents(EventForOutput const &e)
DropMetaData const & dropMetaData() const
BranchChildren branchChildren_
std::vector< OutputItem > OutputItemList
std::string const & fileName() const
void insertEmpty(BranchID parent)
bool initializedFromInput_
void insertChild(BranchID parent, BranchID child)
std::string const moduleLabel_
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
virtual void doExtrasAfterCloseFile()
std::string const & logicalFileName() const
void writeParameterSetRegistry()
std::vector< std::pair< BranchDescription const *, EDGetToken > > SelectedProducts
void fillSelectedItemList(BranchType branchtype, TTree *theInputTree)
std::vector< BranchID > const & parents() const
PoolOutputModule(ParameterSet const &ps)
int remainingEvents() const
void setComment(std::string const &value)
bool overrideInputFileSplitLevels_
bool operator()(OutputItem const &lh, OutputItem const &rh) const
std::string const & currentFileName() const
bool getMapped(key_type const &k, value_type &result) const
void writeFileFormatVersion()
OutputItemListArray selectedOutputItemList_
ESProducts< T, S > products(const T &i1, const S &i2)
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
ProductProvenanceRetriever const * productProvenanceRetrieverPtr() const
SelectedProductsForBranchType const & keptProducts() const
int const & splitLevel() const
BranchID const & branchID() const
EventID const & min(EventID const &lh, EventID const &rh)
void writeProductDependencies()
virtual void reallyOpenFile() override
BranchParents branchParents_
void writeIndexIntoFile()
unsigned int numberOfDigitsInIndex_
void writeThinnedAssociationsHelper()
virtual void writeRun(RunForOutput const &r) override
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
void writeBranchIDListRegistry()
void writeProcessHistoryRegistry()
void fillDependencyGraph()
virtual bool shouldWeCloseFile() const override
allow inheriting classes to override but still be able to call this method in the overridden version ...
virtual void respondToCloseInputFile(FileBlock const &fb) override
DropMetaData dropMetaData_
virtual bool isFileOpen() const override
virtual void beginJob() override
virtual void reallyCloseFile() override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void writeFileIdentifier()
ParentageID const & parentageID() const
virtual ~PoolOutputModule()
virtual void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) override
std::shared_ptr< std::map< std::string, int > > treeMap_
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
std::string statusFileName_
void beginInputFile(FileBlock const &fb)
void writeProductDescriptionRegistry()
volatile std::atomic< bool > shutdown_flag false
virtual void respondToOpenInputFile(FileBlock const &fb) override
static void fillDescriptions(ConfigurationDescriptions &descriptions)
static void fillDescription(ParameterSetDescription &desc)
static ParentageRegistry * instance()
virtual void writeLuminosityBlock(LuminosityBlockForOutput const &lb) override