# TTree::Branch not recognizing actual class in ROOT 6.18/04

**URL:** <https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846>\
**Category:** Newbie\
**Created:** [November 15, 2019, 3:57pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846 "2019-11-15T15:57:21Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 15, 2019, 3:57pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/1 "2019-11-15T15:57:22Z")

</div>

Hello everyone,

this is my code:

test.C:

```auto
#include "myevent.hh"
#include "TROOT.h"
#include <iostream>
#include "TTree.h"

using namespace std;

void test() {
  gROOT->ProcessLine(".L myevent.hh+");
  
  TTree* tree = new TTree("tree", "tree");
  MyEvent* event = new MyEvent();
  tree->Branch("event", "MyEvent", &event);
  
} 

```

myevent.hh:

```auto
#ifndef MYEVENT
#define MYEVENT

class MyEvent : public TObject {
public:
   Double_t number;
   MyEvent(){};
   MyEvent(const MyEvent&) = delete;
   
};

#endif

```

If I go

```nohighlight
$ source root-6.16.00/bin/thisroot.sh
$ root -l test.C

```

this works fine with no errors. Now I log out from my computer account, log in again, and execute

```auto
$ source root-6.18.04/bin/thisroot.sh
$ root -l test.C

```

This gives me  
`Error in <TTree::Branch>: The actual class (TObject) of the object provided for the definition of the branch "event" does not inherit from MyEvent`

To add some context (probably that’s relevant), ROOT 6.16/00 is the precompiled binary that I downloaded from the ROOT website; instead, I have compiled ROOT 6.18/04 from source with

```auto
$ cmake -DCMAKE_BUILD_TYPE="Debug" ../root-6.18.04-source/
$ cmake --build .

```

Can anyone point out what’s wrong here? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 18, 2019, 5:21pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/2 "2019-11-18T17:21:44Z")

</div>

Bumping this thread to be sure that no one has any idea about this…

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [November 18, 2019, 5:34pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/3 "2019-11-18T17:34:39Z")

</div>

Try:

```auto
#include "myevent.hh"
#include "TROOT.h"
#include <iostream>
#include "TTree.h"
#ifdef __CLING__
#include "myevent.h++"
#else
#include "myevent.h"
#endif

using namespace std;

void test() {

  TTree* tree = new TTree("tree", "tree");
  MyEvent* event = new MyEvent();
  tree->Branch("event", "MyEvent", &event);
  
} 

```

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 18, 2019, 6:48pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/4 "2019-11-18T18:48:42Z")

</div>

My first section of test.C now looks like this (I assume it was a typo, since your code as is says “myevent.h” doesn’t exist)

```auto
#include "TROOT.h"
#include <iostream>
#include "TTree.h"
#ifdef __CLING__
#include "myevent.hh++"
#else
#include "myevent.hh"
#endif

```

It still produces the same error, and now if I try to run it with `root test.C+` (which is the way I’ll have to run my actual code), it even produces this fatal error:

```nohighlight
Info in <TUnixSystem::ACLiC>: creating shared library test_C.so
Info in <TUnixSystem::ACLiC>: creating shared library myevent_hh.so
Warning in <ACLiC>: Failed to generate the dependency file for myevent_hh.so
<<< cling interactive line includer >>>:1:10: fatal error: '.' file not found
#include "."
         ^~~
Error in <ACLiC>: Dictionary generation failed!
In file included from input_line_12:6:
././test.C:5:10: fatal error: 'myevent.hh++' file not found
#include "myevent.hh++"
         ^ ~~~~~~~~~~~~~
Error in <ACLiC>: Dictionary generation failed!

```

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 25, 2019, 4:49pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/5 "2019-11-25T16:49:02Z")

</div>

Bumping again… can anyone at least confirm it is a local problem and not a ROOT bug?

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [November 25, 2019, 9:11pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/6 "2019-11-25T21:11:57Z")

</div>

> [@renyhp](#):
>
> My first section of test.C now looks like this

Yes, this was what I meant.

> It still produces the same error,

Strange.

What does:

```auto
.L test.C
c = TClass::GetClass("MyEvent");
if (c) cout << "Isloaded: " << c->IsLoaded() << '\n';

```

prints?

> now if I try to run it with `root test.C+`

Indeed I did not get the #ifdef correct (however the output is still actually odd). For test.C+ to work you would need to use:

```auto
#include "TROOT.h"
#include <iostream>
#include "TTree.h"
#include "myevent.hh"

```

and

```auto
root.exe -b -l -e '.L myevent.h+' 

```

or use

```auto
#include "TROOT.h"
#include <iostream>
#include "TTree.h"
#include "myevent.hh"
#ifdef __ROOTCLING__
#pragma C++ class MyEvent+;
#endif

```

and use `.L test.C+`

Cheers,  
Philippe.

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 25, 2019, 9:46pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/7 "2019-11-25T21:46:14Z")

</div>

Thank you! Now this is what my test.C looks like:

```cpp
#include "TROOT.h"
#include <iostream>
#include "TTree.h"
#include "myevent.hh"
#ifdef __ROOTCLING__
#pragma C++ class MyEvent+;
#endif

using namespace std;

void test() {
  gROOT->ProcessLine(".L myevent.hh++");
  
  TTree* tree = new TTree("tree", "tree");
  MyEvent* event = new MyEvent();
  tree->Branch("event", "MyEvent", &event);
  
  auto c = TClass::GetClass("MyEvent");
  if (c)
    cout << "IsLoaded: " << c->IsLoaded() << endl;
} 

```

and here’s the output:

```nohighlight
$ root -l test.C+
root [0] 
Processing test.C+...
Info in <TUnixSystem::ACLiC>: creating shared library test_C.so
Info in <ACLiC>: script has already been loaded in interpreted mode
Info in <ACLiC>: unloading myevent.hh and compiling it
Info in <TUnixSystem::ACLiC>: creating shared library myevent_hh.so
Error in <TTree::Branch>: The actual class (TObject) of the object provided for the definition of the branch "event" does not inherit from MyEvent
IsLoaded: 1

```

Again, running this with ROOT 6.16/00 prints no error.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [November 25, 2019, 9:59pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/8 "2019-11-25T21:59:23Z")

</div>

Hi,

You no longer need the line:

```auto
  gROOT->ProcessLine(".L myevent.hh++");

```

In,

```auto
#pragma C++ class MyEvent+;

```

I made a fatal typo. I meant:

```auto
#pragma link C++ class MyEvent+;

```

Cheers,

Philippe.

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 25, 2019, 10:45pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/9 "2019-11-25T22:45:02Z")

</div>

Thank you for your fast reply. Unfortunately, even aftere these corrections the error doesn’t go away; the class is still loaded.

```nohighlight
$ root -l test.C+
root [0] 
Processing test.C+...
Info in <TUnixSystem::ACLiC>: creating shared library test_C.so
Error in <TTree::Branch>: The actual class (TObject) of the object provided for the definition of the branch "event" does not inherit from MyEvent
IsLoaded: 1

```

```cpp
//test.C
#include "TROOT.h"
#include <iostream>
#include "TTree.h"
#include "myevent.hh"
#ifdef __ROOTCLING__
#pragma link C++ class MyEvent+;
#endif

using namespace std;

void test() {
  
  TTree* tree = new TTree("tree", "tree");
  MyEvent* event = new MyEvent();
  tree->Branch("event", "MyEvent", &event);
  
  auto c = TClass::GetClass("MyEvent");
  if (c)
    cout << "IsLoaded: " << c->IsLoaded() << endl;
    
} 

```

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 28, 2019, 2:44pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/10 "2019-11-28T14:44:26Z")

</div>

Well at this point I’ll just try recompiling ROOT and hope that somehow the error goes away… The only thing I’m _very_ curious about is if anyone can reproduce this, or I have to dig into some research for an installation problem or whatever.

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [November 28, 2019, 3:22pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/11 "2019-11-28T15:22:53Z")

</div>

I do this like att  
[myevent.C](https://root-forum.cern.ch/uploads/short-url/sDL7LPYjrvrZdyPNHOcZh2u4Ffy.C) (567 Bytes)  
Note the ClassDef, ClassImp  
and run it in a session

```auto
.L myevent.C++
test()

```

works with 6.16.00 6.18.04, 6.19.01  
Otto

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 28, 2019, 4:36pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/12 "2019-11-28T16:36:11Z")

</div>

I added the ClassDef macro in my code and it worked like a charm, thank you so much!!

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [November 28, 2019, 8:02pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/13 "2019-11-28T20:02:11Z")

</div>

My bad for not noticing … Indeed when a class inherits from TObject the ClassDef is compulsory.

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 28, 2019, 9:04pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/14 "2019-11-28T21:04:09Z")

</div>

> My bad for not noticing …

No problem, thank you for helping anyway!

> ClassDef is compulsory

Yeah, I only learned about it now, strange that I hadn’t seen anything about it in the documentation. Also it is strange, at this point, that the same code worked fine without ClassDef in the older version…

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [November 29, 2019, 8:57am UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/15 "2019-11-29T08:57:27Z")

</div>

Hi,  
with r6.16.00 it was worse:  
root/ACliC did not show an error message but MyEvent had  
only the TObject part.  
You may try my example which has the

```auto
event->Dump();
...
You will not see "number"

Cheers
Otto

PS: What I learned meanwhile: 
If the compiler doesnt show any more errors
the real (debugging) work begins
```

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [November 29, 2019, 5:49pm UTC](https://root-forum.cern.ch/t/ttree-branch-not-recognizing-actual-class-in-root-6-18-04/36846/16 "2019-11-29T17:49:27Z")

</div>

Well, that is strange. With ROOT 6.16/00 I was able to successfully fill and read a TTree multiple times with my Event class which didn’t have ClassDef in it… But if it did better work than expected, it’s nothing I’d complain about, I guess 🙂
