How to check existence of gDirectory

I used to use :

if (gDirectory != nullptr)

and it was working.
Now I get the following error:

/home/testbeam/eudaq-v1/monitors/onlinemon/src/ In member function ‘virtual void EUDAQMonitorCollection::Write(TFile*)’:
/home/testbeam/eudaq-v1/monitors/onlinemon/src/ error: ambiguous overload for ‘operator!=’ (operand types are ‘ROOT::Internal::TDirectoryAtomicAdapter’ and ‘std::nullptr_t’)
   if (gDirectory != nullptr) // check if this pointer exists
/home/testbeam/eudaq-v1/monitors/onlinemon/src/ note: candidates are:
/home/testbeam/eudaq-v1/monitors/onlinemon/src/ note: operator!=(TDirectory*, TDirectory*) <built-in>
In file included from /home/testbeam/root/myBuild/include/TDirectoryFile.h:25:0,
                 from /home/testbeam/root/myBuild/include/TFile.h:28,
                 from /home/testbeam/eudaq-v1/monitors/onlinemon/src/../include/EUDAQMonitorCollection.hh:13,
                 from /home/testbeam/eudaq-v1/monitors/onlinemon/src/
/home/testbeam/root/myBuild/include/TDirectory.h:266:12: note: bool ROOT::Internal::TDirectoryAtomicAdapter::operator!=(const TDirectory*) const
       bool operator!=(const TDirectory *other) const {
/home/testbeam/root/myBuild/include/TDirectory.h:274:12: note: bool ROOT::Internal::TDirectoryAtomicAdapter::operator!=(TDirectory*) const
       bool operator!=(TDirectory *other) const {
/home/testbeam/eudaq-v1/monitors/onlinemon/src/ In member function ‘virtual void HitmapCollection::Write(TFile*)’:

Is there a way to check the existence of gDirectory?

_ROOT Version: 2.24.06
_Platform: CENTOS7
_Compiler: GCC 4.8.5

Try: if (gDirectory)

Did you try

if (!gDirectory)

Many thanks Wile and pcanal
It’s working indeed
The simplest solution indeed is the one that most likely fixes the problem


  • Mauro.

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