//////////////////////////////////////////////////////////////////////// /// \class RAT::DU::DSReader /// /// \brief Convenience class for ROOT scripts /// /// \author Stan Seibert /// \author P G Jones /// \author J R Wilson -- contact person /// /// REVISION HISTORY:\n /// 20/07/2011 : P G Jones - Added methods to return the Run object.\n /// 2014-03-26 : P G Jones - Refactor for ds review, moved from src/io.\n /// 2014-12-16 : J Walker - Add method to get Meta information. \n /// 2015-27-05 : N Barros - Add initialization of run in the DB with runID. \n /// 2017-15-05 : N Barros - Changed DSReader to load RATDB default plane lock if input file /// is either data, or run number is not 0 /// /// \details This is the recommended/best way to read a RAT::DS root file. /// Use as follows, /// @verbatim /// DSReader dsReader("filename.root"); /// /// for( size_t iEntry = 0; iEntry < dsReader.GetEntryCount(); iEntry++ ) /// { /// RAT::DS::Entry rDS = dsReader.GetEntry( iEntry ); /// RAT::DS::Run rRun = dsReader.GetRun(); /// } /// @endverbatim /// //////////////////////////////////////////////////////////////////////// #ifndef __RAT_DU_DSReader___ #define __RAT_DU_DSReader___ #include #include #include #include namespace RAT { namespace DS { class Entry; class Run; class Meta; } namespace DU { class DSReader : public TObject { public: /// Construct the DSReader with a filename (inc path) /// /// @param[in] filename to open /// @param[in] useMeta to configure DB or ignore it? DSReader( const std::string& filename, const bool useMeta=true ); /// Construct the DSReader with many files to TChain together /// /// @param[in] filenames to open /// @param[in] useMeta to configure DB or ignore it? DSReader( const std::vector& filenames, const bool useMeta=true ); /// Destruct the DSReader, delete TTrees etc... ~DSReader(); /// Called whenever the run changes void BeginOfRun(); /// Add a new file to the total (should restart any loops!) /// /// @param[in] filename to add void Add( const std::string& filename ); /// Get the entry at index entry /// /// @param[in] entry index of the entry to return /// @return a constant reference to the entry /// @throws DataNotFound if entry is out of range const DS::Entry& GetEntry( const size_t entry ); /// Get the count of entries /// /// @return the total number of entries size_t GetEntryCount() { return fTotalEntries; } /// Get the run. /// /// @return a constant reference to the run const DS::Run& GetRun(); /// Get the run with run ID /// /// @param[in] runID runID to find /// @return a constant reference to the run /// @throws DataNotFound if not appropriate run can be found const DS::Run& GetRunByRunID( const unsigned int runID ); /// Get the run with index /// /// @param[in] index of the run to return /// @return a constant reference to the run /// @throws DataNotFound if index is out of range const DS::Run& GetRunByIndex( const size_t index ); /// Get the count of runs /// /// @return the total number of runs size_t GetRunCount() { return fTotalRuns; } /// Get the Meta information /// /// @return a constant reference to the Meta information const DS::Meta& GetMeta() const { return *fMeta; } // This ROOT macro adds dictionary methods to this class. // The number is 0 as this class is never, and should never be written to disc. // It assumes this class has no virtual methods, use ClassDef if change this. ClassDefNV(DSReader, 1); protected: TChain* fT; ///< The DS T Tree TChain* fRunT; ///< The DS runT Tree DS::Entry* fDS; ///< The current entry DS::Run* fRun; ///< The current run DS::Meta* fMeta; ///< The current Meta information ULong64_t fCurrentEntry; ///< The current entry index ULong64_t fTotalEntries; ///< The total number of entries ULong64_t fCurrentRun; ///< The current run index ULong64_t fTotalRuns; ///< The total number of runs bool fUseMeta; ///< Flag to use or ignore Meta information in file. Default true. }; } // namespace DU } // namespace RAT #endif