43 #include "Compression.h"
53 sorterForJobReportHash(BranchDescription
const*
lh, BranchDescription
const* rh) {
55 lh->fullClassName() < rh->fullClassName() ?
true :
56 lh->fullClassName() > rh->fullClassName() ?
false :
57 lh->moduleLabel() < rh->moduleLabel() ?
true :
58 lh->moduleLabel() > rh->moduleLabel() ?
false :
59 lh->productInstanceName() < rh->productInstanceName() ?
true :
60 lh->productInstanceName() > rh->productInstanceName() ?
false :
61 lh->processName() < rh->processName() ?
true :
66 openTFile(
char const*
name,
int compressionLevel) {
67 TFile*
file = TFile::Open(name,
"recreate",
"", compressionLevel);
69 if(e != std::exception_ptr()) {
71 std::rethrow_exception(e);
79 logicalFile_(logicalFileName),
82 whyNotFastClonable_(om_->whyNotFastClonable()),
83 canFastCloneAux_(
false),
84 filePtr_(openTFile(file_.c_str(), om_->compressionLevel())),
86 eventEntryNumber_(0LL),
87 lumiEntryNumber_(0LL),
98 eventEntryInfoVector_(),
99 pEventEntryInfoVector_(&eventEntryInfoVector_),
104 runTree_(filePtr(),
InRun, om_->
splitLevel(), om_->treeMaxVirtualSize()),
106 dataTypeReported_(
false),
107 processHistoryRegistry_(),
109 branchesWithStoredHistory_(),
110 wrapperBaseTClass_(TClass::GetClass(
"edm::WrapperBase")) {
112 filePtr_->SetCompressionAlgorithm(ROOT::kZLIB);
114 filePtr_->SetCompressionAlgorithm(ROOT::kLZMA);
117 <<
"Allowed compression algorithms are ZLIB and LZMA\n";
144 for(
auto const& item :
om_->selectedOutputItemList()[
branchType]) {
145 item.product_ =
nullptr;
152 item.branchDescription_->produced());
169 std::vector<std::string> branchNames;
170 std::vector<BranchDescription const*> branches;
171 branchNames.reserve(
om_->selectedOutputItemList()[
InEvent].size());
173 for(
auto const& item :
om_->selectedOutputItemList()[
InEvent]) {
174 branchNames.push_back(item.branchDescription_->branchName());
175 branches.push_back(item.branchDescription_);
178 sort_all(branches, sorterForJobReportHash);
180 std::ostringstream oss;
181 char const underscore =
'_';
182 for(
auto const& branch : branches) {
212 if ((whyNotFastClonable &
220 bool isWarning =
true;
222 message <<
"Fast copying of file " << ifileName <<
" to file " << ofileName <<
" is disabled because:\n";
224 message <<
"a SecondaryFileSequence was specified.\n";
229 message <<
"the input file is in an old format.\n";
234 message <<
"events need to be sorted.\n";
238 message <<
"a run or a lumi is not contiguous in the input file.\n";
242 message <<
"events or lumis were selected or skipped by ID.\n";
247 message <<
"initial events, lumis or runs were skipped.\n";
252 message <<
"some events were skipped because of duplicate checking.\n";
256 message <<
"some events were not copied because of maxEvents limit.\n";
261 message <<
"some events were not copied because of maxLumis limit.\n";
266 message <<
"parallel processing was specified.\n";
271 message <<
"an EventSelector was specified.\n";
276 message <<
"some events were not copied because of maxEvents output limit.\n";
281 message <<
"the split level or basket size of a branch or branches was modified.\n";
285 message <<
"The format of a data product has changed.\n";
290 LogWarning(
"FastCloningDisabled") << message.str();
292 LogInfo(
"FastCloningDisabled") << message.str();
303 if(fb.
tree() !=
nullptr) {
307 if(remainingEvents >= 0 && remainingEvents < fb.
tree()->GetEntries()) {
313 if(
om_->overrideInputFileSplitLevels()) {
324 "Merge failure because input file " <<
file_ <<
" has different ROOT split levels or basket sizes\n" <<
325 "than previous files. To allow merging in splite of this, use the configuration parameter\n" <<
326 "overrideInputFileSplitLevels=cms.untracked.bool(True)\n" <<
327 "in every PoolOutputModule.\n";
385 unsigned int const oneK = 1024;
387 return(size >=
om_->maxFileSize());
407 if (reg->anyProductProduced() || !
om_->wantAllEvents()) {
408 esids.push_back(
om_->selectorConfig());
479 &desc,
om_->basketSize(), 0))
481 <<
"Failed to create a branch for Parentages in the output file";
487 orderedIDs[parentageID.second] = parentageID.first;
490 for(
auto const& orderedID : orderedIDs) {
517 ex <<
"The number of entries in at least one output TBranch whose entries\n"
518 "were copied from the input does not match the number of events\n"
519 "recorded in IndexIntoFile. This might (or might not) indicate a\n"
520 "problem related to fast copy.";
521 ex.
addContext(
"Calling RootOutputFile::writeIndexIntoFile");
534 procHistoryVector.push_back(ph.second);
557 std::pair<ParameterSetID, ParameterSetBlob> idToBlob;
558 std::pair<ParameterSetID, ParameterSetBlob>* pIdToBlob = &idToBlob;
562 idToBlob.first =
pset.first;
563 idToBlob.second.pset() =
pset.second.toString();
574 ProductList& pList =
const_cast<ProductList &
>(pReg.productList());
575 for(
auto const&
prod : pList) {
576 if(
prod.second.branchID() !=
prod.second.originalBranchID()) {
583 for(ProductList::iterator it = pList.begin(); it != pList.end();) {
586 ProductList::iterator itCopy = it;
628 treePointer->close();
629 treePointer =
nullptr;
642 if(tree && tree->GetNbranches() != 0) {
649 tree->SetAlias(alias.c_str(), full.c_str());
652 tree->SetAlias(
alias.c_str(), full.c_str());
663 std::set<StoredProductProvenance>& oToFill,
670 for(
auto const& parentID : parentIDs) {
691 std::vector<std::unique_ptr<WrapperBase> > dummies;
697 std::set<StoredProductProvenance> provenanceToKeep;
700 for(
auto const& item : items) {
702 BranchID const&
id = item.branchDescription_->branchID();
705 bool produced = item.branchDescription_->produced();
706 bool keepProvenance = productProvenanceVecPtr !=
nullptr &&
710 bool getProd = (produced || !fastCloning ||
719 assert(eventPrincipal.productProvenanceRetrieverPtr());
724 if(product ==
nullptr) {
727 TClass*
cp = TClass::GetClass(item.branchDescription_->wrappedName().c_str());
731 product = dummy.get();
734 item.product_ = product;
738 if(productProvenanceVecPtr !=
nullptr) productProvenanceVecPtr->assign(provenanceToKeep.begin(), provenanceToKeep.end());
740 if(productProvenanceVecPtr !=
nullptr) productProvenanceVecPtr->clear();
745 std::set<edm::StoredProductProvenance>& oToInsert) {
748 std::set<edm::StoredProductProvenance>::iterator itFound = oToInsert.find(toStore);
749 if(itFound == oToInsert.end()) {
755 <<
"RootOutputFile::insertProductProvenance\n"
756 <<
"The parentage ID index value " << toStore.
parentageIDIndex_ <<
" is out of bounds. The maximum value is currently " <<
parentageIDs_.size()-1 <<
".\n"
757 <<
"This should never happen.\n"
758 <<
"Please report this to the framework hypernews forum 'hn-cms-edmFramework@cern.ch'.\n";
761 oToInsert.insert(toStore);
std::vector< ProcessHistory > ProcessHistoryVector
EventNumber_t event() const
void fillBranches(BranchType const &branchType, Principal const &principal, StoredProductProvenanceVector *productProvenanceVecPtr, ModuleCallingContext const *)
std::string const & idToParameterSetBlobsBranchName()
std::string const & branchName() const
void beginInputFile(FileBlock const &fb, int remainingEvents)
BranchID const & branchID() const
LuminosityBlockAuxiliary lumiAux_
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
WrapperBase const * wrapper() const
EventSelectionIDVector const & eventSelectionIDs() const
std::string const & parentageTreeName()
std::vector< BranchIDList > BranchIDLists
int eventAutoFlushSize() const
void writeProcessHistoryRegistry()
void writeRun(RunPrincipal const &r, ModuleCallingContext const *)
std::map< BranchKey, BranchDescription > ProductList
bool checkSplitLevelsAndBasketSizes(TTree *inputTree) const
bool registerProcessHistory(ProcessHistory const &processHistory)
void writeOne(EventPrincipal const &e, ModuleCallingContext const *)
EventID const & id() const
Provenance getProvenance(ProductID const &pid, ModuleCallingContext const *mcc) const
ProductProvenance const * productProvenance() const
int whyNotFastClonable() const
LuminosityBlockAuxiliary const & aux() const
std::string const & fileFormatVersionBranchName()
edm::propagate_const< TTree * > metaDataTree_
OutputItemListArray const & selectedOutputItemList() const
ProcessHistoryRegistry processHistoryRegistry_
std::string const & processName() const
std::string const & eventSelectionsBranchName()
void setAutoFlush(Long64_t size)
BranchListIndexes const & branchListIndexes() const
bool shouldWeCloseFile() const
bool checkIfFastClonable(TTree *inputTree) const
ProcessHistory const & processHistory() const
std::set< BranchID > branchesWithStoredHistory_
std::vector< EventSelectionID > EventSelectionIDVector
void sortVector_Run_Or_Lumi_Entries()
LuminosityBlockNumber_t luminosityBlock() const
std::string const & parameterSetsTreeName()
std::vector< BranchID > const & parents() const
void writeThinnedAssociationsHelper()
unsigned int parentageIDIndex_
std::map< ParentageID, unsigned int > parentageIDs_
RootOutputTree eventTree_
std::vector< BranchListIndex > BranchListIndexes
std::string moduleName(Provenance const &provenance)
bool getMapped(key_type const &k, value_type &result) const
void addBranch(std::string const &branchName, std::string const &className, void const *&pProd, int splitLevel, int basketSize, bool produced)
edm::propagate_const< PoolOutputModule * > om_
std::string const & moduleLabel() const
IndexIntoFile::EntryNumber_t eventEntryNumber_
std::string const & productInstanceName() const
ProcessHistoryID const & processHistoryID() const
void insertAncestors(ProductProvenance const &iGetParents, EventPrincipal const &principal, bool produced, std::set< StoredProductProvenance > &oToFill, ModuleCallingContext const *)
LuminosityBlockAuxiliary const * pLumiAux_
std::string const & indexIntoFileBranchName()
edm::propagate_const< std::shared_ptr< TFile > > filePtr_
int getFileFormatVersion()
bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) const
RunAuxiliary const & aux() const
ProcessHistoryID const & reducedProcessHistoryID(ProcessHistoryID const &fullID) const
void setProcessHistoryID(ProcessHistoryID const &phid)
std::string const & metaDataTreeName()
PoolOutputModule::OutputItemList OutputItemList
LuminosityBlockNumber_t luminosityBlock() const
void addEntry(ProcessHistoryID const &processHistoryID, RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry)
edm::propagate_const< TClass * > wrapperBaseTClass_
ProductProvenanceRetriever const * productProvenanceRetrieverPtr() const
void writeProductDependencies()
void writeBranchIDListRegistry()
static TTree * makeTTree(TFile *filePtr, std::string const &name, int splitLevel)
element_type const * get() const
std::string const & fullClassName() const
std::string const & processHistoryBranchName()
EventSelectionIDVector const * pEventSelectionIDs_
edm::propagate_const< TTree * > parameterSetsTree_
OutputHandle getForOutput(BranchID const &bid, bool getProd, ModuleCallingContext const *mcc) const
void writeIndexIntoFile()
void writeFileIdentifier()
eventsetup::produce::Produce produced
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
edm::propagate_const< StoredProductProvenanceVector * > pEventEntryInfoVector_
void setBranchAliases(TTree *tree, SelectedProducts const &branches) const
std::string toString() const
std::string const & parentageBranchName()
LuminosityBlockNumber_t luminosityBlock() const
void addContext(std::string const &context)
edm::propagate_const< TTree * > parentageTree_
std::set< std::string > const & branchAliases() const
bool insertProductProvenance(const ProductProvenance &, std::set< StoredProductProvenance > &oToInsert)
void setException(std::exception_ptr e)
void addAuxiliary(std::string const &branchName, T const *&pAux, int bufSize, bool allowCloning=true)
std::vector< StoredProductProvenance > StoredProductProvenanceVector
void writeParameterSetRegistry()
void respondToCloseInputFile(FileBlock const &fb)
IndexIntoFile indexIntoFile_
std::string const & productDescriptionBranchName()
IndexIntoFile::EntryNumber_t runEntryNumber_
ParentageID const & parentageID() const
static void writeTTree(TTree *tree)
ProcessHistoryID const & processHistoryID() const
EventAuxiliary const * pEventAux_
void writeParentageRegistry()
std::vector< BranchDescription const * > SelectedProducts
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
std::exception_ptr getException()
void writeProductDescriptionRegistry()
std::string const & BranchTypeToProductProvenanceBranchName(BranchType const &BranchType)
std::string const & productDependenciesBranchName()
StoredProductProvenanceVector const * pEventEntryInfoVector() const
RootOutputFile(PoolOutputModule *om, std::string const &fileName, std::string const &logicalFileName)
std::string const & thinnedAssociationsHelperBranchName()
std::unique_ptr< WrapperBase > getWrapperBasePtr(void *p, int offset)
std::string const & branchIDListBranchName()
void setProcessHistoryID(ProcessHistoryID const &phid)
std::string const & branchListIndexesBranchName()
void writeFileFormatVersion()
Parentage const & parentage() const
RootOutputTreePtrArray treePointers_
volatile std::atomic< bool > shutdown_flag false
BranchListIndexes const * pBranchListIndexes_
void writeLuminosityBlock(LuminosityBlockPrincipal const &lb, ModuleCallingContext const *)
void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
static ParentageRegistry * instance()
IndexIntoFile::EntryNumber_t lumiEntryNumber_
void optimizeBaskets(ULong64_t size)
EventAuxiliary const & aux() const
std::string const & fileIdentifierBranchName()
RunAuxiliary const * pRunAux_
std::string const & wrappedName() const
tuple size
Write out results.
EventNumber_t event() const
static Registry * instance()
JobReport::Token reportToken_
std::string createGlobalIdentifier()
std::string const & fileName() const
LuminosityBlockID id() const
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)