26 #include "TBranchElement.h" 27 #include "TObjArray.h" 33 #include "boost/algorithm/string.hpp" 40 rootServiceChecker_(),
42 selectedOutputItemList_(),
43 fileName_(pset.getUntrackedParameter<
std::
string>(
"fileName")),
44 logicalFileName_(pset.getUntrackedParameter<
std::
string>(
"logicalFileName")),
45 catalog_(pset.getUntrackedParameter<
std::
string>(
"catalog")),
46 maxFileSize_(pset.getUntrackedParameter<
int>(
"maxSize")),
47 compressionLevel_(pset.getUntrackedParameter<
int>(
"compressionLevel")),
48 compressionAlgorithm_(pset.getUntrackedParameter<
std::
string>(
"compressionAlgorithm")),
49 basketSize_(pset.getUntrackedParameter<
int>(
"basketSize")),
50 eventAutoFlushSize_(pset.getUntrackedParameter<
int>(
"eventAutoFlushCompressedSize")),
51 splitLevel_(
std::
min<
int>(pset.getUntrackedParameter<
int>(
"splitLevel") + 1, 99)),
52 basketOrder_(pset.getUntrackedParameter<
std::
string>(
"sortBaskets")),
53 treeMaxVirtualSize_(pset.getUntrackedParameter<
int>(
"treeMaxVirtualSize")),
54 whyNotFastClonable_(pset.getUntrackedParameter<bool>(
"fastCloning") ?
FileBlock::CanFastClone :
FileBlock::DisabledInConfigFile),
55 dropMetaData_(DropNone),
56 moduleLabel_(pset.getParameter<
std::
string>(
"@module_label")),
57 initializedFromInput_(
false),
61 numberOfDigitsInIndex_(0
U),
64 overrideInputFileSplitLevels_(pset.getUntrackedParameter<bool>(
"overrideInputFileSplitLevels")),
69 std::ostringstream statusfilename;
82 << dropMetaData <<
".\n" 83 <<
"Legal values are 'NONE', 'DROPPED', 'PRIOR', and 'ALL'.\n";
93 for(
auto const&
s: specialSplit) {
95 s.getUntrackedParameter<
int>(
"splitLevel"));
106 for(
auto const&
prod : reg->productList()) {
122 branchDescription_(0),
138 if(tree !=
nullptr) {
139 TObjArray* branches = tree->GetListOfBranches();
140 for(
int i = 0;
i < branches->GetEntries(); ++
i) {
141 TBranchElement*
br = (TBranchElement*)branches->At(
i);
151 if(
treeMap_->empty())
return lh < rh;
154 std::map<std::string, int>::const_iterator lit =
treeMap_->find(lstring);
155 std::map<std::string, int>::const_iterator rit =
treeMap_->find(rstring);
156 bool lfound = (lit !=
treeMap_->end());
157 bool rfound = (rit !=
treeMap_->end());
158 if(lfound && rfound) {
159 return lit->second < rit->second;
169 return std::regex_match(iBranchName,branch_);
174 boost::replace_all(tmp,
"*",
".*");
175 boost::replace_all(tmp,
"?",
".");
176 return std::regex(tmp);
198 for(
auto const& kept : keptVector) {
205 if(theBranch !=
nullptr) {
206 splitLevel = theBranch->GetSplitLevel();
207 basketSize = theBranch->GetBasketSize();
212 splitLevel =
b.splitLevel_;
217 outputItemList.emplace_back(&prod, kept.second, splitLevel, basketSize);
230 for (
auto const& parentToChildren : branchToChildMap) {
231 for (
auto const&
child : parentToChildren.second) {
250 TTree* theInputTree = (branchType ==
InEvent ? fb.
tree() :
267 while (iNumberOfChildren != 0) {
269 iNumberOfChildren /= 10;
284 statusFile << e.
id() <<
" time: " << std::setprecision(3) <<
TimeOfDay() <<
'\n';
336 std::pair<std::string, std::string>
340 <<
"Attempt to open output file before input file. " 341 <<
"Please report this to the core framework developers.\n";
345 bool ext = (offset ==
fileName().size() - suffix.size());
346 if(!ext) suffix.clear();
348 std::ostringstream ofilename;
349 std::ostringstream lfilename;
350 ofilename << fileBase;
367 return std::make_pair(ofilename.str(), lfilename.str());
381 if (provenance !=
nullptr) {
385 std::set<ParentageID>())).first;
409 auto const* ep =
dynamic_cast<EventPrincipal const*
>(&iPrincipal);
424 std::set<ParentageID>
const& eIds = branchParent.second;
425 for(
auto const& eId : eIds) {
429 for(
auto const&
parent : parents) {
440 desc.
setComment(
"Writes runs, lumis, and events into EDM/ROOT files.");
442 ->setComment(
"Name of output file.");
444 ->setComment(
"Passed to job report. Otherwise unused by module.");
446 ->setComment(
"Passed to job report. Otherwise unused by module.");
448 ->setComment(
"Maximum output file size, in kB.\n" 449 "If over maximum, new output file will be started at next input file transition.");
451 ->setComment(
"ROOT compression level of output file.");
453 ->setComment(
"Algorithm used to compress data in the ROOT output file, allowed values are ZLIB and LZMA");
455 ->setComment(
"Default ROOT basket size in output file.");
456 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.");
458 ->setComment(
"Default ROOT branch split level in output file.");
460 ->setComment(
"Legal values: 'sortbasketsbyoffset', 'sortbasketsbybranch', 'sortbasketsbyentry'.\n" 461 "Used by ROOT when fast copying. Affects performance.");
463 ->setComment(
"Size of ROOT TTree TBasket cache. Affects performance.");
465 ->setComment(
"True: Allow fast copying, if possible.\n" 466 "False: Disable fast copying.");
467 desc.
addUntracked<
bool>(
"overrideInputFileSplitLevels",
false)
468 ->setComment(
"False: Use branch split levels and basket sizes from input file, if possible.\n" 469 "True: Always use specified or default split levels and basket sizes.");
471 ->setComment(
"Write a status file. Intended for use by workflow management.");
473 ->setComment(
"Determines handling of per product per event metadata. Options are:\n" 474 "'NONE': Keep all of it.\n" 475 "'DROPPED': Keep it for products produced in current process and all kept products. Drop it for dropped products produced in prior processes.\n" 476 "'PRIOR': Keep it for products produced in current process. Drop it for products produced in prior processes.\n" 477 "'ALL': Drop all of it.");
482 ->setComment(
"PSet is only used by Data Operations and not by this module.");
486 specialSplit.
addUntracked<
std::string>(
"branch")->setComment(
"Name of branch needing a special split level. The name can contain wildcards '*' and '?'");
487 specialSplit.
addUntracked<
int>(
"splitLevel")->setComment(
"The special split level for the branch");
488 desc.
addVPSetUntracked(
"overrideBranchesSplitLevel",specialSplit, std::vector<ParameterSet>());
497 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
virtual bool shouldWeCloseFile() const override
allow inheriting classes to override but still be able to call this method in the overridden version ...
std::string const & branchName() const
SubProcessParentageHelper const * subProcessParentageHelper() const
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
BranchDescription const * branchDescription_
int const & basketSize() const
EventID const & id() const
bool wantAllEvents() const
BranchType const & branchType() 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
std::vector< SpecialSplitLevelForBranch > specialSplitLevelForBranches_
static int const invalidBasketSize
void updateBranchParents(EventForOutput const &e)
DropMetaData const & dropMetaData() const
BranchChildren branchChildren_
std::vector< OutputItem > OutputItemList
std::string const & fileName() const
bool initializedFromInput_
void insertChild(BranchID parent, BranchID child)
BranchChildren const & branchChildren() const
std::string const moduleLabel_
BranchID branchID() const
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
std::regex convert(std::string const &iGlobBranchExpression) const
PoolOutputModule(ParameterSet const &ps)
int remainingEvents() const
void setComment(std::string const &value)
void updateBranchParentsForOneBranch(ProductProvenanceRetriever const *provRetriever, BranchID const &branchID)
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_
map_t const & childLookup() const
std::vector< BranchID > producedBranches_
virtual void preActionBeforeRunEventAsync(WaitingTask *iTask, ModuleCallingContext const &iModuleCallingContext, Principal const &iPrincipal) const override
void readProvenanceAsync(WaitingTask *task, ModuleCallingContext const *moduleCallingContext) const
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_
ProductProvenanceRetriever const * productProvenanceRetrieverPtr() const
void writeIndexIntoFile()
unsigned int numberOfDigitsInIndex_
void writeThinnedAssociationsHelper()
virtual void writeRun(RunForOutput const &r) override
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
virtual bool isFileOpen() const override
void writeBranchIDListRegistry()
void writeProcessHistoryRegistry()
void fillDependencyGraph()
virtual void respondToCloseInputFile(FileBlock const &fb) override
DropMetaData dropMetaData_
virtual void beginJob() override
virtual void reallyCloseFile() override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ProductProvenance const * branchIDToProvenanceForProducedOnly(BranchID const &bid) const
void writeFileIdentifier()
ParentageID const & parentageID() const
virtual ~PoolOutputModule()
std::vector< std::vector< double > > tmp
virtual void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) override
std::shared_ptr< std::map< std::string, int > > treeMap_
VParameterSet getUntrackedParameterSetVector(std::string const &name, VParameterSet const &defaultValue) const
std::string statusFileName_
void beginInputFile(FileBlock const &fb)
void writeProductDescriptionRegistry()
virtual void respondToOpenInputFile(FileBlock const &fb) override
static void fillDescriptions(ConfigurationDescriptions &descriptions)
bool match(std::string const &iBranchName) const
static void fillDescription(ParameterSetDescription &desc)
static ParentageRegistry * instance()
ParameterDescriptionBase * addVPSetUntracked(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
def branchType(schema, name)
virtual void writeLuminosityBlock(LuminosityBlockForOutput const &lb) override