CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

edm::RootOutputFile Class Reference

#include <RootOutputFile.h>

List of all members.

Public Types

typedef
PoolOutputModule::OutputItem 
OutputItem
typedef
PoolOutputModule::OutputItemList 
OutputItemList
typedef std::array
< RootOutputTree
*, NumBranchTypes > 
RootOutputTreePtrArray

Public Member Functions

void beginInputFile (FileBlock const &fb, int remainingEvents)
std::string const & fileName () const
void finishEndFile ()
void respondToCloseInputFile (FileBlock const &fb)
 RootOutputFile (PoolOutputModule *om, std::string const &fileName, std::string const &logicalFileName)
bool shouldWeCloseFile () const
void writeBranchIDListRegistry ()
void writeFileFormatVersion ()
void writeFileIdentifier ()
void writeIndexIntoFile ()
void writeLuminosityBlock (LuminosityBlockPrincipal const &lb)
void writeOne (EventPrincipal const &e)
void writeParameterSetRegistry ()
void writeParentageRegistry ()
void writeProcessConfigurationRegistry ()
void writeProcessHistoryRegistry ()
void writeProductDependencies ()
void writeProductDescriptionRegistry ()
void writeRun (RunPrincipal const &r)
 ~RootOutputFile ()

Private Member Functions

void fillBranches (BranchType const &branchType, Principal const &principal, StoredProductProvenanceVector *productProvenanceVecPtr)
void insertAncestors (ProductProvenance const &iGetParents, EventPrincipal const &principal, bool produced, std::set< StoredProductProvenance > &oToFill)
bool insertProductProvenance (const ProductProvenance &, std::set< StoredProductProvenance > &oToInsert)
void setBranchAliases (TTree *tree, Selections const &branches) const

Private Attributes

std::set< BranchIDbranchesWithStoredHistory_
bool canFastCloneAux_
bool dataTypeReported_
StoredProductProvenanceVector eventEntryInfoVector_
IndexIntoFile::EntryNumber_t eventEntryNumber_
RootOutputTree eventTree_
FileID fid_
std::string file_
boost::shared_ptr< TFile > filePtr_
IndexIntoFile indexIntoFile_
std::string logicalFile_
LuminosityBlockAuxiliary lumiAux_
IndexIntoFile::EntryNumber_t lumiEntryNumber_
RootOutputTree lumiTree_
TTree * metaDataTree_
PoolOutputModule const * om_
TTree * parameterSetsTree_
std::map< ParentageID,
unsigned int > 
parentageIDs_
TTree * parentageTree_
BranchListIndexes const * pBranchListIndexes_
EventAuxiliary const * pEventAux_
StoredProductProvenanceVectorpEventEntryInfoVector_
EventSelectionIDVector const * pEventSelectionIDs_
LuminosityBlockAuxiliary const * pLumiAux_
RunAuxiliary const * pRunAux_
JobReport::Token reportToken_
RunAuxiliary runAux_
IndexIntoFile::EntryNumber_t runEntryNumber_
RootOutputTree runTree_
RootOutputTreePtrArray treePointers_
int whyNotFastClonable_

Detailed Description

Definition at line 40 of file RootOutputFile.h.


Member Typedef Documentation

Definition at line 42 of file RootOutputFile.h.

Definition at line 43 of file RootOutputFile.h.

typedef std::array<RootOutputTree*, NumBranchTypes> edm::RootOutputFile::RootOutputTreePtrArray

Definition at line 44 of file RootOutputFile.h.


Constructor & Destructor Documentation

edm::RootOutputFile::RootOutputFile ( PoolOutputModule om,
std::string const &  fileName,
std::string const &  logicalFileName 
) [explicit]

Definition at line 65 of file RootOutputFile.cc.

References edm::RootOutputTree::addAuxiliary(), edm::RootOutputTree::addBranch(), edm::PoolOutputModule::auxItems(), branchesWithStoredHistory_, edm::poolNames::branchListIndexesBranchName(), edm::BranchDescription::branchName(), revisionDML::branchType(), edm::BranchTypeToAuxiliaryBranchName(), edm::BranchTypeToProductProvenanceBranchName(), edm::PoolOutputModule::catalog(), edm::PoolOutputModule::compressionAlgorithm(), edm::errors::Configuration, edm::createGlobalIdentifier(), cms::Digest::digest(), edm::PoolOutputModule::eventAutoFlushSize(), edm::poolNames::eventSelectionsBranchName(), eventTree_, Exception, fid_, file_, filePtr_, edm::BranchDescription::fullClassName(), edm::BranchDescription::getInterface(), i, edm::InEvent, edm::BranchDescription::init(), edm::InLumi, edm::InRun, logicalFile_, lumiTree_, edm::RootOutputTree::makeTTree(), metaDataTree_, edm::poolNames::metaDataTreeName(), edm::BranchDescription::moduleLabel(), edm::PoolOutputModule::moduleLabel(), edm::NumBranchTypes, om_, parameterSetsTree_, edm::poolNames::parameterSetsTreeName(), parentageTree_, edm::poolNames::parentageTreeName(), pBranchListIndexes_, pEventAux_, pEventEntryInfoVector_, pEventSelectionIDs_, pLumiAux_, edm::BranchDescription::processName(), edm::BranchDescription::productInstanceName(), pRunAux_, reportToken_, runTree_, edm::PoolOutputModule::selectedOutputItemList(), edm::RootOutputTree::setAutoFlush(), edm::sort_all(), AlCaHLTBitMon_QueryRunRegistry::string, treePointers_, and edm::BranchDescription::wrappedName().

                                                                                                                  :
      file_(fileName),
      logicalFile_(logicalFileName),
      reportToken_(0),
      om_(om),
      whyNotFastClonable_(om_->whyNotFastClonable()),
      canFastCloneAux_(false),
      filePtr_(TFile::Open(file_.c_str(), "recreate", "", om_->compressionLevel())),
      fid_(),
      eventEntryNumber_(0LL),
      lumiEntryNumber_(0LL),
      runEntryNumber_(0LL),
      indexIntoFile_(),
      metaDataTree_(0),
      parameterSetsTree_(0),
      parentageTree_(0),
      lumiAux_(),
      runAux_(),
      pEventAux_(0),
      pLumiAux_(&lumiAux_),
      pRunAux_(&runAux_),
      eventEntryInfoVector_(),
      pEventEntryInfoVector_(&eventEntryInfoVector_),
      pBranchListIndexes_(0),
      pEventSelectionIDs_(0),
      eventTree_(filePtr_, InEvent, om_->splitLevel(), om_->treeMaxVirtualSize()),
      lumiTree_(filePtr_, InLumi, om_->splitLevel(), om_->treeMaxVirtualSize()),
      runTree_(filePtr_, InRun, om_->splitLevel(), om_->treeMaxVirtualSize()),
      treePointers_(),
      dataTypeReported_(false),
      parentageIDs_(),
      branchesWithStoredHistory_() {
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,30,0)
    if (om_->compressionAlgorithm() == std::string("ZLIB")) {
      filePtr_->SetCompressionAlgorithm(ROOT::kZLIB);
    } else if (om_->compressionAlgorithm() == std::string("LZMA")) {
      filePtr_->SetCompressionAlgorithm(ROOT::kLZMA);
    } else {
      throw Exception(errors::Configuration) << "PoolOutputModule configured with unknown compression algorithm '" << om_->compressionAlgorithm() << "'\n"
                                             << "Allowed compression algorithms are ZLIB and LZMA\n";
    }
#endif
    if (-1 != om->eventAutoFlushSize()) {
      eventTree_.setAutoFlush(-1*om->eventAutoFlushSize());
    }
    eventTree_.addAuxiliary<EventAuxiliary>(BranchTypeToAuxiliaryBranchName(InEvent),
                                            pEventAux_, om_->auxItems()[InEvent].basketSize_);
    eventTree_.addAuxiliary<StoredProductProvenanceVector>(BranchTypeToProductProvenanceBranchName(InEvent),
                                                     pEventEntryInfoVector_, om_->auxItems()[InEvent].basketSize_);
    eventTree_.addAuxiliary<EventSelectionIDVector>(poolNames::eventSelectionsBranchName(),
                                                    pEventSelectionIDs_, om_->auxItems()[InEvent].basketSize_,false);
    eventTree_.addAuxiliary<BranchListIndexes>(poolNames::branchListIndexesBranchName(),
                                               pBranchListIndexes_, om_->auxItems()[InEvent].basketSize_);

    lumiTree_.addAuxiliary<LuminosityBlockAuxiliary>(BranchTypeToAuxiliaryBranchName(InLumi),
                                                     pLumiAux_, om_->auxItems()[InLumi].basketSize_);

    runTree_.addAuxiliary<RunAuxiliary>(BranchTypeToAuxiliaryBranchName(InRun),
                                        pRunAux_, om_->auxItems()[InRun].basketSize_);

    treePointers_[InEvent] = &eventTree_;
    treePointers_[InLumi]  = &lumiTree_;
    treePointers_[InRun]   = &runTree_;

    for(int i = InEvent; i < NumBranchTypes; ++i) {
      BranchType branchType = static_cast<BranchType>(i);
      RootOutputTree *theTree = treePointers_[branchType];
      for(OutputItemList::const_iterator it = om_->selectedOutputItemList()[branchType].begin(),
          itEnd = om_->selectedOutputItemList()[branchType].end();
          it != itEnd; ++it) {
        it->product_ = 0;
        BranchDescription const& desc = *it->branchDescription_;
        desc.init();
        theTree->addBranch(desc.branchName(),
                           desc.wrappedName(),
                           desc.getInterface(),
                           it->product_,
                           it->splitLevel_,
                           it->basketSize_,
                           it->branchDescription_->produced());
        //make sure we always store product registry info for all branches we create
        branchesWithStoredHistory_.insert(it->branchID());
      }
    }
    // Don't split metadata tree or event description tree
    metaDataTree_         = RootOutputTree::makeTTree(filePtr_.get(), poolNames::metaDataTreeName(), 0);
    parentageTree_ = RootOutputTree::makeTTree(filePtr_.get(), poolNames::parentageTreeName(), 0);
    parameterSetsTree_    = RootOutputTree::makeTTree(filePtr_.get(), poolNames::parameterSetsTreeName(), 0);

    fid_ = FileID(createGlobalIdentifier());

    // For the Job Report, get a vector of branch names in the "Events" tree.
    // Also create a hash of all the branch names in the "Events" tree
    // in a deterministic order, except use the full class name instead of the friendly class name.
    // To avoid extra string copies, we create a vector of pointers into the product registry,
    // and use a custom comparison operator for sorting.
    std::vector<std::string> branchNames;
    std::vector<BranchDescription const*> branches;
    branchNames.reserve(om_->selectedOutputItemList()[InEvent].size());
    branches.reserve(om->selectedOutputItemList()[InEvent].size());
    for(OutputItemList::const_iterator it = om_->selectedOutputItemList()[InEvent].begin(),
          itEnd = om_->selectedOutputItemList()[InEvent].end();
          it != itEnd; ++it) {
      branchNames.push_back(it->branchDescription_->branchName());
      branches.push_back(it->branchDescription_);
    }
    // Now sort the branches for the hash.
    sort_all(branches, sorterForJobReportHash);
    // Now, make a concatenated string.
    std::ostringstream oss;
    char const underscore = '_';
    for(std::vector<BranchDescription const*>::const_iterator it = branches.begin(), itEnd = branches.end(); it != itEnd; ++it) {
      BranchDescription const& bd = **it;
      oss << bd.fullClassName() << underscore
          << bd.moduleLabel() << underscore
          << bd.productInstanceName() << underscore
          << bd.processName() << underscore;
    }
    std::string stringrep = oss.str();
    cms::Digest md5alg(stringrep);

    // Register the output file with the JobReport service
    // and get back the token for it.
    std::string moduleName = "PoolOutputModule";
    Service<JobReport> reportSvc;
    reportToken_ = reportSvc->outputFileOpened(
                      file_, logicalFile_,  // PFN and LFN
                      om_->catalog(),  // catalog
                      moduleName,   // module class name
                      om_->moduleLabel(),  // module label
                      fid_.fid(), // file id (guid)
                      std::string(), // data type (not yet known, so string is empty).
                      md5alg.digest().toString(), // branch hash
                      branchNames); // branch names being written
  }
edm::RootOutputFile::~RootOutputFile ( ) [inline]

Definition at line 47 of file RootOutputFile.h.

{}

Member Function Documentation

void edm::RootOutputFile::beginInputFile ( FileBlock const &  fb,
int  remainingEvents 
)

Definition at line 291 of file RootOutputFile.cc.

References edm::PoolOutputModule::basketOrder(), edm::FileBlock::CanFastClone, canFastCloneAux_, edm::RootOutputTree::checkIfFastClonable(), edm::RootOutputTree::checkSplitLevelsAndBasketSizes(), eventTree_, Exception, file_, edm::FileBlock::fileName(), edm::PoolOutputModule::inputFileCount(), edm::match(), edm::RootOutputTree::maybeFastCloneTree(), edm::errors::MismatchedInputFiles, edm::FileBlock::NoRootInputSource, om_, edm::PoolOutputModule::overrideInputFileSplitLevels(), reportToken_, edm::FileBlock::tree(), edm::FileBlock::whyNotFastClonable(), edm::PoolOutputModule::whyNotFastClonable(), and whyNotFastClonable_.

                                                                              {

    // Reset per input file information
    whyNotFastClonable_ = om_->whyNotFastClonable();
    canFastCloneAux_ = false;

    if(fb.tree() != 0) {

      whyNotFastClonable_ |= fb.whyNotFastClonable();

      if(remainingEvents >= 0 && remainingEvents < fb.tree()->GetEntries()) {
        whyNotFastClonable_ |= FileBlock::OutputMaxEventsTooSmall;
      }

      bool match = eventTree_.checkSplitLevelsAndBasketSizes(fb.tree());
      if(!match) {
        if(om_->overrideInputFileSplitLevels()) {
          // We may be fast copying.  We must disable fast copying if the split levels
          // or basket sizes do not match.
          whyNotFastClonable_ |= FileBlock::SplitLevelMismatch;
        } else {
          // We are using the input split levels and basket sizes from the first input file
          // for copied output branches.  In this case, we throw an exception if any branches
          // have different split levels or basket sizes in a subsequent input file.
          // If the mismatch is in the first file, there is a bug somewhere, so we assert.
          assert(om_->inputFileCount() > 1);
          throw Exception(errors::MismatchedInputFiles, "RootOutputFile::beginInputFile()") <<
            "Merge failure because input file " << file_ << " has different ROOT split levels or basket sizes\n" <<
            "than previous files.  To allow merging in splite of this, use the configuration parameter\n" <<
            "overrideInputFileSplitLevels=cms.untracked.bool(True)\n" <<
            "in every PoolOutputModule.\n";
        }
      }

      // Since this check can be time consuming, we do it only if we would otherwise fast clone.
      if(whyNotFastClonable_ == FileBlock::CanFastClone) {
        if(!eventTree_.checkIfFastClonable(fb.tree())) {
          whyNotFastClonable_ |= FileBlock::BranchMismatch;
        }
      }
      // We now check if we can fast copy the auxiliary branches.
      // We can do so only if we can otherwise fast copy,
      // the input file has the current format (these branches are in the Events Tree),
      // there are no newly dropped or produced products,
      // no metadata has been dropped,
      // ID's have not been modified,
      // and the branch list indexes do not need modification.

      // Note: Fast copy of the EventProductProvenance branch is unsafe
      // unless we can enforce that the parentage information for a fully copied
      // output file will be the same as for the input file, with nothing dropped.
      // This has never been enforced, and, withthe EDAlias feature, it may no longer
      // work by accident.
      // So, for now, we do not enable fast cloning of the non-product branches.
/*
      Service<ConstProductRegistry> reg;
      canFastCloneAux_ = (whyNotFastClonable_ == FileBlock::CanFastClone) &&
                          fb.fileFormatVersion().noMetaDataTrees() &&
                          !om_->hasNewlyDroppedBranch()[InEvent] &&
                          !fb.hasNewlyDroppedBranch()[InEvent] &&
                          om_->dropMetaData() == PoolOutputModule::DropNone &&
                          !reg->anyProductProduced() &&
                          !fb.modifiedIDs() &&
                          fb.branchListIndexesUnchanged();
*/

      // Report the fast copying status.
      Service<JobReport> reportSvc;
      reportSvc->reportFastCopyingStatus(reportToken_, fb.fileName(), whyNotFastClonable_ == FileBlock::CanFastClone);
    } else {
      whyNotFastClonable_ |= FileBlock::NoRootInputSource;
    }

    eventTree_.maybeFastCloneTree(whyNotFastClonable_ == FileBlock::CanFastClone, canFastCloneAux_, fb.tree(), om_->basketOrder());

    // Possibly issue warning or informational message if we haven't fast cloned.
    if(fb.tree() != 0 && whyNotFastClonable_ != FileBlock::CanFastClone) {
      maybeIssueWarning(whyNotFastClonable_, fb.fileName(), file_);
    }
  }
std::string const& edm::RootOutputFile::fileName ( ) const [inline]

Definition at line 68 of file RootOutputFile.h.

References file_.

{return file_;}
void edm::RootOutputFile::fillBranches ( BranchType const &  branchType,
Principal const &  principal,
StoredProductProvenanceVector productProvenanceVecPtr 
) [private]

Definition at line 689 of file RootOutputFile.cc.

References branchesWithStoredHistory_, revisionDML::branchType(), edm::FileBlock::CanFastClone, compareJSON::const, CommonMethods::cp(), edm::PoolOutputModule::DropDroppedPrior, edm::PoolOutputModule::dropMetaData(), edm::PoolOutputModule::DropNone, edm::PoolOutputModule::DropPrior, read312RV_cfg::fastCloning, edm::Principal::getForOutput(), i, edm::InEvent, insertAncestors(), insertProductProvenance(), om_, cmsRelvalreport::principal(), edm::es::produced, edm::OutputHandle::productProvenance(), edm::PoolOutputModule::selectedOutputItemList(), treePointers_, whyNotFastClonable_, and edm::OutputHandle::wrapper().

Referenced by writeLuminosityBlock(), writeOne(), and writeRun().

                                                                        {

    typedef std::vector<std::pair<TClass*, void const*> > Dummies;
    Dummies dummies;

    bool const fastCloning = (branchType == InEvent) && (whyNotFastClonable_ == FileBlock::CanFastClone);

    OutputItemList const& items = om_->selectedOutputItemList()[branchType];

    std::set<StoredProductProvenance> provenanceToKeep;

    // Loop over EDProduct branches, fill the provenance, and write the branch.
    for(OutputItemList::const_iterator i = items.begin(), iEnd = items.end(); i != iEnd; ++i) {

      BranchID const& id = i->branchDescription_->branchID();
      branchesWithStoredHistory_.insert(id);

      bool produced = i->branchDescription_->produced();
      bool keepProvenance = productProvenanceVecPtr != 0 &&
                            (om_->dropMetaData() == PoolOutputModule::DropNone ||
                             om_->dropMetaData() == PoolOutputModule::DropDroppedPrior ||
                            (om_->dropMetaData() == PoolOutputModule::DropPrior && produced));
      bool getProd = (produced || !fastCloning ||
         treePointers_[branchType]->uncloned(i->branchDescription_->branchName()));

      void const* product = 0;
      OutputHandle const oh = principal.getForOutput(id, getProd);
      if(keepProvenance && oh.productProvenance()) {
        insertProductProvenance(*oh.productProvenance(),provenanceToKeep);
        //provenanceToKeep.insert(*oh.productProvenance());
        EventPrincipal const& eventPrincipal = dynamic_cast<EventPrincipal const&>(principal);
        assert(eventPrincipal.branchMapperPtr());
        insertAncestors(*oh.productProvenance(), eventPrincipal, produced, provenanceToKeep);
      }
      product = oh.wrapper();
      if(getProd) {
        if(product == 0) {
          // No product with this ID is in the event.
          // Add a null product.
          TClass* cp = gROOT->GetClass(i->branchDescription_->wrappedName().c_str());
          product = cp->New();
          dummies.emplace_back(cp, product);
        }
        i->product_ = product;
      }
    }

    if(productProvenanceVecPtr != 0) productProvenanceVecPtr->assign(provenanceToKeep.begin(), provenanceToKeep.end());
    treePointers_[branchType]->fillTree();
    if(productProvenanceVecPtr != 0) productProvenanceVecPtr->clear();
    for(Dummies::iterator it = dummies.begin(), itEnd = dummies.end(); it != itEnd; ++it) {
      it->first->Destructor(const_cast<void *>(it->second));
    }
  }
void edm::RootOutputFile::finishEndFile ( )

Definition at line 610 of file RootOutputFile.cc.

References revisionDML::branchType(), filePtr_, i, edm::InEvent, edm::OutputModule::keptProducts(), metaDataTree_, edm::NumBranchTypes, om_, parameterSetsTree_, parentageTree_, reportToken_, setBranchAliases(), diffTreeTool::tree, treePointers_, and edm::RootOutputTree::writeTTree().

                                     {
    metaDataTree_->SetEntries(-1);
    RootOutputTree::writeTTree(metaDataTree_);
    RootOutputTree::writeTTree(parameterSetsTree_);

    RootOutputTree::writeTTree(parentageTree_);

    // Create branch aliases for all the branches in the
    // events/lumis/runs trees. The loop is over all types of data
    // products.
    for(int i = InEvent; i < NumBranchTypes; ++i) {
      BranchType branchType = static_cast<BranchType>(i);
      setBranchAliases(treePointers_[branchType]->tree(), om_->keptProducts()[branchType]);
      treePointers_[branchType]->writeTree();
    }

    // close the file -- mfp
    // Just to play it safe, zero all pointers to objects in the TFile to be closed.
    metaDataTree_ = parentageTree_ = 0;
    for(RootOutputTreePtrArray::iterator it = treePointers_.begin(), itEnd = treePointers_.end(); it != itEnd; ++it) {
      (*it)->close();
      (*it) = 0;
    }
    filePtr_->Close();
    filePtr_.reset();

    // report that file has been closed
    Service<JobReport> reportSvc;
    reportSvc->outputFileClosed(reportToken_);

  }
void edm::RootOutputFile::insertAncestors ( ProductProvenance const &  iGetParents,
EventPrincipal const &  principal,
bool  produced,
std::set< StoredProductProvenance > &  oToFill 
) [private]

Definition at line 664 of file RootOutputFile.cc.

References branchesWithStoredHistory_, edm::ProductProvenance::branchID(), edm::BranchMapper::branchIDToProvenance(), edm::EventPrincipal::branchMapperPtr(), edm::PoolOutputModule::DropAll, edm::PoolOutputModule::DropDroppedPrior, edm::PoolOutputModule::dropMetaData(), edm::PoolOutputModule::DropNone, edm::PoolOutputModule::DropPrior, edm::EventPrincipal::getProvenance(), info, insertProductProvenance(), om_, edm::ProductProvenance::parentage(), edm::Parentage::parents(), and edm::es::produced.

Referenced by fillBranches().

                                                                            {
    assert(om_->dropMetaData() != PoolOutputModule::DropAll);
    assert(produced || om_->dropMetaData() != PoolOutputModule::DropPrior);
    if(om_->dropMetaData() == PoolOutputModule::DropDroppedPrior && !produced) return;
    BranchMapper const& iMapper = *principal.branchMapperPtr();
    std::vector<BranchID> const& parentIDs = iGetParents.parentage().parents();
    for(std::vector<BranchID>::const_iterator it = parentIDs.begin(), itEnd = parentIDs.end();
          it != itEnd; ++it) {
      branchesWithStoredHistory_.insert(*it);
      ProductProvenance const* info = iMapper.branchIDToProvenance(*it);
      if(info) {
        if(om_->dropMetaData() == PoolOutputModule::DropNone ||
                 principal.getProvenance(info->branchID()).product().produced()) {
          if(insertProductProvenance(*info,oToFill) ) {
            //haven't seen this one yet
            insertAncestors(*info, principal, produced, oToFill);
          }
        }
      }
    }
  }
bool edm::RootOutputFile::insertProductProvenance ( const ProductProvenance ,
std::set< StoredProductProvenance > &  oToInsert 
) [private]

Definition at line 748 of file RootOutputFile.cc.

References edm::ProductProvenance::branchID(), edm::StoredProductProvenance::branchID_, Exception, i, edm::BranchID::id(), edm::errors::LogicError, edm::ProductProvenance::parentageID(), edm::StoredProductProvenance::parentageIDIndex_, and parentageIDs_.

Referenced by fillBranches(), and insertAncestors().

                                                                                         {
    StoredProductProvenance toStore;
    toStore.branchID_ = iProv.branchID().id();
    std::set<edm::StoredProductProvenance>::iterator itFound = oToInsert.find(toStore);
    if(itFound == oToInsert.end()) {
      //get the index to the ParentageID or insert a new value if not already present
      std::pair<std::map<edm::ParentageID,unsigned int>::iterator,bool> i = parentageIDs_.insert(std::make_pair(iProv.parentageID(),static_cast<unsigned int>(parentageIDs_.size())));
      toStore.parentageIDIndex_ = i.first->second;
      if(toStore.parentageIDIndex_ >= parentageIDs_.size()) {
        throw edm::Exception(errors::LogicError)
          << "RootOutputFile::insertProductProvenance\n"
          << "The parentage ID index value " << toStore.parentageIDIndex_ << " is out of bounds.  The maximum value is currently " << parentageIDs_.size()-1 << ".\n"
          << "This should never happen.\n"
          << "Please report this to the framework hypernews forum 'hn-cms-edmFramework@cern.ch'.\n";
      }

      oToInsert.insert(toStore);
      return true;
    }
    return false;
  }
void edm::RootOutputFile::respondToCloseInputFile ( FileBlock const &  fb)

Definition at line 372 of file RootOutputFile.cc.

References eventTree_, lumiTree_, runTree_, and edm::RootOutputTree::setEntries().

                                                               {
    eventTree_.setEntries();
    lumiTree_.setEntries();
    runTree_.setEntries();
  }
void edm::RootOutputFile::setBranchAliases ( TTree *  tree,
Selections const &  branches 
) const [private]

Definition at line 643 of file RootOutputFile.cc.

References edm::BranchDescription::branchAliases(), edm::BranchDescription::branchName(), full, i, edm::BranchDescription::moduleLabel(), edm::BranchDescription::productInstanceName(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by finishEndFile().

                                                                                {
    if(tree && tree->GetNbranches() != 0) {
      for(Selections::const_iterator i = branches.begin(), iEnd = branches.end();
          i != iEnd; ++i) {
        BranchDescription const& pd = **i;
        std::string const& full = pd.branchName() + "obj";
        if(pd.branchAliases().empty()) {
          std::string const& alias =
              (pd.productInstanceName().empty() ? pd.moduleLabel() : pd.productInstanceName());
          tree->SetAlias(alias.c_str(), full.c_str());
        } else {
          std::set<std::string>::const_iterator it = pd.branchAliases().begin(), itEnd = pd.branchAliases().end();
          for(; it != itEnd; ++it) {
            tree->SetAlias((*it).c_str(), full.c_str());
          }
        }
      }
    }
  }
bool edm::RootOutputFile::shouldWeCloseFile ( ) const

Definition at line 378 of file RootOutputFile.cc.

References filePtr_, edm::PoolOutputModule::maxFileSize(), om_, and findQualityFiles::size.

                                               {
    unsigned int const oneK = 1024;
    Long64_t size = filePtr_->GetSize()/oneK;
    return(size >= om_->maxFileSize());
  }
void edm::RootOutputFile::writeBranchIDListRegistry ( )

Definition at line 548 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), edm::poolNames::branchIDListBranchName(), edm::OutputModule::branchIDLists(), metaDataTree_, om_, and AlCaHLTBitMon_ParallelJobs::p.

                                                 {
    BranchIDLists const* p = om_->branchIDLists();
    TBranch* b = metaDataTree_->Branch(poolNames::branchIDListBranchName().c_str(), &p, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeFileFormatVersion ( )

Definition at line 489 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), edm::poolNames::fileFormatVersionBranchName(), edm::getFileFormatVersion(), metaDataTree_, and om_.

                                              {
    FileFormatVersion fileFormatVersion(getFileFormatVersion());
    FileFormatVersion* pFileFmtVsn = &fileFormatVersion;
    TBranch* b = metaDataTree_->Branch(poolNames::fileFormatVersionBranchName().c_str(), &pFileFmtVsn, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeFileIdentifier ( )

Definition at line 497 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), fid_, edm::poolNames::fileIdentifierBranchName(), metaDataTree_, and om_.

                                           {
    FileID* fidPtr = &fid_;
    TBranch* b = metaDataTree_->Branch(poolNames::fileIdentifierBranchName().c_str(), &fidPtr, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeIndexIntoFile ( )

Definition at line 504 of file RootOutputFile.cc.

References cms::Exception::addContext(), b, edm::PoolOutputModule::basketSize(), edm::RootOutputTree::checkEntriesInReadBranches(), eventEntryNumber_, eventTree_, indexIntoFile_, edm::poolNames::indexIntoFileBranchName(), metaDataTree_, om_, edm::errors::OtherCMS, and edm::IndexIntoFile::sortVector_Run_Or_Lumi_Entries().

                                          {
    if (eventTree_.checkEntriesInReadBranches(eventEntryNumber_) == false) {
      Exception ex(errors::OtherCMS);
      ex << "The number of entries in at least one output TBranch whose entries\n"
            "were copied from the input does not match the number of events\n"
            "recorded in IndexIntoFile. This might (or might not) indicate a\n"
            "problem related to fast copy.";
      ex.addContext("Calling RootOutputFile::writeIndexIntoFile");
      throw ex;
    }
    indexIntoFile_.sortVector_Run_Or_Lumi_Entries();
    IndexIntoFile* iifPtr = &indexIntoFile_;
    TBranch* b = metaDataTree_->Branch(poolNames::indexIntoFileBranchName().c_str(), &iifPtr, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeLuminosityBlock ( LuminosityBlockPrincipal const &  lb)

Definition at line 426 of file RootOutputFile.cc.

References edm::IndexIntoFile::addEntry(), edm::LuminosityBlockPrincipal::aux(), fillBranches(), indexIntoFile_, edm::InLumi, instance, lumiAux_, lumiEntryNumber_, edm::LuminosityBlockAuxiliary::luminosityBlock(), lumiTree_, edm::RootOutputTree::optimizeBaskets(), edm::Principal::processHistoryID(), edm::LuminosityBlockAuxiliary::run(), and edm::LuminosityBlockAuxiliary::setProcessHistoryID().

                                                                              {
    // Auxiliary branch
    // NOTE: lumiAux_ must be filled before calling fillBranches since it gets written out in that routine.
    lumiAux_ = lb.aux();
    // Use the updated process historyID
    lumiAux_.setProcessHistoryID(lb.processHistoryID());
    // Store the reduced ID in the IndexIntoFile
    ProcessHistoryID reducedPHID = ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(lb.processHistoryID());
    // Add lumi to index.
    indexIntoFile_.addEntry(reducedPHID, lumiAux_.run(), lumiAux_.luminosityBlock(), 0U, lumiEntryNumber_);
    ++lumiEntryNumber_;
    fillBranches(InLumi, lb, 0);
    lumiTree_.optimizeBaskets(10ULL*1024*1024);
  }
void edm::RootOutputFile::writeOne ( EventPrincipal const &  e)

Definition at line 384 of file RootOutputFile.cc.

References edm::IndexIntoFile::addEntry(), edm::EventPrincipal::aux(), edm::EventPrincipal::branchListIndexes(), dtTPAnalyzer_cfg::dataType, dataTypeReported_, edm::EventID::event(), edm::EventAuxiliary::event(), eventEntryNumber_, edm::EventPrincipal::eventSelectionIDs(), fillBranches(), edm::EventPrincipal::id(), indexIntoFile_, edm::InEvent, instance, edm::EventAuxiliary::isRealData(), edm::EventAuxiliary::luminosityBlock(), om_, pBranchListIndexes_, pEventAux_, pEventEntryInfoVector_, pEventSelectionIDs_, edm::EventAuxiliary::processHistoryID(), edm::Principal::processHistoryID(), reportToken_, edm::EventID::run(), edm::EventAuxiliary::run(), edm::OutputModule::selectorConfig(), AlCaHLTBitMon_QueryRunRegistry::string, and edm::OutputModule::wantAllEvents().

                                                       {
    // Auxiliary branch
    pEventAux_ = &e.aux();

    // Because getting the data may cause an exception to be thrown we want to do that
    // first before writing anything to the file about this event
    // NOTE: pEventAux_, pBranchListIndexes_, pEventSelectionIDs_, and pEventEntryInfoVector_
    // must be set before calling fillBranches since they get written out in that routine.
    assert(pEventAux_->processHistoryID() == e.processHistoryID());
    pBranchListIndexes_ = &e.branchListIndexes();

    // Note: The EventSelectionIDVector should have a one to one correspondence with the processes in the process history.
    // Therefore, a new entry should be added if and only if the current process has been added to the process history,
    // which is done if and only if there is a produced product.
    Service<ConstProductRegistry> reg;
    EventSelectionIDVector esids = e.eventSelectionIDs();
    if (reg->anyProductProduced() || !om_->wantAllEvents()) {
      esids.push_back(om_->selectorConfig());
    }
    pEventSelectionIDs_ = &esids;
    fillBranches(InEvent, e, pEventEntryInfoVector_);

    // Add the dataType to the job report if it hasn't already been done
    if(!dataTypeReported_) {
      Service<JobReport> reportSvc;
      std::string dataType("MC");
      if(pEventAux_->isRealData())  dataType = "Data";
      reportSvc->reportDataType(reportToken_, dataType);
      dataTypeReported_ = true;
    }

    // Store the reduced ID in the IndexIntoFile
    ProcessHistoryID reducedPHID = ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(e.processHistoryID());
    // Add event to index
    indexIntoFile_.addEntry(reducedPHID, pEventAux_->run(), pEventAux_->luminosityBlock(), pEventAux_->event(), eventEntryNumber_);
    ++eventEntryNumber_;

    // Report event written
    Service<JobReport> reportSvc;
    reportSvc->eventWrittenToFile(reportToken_, e.id().run(), e.id().event());
  }
void edm::RootOutputFile::writeParameterSetRegistry ( )

Definition at line 555 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), edm::poolNames::idToParameterSetBlobsBranchName(), instance, edm::detail::ThreadSafeRegistry< KEY, T, E >::instance(), om_, and parameterSetsTree_.

                                                 {
    std::pair<ParameterSetID, ParameterSetBlob> idToBlob;
    std::pair<ParameterSetID, ParameterSetBlob>* pIdToBlob = &idToBlob;
    TBranch* b = parameterSetsTree_->Branch(poolNames::idToParameterSetBlobsBranchName().c_str(),&pIdToBlob,om_->basketSize(), 0);

    for(pset::Registry::const_iterator it = pset::Registry::instance()->begin(),
        itEnd = pset::Registry::instance()->end();
        it != itEnd;
        ++it) {
      idToBlob.first = it->first;
      idToBlob.second.pset() = it->second.toString();

      b->Fill();
    }
  }
void edm::RootOutputFile::writeParentageRegistry ( )

Definition at line 456 of file RootOutputFile.cc.

References edm::PoolOutputModule::basketSize(), Exception, edm::errors::FatalRootError, edm::detail::ThreadSafeRegistry< KEY, T, E >::getMapped(), edm::detail::ThreadSafeRegistry< KEY, T, E >::insertMapped(), instance, om_, edm::poolNames::parentageBranchName(), parentageIDs_, and parentageTree_.

                                              {
    Parentage const* desc(0);

    if(!parentageTree_->Branch(poolNames::parentageBranchName().c_str(),
                                        &desc, om_->basketSize(), 0))
      throw Exception(errors::FatalRootError)
        << "Failed to create a branch for Parentages in the output file";

    
    //NOTE: for some reason the empty Parentage is not added to the registry some of the time
    ParentageRegistry& ptReg = *ParentageRegistry::instance();
    ptReg.insertMapped(Parentage());
    
    std::vector<ParentageID> orderedIDs(parentageIDs_.size());
    for(std::map<ParentageID,unsigned int>::const_iterator it = parentageIDs_.begin(),
        itEnd = parentageIDs_.end();
        it != itEnd;
        ++it) {
      orderedIDs[it->second]=it->first;
    }
    //now put them into the TTree in the correct order
    for(std::vector<ParentageID>::const_iterator it = orderedIDs.begin(),
        itEnd = orderedIDs.end();
        it != itEnd;
        ++it) {
      desc = ptReg.getMapped(*it);
      //NOTE: some old format files have missing Parentage info
      // so a null value of desc can't be fatal.
      // Root will default construct an object in that case.
      parentageTree_->Fill();
    }    
  }
void edm::RootOutputFile::writeProcessConfigurationRegistry ( )

Definition at line 521 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), alignCSCRings::e, i, instance, metaDataTree_, om_, AlCaHLTBitMon_ParallelJobs::p, edm::poolNames::processConfigurationBranchName(), and edm::sort_all().

                                                         {
    typedef ProcessConfigurationRegistry::collection_type Map;
    Map const& procConfigMap = ProcessConfigurationRegistry::instance()->data();
    ProcessConfigurationVector procConfigVector;
    for(Map::const_iterator i = procConfigMap.begin(), e = procConfigMap.end(); i != e; ++i) {
      procConfigVector.push_back(i->second);
    }
    sort_all(procConfigVector);
    ProcessConfigurationVector* p = &procConfigVector;
    TBranch* b = metaDataTree_->Branch(poolNames::processConfigurationBranchName().c_str(), &p, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeProcessHistoryRegistry ( )

Definition at line 535 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), alignCSCRings::e, i, instance, metaDataTree_, om_, AlCaHLTBitMon_ParallelJobs::p, and edm::poolNames::processHistoryBranchName().

                                                   {
    typedef ProcessHistoryRegistry::collection_type Map;
    Map const& procHistoryMap = ProcessHistoryRegistry::instance()->data();
    ProcessHistoryVector procHistoryVector;
    for(Map::const_iterator i = procHistoryMap.begin(), e = procHistoryMap.end(); i != e; ++i) {
      procHistoryVector.push_back(i->second);
    }
    ProcessHistoryVector* p = &procHistoryVector;
    TBranch* b = metaDataTree_->Branch(poolNames::processHistoryBranchName().c_str(), &p, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeProductDependencies ( )

Definition at line 602 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), edm::OutputModule::branchChildren(), metaDataTree_, om_, and edm::poolNames::productDependenciesBranchName().

                                                {
    BranchChildren& pDeps = const_cast<BranchChildren&>(om_->branchChildren());
    BranchChildren* ppDeps = &pDeps;
    TBranch* b = metaDataTree_->Branch(poolNames::productDependenciesBranchName().c_str(), &ppDeps, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeProductDescriptionRegistry ( )

Definition at line 571 of file RootOutputFile.cc.

References b, edm::PoolOutputModule::basketSize(), branchesWithStoredHistory_, end, metaDataTree_, om_, parseEventContent::prod, and edm::poolNames::productDescriptionBranchName().

                                                       {
    // Make a local copy of the ProductRegistry, removing any transient or pruned products.
    typedef ProductRegistry::ProductList ProductList;
    Service<ConstProductRegistry> reg;
    ProductRegistry pReg(reg->productList());
    ProductList& pList  = const_cast<ProductList &>(pReg.productList());
    for(auto const& prod : pList) {
      if(prod.second.branchID() != prod.second.originalBranchID()) {
        if(branchesWithStoredHistory_.find(prod.second.branchID()) != branchesWithStoredHistory_.end()) {
          branchesWithStoredHistory_.insert(prod.second.originalBranchID());
        }
      }
    }
    std::set<BranchID>::iterator end = branchesWithStoredHistory_.end();
    for(ProductList::iterator it = pList.begin(); it != pList.end();) {
      if(branchesWithStoredHistory_.find(it->second.branchID()) == end) {
        // avoid invalidating iterator on deletion
        ProductList::iterator itCopy = it;
        ++it;
        pList.erase(itCopy);

      } else {
        ++it;
      }
    }

    ProductRegistry* ppReg = &pReg;
    TBranch* b = metaDataTree_->Branch(poolNames::productDescriptionBranchName().c_str(), &ppReg, om_->basketSize(), 0);
    assert(b);
    b->Fill();
  }
void edm::RootOutputFile::writeRun ( RunPrincipal const &  r)

Definition at line 441 of file RootOutputFile.cc.

References edm::IndexIntoFile::addEntry(), edm::RunPrincipal::aux(), fillBranches(), indexIntoFile_, edm::InRun, instance, edm::RootOutputTree::optimizeBaskets(), edm::Principal::processHistoryID(), edm::RunAuxiliary::run(), runAux_, runEntryNumber_, runTree_, and edm::RunAuxiliary::setProcessHistoryID().

                                                     {
    // Auxiliary branch
    // NOTE: runAux_ must be filled before calling fillBranches since it gets written out in that routine.
    runAux_ = r.aux();
    // Use the updated process historyID
    runAux_.setProcessHistoryID(r.processHistoryID());
    // Store the reduced ID in the IndexIntoFile
    ProcessHistoryID reducedPHID = ProcessHistoryRegistry::instance()->extra().reduceProcessHistoryID(r.processHistoryID());
    // Add run to index.
    indexIntoFile_.addEntry(reducedPHID, runAux_.run(), 0U, 0U, runEntryNumber_);
    ++runEntryNumber_;
    fillBranches(InRun, r, 0);
    runTree_.optimizeBaskets(10ULL*1024*1024);
  }

Member Data Documentation

Definition at line 100 of file RootOutputFile.h.

Referenced by beginInputFile().

Definition at line 123 of file RootOutputFile.h.

Referenced by writeOne().

Definition at line 115 of file RootOutputFile.h.

Definition at line 103 of file RootOutputFile.h.

Referenced by writeIndexIntoFile(), and writeOne().

Definition at line 102 of file RootOutputFile.h.

Referenced by RootOutputFile(), and writeFileIdentifier().

std::string edm::RootOutputFile::file_ [private]

Definition at line 95 of file RootOutputFile.h.

Referenced by beginInputFile(), fileName(), and RootOutputFile().

boost::shared_ptr<TFile> edm::RootOutputFile::filePtr_ [private]

Definition at line 101 of file RootOutputFile.h.

Referenced by finishEndFile(), RootOutputFile(), and shouldWeCloseFile().

Definition at line 106 of file RootOutputFile.h.

Referenced by writeIndexIntoFile(), writeLuminosityBlock(), writeOne(), and writeRun().

std::string edm::RootOutputFile::logicalFile_ [private]

Definition at line 96 of file RootOutputFile.h.

Referenced by RootOutputFile().

Definition at line 110 of file RootOutputFile.h.

Referenced by writeLuminosityBlock().

Definition at line 104 of file RootOutputFile.h.

Referenced by writeLuminosityBlock().

Definition at line 120 of file RootOutputFile.h.

Referenced by respondToCloseInputFile(), RootOutputFile(), and writeLuminosityBlock().

Definition at line 108 of file RootOutputFile.h.

Referenced by finishEndFile(), RootOutputFile(), and writeParameterSetRegistry().

std::map<ParentageID,unsigned int> edm::RootOutputFile::parentageIDs_ [private]

Definition at line 124 of file RootOutputFile.h.

Referenced by insertProductProvenance(), and writeParentageRegistry().

Definition at line 109 of file RootOutputFile.h.

Referenced by finishEndFile(), RootOutputFile(), and writeParentageRegistry().

Definition at line 117 of file RootOutputFile.h.

Referenced by RootOutputFile(), and writeOne().

Definition at line 112 of file RootOutputFile.h.

Referenced by RootOutputFile(), and writeOne().

Definition at line 116 of file RootOutputFile.h.

Referenced by RootOutputFile(), and writeOne().

Definition at line 118 of file RootOutputFile.h.

Referenced by RootOutputFile(), and writeOne().

Definition at line 113 of file RootOutputFile.h.

Referenced by RootOutputFile().

Definition at line 114 of file RootOutputFile.h.

Referenced by RootOutputFile().

Definition at line 97 of file RootOutputFile.h.

Referenced by beginInputFile(), finishEndFile(), RootOutputFile(), and writeOne().

Definition at line 111 of file RootOutputFile.h.

Referenced by writeRun().

Definition at line 105 of file RootOutputFile.h.

Referenced by writeRun().

Definition at line 121 of file RootOutputFile.h.

Referenced by respondToCloseInputFile(), RootOutputFile(), and writeRun().

Definition at line 122 of file RootOutputFile.h.

Referenced by fillBranches(), finishEndFile(), and RootOutputFile().

Definition at line 99 of file RootOutputFile.h.

Referenced by beginInputFile(), and fillBranches().