REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Public Member Functions | Data Fields | Private Member Functions | Private Attributes | Friends
REST_Reflection::TRestReflector Class Reference

Detailed Description

Wrapper class for different type objects

Supports both class objects(string, vector, TRestMetadata, etc.) and basic type objects(int, double, etc.). Implements object wrapping, type assembly, data member reflection, memory streaming, and string conversion. We set a type alias any for this class.

Example 1: Type assembly & Value assignment

TRestEventProcess* proc = REST_Reflection::Assembly("TRestRawSignalAnalysisProcess");
proc->PrintMetadata();
any member = REST_Reflection::GetDataMember(obj, "fIntegralRange");
TVector2 v(10, 50);
member.SetValue(v);
proc->PrintMetadata();
A base class for any REST event process.
virtual void PrintMetadata()
Implemented it in the derived metadata class to print out specific metadata information.
TRestReflector Assembly(const std::string &typeName)
Assembly an object of type: typeName, returning the allocated memory address and size.

Example 2: Object wrapping & Memory streaming

map<int, double> a{{6, 1.4}, {7, 1.23}};
map<int, double> b;
ToString(any(a)); // returns string: "map<int,double> @0x7f2b03ff0038"
any(a) >> any(b); // copy a's data to b
b[6]; // we can get value 1.4
std::string ToString() const
Convert the wrapped object to std::string.

Example 3: Convert to string

TVector2 a(1,3);
ToString(a); // shows the string "(1,3)"
vector<int> b{3,5,7,9,2};
cout << any(b) << endl; // prints the content of b in string: "{3,5,7,9,2}"

Definition at line 286 of file TRestReflector.h.

Public Member Functions

void Assembly ()
 Assembly a new object, and save its address. The old object will be destroied if not null. More...
 
void Destroy () const
 Destroy the current object. It will make the class to be zombie. More...
 
TRestReflector GetDataMember (const std::string &name)
 Find the class's datamember as TRestReflector object, including those from base class. More...
 
TRestReflector GetDataMember (int ID)
 Get the i-th datamember of the class, ignoring those from base class. More...
 
std::string GetDataMemberValueString (const std::string &name)
 Get the value of datamember as std::string. More...
 
std::vector< std::string > GetListOfDataMembers () const
 Get a list of the class's datamembers as a std::vector of std::string, including those from base class. More...
 
int GetNumberOfDataMembers () const
 Get the number of data members of a class. More...
 
template<typename T >
GetValue ()
 Get the value of the wrapped type, not recommended to use. More...
 
template<class T >
void InitFromTemplate ()
 
bool IsZombie () const
 If this object type wrapper is invalid. More...
 
template<class T >
 operator T* ()
 
void operator>> (const TRestReflector &to)
 Deep copy the content of the wrapped object to to. More...
 
void ParseString (const std::string &str) const
 Set the value of the wrapped object from std::string. More...
 
void PrintMemory (int bytepreline=16)
 Print the Hex memory std::map of the wrappered object. More...
 
template<class T >
void SetValue (const T &val)
 Set the value of the wrapped type. More...
 
std::string ToString () const
 Convert the wrapped object to std::string. More...
 
 TRestReflector ()
 Default constructor. More...
 
template<class T >
 TRestReflector (const T &obj)
 Constructor to wrap an object. Any typed object can be revieved as argument. More...
 
template<class T >
 TRestReflector (T *obj)
 Constructor to wrap an object pointer. More...
 
 TRestReflector (void *address, const std::string &type)
 Constructor from a certain address and a certain type. More...
 

Data Fields

char * address = 0
 Address of the wrapped object. More...
 
TClass * cl = 0
 Pointer to the corresponding TClass helper, if the wrapped object is in class type. More...
 
bool is_data_type = false
 Pointer to the corresponding TDataType helper, if the wrapped object is in data type. More...
 
std::string name = ""
 Name field. More...
 
int size = 0
 Size of the object. More...
 
std::string type = ""
 Type of the wrapped object. More...
 
const std::type_info * typeinfo = 0
 value of typeid(T).name() of the wrapped object More...
 

Private Member Functions

int InitDictionary ()
 Prepare the ROOT dictionary for this type. More...
 

Private Attributes

bool onheap = false
 If on heap, we can call Destroy() to TRestReflector. True only when initialized from Assembly() More...
 

Friends

std::ostream & operator<< (std::ostream &cin, TRestReflector ptr)
 Output overload by calling ToString();. More...
 

Constructor & Destructor Documentation

◆ TRestReflector() [1/4]

REST_Reflection::TRestReflector::TRestReflector ( )
inline

Default constructor.

Definition at line 364 of file TRestReflector.h.

◆ TRestReflector() [2/4]

REST_Reflection::TRestReflector::TRestReflector ( void *  address,
const std::string &  type 
)

Constructor from a certain address and a certain type.

Definition at line 57 of file TRestReflector.cxx.

◆ TRestReflector() [3/4]

template<class T >
REST_Reflection::TRestReflector::TRestReflector ( const T &  obj)
inline

Constructor to wrap an object. Any typed object can be revieved as argument.

Definition at line 369 of file TRestReflector.h.

◆ TRestReflector() [4/4]

template<class T >
REST_Reflection::TRestReflector::TRestReflector ( T *  obj)
inline

Constructor to wrap an object pointer.

Definition at line 375 of file TRestReflector.h.

Member Function Documentation

◆ Assembly()

void REST_Reflection::TRestReflector::Assembly ( )

Assembly a new object, and save its address. The old object will be destroied if not null.

Definition at line 75 of file TRestReflector.cxx.

◆ Destroy()

void REST_Reflection::TRestReflector::Destroy ( ) const

Destroy the current object. It will make the class to be zombie.

Definition at line 90 of file TRestReflector.cxx.

◆ GetDataMember() [1/2]

TRestReflector REST_Reflection::TRestReflector::GetDataMember ( const std::string &  name)

Find the class's datamember as TRestReflector object, including those from base class.

Definition at line 288 of file TRestReflector.cxx.

◆ GetDataMember() [2/2]

TRestReflector REST_Reflection::TRestReflector::GetDataMember ( int  ID)

Get the i-th datamember of the class, ignoring those from base class.

Definition at line 316 of file TRestReflector.cxx.

◆ GetDataMemberValueString()

string REST_Reflection::TRestReflector::GetDataMemberValueString ( const std::string &  name)

Get the value of datamember as std::string.

Definition at line 363 of file TRestReflector.cxx.

◆ GetListOfDataMembers()

vector< string > REST_Reflection::TRestReflector::GetListOfDataMembers ( ) const

Get a list of the class's datamembers as a std::vector of std::string, including those from base class.

Definition at line 332 of file TRestReflector.cxx.

◆ GetNumberOfDataMembers()

int REST_Reflection::TRestReflector::GetNumberOfDataMembers ( ) const

Get the number of data members of a class.

Definition at line 371 of file TRestReflector.cxx.

◆ GetValue()

template<typename T >
T REST_Reflection::TRestReflector::GetValue ( )
inline

Get the value of the wrapped type, not recommended to use.

Definition at line 316 of file TRestReflector.h.

◆ InitDictionary()

int REST_Reflection::TRestReflector::InitDictionary ( )
private

Prepare the ROOT dictionary for this type.

Definition at line 154 of file TRestReflector.cxx.

◆ InitFromTemplate()

template<class T >
void REST_Reflection::TRestReflector::InitFromTemplate ( )
inline

Definition at line 381 of file TRestReflector.h.

◆ IsZombie()

bool REST_Reflection::TRestReflector::IsZombie ( ) const

If this object type wrapper is invalid.

Definition at line 256 of file TRestReflector.cxx.

◆ operator T*()

template<class T >
REST_Reflection::TRestReflector::operator T* ( )
inline

Type conversion operator. With this, one can implicitly convert TRestReflector object to pointer of certain type. For example, TRestEvent* eve = REST_Reflection::Assembly("TRestRawSignalEvent");

Definition at line 360 of file TRestReflector.h.

◆ operator>>()

void REST_Reflection::TRestReflector::operator>> ( const TRestReflector to)

Deep copy the content of the wrapped object to to.

Definition at line 124 of file TRestReflector.cxx.

◆ ParseString()

void REST_Reflection::TRestReflector::ParseString ( const std::string &  str) const

Set the value of the wrapped object from std::string.

Definition at line 141 of file TRestReflector.cxx.

◆ PrintMemory()

void REST_Reflection::TRestReflector::PrintMemory ( int  bytepreline = 16)

Print the Hex memory std::map of the wrappered object.

Definition at line 107 of file TRestReflector.cxx.

◆ SetValue()

template<class T >
void REST_Reflection::TRestReflector::SetValue ( const T &  val)
inline

Set the value of the wrapped type.

Definition at line 327 of file TRestReflector.h.

◆ ToString()

string REST_Reflection::TRestReflector::ToString ( ) const

Convert the wrapped object to std::string.

Definition at line 126 of file TRestReflector.cxx.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  cin,
TRestReflector  ptr 
)
friend

Output overload by calling ToString();.

Definition at line 313 of file TRestReflector.h.

Field Documentation

◆ address

char* REST_Reflection::TRestReflector::address = 0

Address of the wrapped object.

Definition at line 301 of file TRestReflector.h.

◆ cl

TClass* REST_Reflection::TRestReflector::cl = 0

Pointer to the corresponding TClass helper, if the wrapped object is in class type.

Definition at line 305 of file TRestReflector.h.

◆ is_data_type

bool REST_Reflection::TRestReflector::is_data_type = false

Pointer to the corresponding TDataType helper, if the wrapped object is in data type.

Definition at line 307 of file TRestReflector.h.

◆ name

std::string REST_Reflection::TRestReflector::name = ""

Name field.

Definition at line 295 of file TRestReflector.h.

◆ onheap

bool REST_Reflection::TRestReflector::onheap = false
private

If on heap, we can call Destroy() to TRestReflector. True only when initialized from Assembly()

Definition at line 291 of file TRestReflector.h.

◆ size

int REST_Reflection::TRestReflector::size = 0

Size of the object.

Definition at line 303 of file TRestReflector.h.

◆ type

std::string REST_Reflection::TRestReflector::type = ""

Type of the wrapped object.

Definition at line 297 of file TRestReflector.h.

◆ typeinfo

const std::type_info* REST_Reflection::TRestReflector::typeinfo = 0

value of typeid(T).name() of the wrapped object

Definition at line 299 of file TRestReflector.h.


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