Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JROOT::JRootTypewriter Class Reference

ROOT type writer. More...

#include <JRootTypewriter.hh>

Inheritance diagram for JROOT::JRootTypewriter:
std::map< std::string, std::shared_ptr< JAbstractTypewriter > >

Public Member Functions

 JRootTypewriter ()
 Default constructor.
 
template<class T >
void operator() (std::ostream &out, const T &object) const
 Print object.
 
void operator() (std::ostream &out, const JRootWritableClass &object) const
 Print object.
 
void operator() (std::ostream &out, TVirtualStreamerInfo *info, const char *ps) const
 Print object.
 
void operator() (std::ostream &out, const JBranchClass &object) const
 Print object.
 
template<class T >
void operator() (const JType< T > &type)
 Addition of class.
 

Protected Member Functions

void print (std::ostream &out, const std::string prefix, const char *type, const char *object) 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.
 
template<class TArray_t >
void print (std::ostream &out, const std::string prefix, const TArray *pA) const
 Print TArray.
 
void print (std::ostream &out, const std::string prefix, const JRootWritableClass &object) const
 Print object.
 
void print (std::ostream &out, const std::string prefix, TVirtualStreamerInfo *info, const char *ps) const
 Print object.
 

Detailed Description

ROOT type writer.

Definition at line 259 of file JRootTypewriter.hh.

Constructor & Destructor Documentation

◆ JRootTypewriter()

JROOT::JRootTypewriter::JRootTypewriter ( )
inline

Default constructor.

Definition at line 266 of file JRootTypewriter.hh.

267 {
268 using namespace JPP;
269
270 for_each<JRemove<JPrimitiveTypes_t, long double>::typelist>(*this);
271
272 (*this)(JType<std::string>());
273 (*this)(JType<std::size_t>());
274
275#define VALUE_TYPE(__TYPE__) value_type(#__TYPE__, new JObjectTypewriter<__TYPE__>())
276
277 this->insert(VALUE_TYPE(Char_t));
278 this->insert(VALUE_TYPE(UChar_t));
279 this->insert(VALUE_TYPE(Short_t));
280 this->insert(VALUE_TYPE(UShort_t));
281 this->insert(VALUE_TYPE(Int_t));
282 this->insert(VALUE_TYPE(UInt_t));
283 this->insert(VALUE_TYPE(Long_t));
284 this->insert(VALUE_TYPE(ULong_t));
285 this->insert(VALUE_TYPE(Long64_t));
286 this->insert(VALUE_TYPE(ULong64_t));
287 this->insert(VALUE_TYPE(Float_t));
288 this->insert(VALUE_TYPE(Double_t));
289 this->insert(VALUE_TYPE(TString));
290
291#undef VALUE_TYPE
292 }
#define VALUE_TYPE(__TYPE__)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for a type holder.
Definition JType.hh:19

Member Function Documentation

◆ operator()() [1/5]

template<class T >
void JROOT::JRootTypewriter::operator() ( std::ostream & out,
const T & object ) const
inline

Print object.

Parameters
outoutput stream
objectobject

Definition at line 302 of file JRootTypewriter.hh.

303 {
304 (*this)(out, JRootWritableClass(object));
305 }

◆ operator()() [2/5]

void JROOT::JRootTypewriter::operator() ( std::ostream & out,
const JRootWritableClass & object ) const
inline

Print object.

Parameters
outoutput stream
objectobject

Definition at line 314 of file JRootTypewriter.hh.

315 {
316 this->print(out, object.getTypename(), object);
317 }
void print(std::ostream &out, const std::string prefix, const char *type, const char *object) const
Print object.

◆ operator()() [3/5]

void JROOT::JRootTypewriter::operator() ( std::ostream & out,
TVirtualStreamerInfo * info,
const char * ps ) const
inline

Print object.

Parameters
outoutput stream
infopointer to streamer information
pspointer to data

Definition at line 327 of file JRootTypewriter.hh.

328 {
329 this->print(out, info->GetClass()->GetName(), info, ps);
330 }

◆ operator()() [4/5]

void JROOT::JRootTypewriter::operator() ( std::ostream & out,
const JBranchClass & object ) const
inline

Print object.

Parameters
outoutput stream
objectobject

Definition at line 339 of file JRootTypewriter.hh.

340 {
341 if (object.getClass() != NULL)
342 this->print(out, object.getName(), object.getClass()->GetStreamerInfo(), static_cast<const JRootReadableClass&>(object).getAddress());
343 else
344 this->print(out, object.getName(), object.getDictionary()->GetName(), static_cast<const JRootReadableClass&>(object).getAddress());
345 }
const char * getName()
Get ROOT name of given data type.

◆ operator()() [5/5]

template<class T >
void JROOT::JRootTypewriter::operator() ( const JType< T > & type)
inline

Addition of class.

Parameters
typedata type

Definition at line 354 of file JRootTypewriter.hh.

355 {
356 this->insert(value_type(JRoot::getTypename<T>(), new JObjectTypewriter<T>()));
357 }
static const char * getTypename()
Get ROOT typename for given template class.
Definition JRoot.hh:138

◆ print() [1/5]

void JROOT::JRootTypewriter::print ( std::ostream & out,
const std::string prefix,
const char * type,
const char * object ) const
inlineprotected

Print object.

Parameters
outoutput stream
prefixprefix
typetype
objectpointer to object

Definition at line 369 of file JRootTypewriter.hh.

370 {
371 using namespace std;
372
373 const_iterator i1 = this->find(type);
374
375 out << prefix;
376 out << " <" << type << "> ";
377
378 if (i1 != this->end())
379 i1->second->print(out, object);
380 else
381 out << "?";
382
383 out << endl;
384 }

◆ print() [2/5]

void JROOT::JRootTypewriter::print ( std::ostream & out,
const std::string prefix,
const char * type,
const char * ps,
const size_t ns,
const size_t size ) const
inlineprotected

Print array of objects.

Parameters
outoutput stream
prefixprefix
typetype
pspointer to begin of array
nsnumber of elements
sizesize of element

Definition at line 397 of file JRootTypewriter.hh.

398 {
399 using namespace std;
400
401 const_iterator i1 = this->find(type);
402
403 out << prefix;
404 out << " <" << type << "> ";
405
406 if (i1 != this->end()) {
407
408 for (size_t i = 0; i != ns; ++i) {
409 i1->second->print(out, ps + i * size);
410 }
411
412 } else {
413
414 out << "?";
415 }
416
417 out << endl;
418 }

◆ print() [3/5]

template<class TArray_t >
void JROOT::JRootTypewriter::print ( std::ostream & out,
const std::string prefix,
const TArray * pA ) const
inlineprotected

Print TArray.

Parameters
outoutput stream
prefixprefix
pApointer to array

Definition at line 429 of file JRootTypewriter.hh.

430 {
431 using namespace std;
432
433 const TArray_t* p = dynamic_cast<const TArray_t*>(pA);
434
435 if (p != NULL) {
436 for (Int_t i = 0; i != p->GetSize(); ++i) {
437 out << prefix << "[" << i << "]" << ' ' << p->At(i) << endl;
438 }
439 }
440 }

◆ print() [4/5]

void JROOT::JRootTypewriter::print ( std::ostream & out,
const std::string prefix,
const JRootWritableClass & object ) const
inlineprotected

Print object.

Parameters
outoutput stream
prefixprefix
objectobject

Definition at line 450 of file JRootTypewriter.hh.

451 {
452 using namespace std;
453
454 if (object.is_valid()) {
455
456 if (this->count(object.getTypename()) != 0) {
457
458 this->print(out, prefix, object.getTypename(), object.getAddress());
459
460 } else if (object.getClass() != NULL) {
461
462 if (object.getClass() == TArray::Class()) {
463
464 TArray* p = (TArray*) (object.getAddress());
465
466 if (p->GetSize() == 0) {
467 out << prefix << " <" << p->IsA()->GetName() << "> " << "{}" << endl;
468 } else {
469 print<TArrayC>(out, prefix, p);
470 print<TArrayS>(out, prefix, p);
471 print<TArrayI>(out, prefix, p);
472 print<TArrayL>(out, prefix, p);
473 print<TArrayF>(out, prefix, p);
474 print<TArrayD>(out, prefix, p);
475 }
476
477 } else if (object.getClass() == TList::Class()) {
478
479 int i = 0;
480
481 for (TIter next((TList*) object.getAddress()); const TObject *p1 = (const TObject*) next(); ++i) {
482 print(out, prefix + "[" + to_string(i) + "]", JRootWritableClass(p1->IsA(), (const char*) p1));
483 }
484
485 } else if (object.getClass()->GetCollectionProxy() != NULL) {
486
487 unique_ptr<TVirtualCollectionProxy> p1(object.getClass()->GetCollectionProxy()->Generate());
488
489 p1->PushProxy(const_cast<char*>(object.getAddress()));
490
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));
494 }
495 } else {
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));
498 }
499 }
500
501 } else {
502
503 if (object.getClass()->GetListOfBases() != NULL) {
504
505 for (TIter next(object.getClass()->GetListOfBases()); const TBaseClass *p1 = (const TBaseClass*) next(); ) {
506
507 if (JRoot::is_class(p1->GetName())) {
508 this->print(out, prefix, object.get(*p1));
509 }
510 }
511 }
512
513 if (object.getClass()->GetListOfDataMembers() != NULL) {
514
515 if (!object.getClass()->InheritsFrom(TClass::GetClass<TArray>())) {
516
517 for (TIter next(object.getClass()->GetListOfDataMembers()); const TDataMember *p1 = (const TDataMember*) next(); ) {
518
519 if (JRoot::is_class(p1->GetName()) && !JRoot::is_static(*p1)) {
520
521 if (!p1->IsEnum() && p1->IsPersistent()) {
522 this->print(out, prefix + "." + p1->GetName(), object.get(*p1));
523 }
524 }
525 }
526 }
527 }
528 }
529 }
530 }
531 }
TPaveText * p1
std::string to_string(const T &value)
Convert value to string.
bool is_valid(const json &js)
Check validity of JSon data.
static bool is_class(const char *const name)
Check name of class against internal ROOT class names.
Definition JRoot.hh:30
static bool is_static(const TDataMember &object)
Check if data member is static.
Definition JRoot.hh:109

◆ print() [5/5]

void JROOT::JRootTypewriter::print ( std::ostream & out,
const std::string prefix,
TVirtualStreamerInfo * info,
const char * ps ) const
inlineprotected

Print object.

Parameters
outoutput stream
prefixprefix
infopointer to streamer information
pspointer to data

Definition at line 542 of file JRootTypewriter.hh.

543 {
544 using namespace std;
545
546 if (info != NULL) {
547
548 for (TIter next(info->GetElements()); TStreamerElement* ts = dynamic_cast<TStreamerElement*>(next()); ) {
549
550 if (this->count(ts->GetTypeName()) != 0) {
551
552 if (ts->GetArrayLength() == 0)
553 this->print(out, prefix + "." + ts->GetName(), ts->GetTypeName(), ps + ts->GetOffset());
554 else
555 this->print(out, prefix + "." + ts->GetName(), ts->GetTypeName(), ps + ts->GetOffset(), ts->GetArrayLength(), ts->GetSize() / ts->GetArrayLength());
556
557 } else if (ts->GetClass() != NULL) {
558
559 if (ts->IsaPointer()) {
560
561 char* po = NULL;
562
563 memcpy(&po, ps + ts->GetOffset(), sizeof(char*));
564
565 if (po != NULL) {
566
567 if (ts->GetClass()->InheritsFrom(TList::Class())) {
568
569 this->print(out, prefix + "." + ts->GetName(), JRootWritableClass(TList::Class(), po));
570
571 } else {
572
573 this->print(out, prefix + "." + ts->GetName(), ts->GetClass()->GetStreamerInfo(), po);
574 }
575
576 } else {
577
578 out << prefix << "." << ts->GetName() << " <" << ts->GetTypeName() << "> " << "NULL" << endl;
579 }
580
581 } else if (ts->GetClass()->InheritsFrom(TArray::Class())) {
582
583 print(out, prefix + "." + ts->GetName(), JRootWritableClass(TArray::Class(), ps + ts->GetOffset()));
584
585 } else if (ts->GetClass()->InheritsFrom(TDirectory::Class())) {
586
587 // do nothing
588
589 } else if (ts->GetClass()->GetCollectionProxy() != NULL) {
590
591 print(out, prefix + "." + ts->GetName(), JRootWritableClass(ts->GetClass(), ps + ts->GetOffset()));
592
593 } else {
594
595 if (JRoot::is_class(ts->GetName())) {
596 this->print(out, prefix + "." + ts->GetName(), ts->GetClass()->GetStreamerInfo(), ps + ts->GetOffset());
597 }
598 }
599 }
600 }
601 }
602 }

The documentation for this class was generated from the following file: