1 #ifndef __JROOT__JTREEWRITER__
2 #define __JROOT__JTREEWRITER__
4 #pragma GCC diagnostic push
5 #pragma GCC diagnostic ignored "-Wall"
8 #pragma GCC diagnostic pop
15 #include "TRealData.h"
18 namespace JPP {
using namespace JROOT; }
34 template<
class T,
bool flat = false>
88 using TTree::GetBranch;
115 TClass* t_class = TClass::GetClass<T>();
117 if (t_class ==
nullptr) {
121 TIter next(t_class->GetListOfRealData());
122 TRealData*
data{
nullptr};
125 auto* base =
reinterpret_cast<uint8_t*
>(&object);
127 while ((
data =
dynamic_cast<TRealData*
>(next())) !=
nullptr) {
131 auto* member =
data->GetDataMember();
132 auto*
address =
reinterpret_cast<uint8_t*
>(base + member->GetOffset());
133 std::string type_name =
data->GetDataMember()->GetTypeName();
135 if (member->GetArrayDim() > 0) {
141 if (type_code.empty()) {
145 std::string leaf =
data->GetName();
146 leaf +=
"/" + type_code;
149 branches_.push_back(
branch);
150 offsets_ .push_back(member->GetOffset());
163 auto* base =
const_cast<uint8_t*
>(
reinterpret_cast<const uint8_t*
>(&object));
165 for (
size_t i = 0; i < branches_.size(); i++) {
166 branches_[i]->SetAddress(
reinterpret_cast<uint8_t*
>(base + offsets_[i]));
177 #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 TString & getBranchName() const
Get TBranch name.
int getCompressionLevel() const
Get compression level.
int getSplitLevel() const
Get split level.
const TString & getTreeName() const
Get TTree name.
const TString & getTreeTitle() const
Get TTree title.
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.
JTreeCopyWriter< T > & getTreeCopyWriter()
Get the TTree writer and copy for this type of object.
static bool is_tobject_member(const char *name)
Check if name is one of TObject own data members (fBits or fUniqueID, for Root <= 6....
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...
Interface for template TTree writing and copying.
virtual Int_t copy(JReader &in)=0
Copy data.