1#ifndef __JROOT_TYPEWRITER__
2#define __JROOT_TYPEWRITER__
10#include "TDictionary.h"
11#include "TVirtualCollectionProxy.h"
12#include "TStreamerInfo.h"
13#include "TStreamerElement.h"
14#include "TBaseClass.h"
15#include "TDataMember.h"
24#include "TDirectory.h"
33namespace JPP {
using namespace JROOT; }
58 virtual void print(std::ostream& out,
const char* po)
const = 0;
78 virtual void print(std::ostream& out,
const char* po)
const override
80 out << * ((
const T*) po);
94 const TString* str = (
const TString*) po;
97 out <<
"\"" << *str <<
"\"";
111 out <<
"\"" << * ((
const std::string*) po) <<
"\"";
126 out <<
"0x" << hex << (int) *po << dec;
141 out <<
"\0x" << hex << (
unsigned int) *po << dec;
170 if (this->
type != kOther_t) {
171 this->
address =
new char[TDataType::GetDataType(this->
type)->Size()];
186 this->
name = pb->GetName();
190 if (pb->GetExpectedType(cs, this->type) == 0) {
195 this->
dictionary = TDictionary::GetDictionary(TDataType::GetTypeName(this->
type));
197 if (this->
type != kOther_t) {
198 this->
address =
new char[TDataType::GetDataType(this->
type)->Size()];
210 if (this->
type != kOther_t) {
225 return this->
name.c_str();
260 public std::map<std::string, std::shared_ptr<JAbstractTypewriter> >
270 for_each<JRemove<JPrimitiveTypes_t, long double>::typelist>(*this);
275#define VALUE_TYPE(__TYPE__) value_type(#__TYPE__, new JObjectTypewriter<__TYPE__>())
316 this->
print(out,
object.getTypename(),
object);
327 void operator()(std::ostream& out, TVirtualStreamerInfo* info,
const char* ps)
const
329 this->
print(out, info->GetClass()->GetName(), info, ps);
341 if (
object.getClass() != NULL)
369 void print(std::ostream& out,
const std::string prefix,
const char* type,
const char*
object)
const
373 const_iterator i1 = this->find(type);
376 out <<
" <" << type <<
"> ";
378 if (i1 != this->end())
379 i1->second->print(out,
object);
397 void print(std::ostream& out,
const std::string prefix,
const char* type,
const char* ps,
const size_t ns,
const size_t size)
const
401 const_iterator i1 = this->find(type);
404 out <<
" <" << type <<
"> ";
406 if (i1 != this->end()) {
408 for (
size_t i = 0; i != ns; ++i) {
409 i1->second->print(out, ps + i * size);
428 template<
class TArray_t>
429 void print(std::ostream& out,
const std::string prefix,
const TArray* pA)
const
433 const TArray_t* p =
dynamic_cast<const TArray_t*
>(pA);
436 for (Int_t i = 0; i != p->GetSize(); ++i) {
437 out << prefix <<
"[" << i <<
"]" <<
' ' << p->At(i) << endl;
454 if (
object.is_valid()) {
456 if (this->count(
object.getTypename()) != 0) {
458 this->
print(out, prefix,
object.getTypename(),
object.getAddress());
460 }
else if (
object.getClass() != NULL) {
462 if (
object.getClass() == TArray::Class()) {
464 TArray* p = (TArray*) (
object.getAddress());
466 if (p->GetSize() == 0) {
467 out << prefix <<
" <" << p->IsA()->GetName() <<
"> " <<
"{}" << endl;
477 }
else if (
object.getClass() == TList::Class()) {
481 for (TIter next((TList*)
object.getAddress());
const TObject *
p1 = (
const TObject*) next(); ++i) {
485 }
else if (
object.getClass()->GetCollectionProxy() != NULL) {
487 unique_ptr<TVirtualCollectionProxy>
p1(
object.getClass()->GetCollectionProxy()->Generate());
489 p1->PushProxy(
const_cast<char*
>(
object.getAddress()));
491 if (
p1->GetValueClass() == NULL) {
492 for (UInt_t i = 0; i !=
p1->Size(); ++i) {
493 this->
print(out, prefix +
"[" + to_string(i) +
"]", TDataType::GetTypeName(
p1->GetType()), (
const char*)
p1->At(i));
496 for (UInt_t i = 0; i !=
p1->Size(); ++i) {
497 this->
print(out, prefix +
"[" + to_string(i) +
"]",
p1->GetValueClass()->GetStreamerInfo(), (
const char*)
p1->At(i));
503 if (
object.getClass()->GetListOfBases() != NULL) {
505 for (TIter next(
object.getClass()->GetListOfBases());
const TBaseClass *
p1 = (
const TBaseClass*) next(); ) {
508 this->
print(out, prefix,
object.get(*
p1));
513 if (
object.getClass()->GetListOfDataMembers() != NULL) {
515 if (!
object.getClass()->InheritsFrom(TClass::GetClass<TArray>())) {
517 for (TIter next(
object.getClass()->GetListOfDataMembers());
const TDataMember *
p1 = (
const TDataMember*) next(); ) {
521 if (!
p1->IsEnum() &&
p1->IsPersistent()) {
522 this->
print(out, prefix +
"." +
p1->GetName(),
object.get(*
p1));
542 void print(std::ostream& out,
const std::string prefix, TVirtualStreamerInfo* info,
const char* ps)
const
548 for (TIter next(info->GetElements()); TStreamerElement* ts =
dynamic_cast<TStreamerElement*
>(next()); ) {
550 if (this->count(ts->GetTypeName()) != 0) {
552 if (ts->GetArrayLength() == 0)
553 this->
print(out, prefix +
"." + ts->GetName(), ts->GetTypeName(), ps + ts->GetOffset());
555 this->
print(out, prefix +
"." + ts->GetName(), ts->GetTypeName(), ps + ts->GetOffset(), ts->GetArrayLength(), ts->GetSize() / ts->GetArrayLength());
557 }
else if (ts->GetClass() != NULL) {
559 if (ts->IsaPointer()) {
563 memcpy(&po, ps + ts->GetOffset(),
sizeof(
char*));
567 if (ts->GetClass()->InheritsFrom(TList::Class())) {
573 this->
print(out, prefix +
"." + ts->GetName(), ts->GetClass()->GetStreamerInfo(), po);
578 out << prefix <<
"." << ts->GetName() <<
" <" << ts->GetTypeName() <<
"> " <<
"NULL" << endl;
581 }
else if (ts->GetClass()->InheritsFrom(TArray::Class())) {
585 }
else if (ts->GetClass()->InheritsFrom(TDirectory::Class())) {
589 }
else if (ts->GetClass()->GetCollectionProxy() != NULL) {
596 this->
print(out, prefix +
"." + ts->GetName(), ts->GetClass()->GetStreamerInfo(), ps + ts->GetOffset());
Type list of primitive data types.
#define VALUE_TYPE(__TYPE__)
Interface for printing of a template class.
virtual void print(std::ostream &out, const char *po) const =0
Print object.
virtual ~JAbstractTypewriter()
Virtual destructor.
Implementation for printing of a template class.
virtual void print(std::ostream &out, const char *po) const override
Print object.
void operator()(std::ostream &out, TVirtualStreamerInfo *info, const char *ps) const
Print object.
void print(std::ostream &out, const std::string prefix, const char *type, const char *ps, const size_t ns, const size_t size) const
Print array of objects.
void print(std::ostream &out, const std::string prefix, const char *type, const char *object) const
Print object.
void operator()(std::ostream &out, const JBranchClass &object) const
Print object.
void print(std::ostream &out, const std::string prefix, const TArray *pA) const
Print TArray.
void print(std::ostream &out, const std::string prefix, TVirtualStreamerInfo *info, const char *ps) const
Print object.
void operator()(std::ostream &out, const T &object) const
Print object.
void operator()(std::ostream &out, const JRootWritableClass &object) const
Print object.
void print(std::ostream &out, const std::string prefix, const JRootWritableClass &object) const
Print object.
JRootTypewriter()
Default constructor.
void operator()(const JType< T > &type)
Addition of class.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
const char * getName()
Get ROOT name of given data type.
Auxiliary class for a type holder.
JBranchClass()
Default constructor.
JBranchClass(const JBranchClass &bc)
Copy constructor.
EDataType getType() const
Get type.
JBranchClass(TBranch *pb)
Constructor.
void * getAddress()
Get branch address.
~JBranchClass()
Destructor.
const char *const getName() const
Get name.
TDictionary * dictionary
pointer to ROOT dictionary
ROOT class for reading into object.
ROOT class for writing from object.
static bool is_class(const char *const name)
Check name of class against internal ROOT class names.
static bool is_static(const TDataMember &object)
Check if data member is static.
static const char * getTypename()
Get ROOT typename for given template class.