Jpp test-rotations-new
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 i1->second->print(out, ps + i * size);
275 }
276
277 } else {
278
279 out << "?";
280 }
281
282 out << endl;
283 }

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

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

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

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

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

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