44 #include "Compression.h" 54 sorterForJobReportHash(BranchDescription
const*
lh, BranchDescription
const* rh) {
56 lh->fullClassName() < rh->fullClassName() ?
true :
57 lh->fullClassName() > rh->fullClassName() ?
false :
58 lh->moduleLabel() < rh->moduleLabel() ?
true :
59 lh->moduleLabel() > rh->moduleLabel() ?
false :
60 lh->productInstanceName() < rh->productInstanceName() ?
true :
61 lh->productInstanceName() > rh->productInstanceName() ?
false :
62 lh->processName() < rh->processName() ?
true :
67 openTFile(
char const*
name,
int compressionLevel) {
68 TFile*
file = TFile::Open(name,
"recreate",
"", compressionLevel);
70 if(e != std::exception_ptr()) {
72 std::rethrow_exception(e);
80 logicalFile_(logicalFileName),
83 whyNotFastClonable_(om_->whyNotFastClonable()),
84 canFastCloneAux_(
false),
85 filePtr_(openTFile(file_.c_str(), om_->compressionLevel())),
87 eventEntryNumber_(0LL),
88 lumiEntryNumber_(0LL),
100 eventEntryInfoVector_(),
101 pEventEntryInfoVector_(&eventEntryInfoVector_),
106 runTree_(filePtr(),
InRun, om_->
splitLevel(), om_->treeMaxVirtualSize()),
108 dataTypeReported_(
false),
109 processHistoryRegistry_(),
111 branchesWithStoredHistory_(),
112 wrapperBaseTClass_(TClass::GetClass(
"edm::WrapperBase")) {
114 filePtr_->SetCompressionAlgorithm(ROOT::kZLIB);
116 filePtr_->SetCompressionAlgorithm(ROOT::kLZMA);
119 <<
"Allowed compression algorithms are ZLIB and LZMA\n";
146 for(
auto const& item :
om_->selectedOutputItemList()[
branchType]) {
147 item.product_ =
nullptr;
154 item.branchDescription_->produced());
171 std::vector<std::string> branchNames;
172 std::vector<BranchDescription const*> branches;
173 branchNames.reserve(
om_->selectedOutputItemList()[
InEvent].size());
175 for(
auto const& item :
om_->selectedOutputItemList()[
InEvent]) {
176 branchNames.push_back(item.branchDescription_->branchName());
177 branches.push_back(item.branchDescription_);
180 sort_all(branches, sorterForJobReportHash);
182 std::ostringstream oss;
183 char const underscore =
'_';
184 for(
auto const& branch : branches) {
214 if ((whyNotFastClonable &
222 bool isWarning =
true;
224 message <<
"Fast copying of file " << ifileName <<
" to file " << ofileName <<
" is disabled because:\n";
226 message <<
"a SecondaryFileSequence was specified.\n";
231 message <<
"the input file is in an old format.\n";
236 message <<
"events need to be sorted.\n";
240 message <<
"a run or a lumi is not contiguous in the input file.\n";
244 message <<
"events or lumis were selected or skipped by ID.\n";
249 message <<
"initial events, lumis or runs were skipped.\n";
254 message <<
"some events were skipped because of duplicate checking.\n";
258 message <<
"some events were not copied because of maxEvents limit.\n";
263 message <<
"some events were not copied because of maxLumis limit.\n";
268 message <<
"parallel processing was specified.\n";
273 message <<
"an EventSelector was specified.\n";
278 message <<
"some events were not copied because of maxEvents output limit.\n";
283 message <<
"the split level or basket size of a branch or branches was modified.\n";
287 message <<
"The format of a data product has changed.\n";
292 LogWarning(
"FastCloningDisabled") << message.str();
294 LogInfo(
"FastCloningDisabled") << message.str();
305 if(fb.
tree() !=
nullptr) {
309 if(remainingEvents >= 0 && remainingEvents < fb.
tree()->GetEntries()) {
315 if(
om_->overrideInputFileSplitLevels()) {
324 assert(
om_->inputFileCount() > 1);
326 "Merge failure because input file " <<
file_ <<
" has different ROOT split levels or basket sizes\n" <<
327 "than previous files. To allow merging in splite of this, use the configuration parameter\n" <<
328 "overrideInputFileSplitLevels=cms.untracked.bool(True)\n" <<
329 "in every PoolOutputModule.\n";
387 unsigned int const oneK = 1024;
389 return(size >=
om_->maxFileSize());
408 if (reg->anyProductProduced() || !
om_->wantAllEvents()) {
409 esids.push_back(
om_->selectorConfig());
413 assert(provRetriever);
484 &desc,
om_->basketSize(), 0))
486 <<
"Failed to create a branch for Parentages in the output file";
492 orderedIDs[parentageID.second] = parentageID.first;
495 for(
auto const& orderedID : orderedIDs) {
522 ex <<
"The number of entries in at least one output TBranch whose entries\n" 523 "were copied from the input does not match the number of events\n" 524 "recorded in IndexIntoFile. This might (or might not) indicate a\n" 525 "problem related to fast copy.";
526 ex.
addContext(
"Calling RootOutputFile::writeIndexIntoFile");
539 procHistoryVector.push_back(ph.second);
562 std::pair<ParameterSetID, ParameterSetBlob> idToBlob;
563 std::pair<ParameterSetID, ParameterSetBlob>* pIdToBlob = &idToBlob;
567 idToBlob.first =
pset.first;
568 idToBlob.second.pset() =
pset.second.toString();
579 ProductList& pList =
const_cast<ProductList &
>(pReg.productList());
580 for(
auto const&
prod : pList) {
581 if(
prod.second.branchID() !=
prod.second.originalBranchID()) {
588 for(ProductList::iterator it = pList.begin(); it != pList.end();) {
591 ProductList::iterator itCopy = it;
633 treePointer->close();
634 treePointer =
nullptr;
647 if(tree && tree->GetNbranches() != 0) {
654 tree->SetAlias(alias.c_str(), full.c_str());
657 tree->SetAlias(
alias.c_str(), full.c_str());
668 std::set<BranchID>
const &iProducedIDs,
669 std::set<StoredProductProvenance>& oToFill) {
674 for(
auto const& parentID : parentIDs) {
694 std::vector<std::unique_ptr<WrapperBase> > dummies;
702 std::set<StoredProductProvenance> provenanceToKeep;
708 std::set<BranchID> producedBranches;
711 for(
auto bd : preg->allBranchDescriptions()) {
712 if(bd->produced() && bd->branchType() ==
InEvent) {
713 producedBranches.insert(bd->branchID());
719 for(
auto const& item : items) {
721 BranchID const&
id = item.branchDescription_->branchID();
724 bool produced = item.branchDescription_->produced();
725 bool getProd = (produced || !fastCloning ||
treePointers_[
branchType]->uncloned(item.branchDescription_->branchName()));
726 bool keepProvenance = doProvenance && (produced || keepProvenanceForPrior);
734 if(found && keepProvenance) {
737 if(product ==
nullptr) {
740 TClass*
cp = item.branchDescription_->wrappedType().getClass();
741 assert(cp !=
nullptr);
745 product = dummy.get();
748 item.product_ = product;
750 if (keepProvenance && productProvenance ==
nullptr) {
751 productProvenance = provRetriever->
branchIDToProvenance(item.branchDescription_->originalBranchID());
753 if(productProvenance) {
755 insertAncestors(*productProvenance, provRetriever, produced, producedBranches, provenanceToKeep);
759 if(doProvenance) productProvenanceVecPtr->assign(provenanceToKeep.begin(), provenanceToKeep.end());
761 if(doProvenance) productProvenanceVecPtr->clear();
766 std::set<edm::StoredProductProvenance>& oToInsert) {
769 std::set<edm::StoredProductProvenance>::iterator itFound = oToInsert.find(toStore);
770 if(itFound == oToInsert.end()) {
776 <<
"RootOutputFile::insertProductProvenance\n" 777 <<
"The parentage ID index value " << toStore.
parentageIDIndex_ <<
" is out of bounds. The maximum value is currently " <<
parentageIDs_.size()-1 <<
".\n" 778 <<
"This should never happen.\n" 779 <<
"Please report this to the framework hypernews forum 'hn-cms-edmFramework@cern.ch'.\n";
782 oToInsert.insert(toStore);
std::vector< ProcessHistory > ProcessHistoryVector
EventNumber_t event() const
std::string const & idToParameterSetBlobsBranchName()
std::string const & branchName() const
void beginInputFile(FileBlock const &fb, int remainingEvents)
BranchID const & branchID() const
virtual ProcessHistory const & processHistory() const
LuminosityBlockAuxiliary lumiAux_
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
EventID const & id() const
std::string const & parentageTreeName()
std::vector< BranchIDList > BranchIDLists
int eventAutoFlushSize() const
EventAuxiliary const & eventAuxiliary() const
void writeProcessHistoryRegistry()
void insertAncestors(ProductProvenance const &iGetParents, ProductProvenanceRetriever const *iMapper, bool produced, std::set< BranchID > const &producedBranches, std::set< StoredProductProvenance > &oToFill)
std::map< BranchKey, BranchDescription > ProductList
bool checkSplitLevelsAndBasketSizes(TTree *inputTree) const
bool registerProcessHistory(ProcessHistory const &processHistory)
int whyNotFastClonable() const
std::string const & fileFormatVersionBranchName()
edm::propagate_const< TTree * > metaDataTree_
unsigned long nEventsInLumi_
OutputItemListArray const & selectedOutputItemList() const
ProcessHistoryRegistry processHistoryRegistry_
std::string const & processName() const
BranchListIndexes const & branchListIndexes() const
ProductProvenance const * productProvenance() const
std::string const & eventSelectionsBranchName()
void writeLuminosityBlock(LuminosityBlockForOutput const &lb)
void setAutoFlush(Long64_t size)
bool shouldWeCloseFile() const
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const
bool checkIfFastClonable(TTree *inputTree) 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< std::pair< BranchDescription const *, EDGetToken > > SelectedProducts
std::vector< BranchID > const & parents() const
void writeThinnedAssociationsHelper()
unsigned int parentageIDIndex_
std::map< ParentageID, unsigned int > parentageIDs_
bool getByToken(EDGetToken token, TypeID const &typeID, BasicHandle &result) const
RootOutputTree eventTree_
EventSelectionIDVector const & eventSelectionIDs() const
Provenance const * provenance() const
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
LuminosityBlockAuxiliary const * pLumiAux_
std::string const & indexIntoFileBranchName()
edm::propagate_const< std::shared_ptr< TFile > > filePtr_
void writeOne(EventForOutput const &e)
WrapperBase const * wrapper() const
ProductProvenanceRetriever const * productProvenanceRetrieverPtr() const
int getFileFormatVersion()
bool checkEntriesInReadBranches(Long64_t expectedNumberOfEntries) 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_
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_
void writeIndexIntoFile()
void writeFileIdentifier()
RunAuxiliary const & runAuxiliary() const
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_
ProcessHistoryID const & processHistoryID() const
void writeParentageRegistry()
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_
BranchListIndexes const * pBranchListIndexes_
void maybeFastCloneTree(bool canFastClone, bool canFastCloneAux, TTree *tree, std::string const &option)
LuminosityBlockID const & id() const
const eventsetup::produce::Produce produced
static ParentageRegistry * instance()
IndexIntoFile::EntryNumber_t lumiEntryNumber_
void optimizeBaskets(ULong64_t size)
void writeRun(RunForOutput const &r)
std::string const & fileIdentifierBranchName()
RunAuxiliary const * pRunAux_
std::string const & wrappedName() const
EventNumber_t event() const
def branchType(schema, name)
static Registry * instance()
JobReport::Token reportToken_
std::string createGlobalIdentifier()
void fillBranches(BranchType const &branchType, OccurrenceForOutput const &occurrence, StoredProductProvenanceVector *productProvenanceVecPtr=0, ProductProvenanceRetriever const *provRetriever=0)
std::string const & fileName() const
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)