ROOT6 scripts not able to find class declared with ClassDef/ClassImp

Hello ROOT experts —

I am trying to run some ROOT scripts that use a new class I wrote, using the ClassDef/ClassImp macros to allow ROOT to see it.

Basically, I want to run these two scripts in a bash shell:

root -b -q -l ‘compileCode.cc’
root -b -q -l ‘runTest.cc’

where compileCode.cc is —

{
std::cout << " >>> Compiling testClass.cc" << std::endl;
gROOT->ProcessLine(string(“.L testClass.cc++”).c_str());
}

and runTest.cc is —

{
std::cout << " >>> Compiling testClass.cc" << std::endl;
gROOT->ProcessLine(string(“.L testClass.cc+”).c_str());

testClass classInstance(5);
classInstance.aTestMethod();
}

when I do this I get the following error —

/afs/cern.ch/user/a/awisecar/WJetsTreeAnalysis16_lxplus7/CMSSW_7_6_0/src/classTest/./runTest.cc:17:14: error: expected ‘;’ after expression
testClass classInstance(5); //specified argument
^
;
/afs/cern.ch/user/a/awisecar/WJetsTreeAnalysis16_lxplus7/CMSSW_7_6_0/src/classTest/./runTest.cc:17:15: error: use of undeclared identifier ‘classInstance’
testClass classInstance(5); //specified argument
^
/afs/cern.ch/user/a/awisecar/WJetsTreeAnalysis16_lxplus7/CMSSW_7_6_0/src/classTest/./runTest.cc:18:5: error: use of undeclared identifier ‘classInstance’
classInstance.aTestMethod();
^

this doesn’t make sense to me because when I enter the root prompt and run the commands individually —

root -b
gROOT->ProcessLine(string(“.L testClass.cc++”).c_str())
testClass classInstance(5)
classInstance.aTestMethod()

the class structure is found and executes the commands correctly.

The class is called testClass and is declared in the following files, using ClassDef & ClassImp:

testClass.h —

#ifndef TESTCLASS_H
#define TESTCLASS_H
#include “TObject.h”

class testClass : public TObject {
public:
testClass(int anInteger = 0);
~testClass();
void aTestMethod();

//Define the class for the dictionary
ClassDef(testClass, 2);
};
#endif

and testClass.cc —

#include
#include “testClass.h”

using namespace std;

ClassImp(testClass)

testClass::testClass(int anInteger){
std::cout << “\nyou have created an instance of the testClass class” << std::endl;
std::cout << "anInteger = " << anInteger << std::endl;
}

testClass::~testClass(){
}

void testClass::aTestMethod(){
std::cout << “\nthis is a test of the testClass::aTestMethod function” << std::endl;
}

Can you enlighten me on why this is not working?
I am running on lxplus7 and using the environment within CMSSW_7_6_0 (ROOT 6.02/13 and gcc 4.9.3).

Thanks, Andrew.

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