#ifndef __JROOT__JTREEREADER__ #define __JROOT__JTREEREADER__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wall" #include "TFile.h" #include "TTree.h" #include "TDictionary.h" #pragma GCC diagnostic pop #include "JROOT/JRootAddress.hh" #include "JROOT/JTreeParameters.hh" #include "JLang/JPointer.hh" /** * \file * TTree reading for template data type. * \author mdejong */ namespace JROOT {} namespace JPP { using namespace JROOT; } namespace JROOT { using JLANG::JPointer; /** * Interface for TTree reading. */ struct JAbstractTreeReader : public JPointer { /** * Load TTree from given file. * * \param file pointer to file * \return true when TTree correctly loaded; else false */ virtual bool load(TFile* file) = 0; /** * Get ROOT dictionary. * * \return dictionary. */ virtual const TDictionary* getDictionary() = 0; }; /** * Auxiliary class for template TTree reading. */ template class JTreeReader : public JAbstractTreeReader, public JTreeParameters, public JRootAddress { public: /** * Constructor. * * Note that the default TTree parameters are obtained using method JROOT::getTreeParameters. * * \param parameters parameters of TTree */ JTreeReader(const JTreeParameters& parameters = JROOT::getTreeParameters()) : JTreeParameters(parameters) {} /** * Load TTree from given file. * * This methods releases the pending memory allocated from previous data reading. * * \param file pointer to file * \return true when TTree correctly loaded; else false */ virtual bool load(TFile* file) override { this->release(); if (file != NULL) { this->set(dynamic_cast(file->Get(this->getTreeName()))); if (this->is_valid()) { this->get()->SetBranchAddress(this->getBranchName(), &this->address); return true; } } return false; } /** * Get ROOT dictionary. * * \return dictionary. */ virtual const TDictionary* getDictionary() override { return TDictionary::GetDictionary(T::Class_Name()); } }; } #endif