Confusion about batch processing root files

In my work, I need to batch convert a batch of similarly named root files into binary files. The solution I think is to first makeclass a root file and then modify the .h and .c files. Then put them in the include folder and src folder respectively, and then I can utilize loops in the main function to process them. So I modified the constructor in MakeClass:

ana(TTree *tree = 0, TString filename = "");
ana::ana(TTree *tree, TString filename) : fChain(0)
{
   // if parameter tree is not specified (or zero), connect the file
   // used to generate this class and read the Tree.
   if (tree == 0)
   {
      TFile *f = (TFile *)gROOT->GetListOfFiles()->FindObject(filename);
      if (!f || !f->IsOpen())
      {
         f = new TFile(filename);
      }
      f->GetObject("tr", tree);
   }
   Init(tree);
}

But when I do Makefile, I keep getting an error:
main.cpp:(.text.startup+0x131): undefined reference to `ana::ana(TTree*, TString)’
I changed its constructor, and I’m sure I changed the definition of the constructor, but makefile still looks looking for the constructor generated by the makeclass earlier. This confused me a bit, so I came to ask for help, hoping that everyone could help me solve my problem, or provide me with a lot of file names similar to run0017.root, run0018.root… Such a regular root file idea or code that can be forked. Thank you all.

ROOT files are binary files. I don’t understand “I need to batch convert a batch of similarly named root files into binary files”. Can you explain?

Thank you for you apply, i want to convert ‘.root’ to '.net’ that can use by my other software. I’m not very familiar with root, so I may have been wrong before, so I’m going to change the Loop function now, and when I want to use other root files, I can declare the class directly in the loop.

    string filename = Form("run%05d_final.root", number);
    TFile *ipf = new TFile(filename.c_str());
    TTree *ipt = (TTree *)ipf->Get("tr");
    ana *analysis = new ana(ipt); 
    analysis->Loop(ipt, number);  
    delete analysis;

Of course, there is still a problem here, that is, I did not delete ipf at the end of the function, but this is a new variable that will always occupy memory, but when I want to close the file, or directly unoccupy ipf, root will prompt me that the array is out of bounds, I don’t know how to solve it, but this code can meet my needs for the time being, so I didn’t continue to explore.

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