Jpp 20.0.0-rc.8
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 char *const name, 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 146 of file JRootTypewriter.hh.

Constructor & Destructor Documentation

◆ JRootTypewriter()

JROOT::JRootTypewriter::JRootTypewriter ( )
inline

Default constructor.

Definition at line 153 of file JRootTypewriter.hh.

154 {
155 handler(*this);
156 }
void handler(JType_t &object)
Apply ROOT types handler to given object.

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 166 of file JRootTypewriter.hh.

167 {
168 (*this)(out, JRootWritableClass(object));
169 }

◆ operator()() [2/5]

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

Print object.

Parameters
outoutput stream
objectobject

Definition at line 178 of file JRootTypewriter.hh.

179 {
180 this->print(out, object.getTypename(), object);
181 }
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 191 of file JRootTypewriter.hh.

192 {
193 this->print(out, info->GetClass()->GetName(), info, ps);
194 }

◆ operator()() [4/5]

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

Print object.

Parameters
outoutput stream
objectobject

Definition at line 203 of file JRootTypewriter.hh.

204 {
205 if (object.getClass() != NULL)
206 this->print(out, object.getName(), object.getClass()->GetStreamerInfo(), static_cast<const JRootReadableClass&>(object).getAddress());
207 else
208 this->print(out, object.getName(), object.getDictionary()->GetName(), static_cast<const JRootReadableClass&>(object).getAddress());
209 }
const char * getName()
Get ROOT name of given data type.

◆ operator()() [5/5]

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

Addition of class.

Parameters
namedata name
typedata type

Definition at line 219 of file JRootTypewriter.hh.

220 {
221 this->insert(value_type(name, new JObjectTypewriter<T>()));
222 }

◆ 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 234 of file JRootTypewriter.hh.

235 {
236 using namespace std;
237
238 const_iterator i1 = this->find(type);
239
240 out << prefix;
241 out << " <" << type << "> ";
242
243 if (i1 != this->end())
244 i1->second->print(out, object);
245 else
246 out << "?";
247
248 out << endl;
249 }

◆ 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 262 of file JRootTypewriter.hh.

263 {
264 using namespace std;
265
266 const_iterator i1 = this->find(type);
267
268 out << prefix;
269 out << " <" << type << "> ";
270
271 if (i1 != this->end()) {
272
273 for (size_t i = 0; i != ns; ++i) {
274
275 out << (i != 0 ? " " : "");
276
277 i1->second->print(out, ps + i * size);
278 }
279
280 } else {
281
282 out << "?";
283 }
284
285 out << endl;
286 }

◆ 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 297 of file JRootTypewriter.hh.

298 {
299 using namespace std;
300
301 const TArray_t* p = dynamic_cast<const TArray_t*>(pA);
302
303 if (p != NULL) {
304 for (Int_t i = 0; i != p->GetSize(); ++i) {
305 out << prefix << "[" << i << "]" << ' ' << p->At(i) << endl;
306 }
307 }
308 }

◆ 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 318 of file JRootTypewriter.hh.

319 {
320 using namespace std;
321
322 if (object.is_valid()) {
323
324 if (this->count(object.getTypename()) != 0) {
325
326 this->print(out, prefix, object.getTypename(), object.getAddress());
327
328 } else if (object.getClass() != NULL) {
329
330 if (object.getClass() == TArray::Class()) {
331
332 TArray* p = (TArray*) (object.getAddress());
333
334 if (p->GetSize() == 0) {
335 out << prefix << " <" << p->IsA()->GetName() << "> " << "{}" << endl;
336 } else {
337 print<TArrayC>(out, prefix, p);
338 print<TArrayS>(out, prefix, p);
339 print<TArrayI>(out, prefix, p);
340 print<TArrayL>(out, prefix, p);
341 print<TArrayF>(out, prefix, p);
342 print<TArrayD>(out, prefix, p);
343 }
344
345 } else if (object.getClass() == TList::Class()) {
346
347 int i = 0;
348
349 for (TIter next((TList*) object.getAddress()); const TObject *p1 = (const TObject*) next(); ++i) {
350 print(out, prefix + "[" + to_string(i) + "]", JRootWritableClass(p1->IsA(), (const char*) p1));
351 }
352
353 } else if (object.getClass()->GetCollectionProxy() != NULL) {
354
355 unique_ptr<TVirtualCollectionProxy> p1(object.getClass()->GetCollectionProxy()->Generate());
356
357 p1->PushProxy(const_cast<char*>(object.getAddress()));
358
359 if (p1->GetValueClass() == NULL) {
360 for (UInt_t i = 0; i != p1->Size(); ++i) {
361 this->print(out, prefix + "[" + to_string(i) + "]", TDataType::GetTypeName(p1->GetType()), (const char*) p1->At(i));
362 }
363 } else {
364 for (UInt_t i = 0; i != p1->Size(); ++i) {
365 this->print(out, prefix + "[" + to_string(i) + "]", p1->GetValueClass()->GetStreamerInfo(), (const char*) p1->At(i));
366 }
367 }
368
369 } else {
370
371 if (object.getClass()->GetListOfBases() != NULL) {
372
373 for (TIter next(object.getClass()->GetListOfBases()); const TBaseClass *p1 = (const TBaseClass*) next(); ) {
374
375 if (JRoot::is_class(p1->GetName())) {
376 this->print(out, prefix, object.get(*p1));
377 }
378 }
379 }
380
381 if (object.getClass()->GetListOfDataMembers() != NULL) {
382
383 if (!object.getClass()->InheritsFrom(TClass::GetClass<TArray>())) {
384
385 for (TIter next(object.getClass()->GetListOfDataMembers()); const TDataMember *p1 = (const TDataMember*) next(); ) {
386
387 if (JRoot::is_class(p1->GetName()) && !JRoot::is_static(*p1)) {
388
389 if (!p1->IsEnum() && p1->IsPersistent()) {
390 this->print(out, prefix + "." + p1->GetName(), object.get(*p1));
391 }
392 }
393 }
394 }
395 }
396 }
397 }
398 }
399 }
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 410 of file JRootTypewriter.hh.

411 {
412 using namespace std;
413
414 if (info != NULL) {
415
416 for (TIter next(info->GetElements()); TStreamerElement* ts = dynamic_cast<TStreamerElement*>(next()); ) {
417
418 if (this->count(ts->GetTypeName()) != 0) {
419
420 if (ts->GetArrayLength() == 0)
421 this->print(out, prefix + "." + ts->GetName(), ts->GetTypeName(), ps + ts->GetOffset());
422 else
423 this->print(out, prefix + "." + ts->GetName(), ts->GetTypeName(), ps + ts->GetOffset(), ts->GetArrayLength(), ts->GetSize() / ts->GetArrayLength());
424
425 } else if (ts->GetClass() != NULL) {
426
427 if (ts->IsaPointer()) {
428
429 char* po = NULL;
430
431 memcpy(&po, ps + ts->GetOffset(), sizeof(char*));
432
433 if (po != NULL) {
434
435 if (ts->GetClass()->InheritsFrom(TList::Class())) {
436
437 this->print(out, prefix + "." + ts->GetName(), JRootWritableClass(TList::Class(), po));
438
439 } else {
440
441 this->print(out, prefix + "." + ts->GetName(), ts->GetClass()->GetStreamerInfo(), po);
442 }
443
444 } else {
445
446 out << prefix << "." << ts->GetName() << " <" << ts->GetTypeName() << "> " << "NULL" << endl;
447 }
448
449 } else if (ts->GetClass()->InheritsFrom(TArray::Class())) {
450
451 print(out, prefix + "." + ts->GetName(), JRootWritableClass(TArray::Class(), ps + ts->GetOffset()));
452
453 } else if (ts->GetClass()->InheritsFrom(TDirectory::Class())) {
454
455 // do nothing
456
457 } else if (ts->GetClass()->GetCollectionProxy() != NULL) {
458
459 print(out, prefix + "." + ts->GetName(), JRootWritableClass(ts->GetClass(), ps + ts->GetOffset()));
460
461 } else {
462
463 if (JRoot::is_class(ts->GetName())) {
464 this->print(out, prefix + "." + ts->GetName(), ts->GetClass()->GetStreamerInfo(), ps + ts->GetOffset());
465 }
466 }
467 }
468 }
469 }
470 }

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