Home | News | Documentation | Download

Create a branch from inheritance classes

I am trying to create a branche based on inhritence classe.(the code based on makeclass method)

1.class Track :public Vec3D
2.class Vec3D {
3. fChain->Branch(“TrackList_”, &TrackList_)/*how i am creating the branch */

what i am looking

> Blockquote

TrackList_:
                id_    
                E_                  
                t_                    
                valid_
                vec:
                                 x
                                 y
                                 z

this is the message i got .

 Warning in <TStreamerInfo::Build>: Track: base class Vec3D has no streamer or dictionary it will not be saved
(analyse) @0x2b53550

you will find the codes used below

analyse.C (1.5 KB) analyse.h (6.3 KB) Track.h (337 Bytes) Vec3D.h (190 Bytes)

Hi. Have you tried to make your class inherit from TObject (class Vec3D :public TObject {…)? I think this way you would use the “ROOT defined” streamer for input/output
I hope this fix the problem

Hi @EVTO
first of all i would thanks you for your reply .
i try to do same changes in my code but i get this message
1-class Track : public Vec3D{
2-class Vec3D : public TObject {

Error in <TTree::Branch>: The actual class (TObject) of the object provided for the definition of the branch "TrackList_" does not inherit from Track
(analyse2) @0xec6c30

Maybe I have an idea but I don’t want to say something stupid so I will try on my laptop first and if it works I will tell you then :sweat_smile:

1 Like

ROOT needs to know how to store your classes. That info is called “a dictionary”. You can get it simply by running .L analyse.C+ (note the trailing +), and putting

#ifdef __CLING__
#pragma link C++ class Vec3D+;
#endif

into analyse.C. If you build your own binary etc, please check https://root.cern/manual/integrate_root_into_my_cmake_project/

Cheers, Axel.

1 Like

Hi @Axel
thanks for your answer
i got the same message iven if i add this code in the Linkdef.h file

#ifdef __CLING__
#pragma link C++ class Vec3D+;
#endif

could you please explain more details
thanks

Hi @Axel @EVTO
i have a question
it is the right command line to create a branch from inheritance class ? :

   TfChain->Branch("TrackList_", &TrackList_,2,32000);

and this is the class

#ifndef Track_h
#define Track_h
#include "TObject.h"
#include "TObjArray.h"
#include "Vec3D.h"

class Track : public Vec3D{

public: 
   unsigned int id_;         ///< Unique identifier
   double       E_;                    ///< Energy
   double       t_;                    ///< time  o
   bool         valid_;                ///< Boolean to ev.
   Vec3D        position_;
  }TrackList_;

#endif

thsnks

Hi @eddymaoui. I think this way you create a branch with a buffer of 2 bytes and 32000 splitting of the branch. Maybe you want the opposite, (… , … ,32000, 2)?

Plus you need to generate the dictionary for the type of the data you want to store - so Track, I guess?

#ifdef __CLING__
#pragma link C++ class Vec3D+;
#pragma link C++ class Track+;
#endif

should help. What do you do with your Linkdef.h file, is that passed to rootcling? Can you share the dictionary source file that’s generated?

1 Like

Hi @Axel
Sorry for the delay
i am generating the dictionnaire with :

rootcling -f MyDictionary.cxx analyse2.h Hit.h Neutrino.h Track.h Vec3D.h LinkDef.h

when a look to the output via new TBrowser i find the track inherit from the vec 3D
but it still gives me this warning :

Warning in <TStreamerInfo::Build>: Track: base class Vec3D has no streamer or dictionary it will not be saved
(analyse2) @0x27edb40

MyDictionary.cxx (9.7 KB)
Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.