Scanning TDataMemberList

Hi rooters,
i’m trying to take advantage of the introspection-like feature of the Dictionary to read the data properties from my own classes using them in a wrapper-like mode.
In short i take a class of mine and i do the following

tc = new TClass(className);
keys = tc->GetListOfDataMembers();
tdm = (TDataMember*)keys->First();
while(tdm){
type = new string(tdm->GetTypeName());
size = tdm->GetArrayDim();
if(size > 0){
for (int i = 0; i < size; i++){
printf("[%i]", tdm->GetMaxIndex(i));
}
tdm = (TDataMember*)keys->After(tdm);
}

in this way i can recover the type and the size of any properties of basic type (that is the DataMembers which satisfies the IsBasic() method), so for example for one of my class i have

IEV2 int
calped int[96][11][4]
calgood int[96][11][4]
calthr int[96][11][4]
calrms int[96][11][4]
calbase int[96][11][4]
calvar int[96][11][4]
calpuls int[96][11][4]

and that’s tha same i have with my script, BUT (!) only the first time i execute it, the second time (and the following ones until i quit ROOT and restart it, after which it repeate the same phenomenon) i got

fgIsA TClass <--------- this one appears after the first run
IEV2 int
calped int[96][11][4]
calgood int[96][11][4]
calthr int[96][11][4]
calrms int[96][11][4]
calbase int[96][11][4]
calvar int[96][11][4]
calpuls int[96][11][4]

Another thing i cannot explain is the following: just take another one of my classes; here i have the following properties:

Log_crc_ok int
Records TClonesArray

but the first time i run my script i got

fgRecords TClonesArray <-----why i have this one???
Log_crc_ok int
Records TClonesArray

all the following i got

fgIsA TClass <----it appears still here
fgRecords TClonesArray
Log_crc_ok int
Records TClonesArray

Sorry for my long explaination, thanks
Maurizio

Replace your first statement
tc = new TClass(className);
by
tc = gROOT->GetClass(className);

The TClass object is already created in teh dictionary.

Rene

Thanks, that’s ok for the first question…the fgIsA disappears…
But what’s the reason for the second trouble? I mean why i got

Records TClonesArray
fgRecords TClonesArray <-----what’s the reason of this “Records” copy here?
Log_crc_ok int

Cheers

No idea of what is happening without running your code.
At the command prompt, do
gROOT->GetClass(“classname”)->GetListOfDataMembers()->ls()

Rene

here is the output…

root [76] gROOT->GetClass(“pamela::LogEvent”)->GetListOfDataMembers()->ls()
OBJ: TDataMember fgRecords : 0 at: 0x1c6cb10
OBJ: TDataMember Log_crc_ok : 0 at: 0x1c6cce0
OBJ: TDataMember Records : 0 at: 0x1c62ca0
OBJ: TDataMember fgIsA : 0 at: 0x1c62ea0

anyway if you want to check the script too is attached here. The shared library loaded in the begin of the main funcion is of no real meaning for the topic of the problem (i supose…)

Maurizio
eventScanner.c (1.84 KB)

HI Maurizio,

In order to understand your issue we would need your class (pamela::LogEvent).

Cheers,
Philippe

ok… now i’ve attached a bunch of files the main class is the LogEvent which contain aTClonesArray. Just for sake of completeness i added the class which is inserted into the previuos TCloneArray variable, the LinkDef.h i use for the rootcint and the generated Dict.h and Dict.c

thanks
Maurizio
LogEvent.tar.gz (7.34 KB)

Hi,

The output is a expected since you class is defined as

class LogEvent: public pamela::SubPacket { private: static TClonesArray *fgRecords; public: int Log_crc_ok; TClonesArray* Records; ... ClassDef(LogEvent,1); };
The list of data members contains ALL data members including the static data members!. In addition ClassDef add a static datamember fgIsA which hold a pointer to the TClass for your class.

Also I am wondering what you are trying to accomplish in the first place (they may or may not :slight_smile: be a better way).

Cheers,
Philippe

Goosh!.. i really need some holiday if i lost in my code in such silly way… thanks anyway :slight_smile:

Maurizio

Hi,

Also you can detect static data members with (d being a TDataMember):

Cheers,
Philippe