Impossible to root -l my .C codes

Hi everyone,

I have a problem with all my .C codes with int main() when I try to execute them with the root -l command. Indeed, when I do this, I obtain :

alo@MacBook-Pro TMVA_TEST_Run1 % root -l MergeNTuplesForTraining.C
root [0] 
Processing MergeNTuplesForTraining.C...
input_line_9:2:2: error: no matching function for call to 'MergeNTuplesForTraining'
 MergeNTuplesForTraining() /* .x tries to invoke function `MergeNTuplesForTraining` */
 ^~~~~~~~~~~~~~~~~~~~~~~
/Users/alo/Documents/STAGE_M2.nosync/Root_stage_M2/TMVA_TEST_Run1/MergeNTuplesForTraining.C:16:5: note: candidate function not viable: requires at least 2 arguments, but 0 were provided
int MergeNTuplesForTraining(std::string OutputFileName, std::vector<std::pair<std::string, std::string>> InputFilenames, uint MaxEv = -1)
    ^

My code is like :

int MergeNTuplesForTraining(std::string OutputFileName, std::vector<std::pair<std::string, std::string>> InputFilenames, uint MaxEv = -1) {
// My function
}

int main() {
  std::vector<std::pair<std::string, std::string>> SignalForTraining_Up_Vec;
  SignalForTraining_Up_Vec.emplace_back(std::make_pair("/Users/alo/Documents/STAGE_M2.nosync/Root_stage_M2/TMVA_TEST_Run1/Tuples/Signal/DTT_13512010_Bs_Kmunu_DecProdCut_Up_Py8_MC12.root","Bs2KmuNuTuple"));

  MergeNTuplesForTraining("DataForTraining/SignalForTraining_Up.root", {SignalForTraining_Up_Vec});
}

And I obtain this with all my codes.

But, if I do the following thing :

alo@MacBook-Pro TMVA_TEST_Run1 % root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/04                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosxarm64 on May 08 2023, 02:44:07                   |
  | From tags/v6-28-04@v6-28-04                                      |
  | With Apple clang version 14.0.3 (clang-1403.0.22.14.1)           |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] .L MergeNTuplesForTraining.C 
root [1] main()

Everything is working ! Can you help me with that ? Thanks !


ROOT Version: 6.28/04
Platform: macOS 13.3.1 (a) (22E772610a)
Compiler: clang-1403.0.22.14.1


root -l -e '.L MergeNTuplesForTraining.C' -e 'main();'

1 Like

Thanks for the answer, it is working ! But, is it possible to run my .C just by doing root -l .C ? And, if yes, which modification I need to make on my code ?

ROOT Primer β†’ ROOT Macros ;
ROOT Manual β†’ Basics β†’ ROOT macros and shared libraries

1 Like

Yes, you just need to rename the function main to MergeNTuplesForTraining (i.e. name of the script without extension)

1 Like

Yeah, I figured that’s out afterwards but thanks!