#ifndef __JROOT__JTREEPARAMETERS__ #define __JROOT__JTREEPARAMETERS__ #include #include #include "TString.h" #include "JLang/JType.hh" #include "JLang/JNullType.hh" /** * \author mdejong */ namespace JROOT {} namespace JPP { using namespace JROOT; } namespace JROOT { using JLANG::JType; using JLANG::JNullType; /** * Data structure for TTree parameters. */ class JTreeParameters { public: /** * Constructor. * * \param treeName TTree name * \param treeTitle TTree title * \param branchName TBranch name * \param compressionLevel TBranch compression level * \param basketSize TBranch basket size * \param splitLevel TBranch split level */ JTreeParameters(const TString& treeName, const TString& treeTitle, const TString& branchName = "", const int compressionLevel = 1, const int basketSize = 65536, const int splitLevel = 1) { this->treeName = treeName; this->treeTitle = treeTitle; this->branchName = branchName; this->compressionLevel = compressionLevel; this->basketSize = basketSize; this->splitLevel = splitLevel; } /** * Get TTree parameters. * * \return TTree parameters */ inline const JTreeParameters& getTreeParameters() const { return static_cast(*this); } /** * Get TTree name. * * \return TTree name */ const TString& getTreeName() const { return treeName; } /** * Get TTree title. * * \return TTree title */ const TString& getTreeTitle() const { return treeTitle; } /** * Get TBranch name. * * \return TBranch name */ const TString& getBranchName() const { return (branchName != "" ? branchName : treeName); } /** * Get compression level. * * \return compression level */ int getCompressionLevel() const { return compressionLevel; } /** * Get basket size. * * \return basket size */ int getBasketSize() const { return basketSize; } /** * Get split level. * * \return split level */ int getSplitLevel() const { return splitLevel; } /** * Write TTree parameters to output. * * \param out output stream * \param object TTree parameters * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JTreeParameters& object) { using namespace std; return out << setw(24) << left << object.getTreeName() << right << ' ' << setw(24) << left << object.getBranchName() << right << ' ' << setw(1) << object.getCompressionLevel() << ' ' << setw(8) << object.getBasketSize() << ' ' << setw(1) << object.getSplitLevel(); } protected: TString treeName; //!< TTree name TString treeTitle; //!< TTree title TString branchName; //!< TBranch name int compressionLevel; //!< TBranch compression level int basketSize; //!< TBranch basket size int splitLevel; //!< TBranch split level }; /** * Template definition for method returning TTree parameters. * The template argument refers to the class for which ROOT TTree I/O is desired. * * \return TTree parameters */ template inline JTreeParameters getTreeParameters() { return getTreeParameters(JType()); } /** * Method with argument definition for obtaining TTree parameters. * The method argument refers to the class for which ROOT TTree I/O is desired. * This method should then be overloaded and the overloaded method should * return a JTreeParameters object with the corresponding TTree parameters. * * \param type data type * \return TTree parameters */ template inline JNullType getTreeParameters(const JType& type); /** * Test availability of TTree parameters for given class. * * The parameter result evaluates to true if for this class TTree parameters are defined. */ template class JTreeParametersAvailable { private: class JSmall { char buffer; }; class JBig { int buffer; }; static JBig JTest(...); static JSmall JTest(const JTreeParameters&); public: static const bool result = sizeof(JTest(getTreeParameters(JType()))) == sizeof(JSmall); //!< true if TTree parameters available; else false }; } #endif