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

Data Fields

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

Private Member Functions

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

Private Attributes

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

Friends

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

Member Function Documentation

◆ 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.


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