I have the main macro Analyze.C that looks like:
#include "DataTable.h"
void Analyze() {
gROOT->Reset();
DataTable dt = new DataTable(blah);
//creates a .root file & writes two TTrees into the root file
//some calculations using DataTable (e.g. dt.dLookUp(d) where d is a doulbe) & TMath
//adds a branch to each TTree in the file
}
and I have DataTable.h and DataTable.cpp that defines the class DataTable & its relevant methods.
However, when I run .x Analyze.C on interactive root, I get errors like:
IncrementalExecutor::executeFunction: symbol ‘_ZN7DataTable7dLookUpEd’ unresolved while linking [cling interface function]!
You are probably missing the definition of DataTable::dLookUp(double)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol ‘_ZN7DataTableC1ESs’ unresolved while linking [cling interface function]!
You are probably missing the definition of DataTable::DataTable(std::string)
Maybe you need to load the corresponding shared library?
So, it seems that interpreter does not “include” DataTable.h and therefore is not aware of what the DataTable constructor (using one string parameter) is or its method “dLookUp” is.
Here is the weird thing: if I try the same thing AGAIN immediately (literally, up arrow and then enter), the macro starts running without any error about the DataTable class. However, without doing the calculation corresponding to DataTable::dLookUp(double d), it uses d as it is. When it is finished running, the trees & root file are saved properly, but the values in the TTree reflects not the calculated result of DataTable::dLookUp(d) but simply d.
How is this happening, and how should I fix this? How do I import/include a class that is defined in a different .h and .cpp file within a macro?
I have tried:
- Get rid of #include “CDTable.h” in the Analyze.C macro file
- In root, before running the macro, run .L CDTable.h
- Then, run macro .x Analyze.C
I get the exact same error as above and the same weird “run” when I execute the macro again.
- Get rid of #include “CDTable.h” in the Analyze.C macro file
- In root, before running the macro, run gSystem->Load(“CDTable.h”);
- Then, run macro .x Analyze.C
However, I get an error that looks like:
Analyze.C:18:2: error: unknown type
name 'DataTable’
DataTable dt = DataTable(“DataLookUp.dat”);
^
Analyze.C:18:16: error: use of
undeclared identifier 'DataTable’
DataTable dt = DataTable(“DataLookUp.dat”);
^
so it still does not understand what the class DataTable is. If I repeat, I get the same error message (not a weird run where it skips the DataTable related lines)
So, what is wrong here? How can I import/include/load a .h or .cpp file that defines a class, and utilize when executing a macro?