Function test() is not defined in current scope. I need help!

I am having trouble running a macro that contains code for a histogram that contains data from a root file. I worked with a friend to created the code contained in the macro and the code was done on a Mac then emailed to me to run on windows. When I try to run the macro as .x test.c I am given the following error message.

Function test() is not defined in current scope C:\Users\trent\Desktop\Research\test.c(45)

I found a similar article on this forum and it had mentioned that you must not have your code began like

int main()
{ void test{

}
I found that this did not apply to my situation. I then found another article stating that you must run the macro as .L test.C or .L test.C+. When I try to do this I am presented with the following message.

Warning: template pair duplicate definition C:\root_v5.34.36/cint\cint\stl_pair.h(31)
Warning: template reverse_iterator duplicate definition C:\root_v5.34.36/cint\cint\stl_iterator.h(269)
Warning: template allocator duplicate definition C:\root_v5.34.36/cint\cint\stl\defalloc.h(134)
Warning: template vector duplicate definition C:\root_v5.34.36/cint\cint\stl_vector.h(44)
Then taken to another root line. I am unsure what is going on and I really need some help! This is my code BTW.

#include <iostream>
#include "TComplex.h"
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include "TMath.h"
#include <math.h>
#include "TChain.h"
#include "TFile.h"
#include "TKey.h"
#include "TObject.h"
#include "TObjString.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH3D.h"
#include "TProfile.h"
#include "TCanvas.h"
#include "TBits.h"
#include "TRefArray.h"
#include "TStopwatch.h"
#include "TAxis.h"
#include "TRandom.h"
#include "TList.h"
#include "TComplex.h"
#include "TLegend.h"
#include "TMath.h"
#include "TLatex.h"
#include "TStyle.h"
#include "TMultiGraph.h"
#include "TGraphErrors.h"
#include "TGraphAsymmErrors.h"
#include "TTree.h"
#include "TH1F.h"
#include <fstream>

using namespace std;

void test () {

TFile *file = TFile::Open("\Users\trent\Desktop\mcglauber7ca_A208_sgm64.0.root");
TTree *tree = (TTree*) file->Get("nt;1");
float v2;
cout << v2 <<endl;
TH1F *hist = new TH1F("hist","hist",1000,0,0.3);
int nentries = tree->GetEntries();
cout << nentries <<endl;

for (int i = 1; i <nentries ; i++) {
tree->GetEntry(i);
if(i%1000==0) cout << v2 <<endl;
hist->Fill(v2);
}
hist->Draw();
return 0;
}


Running the file on lxplus with the version you specify seems to be working when I try. You could perhaps run it there?

I’m afraid I cannot give you more assistance on windows.

I tried with root5 on Mac and I do not get the error you mentioned.
Note that your has an error anyway: it is “void” and you have “return 0” in it.

Note also that C:\Users\trent\Desktop\Research\test.c(45) (i.e. like 45) doesn’t contain the word “test”, but

    TTree *tree = (TTree*) file->Get("nt;1");


if the file you sent corresponds to the file at C:\Users\trent\Desktop\Research\test.c. Please double-check that it’s the file you think it is.

Also, backslashes in file names need to be escaped in C++ (and most other languages): TFile::Open("\\Users\\trent\\Desktop\\mcglauber7ca_A208_sgm64.0.root");.

Cheers, Axel.

Also, backslashes in file names need to be escaped in C++ (and most other languages)

actually, only in C/C++ (and Fortran?).
python handles them just find:

>>> str = r"foo\bar\n"
>>> print str
foo\bar\n
>>> print "foo\nbar"
foo
bar


same thing for Go: https://play.golang.org/p/NqD3owty8H

What is that r in front of the string?

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