1#ifndef __JROOT__JTREEWRITER__
2#define __JROOT__JTREEWRITER__
4#pragma GCC diagnostic push
5#pragma GCC diagnostic ignored "-Wall"
8#pragma GCC diagnostic pop
18namespace JPP {
using namespace JROOT; }
34 template<
class T,
bool flat = false>
91 using TTree::GetBranch;
118 TClass* t_class = TClass::GetClass<T>();
120 if (t_class ==
nullptr) {
124 TIter next(t_class->GetListOfRealData());
125 TRealData* data{
nullptr};
128 auto* base =
reinterpret_cast<uint8_t*
>(&object);
130 while ((data =
dynamic_cast<TRealData*
>(next())) !=
nullptr) {
134 auto* member = data->GetDataMember();
135 auto*
address =
reinterpret_cast<uint8_t*
>(base + member->GetOffset());
136 std::string type_name = data->GetDataMember()->GetTypeName();
138 if (member->GetArrayDim() > 0) {
144 if (type_code.empty()) {
148 std::string leaf = data->GetName();
149 leaf +=
"/" + type_code;
150 auto branch = Branch(data->GetName(),
address, leaf.c_str());
152 branches_.push_back(
branch);
153 offsets_ .push_back(member->GetOffset());
166 auto* base =
const_cast<uint8_t*
>(
reinterpret_cast<const uint8_t*
>(&object));
168 for (
size_t i = 0; i < branches_.size(); i++) {
169 branches_[i]->SetAddress(
reinterpret_cast<uint8_t*
>(base + offsets_[i]));
180#if ROOT_VERSION_CODE <= ROOT_VERSION(6,26,0)
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Interface for binary input.
Implementation for template TTree writing and copying.
virtual Int_t copy(JReader &in) override
Copy data.
JTreeCopyWriter(const JTreeCopyWriter< T > &writer)
Hide copy constructor.
static JTreeCopyWriter< T > & getInstance()
Get reference to unique instance of this class object.
JTreeCopyWriter(const JTreeParameters &tree)
Constructor.
Data structure for TTree parameters.
int getBasketSize() const
Get basket size.
const JTreeParameters & getTreeParameters() const
Get TTree parameters.
Long64_t getAutoFlush() const
Get auto flush.
int getCompressionLevel() const
Get compression level.
int getSplitLevel() const
Get split level.
const TString & getBranchName() const
Get TBranch name.
const TString & getTreeTitle() const
Get TTree title.
const TString & getTreeName() const
Get TTree name.
std::vector< TBranch * > branches_
JTreeWriter(const JTreeParameters ¶meters)
Constructor.
std::vector< Long_t > offsets_
Int_t Write(const T &object)
Data object output equivalent of TTree::Fill().
Auxiliary class for default template TTree writing.
JTreeWriter(const JTreeParameters ¶meters=JROOT::getTreeParameters< T >())
Constructor.
const TBranch * GetBranch() const
Get the pointer to the unique TBranch belonging this TTree.
const T * address
Pointer to unique object belonging to this TTree.
TBranch * branch
Pointer to unique branch belonging to this TTree.
Int_t Write(const T &object)
Data object output equivalent of TTree::Fill().
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
JTreeParameters & getTreeParameters()
Template definition for method returning TTree parameters.
JTreeCopyWriter< T > & getTreeCopyWriter()
Get the TTree writer and copy for this type of object.
static std::string getTypeCode(const std::string &type_name)
Return the type code (used to create primitive leaves in basic Root tree branches) corresponding to t...
static bool is_tobject_member(const char *name)
Check if name is one of TObject own data members (fBits or fUniqueID, for ROOT <= 6....
Interface for template TTree writing and copying.
virtual Int_t copy(JReader &in)=0
Copy data.