Vector declaration error

Relatively new to ROOT so this could be a simple human error!

Hello! I’m trying to analyze data from a tree. I had ROOT generate analyze.C and analyze.h from my tree, edited analyze.C to do some analysis I need, and am trying to compile/run it but getting errors. In particular, trying

g++ -O analyze analyze.C root-config --cflags --libs

gives a set of errors of repeating

analyze.h:57: error: ISO C++ forbids declaration of ‘vector’ with no type
analyze.h:57: error: expected ‘;’ before ‘<’ token

(there are a bunch of these then a bunch of subsequent errors I’m pretty sure are just stemming from this vector issue)

The lines in question in analyze.h look like

vector< double> *Hit_t;
vector < double> *Hit_posx;
vector< double> *Hit_posy;
vector< double> *Hit_E;

for example. I’m reasonably sure that there isn’t actually a problem with the root file itself or the simulation the data is comping from considering it works and others use it fine, and it seems weird that the issue would be in a file automatically generated by ROOT.

First post here so let me know if there’s more information that could be useful!

ROOT Version: 5.34.21
Platform: Ubuntu installed on Windows connected to server
Compiler: trying g++ here but also tried inside ROOT

Attach your “analyze.h” file for inspection.

Either replace all “vector<...” with “std::vector<...” (preferred) or right after “#include <vector>” add “using std::vector;” (deprecated).

Added the std:: before all the vectors. Now I get

/usr/lib/…/lib64/crt1.o: In function `_start’:

(.text+0x20): undefined reference to `main’

collect2: error: ld returned 1 exit status

You need to follow “usage instructions” shown in the generated “analyze.C” file.

Maybe you need to have a look at the: “ROOT User’s Guide” -> “Trees” -> “Using TTree::MakeClass”

If you want to create a “standalone application”, try something like this:

// ... add the source code below into the original "analyze.C" file ...
#if !defined(__CINT__) && !defined(__CLING__) && !defined(__ACLIC__)
// "Standalone Application" entry point
int main(int /*argc*/, char** /*argv*/) {
  analyze *t = new analyze(); // create an "analyze" instance
  // t->Show(0); // just for fun
  // open an output file for any histograms created in "t->Loop();" below
  TFile *f = TFile::Open("analyze.root", "recreate");
  t->Loop(); // loop through all tree entries
  f->Write(); // store all "owned" objects (e.g. histograms)
  delete f; // automatically deletes any "owned" objects, too
  delete t; // cleanup
  return 0; // success
#endif /* !defined(__CINT__) && !defined(__CLING__) && !defined(__ACLIC__) */
1 Like