CMS 3D CMS Logo

RootOutputFile.h

Go to the documentation of this file.
00001 #ifndef IOPool_Output_RootOutputFile_h
00002 #define IOPool_Output_RootOutputFile_h
00003 
00005 //
00006 // Class RootOutputFile
00007 //
00008 // Oringinal Author: Luca Lista
00009 // Current Author: Bill Tanenbaum
00010 //
00012 
00013 #include <map>
00014 #include <string>
00015 #include <vector>
00016 
00017 #include "boost/array.hpp"
00018 #include "boost/shared_ptr.hpp"
00019 
00020 #include "FWCore/Framework/interface/Frameworkfwd.h"
00021 #include "FWCore/MessageLogger/interface/JobReport.h"
00022 #include "DataFormats/Provenance/interface/BranchDescription.h"
00023 #include "DataFormats/Provenance/interface/BranchID.h"
00024 #include "DataFormats/Provenance/interface/BranchType.h"
00025 #include "DataFormats/Provenance/interface/FileID.h"
00026 #include "DataFormats/Provenance/interface/FileIndex.h"
00027 #include "DataFormats/Provenance/interface/Selections.h"
00028 #include "DataFormats/Provenance/interface/EventEntryInfo.h"
00029 #include "DataFormats/Provenance/interface/RunLumiEntryInfo.h"
00030 #include "IOPool/Output/src/PoolOutputModule.h"
00031 #include "IOPool/Output/src/RootOutputTree.h"
00032 
00033 class TTree;
00034 class TFile;
00035 #include "TROOT.h"
00036 
00037 namespace edm {
00038   class PoolOutputModule;
00039   class History;
00040 
00041   class RootOutputFile {
00042   public:
00043     typedef PoolOutputModule::OutputItem OutputItem;
00044     typedef PoolOutputModule::OutputItemList OutputItemList;
00045     typedef boost::array<RootOutputTree *, NumBranchTypes> RootOutputTreePtrArray;
00046     explicit RootOutputFile(PoolOutputModule * om, std::string const& fileName,
00047                             std::string const& logicalFileName);
00048     ~RootOutputFile() {}
00049     void writeOne(EventPrincipal const& e);
00050     //void endFile();
00051     void writeLuminosityBlock(LuminosityBlockPrincipal const& lb);
00052     void writeRun(RunPrincipal const& r);
00053     void writeEntryDescriptions();
00054     void writeFileFormatVersion();
00055     void writeFileIdentifier();
00056     void writeFileIndex();
00057     void writeEventHistory();
00058     void writeProcessConfigurationRegistry();
00059     void writeProcessHistoryRegistry();
00060     void writeModuleDescriptionRegistry();
00061     void writeParameterSetRegistry();
00062     void writeProductDescriptionRegistry();
00063     void writeProductDependencies();
00064 
00065     void finishEndFile();
00066     void beginInputFile(FileBlock const& fb, bool fastClone);
00067     void respondToCloseInputFile(FileBlock const& fb);
00068     bool shouldWeCloseFile() const;
00069 
00070   private:
00071 
00072     //-------------------------------
00073     // Local types
00074     //
00075     typedef EventEntryInfo::EntryInfoVector EventEntryInfoVector;
00076     typedef LumiEntryInfo::EntryInfoVector LumiEntryInfoVector;
00077     typedef RunEntryInfo::EntryInfoVector RunEntryInfoVector;
00078 
00079     //-------------------------------
00080     // Private functions
00081 
00082     void setBranchAliases(TTree *tree, Selections const& branches) const;
00083 
00084     template <typename T>
00085     void fillBranches(BranchType const& branchType, Principal const& principal, std::vector<T> * entryInfoVecPtr);
00086 
00087      template <typename T>
00088      static void insertAncestors(const T& iParents,
00089                           const BranchMapper& iMapper,
00090                           std::set<T>& oToFill);
00091 
00092      void insertAncestors(const EventEntryInfo& iGetParents,
00093                           const BranchMapper& iMapper,
00094                           std::set<EventEntryInfo>& oToFill);
00095         
00096     //-------------------------------
00097     // Member data
00098 
00099     std::string file_;
00100     std::string logicalFile_;
00101     JobReport::Token reportToken_;
00102     PoolOutputModule const* om_;
00103     bool currentlyFastCloning_;
00104     boost::shared_ptr<TFile> filePtr_;
00105     FileID fid_;
00106     FileIndex fileIndex_;
00107     FileIndex::EntryNumber_t eventEntryNumber_;
00108     FileIndex::EntryNumber_t lumiEntryNumber_;
00109     FileIndex::EntryNumber_t runEntryNumber_;
00110     TTree * metaDataTree_;
00111     TTree * entryDescriptionTree_;
00112     TTree * eventHistoryTree_;
00113     EventAuxiliary const*           pEventAux_;
00114     LuminosityBlockAuxiliary const* pLumiAux_;
00115     RunAuxiliary const*             pRunAux_;
00116     EventEntryInfoVector            eventEntryInfoVector_;
00117     LumiEntryInfoVector             lumiEntryInfoVector_;
00118     RunEntryInfoVector              runEntryInfoVector_;
00119     EventEntryInfoVector *          pEventEntryInfoVector_;
00120     LumiEntryInfoVector *           pLumiEntryInfoVector_;
00121     RunEntryInfoVector *            pRunEntryInfoVector_;
00122     History const*                  pHistory_;
00123     RootOutputTree eventTree_;
00124     RootOutputTree lumiTree_;
00125     RootOutputTree runTree_;
00126     RootOutputTreePtrArray treePointers_;
00127     bool dataTypeReported_;
00128     std::set<BranchID> branchesWithStoredHistory_;
00129   };
00130    
00131    //Used by the 'fillBranches' code
00132    template <typename T>
00133    void RootOutputFile::insertAncestors(const T& iGetParents,
00134                                         const BranchMapper& iMapper,
00135                                         std::set<T>& oToFill) {
00136       //do nothing
00137    }
00138 
00139    
00140    
00141   template <typename T>
00142   void RootOutputFile::fillBranches(
00143                 BranchType const& branchType,
00144                 Principal const& principal,
00145                 std::vector<T> * entryInfoVecPtr) {
00146 
00147     std::vector<boost::shared_ptr<EDProduct> > dummies;
00148 
00149     bool const fastCloning = (branchType == InEvent) && currentlyFastCloning_;
00150     
00151     OutputItemList const& items = om_->selectedOutputItemList()[branchType];
00152 
00153     std::set<T> keep;
00154 
00155     std::set<T> keepPlusAncestors;
00156 
00157     // Loop over EDProduct branches, fill the provenance, and write the branch.
00158     for (OutputItemList::const_iterator i = items.begin(), iEnd = items.end(); i != iEnd; ++i) {
00159 
00160       BranchID const& id = i->branchDescription_->branchID();
00161       branchesWithStoredHistory_.insert(id);
00162        
00163       bool getProd = (i->branchDescription_->produced() ||
00164          !fastCloning || treePointers_[branchType]->uncloned(i->branchDescription_->branchName()));
00165 
00166       EDProduct const* product = 0;
00167       OutputHandle<T> const oh = principal.getForOutput<T>(id, getProd);
00168       if (!oh.entryInfo()) {
00169         // No product with this ID is in the event.
00170         // Create and write the provenance.
00171         if (i->branchDescription_->produced()) {
00172           keep.insert(T(i->branchDescription_->branchID(),
00173                       productstatus::neverCreated(),
00174                       i->branchDescription_->moduleDescriptionID()));
00175           keepPlusAncestors.insert(T(i->branchDescription_->branchID(),
00176                               productstatus::neverCreated(),
00177                               i->branchDescription_->moduleDescriptionID()));
00178         } else {
00179           keep.insert(T(i->branchDescription_->branchID(),
00180                       productstatus::dropped(),
00181                       i->branchDescription_->moduleDescriptionID()));
00182           keepPlusAncestors.insert(T(i->branchDescription_->branchID(),
00183                               productstatus::dropped(),
00184                               i->branchDescription_->moduleDescriptionID()));
00185         }
00186       } else {
00187         product = oh.wrapper();
00188         keep.insert(*oh.entryInfo());
00189         keepPlusAncestors.insert(*oh.entryInfo());
00190         assert(principal.branchMapperPtr());
00191         insertAncestors(*oh.entryInfo(),*principal.branchMapperPtr(),keepPlusAncestors);
00192       }
00193       if (getProd) {
00194         if (product == 0) {
00195           // No product with this ID is in the event.
00196           // Add a null product.
00197           TClass *cp = gROOT->GetClass(i->branchDescription_->wrappedName().c_str());
00198           boost::shared_ptr<EDProduct> dummy(static_cast<EDProduct *>(cp->New()));
00199           dummies.push_back(dummy);
00200           product = dummy.get();
00201         }
00202         i->product_ = product;
00203       }
00204     }
00205      
00206     if (om_->dropMetaData()) {
00207       entryInfoVecPtr->assign(keep.begin(),keep.end());
00208     } else {
00209       entryInfoVecPtr->assign(keepPlusAncestors.begin(),keepPlusAncestors.end());
00210     }
00211     treePointers_[branchType]->fillTree();
00212     entryInfoVecPtr->clear();
00213   }
00214 
00215 }
00216 
00217 #endif

Generated on Tue Jun 9 17:39:15 2009 for CMSSW by  doxygen 1.5.4