ROOT Version: 6.26.00
Platform: Ubuntu 20.04.4 LTS
Compiler: g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Dear ROOT team and users,
As a beginner in ROOT and C language, I am trying to debug a root macro. For this purpose I tried to use the debugging platform that have been provided in [root.cern → debuging-root-scripts-in-eclipse]. Unfortunately I can’t proceed with the debugging because building the code is not successful. I am receiving the following errors upon compiling the “analysis.C” :
main.cpp:
#include <TApplication.h>
// TODO: Include your ROOT script below
#include "analysis.C"
int main(int argc, char **argv) {
// Instantiate TApplication
TApplication* app = new TApplication("rootEclipse", &argc, argv);
// TODO: Call your ROOT script entry fiunction
analysis();
// Enter the event loop
app->Run();
// Return success
return 0;
}
analysis.C:
#include <iostream>
#include "TROOT.h"
#include "DNAVolumeType.hh"
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <TCanvas.h>
#include <TH1.h>
using namespace std;
template<typename T>
class ThreeVector
{
private:
T _x, _y, _z;
public:
ThreeVector():_x(0),_y(0),_z(0){}
ThreeVector(T x, T y, T z)
:_x(x),_y(y),_z(z){}
~ThreeVector(){}
T x() const
{
return _x;
}
T y() const
{
return _y;
}
T z() const
{
return _z;
}
bool operator ==(const ThreeVector<T>& right) const
{
return (_x == right._x) &&
(_y == right._y) &&
(_z == right._z);
}
ThreeVector<T>& operator =(const ThreeVector<T>& right) = default;
ClassDef(ThreeVector,1)
};
#if !defined(__CLING__)
templateClassImp(ThreeVector);
#endif
class Molecule
{
public:
Molecule(){}
Molecule(string name,
int copyNumber,
const ThreeVector<double>& position,
int strand)
: fName(name)
, fCopyNumber(copyNumber)
, fPosition(position)
, fStrand(strand)
{}
~Molecule(){}
public:
string fName;
string fMaterial;
int fCopyNumber;
int fStrand;
ThreeVector<double> fPosition;
double fRadius;
double fRadiusWater;
ClassDef(Molecule,1)
};
#if !defined(__CLING__)
templateClassImp(Molecule);
#endif
std::vector<Molecule> molecule()
{
std::vector<Molecule> fMolecules;
double size;
string name;
ifstream file("VoxelStraight.fab2g4dna");
if(!file.is_open())
{
string msg ="VoxelStraight.fab2g4dna could not be opened";
throw std::invalid_argument(msg);
}
string line;
while(getline(file, line) )
{
if(line.empty())
{
continue;
}
istringstream issLine(line);
string firstItem;
issLine >> firstItem;
if("_Size" == firstItem)
{
issLine >> size;
}
else if("_pl" == firstItem)
{
string name;
issLine >> name;
string material;
issLine >> material;
int strand;
issLine >> strand;
int copyNumber;
issLine >> copyNumber;
double x;
issLine >> x;
double y;
issLine >> y;
double z;
issLine >> z;
Molecule molecule(name,
copyNumber,
ThreeVector<double>(x, y, z),
strand);
fMolecules.push_back(molecule);
}
}
file.close();
return fMolecules;
}
void analysis()
{
TH1* hist = new TH1D("hist", "hist", 10, 0, 10);
hist->FillRandom("gaus", 10000);
hist->Draw();
}
and the errors are:
/usr/bin/ld: CMakeFiles/root-eclipse.dir/src/main.cpp.o: in function `Molecule::Molecule(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, ThreeVector<double> const&, int)':
/usr/bin/ld: CMakeFiles/root-eclipse.dir/src/main.cpp.o: in function `Molecule::~Molecule()':
/usr/bin/ld: CMakeFiles/root-eclipse.dir/src/main.cpp.o: in function `Molecule::Molecule(Molecule const&)':
analysis.C:63: undefined reference to `vtable for Molecule'
/usr/bin/ld: CMakeFiles/root-eclipse.dir/src/main.cpp.o:(.data.rel.ro._ZTV11ThreeVectorIdE[_ZTV11ThreeVectorIdE]+0x28): undefined reference to `ThreeVector<double>::Streamer(TBuffer&)'
analysis.C:55: undefined reference to `ThreeVector<double>::Class()'
Since I am a new user I could not attach the “DNAVolumeType.hh” and the “CMakeList.txt”.
Just in case it could help:
I am using the Geant4-DNA package. The outputs of the example that I am using (dnadamage1) are 2 “.root” files. The final results are obtained using two ROOT macro files: “molecule.C” and “plot.C” through executing:
{
gROOT->ProcessLine(".L molecule.C");
gROOT->ProcessLine(".x plot.C");
}
Now, In order to be able to debug these codes, I am trying to combine “molecule.C” and “plot.C” into one(the “analysis.C”) as a standalone C++ code. I started with bringing the “molecule.C”, where I am encountering the above mentioned errors. If having the “plot.C” or “molecule.C” could help, I can share them with email.
Many thanks in advance,
Cheers,
Ali.