# TTreeReader TChain notify on change of file

**URL:** <https://root-forum.cern.ch/t/ttreereader-tchain-notify-on-change-of-file/58244>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [February 22, 2024, 12:59pm UTC](https://root-forum.cern.ch/t/ttreereader-tchain-notify-on-change-of-file/58244 "2024-02-22T12:59:18Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![zhubacek](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/9de0a6/32.png) [@zhubacek](https://root-forum.cern.ch/u/zhubacek)\
**Post date:** [April 16, 2024, 8:27pm UTC](https://root-forum.cern.ch/t/ttreereader-tchain-notify-on-change-of-file/58244/5 "2024-04-16T20:27:00Z")

</div>

Dear @vpadulan ,  
Thank you very much!

I slightly extended the notifier to get for example the current filename:

```auto
struct MyNotifier{
  MyNotifier() : fChain(0)
  {}
  void Init(TTree* tree)
  {
    fChain=tree;
  }
    bool Notify(){
      
        std::cout << "Notification! reading new file" << "\n";
	std::cout <<"File name: "<<fChain->GetCurrentFile()->GetName()<<std::endl;

	return true;
    }
  TTree *fChain;
};

```

This works well with the chain, but when I try what you suggest with the TTreeReader:

```auto
...
    TTreeReader myReader(&c);
    TTreeReaderValue<int> var1(myReader,"column1");
    
    MyNotifier n;
    n.Init(&c);
    TNotifyLink<MyNotifier> l{&n};
    l.PrependLink(*myReader.GetTree());
    int counter =0;
    while (myReader.Next())
      {
	counter++;
	std::cout <<"Event: "<<counter<<" "<<*var1<<std::endl;
      }

```

works as well, however I get a warning:  
`Warning in <TChain::TTree::SetNotify>: The tree or chain already has a fNotify registered and it is a TNotifyLink, while the new object is not a TNotifyLink. Setting fNotify to the new value will lead to an orphan linked list of TNotifyLinks and it is most likely not intended. If this is the intended goal, please call SetNotify(nullptr) first to silence this warning.`  
it seems that the notification is set up twice?

In that case, I don’t understand which Notify link is already set up? I tried calling ` c.SetNotify(nullptr);` before setting up `myReader` and `MyNotifier` but this didn’t help?

Thank you  
Zdenek

---

_[View the full topic](https://root-forum.cern.ch/t/ttreereader-tchain-notify-on-change-of-file/58244)._
