#ifndef __JROOT__JTREEWRITEROBJECTOUTPUT__ #define __JROOT__JTREEWRITEROBJECTOUTPUT__ #include "JLang/JTypeList.hh" #include "JLang/JNullType.hh" #include "JLang/JObjectOutput.hh" #include "JROOT/JTreeWriter.hh" /** * \author mdejong */ namespace JROOT {} namespace JPP { using namespace JROOT; } namespace JROOT { using JLANG::JObjectOutput; using JLANG::JTypeList; using JLANG::JNullType; template class JRootCreateFlatTree : public std::false_type {}; /** * JTreeWriter object output. * * This class implements the JLANG::JObjectOutput interface. */ template class JTreeWriterObjectOutput : public virtual JObjectOutput { protected: /** * Default constructor. */ JTreeWriterObjectOutput() : out(new JTreeWriter::value>(getTreeParameters())), del(true) {} /** * Destructor. */ ~JTreeWriterObjectOutput() { if (del) { delete out; } } /** * Set directory. * * \param dir pointer to directory */ void SetDirectory(TDirectory* dir) { out->SetDirectory(dir); del = (dir == NULL); } JTreeWriter::value>* out; bool del; // delete TTree on destruction public: /** * Get TreeWriter. * * \return TreeWriter */ JTreeWriter& getTreeWriter() { return *out; } /** * Object output. * * \param object object * \return true if OK; else false */ virtual bool put(const T& object) override { return (out->Write(object) > 0); } /** * Set circular buffer size. * * \param size number of entries */ void SetCircular(Long64_t size) { out->SetCircular(size); } /** * Reset TTree. */ void Reset() { out->Reset(); } private: JTreeWriterObjectOutput(const JTreeWriterObjectOutput&); JTreeWriterObjectOutput(JTreeWriterObjectOutput&&); JTreeWriterObjectOutput& operator=(const JTreeWriterObjectOutput&); JTreeWriterObjectOutput& operator=(JTreeWriterObjectOutput&&); }; /** * Implementation of JTreeWriterObjectOutput for multiple data types. * * This class recursively implements the JLANG::JObjectOutput interface * for all data types by deriving from: * - JTreeWriterObjectOutput; and * - JTreeWriterObjectOutput. */ template class JTreeWriterObjectOutput< JTypeList > : public virtual JObjectOutput< JTypeList >, public JTreeWriterObjectOutput, public JTreeWriterObjectOutput { protected: /** * Set directory. * * \param dir pointer to directory */ void SetDirectory(TDirectory* dir) { JTreeWriterObjectOutput::SetDirectory(dir); JTreeWriterObjectOutput::SetDirectory(dir); } public: using JTreeWriterObjectOutput::put; using JTreeWriterObjectOutput::put; /** * Set circular buffer size. * * \param size number of entries */ void SetCircular(Long64_t size) { JTreeWriterObjectOutput::SetCircular(size); JTreeWriterObjectOutput::SetCircular(size); } /** * Reset TTree. */ void Reset() { JTreeWriterObjectOutput::Reset(); JTreeWriterObjectOutput::Reset(); } }; /** * Terminator class of recursive JTreeWriterObjectOutput class. */ template class JTreeWriterObjectOutput< JTypeList > : public JTreeWriterObjectOutput {}; } #endif