Root file writing questions

Hi Rooters,

I have two questions regarding writing in root file. It might be very simple question but I could not find clue.

  1. I have a class for data (not inherited from TObject) and I am writing the data in root file. After successful compilation, when I run the code I got following error:
Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for CompositeParticleClass!
Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for GammaClass!

but it ran successfully and I can see data written in root file.

To remove the above error, I have included following lines in data class (these line are not included before)

ClassDef(Particle, 0);  // in header file
ClassImp(Particle)      // in implementation file

In this case, I do not see any error, code ran successfully but no data are written in root file.

  1. When I plot the leafs in root file using TBrower, it crashes after few plots (unpredictable).

Any idea will be appreciated.
Thanks.

[quote] I have a class for data (not inherited from TObject) and I am writing the data in root file. After successful compilation, when I run the code I got following error:[/quote]Did you generate the dictionary for ALL the classes that need to be stored?

ClassDef(Particle, 0); // in header fileThe ‘zero’ in your ClassDef explicitly tell ROOT that you do NOT want to store any of the data of the class Particle. When using a ClassDef for a class that need to be stored, the 2nd parameter (the version number) needs to be 1 or more.

[quote]When I plot the leafs in root file using TBrower, it crashes after few plots (unpredictable).[/quote]This is likely related to the ShowMember errors (another typical case is if some the data members (especially pointers) are not properly initialized in the default constructor).

Cheers,
Philippe.

Thanks. Yes, I have generate the dictionary for all classes.

Here is the simplified version of the problem ( I am writing a simulation program):
I have a class called “CompositeParticle” to hold resonances and “Particle” to hold stable particles. “CompositeParticle” (derived from “Particle”) class have a vector of “Particle*” (pointer) to hold its decay products.

CompositeParticle *res = midFinal;
vector<Particle*> decay = res->GetDecayProducts();

There is a main class, which uses all these classes, which has a vector called “finalParticles” of type “Particle*” (pointer), and it holds all final particles. I insert all final particles in this vector,

finalParticles.push_back(decay[0]);
finalParticles.push_back(decay[1]);
.........
.........

I have another class “EventClass”.
I write all particles from “finalParticles” vector to a vector of type “Particle” (not pointer) in this “EventClass” object and write it to root file (same method is working in my different code, a little simple version). So, all the particles in root file should be of “Particle” type only. But when I run the program to write in root file, it says, while filling the tree,:

Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for CompositeParticle!

As far a know, nothing is written of type CompositeParticle. Why is it comming? Because of this data is written but partially.
Even I used static_cast

finalParticles.push_back(static_cast<Particle*> (decay[0]));

but same problem.
Thanks.

[quote]Error in TClass::BuildRealData: Cannot find any ShowMembers function for CompositeParticle![/quote]Humm maybe you did not request the I/O support for the class. I.e. maybe you linkdef contains:#pragma link C++ class CompositeParticle;rather than #pragma link C++ class CompositeParticle+;(And I am guessing that CompositeParticle does not have a ClassDef ; if CompositeParticle does have a ClassDef there is no mechanism I know of that would lead to this message and thus I would need a complete running example showing the problem).

Cheers,
Philippe.

Hi Philippe,

Removing “+” solved the problem partially. I am trying to figure out the solution for remaining problem.

As I have mentioned earlier that I write the objects in a vector (variable in EventClass class) and fill the tree with EventClass. I found out that this works only to write in root file but there is problem while reading back the root file. I can’t read back using EventClass, it crashes. So, I tried to use TCloneArrays which requires my “Particle” class to be derived from TObject. When I tried to do this, there are many function name conflict between TObject class and my class. This will be problem especially when program becomes bigger. Is there any other way to do this? Simply I want to write an array or vector of objects (per event) of type “Particle” in root file using class “EventClass” so that I can read back the root file using methods in “EventClass”.

Thanks.

[quote]Removing “+” solved the problem partially. I am trying to figure out the solution for remaining problem. [/quote]I am really confused … 'removing “+” ’ should make the problem worth not better. If you have a ClassDef it would make you use an older version of the I/O and if you don’t have a ClassDef it prevents the I/O for your class …

[quote] I can’t read back using EventClass, it crashes.[/quote]Given the confusing situation you seemed to have ended up with, this is not surprising :slight_smile:. Most likely (well at least in the usual cases) this means that the default constructor is not properly initializing the data members (in particular the pointers).

[quote]When I tried to do this, there are many function name conflict between TObject class and my class. [/quote]Really, like what for example?

[quote]Simply I want to write an array or vector of objects (per event) of type “Particle” in root file using class “EventClass” so that I can read back the root file using methods in “EventClass”.[/quote]You can either use a TClonesArray or a vector (as long as you generate the dictionary for the vector and all its content.

Cheers,
Philippe.

There was few problems in my code. Now it is fixed and working ok. Thanks for helpful suggestions. :smiley: