# Using TTree::MakeClass()

**URL:** <https://root-forum.cern.ch/t/using-ttree-makeclass/15175>\
**Category:** ROOT\
**Created:** [October 31, 2012, 7:12pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175 "2012-10-31T19:12:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmosquer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bcef8e/32.png) [@cmosquer](https://root-forum.cern.ch/u/cmosquer)\
**Post date:** [October 31, 2012, 7:12pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175/1 "2012-10-31T19:12:29Z")

</div>

Hello  
I am trying to create my own derived class from a class generated via

```auto
 TFile *inFile = TFile::Open(fn);
  inFile->ls();
 
  TTree *dataTree;   
inFile->GetObject("myG4dataTree", dataTree);
 dataTree->MakeClass("MyDataTree");
```

I have created my own class called G4TreeEngine which I have attached, I have created the G4TreeEngineLinkDef.hxx and makefile. Question: Do I need to also include the ClassImp line in my MyDataTree class? It would be odd since each time I generate this class viadataTree-\>MakeClass(“MyDataTree”); then i woul dhave to edit the file to include this line.  
When I compile, I get the following error:

> [@](#):
>
> bash-4.2$ make  
> rm -f core G4TreeEngine  
> rootcint -f G4TreeEngineDict.cxx -c MyDataTree.hxx G4TreeEngine.hxx G4TreeEngineLinkDef.hxx  
> g++ `root-config --cflags --glibs` -o G4TreeEngine G4TreeEngine.cxx G4TreeEngineDict.cxx  
> /tmp/ccY7Yzu1.o: In function `G4TreeEngine::G4TreeEngine()': G4TreeEngine.cxx:(.text+0x19): undefined reference to `MyDataTree::MyDataTree(TTree\*)’  
> /tmp/ccY7Yzu1.o: In function `G4TreeEngine::~G4TreeEngine()': G4TreeEngine.cxx:(.text+0x49): undefined reference to `MyDataTree::~MyDataTree()’  
> /tmp/ccY7Yzu1.o:(.rodata.\_ZTV12G4TreeEngine[\_ZTV12G4TreeEngine]+0x20): undefined reference to `MyDataTree::Cut(long long)' /tmp/ccY7Yzu1.o:(.rodata._ZTV12G4TreeEngine[_ZTV12G4TreeEngine]+0x28): undefined reference to `MyDataTree::GetEntry(long long)’  
> /tmp/ccY7Yzu1.o:(.rodata.\_ZTV12G4TreeEngine[\_ZTV12G4TreeEngine]+0x30): undefined reference to `MyDataTree::LoadTree(long long)' /tmp/ccY7Yzu1.o:(.rodata._ZTV12G4TreeEngine[_ZTV12G4TreeEngine]+0x38): undefined reference to `MyDataTree::Init(TTree\*)’  
> /tmp/ccY7Yzu1.o:(.rodata.\_ZTV12G4TreeEngine[\_ZTV12G4TreeEngine]+0x48): undefined reference to `MyDataTree::Notify()' /tmp/ccY7Yzu1.o:(.rodata._ZTV12G4TreeEngine[_ZTV12G4TreeEngine]+0x50): undefined reference to `MyDataTree::Show(long long)’  
> /tmp/ccY7Yzu1.o:(.rodata.\_ZTI12G4TreeEngine[\_ZTI12G4TreeEngine]+0x10): undefined reference to `typeinfo for MyDataTree' /tmp/cccvlY1X.o: In function `ROOT::GenerateInitInstanceLocal(MyDataTree const\*)‘:  
> G4TreeEngineDict.cxx:(.text+0xdd): undefined reference to `typeinfo for MyDataTree' /tmp/cccvlY1X.o: In function `ROOT::new\_MyDataTree(void\*)’:  
> G4TreeEngineDict.cxx:(.text+0x15d1): undefined reference to `MyDataTree::MyDataTree(TTree*)' G4TreeEngineDict.cxx:(.text+0x15f0): undefined reference to `MyDataTree::MyDataTree(TTree\*)’  
> /tmp/cccvlY1X.o: In function `ROOT::newArray_MyDataTree(long, void*)': G4TreeEngineDict.cxx:(.text+0x169e): undefined reference to `MyDataTree::MyDataTree(TTree\*)’  
> G4TreeEngineDict.cxx:(.text+0x1703): undefined reference to `MyDataTree::MyDataTree(TTree*)' /tmp/cccvlY1X.o: In function `G\_\_G4TreeEngineDict\_541\_0\_1(G\_\_value\*, char const\*, G\_\_param\*, int)‘:  
> G4TreeEngineDict.cxx:(.text+0x1a62): undefined reference to `MyDataTree::MyDataTree(TTree*)' /tmp/cccvlY1X.o:G4TreeEngineDict.cxx:(.text+0x1ae2): more undefined references to `MyDataTree::MyDataTree(TTree\*)’ follow  
> /tmp/cccvlY1X.o: In function `MyDataTree::MyDataTree(MyDataTree const&)': G4TreeEngineDict.cxx:(.text._ZN10MyDataTreeC2ERKS_[_ZN10MyDataTreeC5ERKS_]+0x13): undefined reference to `vtable for MyDataTree’  
> collect2: error: ld returned 1 exit status  
> make: \*\*\* [all] Error 1  
> bash-4.2$

What am I missing?  
Thanks,  
C.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 31, 2012, 7:29pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175/2 "2012-10-31T19:29:59Z")

</div>

How about: `#pragma link C++ class MyDataTree+;`

---

<div class="post-metadata">

**Author:** ![cmosquer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bcef8e/32.png) [@cmosquer](https://root-forum.cern.ch/u/cmosquer)\
**Post date:** [October 31, 2012, 7:41pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175/3 "2012-10-31T19:41:37Z")

</div>

Sorry, I forgot to attach my files…  
I have in my G4TreeEngineLinkDef.hxx

C.

```auto

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class MyDataTree+;
#pragma link C++ class G4TreeEngine+;

#endif

```

my makefile looks like this:

```auto
all:
	rm -f core G4TreeEngine
	rootcint -f G4TreeEngineDict.cxx -c MyDataTree.hxx G4TreeEngine.hxx G4TreeEngineLinkDef.hxx
	g++ `root-config --cflags --glibs` -o G4TreeEngine G4TreeEngine.cxx G4TreeEngineDict.cxx

clean:
	rm -f *.*~ G4TreeEngineDict.cxx G4TreeEngineDict.hxx core G4TreeEngine

```

[G4TreeEngineLinkDef.hxx](https://root-forum.cern.ch/uploads/default/original/2X/c/c467d20d5d3c78817bd3d8de5462d798c333763e.hxx) (193 Bytes)  
[MyDataTree.hxx](https://root-forum.cern.ch/uploads/default/original/2X/9/9b6187c1791e6e8eed93e8dc6ad03307da7918a4.hxx) (8.1 KB)  
[MyDataTree.cxx](https://root-forum.cern.ch/uploads/default/original/2X/4/4a7882d585da84f78d5feb092484ecfa947ed75f.cxx) (1.46 KB)  
[G4TreeEngine.cxx](https://root-forum.cern.ch/uploads/default/original/2X/0/07c6f3747acc73540f927f84e5a4ddd6146b0172.cxx) (1.86 KB)  
[G4TreeEngine.hxx](https://root-forum.cern.ch/uploads/default/original/2X/6/69bfe347798dc377e86e8226b11291198d42cf03.hxx) (304 Bytes)

---

<div class="post-metadata">

**Author:** ![cmosquer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bcef8e/32.png) [@cmosquer](https://root-forum.cern.ch/u/cmosquer)\
**Post date:** [October 31, 2012, 7:54pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175/4 "2012-10-31T19:54:40Z")

</div>

I was missing one declaration in my makefile. now everything seems to be working. I have still the question regarding the ClassImp() call inside the generated class… is it needed?

I will experiement further later on…  
Just to complete this post, changes in my make file was:

```auto
g++ `root-config --cflags --glibs` -o G4TreeEngine MyDataTree.cxx G4TreeEngine.cxx G4TreeEngineDict.cxx
```

Cheers,  
C.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 31, 2012, 7:59pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175/5 "2012-10-31T19:59:43Z")

</div>

A small fix to your “G4TreeEngine.cxx”: ` printf("At %lld Entry %d hits %d %d %d \n",jentry+k,k,na_hits,ng_hits,nu_hits);` and to your “Makefile”: `	`root-config --cxx --cflags` -o G4TreeEngine MyDataTree.cxx G4TreeEngine.cxx G4TreeEngineDict.cxx `root-config --glibs``

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 31, 2012, 8:04pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175/6 "2012-10-31T20:04:32Z")

</div>

See [url][Simple way to create and merge shared libraries?](https://root-forum.cern.ch/t/simple-way-to-create-and-merge-shared-libraries/11652/6) for some additional neat Philippe’s notes concerning “ClassDef” / “ClassImp” / “TObject inheritance”.

---

<div class="post-metadata">

**Author:** ![cmosquer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bcef8e/32.png) [@cmosquer](https://root-forum.cern.ch/u/cmosquer)\
**Post date:** [October 31, 2012, 8:18pm UTC](https://root-forum.cern.ch/t/using-ttree-makeclass/15175/7 "2012-10-31T20:18:17Z")

</div>

Just a BIG thank you!  
C.
