diff --git a/tree/treeplayer/inc/TTreeReaderGenerator.h b/tree/treeplayer/inc/TTreeReaderGenerator.h index ff8cedaeca6b7..ed1dade64517d 100644 --- a/tree/treeplayer/inc/TTreeReaderGenerator.h +++ b/tree/treeplayer/inc/TTreeReaderGenerator.h @@ -33,6 +33,8 @@ class TLeaf; namespace ROOT { namespace Internal { + TString GetCppName(TString name); + /// 0 for the general case, 1 when this a split clases inside a TClonesArray, /// 2 when this is a split classes inside an STL container. enum ELocation { kOut=0, kClones, kSTL }; diff --git a/tree/treeplayer/src/TTreePlayer.cxx b/tree/treeplayer/src/TTreePlayer.cxx index a1b33a3e13106..036153641c6c7 100644 --- a/tree/treeplayer/src/TTreePlayer.cxx +++ b/tree/treeplayer/src/TTreePlayer.cxx @@ -733,17 +733,20 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) opt.ToLower(); // Connect output files - if (!classname) classname = fTree->GetName(); + const TString fileNameStem = classname ? classname : fTree->GetName(); + const TString cppClassName = ROOT::Internal::GetCppName(fileNameStem); + if (cppClassName != fileNameStem) + Warning("TTreePlayer::MakeClass", "The %s name provided ('%s') is not a valid C++ identifier and will be converted to '%s'.",(classname ? "class" : "tree"), fileNameStem.Data(), cppClassName.Data()); TString thead; - thead.Form("%s.h", classname); + thead.Form("%s.h", fileNameStem.Data()); FILE *fp = fopen(thead, "w"); if (!fp) { Error("MakeClass","cannot open output file %s", thead.Data()); return 3; } TString tcimp; - tcimp.Form("%s.C", classname); + tcimp.Form("%s.C", fileNameStem.Data()); FILE *fpc = fopen(tcimp, "w"); if (!fpc) { Error("MakeClass","cannot open output file %s", tcimp.Data()); @@ -780,8 +783,8 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } fprintf(fp,"//////////////////////////////////////////////////////////\n"); fprintf(fp,"\n"); - fprintf(fp,"#ifndef %s_h\n",classname); - fprintf(fp,"#define %s_h\n",classname); + fprintf(fp,"#ifndef %s_h\n",cppClassName.Data()); + fprintf(fp,"#define %s_h\n",cppClassName.Data()); fprintf(fp,"\n"); fprintf(fp,"#include \n"); fprintf(fp,"#include \n"); @@ -858,11 +861,11 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fp,"\n"); if (opt.Contains("selector")) { - fprintf(fp,"class %s : public TSelector {\n",classname); + fprintf(fp,"class %s : public TSelector {\n",cppClassName.Data()); fprintf(fp,"public :\n"); fprintf(fp," TTree *fChain; //!pointer to the analyzed TTree or TChain\n"); } else { - fprintf(fp,"class %s {\n",classname); + fprintf(fp,"class %s {\n",cppClassName.Data()); fprintf(fp,"public :\n"); fprintf(fp," TTree *fChain; //!pointer to the analyzed TTree or TChain\n"); fprintf(fp," Int_t fCurrent; //!current Tree number in a TChain\n"); @@ -975,11 +978,11 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) leafStatus[l] = 0; } if (bre->GetType() == 3 || bre->GetType() == 4) { - fprintf(fp," %-15s %s_;\n","Int_t", branchname); + fprintf(fp," %-15s %s_;\n","Int_t", ROOT::Internal::GetCppName(branchname).Data()); continue; } if (bre->IsBranchFolder()) { - fprintf(fp," %-15s *%s;\n",bre->GetClassName(), branchname); + fprintf(fp," %-15s *%s;\n",bre->GetClassName(), ROOT::Internal::GetCppName(branchname).Data()); mustInit.Add(bre); continue; } else { @@ -987,16 +990,16 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } if (bre->GetStreamerType() < 0) { if (branch->GetListOfBranches()->GetEntriesFast()) { - fprintf(fp,"%s%-15s *%s;\n",headcom,bre->GetClassName(), branchname); + fprintf(fp,"%s%-15s *%s;\n",headcom,bre->GetClassName(), ROOT::Internal::GetCppName(branchname).Data()); } else { - fprintf(fp,"%s%-15s *%s;\n",head,bre->GetClassName(), branchname); + fprintf(fp,"%s%-15s *%s;\n",head,bre->GetClassName(), ROOT::Internal::GetCppName(branchname).Data()); mustInit.Add(bre); } continue; } if (bre->GetStreamerType() == 0) { if (!TClass::GetClass(bre->GetClassName())->HasInterpreterInfo()) {leafStatus[l] = 1; head = headcom;} - fprintf(fp,"%s%-15s *%s;\n",head,bre->GetClassName(), branchname); + fprintf(fp,"%s%-15s *%s;\n",head,bre->GetClassName(), ROOT::Internal::GetCppName(branchname).Data()); if (leafStatus[l] == 0) mustInit.Add(bre); continue; } @@ -1016,11 +1019,11 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) if (elem->IsA() == TStreamerBase::Class()) {leafStatus[l] = 1; continue;} if (!TClass::GetClass(elem->GetTypeName())) {leafStatus[l] = 1; continue;} if (!TClass::GetClass(elem->GetTypeName())->HasInterpreterInfo()) {leafStatus[l] = 1; head = headcom;} - if (leafcount) fprintf(fp,"%s%-15s %s[kMax%s];\n",head,elem->GetTypeName(), branchname,blen); - else fprintf(fp,"%s%-15s %s;\n",head,elem->GetTypeName(), branchname); + if (leafcount) fprintf(fp,"%s%-15s %s[kMax%s];\n",head,elem->GetTypeName(), ROOT::Internal::GetCppName(branchname).Data(),blen); + else fprintf(fp,"%s%-15s %s;\n",head,elem->GetTypeName(), ROOT::Internal::GetCppName(branchname).Data()); } else { if (!TClass::GetClass(bre->GetClassName())->HasInterpreterInfo()) {leafStatus[l] = 1; head = headcom;} - fprintf(fp,"%s%-15s %s;\n",head,bre->GetClassName(), branchname); + fprintf(fp,"%s%-15s %s;\n",head,bre->GetClassName(), ROOT::Internal::GetCppName(branchname).Data()); } continue; } @@ -1069,12 +1072,12 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } if (dimensions.Length()) { if (kmax) fprintf(fp," %-14s %s%s[kMax%s]%s; //[%s]\n",leaf->GetTypeName(), stars, - branchname,blen,dimensions.Data(),leafcountName); + ROOT::Internal::GetCppName(branchname).Data(),blen,dimensions.Data(),leafcountName); else fprintf(fp," %-14s %s%s[%d]%s; //[%s]\n",leaf->GetTypeName(), stars, - branchname,len,dimensions.Data(),leafcountName); + ROOT::Internal::GetCppName(branchname).Data(),len,dimensions.Data(),leafcountName); } else { - if (kmax) fprintf(fp," %-14s %s%s[kMax%s]; //[%s]\n",leaf->GetTypeName(), stars, branchname,blen,leafcountName); - else fprintf(fp," %-14s %s%s[%d]; //[%s]\n",leaf->GetTypeName(), stars, branchname,len,leafcountName); + if (kmax) fprintf(fp," %-14s %s%s[kMax%s]; //[%s]\n",leaf->GetTypeName(), stars, ROOT::Internal::GetCppName(branchname).Data(),blen,leafcountName); + else fprintf(fp," %-14s %s%s[%d]; //[%s]\n",leaf->GetTypeName(), stars, ROOT::Internal::GetCppName(branchname).Data(),len,leafcountName); } if (stars[0]=='*') { TNamed *n; @@ -1084,10 +1087,10 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } } else { if (strstr(branchname,"[")) len = 1; - if (len < 2) fprintf(fp," %-15s %s;\n",leaf->GetTypeName(), branchname); + if (len < 2) fprintf(fp," %-15s %s;\n",leaf->GetTypeName(), ROOT::Internal::GetCppName(branchname).Data()); else { - if (twodim) fprintf(fp," %-15s %s%s;\n",leaf->GetTypeName(), branchname,(char*)strstr(leaf->GetTitle(),"[")); - else fprintf(fp," %-15s %s[%d];\n",leaf->GetTypeName(), branchname,len); + if (twodim) fprintf(fp," %-15s %s%s;\n",leaf->GetTypeName(), ROOT::Internal::GetCppName(branchname).Data(),(char*)strstr(leaf->GetTitle(),"[")); + else fprintf(fp," %-15s %s[%d];\n",leaf->GetTypeName(), ROOT::Internal::GetCppName(branchname).Data(),len); } } } @@ -1104,8 +1107,8 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) // generate class member functions prototypes if (opt.Contains("selector")) { fprintf(fp,"\n"); - fprintf(fp," %s(TTree * /*tree*/ =0) : fChain(0) { }\n",classname) ; - fprintf(fp," ~%s() override { }\n",classname); + fprintf(fp," %s(TTree * /*tree*/ =0) : fChain(0) { }\n",cppClassName.Data()) ; + fprintf(fp," ~%s() override { }\n",cppClassName.Data()); fprintf(fp," Int_t Version() const override { return 2; }\n"); fprintf(fp," void Begin(TTree *tree) override;\n"); fprintf(fp," void SlaveBegin(TTree *tree) override;\n"); @@ -1119,15 +1122,15 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fp," TList* GetOutputList() const override { return fOutput; }\n"); fprintf(fp," void SlaveTerminate() override;\n"); fprintf(fp," void Terminate() override;\n\n"); - fprintf(fp," ClassDefOverride(%s,0);\n",classname); + fprintf(fp," ClassDefOverride(%s,0);\n",cppClassName.Data()); fprintf(fp,"};\n"); fprintf(fp,"\n"); fprintf(fp,"#endif\n"); fprintf(fp,"\n"); } else { fprintf(fp,"\n"); - fprintf(fp," %s(TTree *tree=0);\n",classname); - fprintf(fp," virtual ~%s();\n",classname); + fprintf(fp," %s(TTree *tree=0);\n",cppClassName.Data()); + fprintf(fp," virtual ~%s();\n",cppClassName.Data()); fprintf(fp," virtual Int_t Cut(Long64_t entry);\n"); fprintf(fp," virtual Int_t GetEntry(Long64_t entry);\n"); fprintf(fp," virtual Long64_t LoadTree(Long64_t entry);\n"); @@ -1141,9 +1144,9 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fp,"\n"); } // generate code for class constructor - fprintf(fp,"#ifdef %s_cxx\n",classname); + fprintf(fp,"#ifdef %s_cxx\n",cppClassName.Data()); if (!opt.Contains("selector")) { - fprintf(fp,"%s::%s(TTree *tree) : fChain(0) \n",classname,classname); + fprintf(fp,"%s::%s(TTree *tree) : fChain(0) \n",cppClassName.Data(),cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp,"// if parameter tree is not specified (or zero), connect the file\n"); fprintf(fp,"// used to generate this class and read the Tree.\n"); @@ -1199,7 +1202,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) // generate code for class destructor() if (!opt.Contains("selector")) { - fprintf(fp,"%s::~%s()\n",classname,classname); + fprintf(fp,"%s::~%s()\n",cppClassName.Data(),cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp," if (!fChain) return;\n"); if (isHbook) { @@ -1212,7 +1215,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } // generate code for class member function GetEntry() if (!opt.Contains("selector")) { - fprintf(fp,"Int_t %s::GetEntry(Long64_t entry)\n",classname); + fprintf(fp,"Int_t %s::GetEntry(Long64_t entry)\n",cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp,"// Read contents of entry.\n"); @@ -1222,7 +1225,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } // generate code for class member function LoadTree() if (!opt.Contains("selector")) { - fprintf(fp,"Long64_t %s::LoadTree(Long64_t entry)\n",classname); + fprintf(fp,"Long64_t %s::LoadTree(Long64_t entry)\n",cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp,"// Set the environment to read one entry\n"); fprintf(fp," if (!fChain) return -5;\n"); @@ -1238,7 +1241,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } // generate code for class member function Init(), first pass = get branch pointer - fprintf(fp,"void %s::Init(TTree *tree)\n",classname); + fprintf(fp,"void %s::Init(TTree *tree)\n",cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp," // The Init() function is called when the selector needs to initialize\n" " // a new tree or chain. Typically here the branch addresses and branch\n" @@ -1267,7 +1270,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) if (*bname == '>') *bname='_'; bname++; } - fprintf(fp," %s = 0;\n",branchname ); + fprintf(fp," %s = 0;\n",ROOT::Internal::GetCppName(branchname).Data() ); } } if (mustInitArr.Last()) { @@ -1338,9 +1341,9 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } if (leafcount) len = leafcount->GetMaximum()+1; if (len > 1) fprintf(fp,"%s fChain->SetBranchAddress(\"%s\", %s, &b_%s);\n", - maybedisable,branch->GetName(), branchname, R__GetBranchPointerName(leaf).Data()); + maybedisable,branch->GetName(), ROOT::Internal::GetCppName(branchname).Data(), R__GetBranchPointerName(leaf).Data()); else fprintf(fp,"%s fChain->SetBranchAddress(\"%s\", &%s, &b_%s);\n", - maybedisable,branch->GetName(), branchname, R__GetBranchPointerName(leaf).Data()); + maybedisable,branch->GetName(), ROOT::Internal::GetCppName(branchname).Data(), R__GetBranchPointerName(leaf).Data()); } //must call Notify in case of MakeClass if (!opt.Contains("selector")) { @@ -1351,7 +1354,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fp,"\n"); // generate code for class member function Notify() - fprintf(fp,"bool %s::Notify()\n",classname); + fprintf(fp,"bool %s::Notify()\n",cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp," // The Notify() function is called when a new file is opened. This\n" " // can be either for a new TTree in a TChain or when when a new TTree\n" @@ -1364,7 +1367,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) // generate code for class member function Show() if (!opt.Contains("selector")) { - fprintf(fp,"void %s::Show(Long64_t entry)\n",classname); + fprintf(fp,"void %s::Show(Long64_t entry)\n",cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp,"// Print contents of entry.\n"); fprintf(fp,"// If entry is not specified, print current entry\n"); @@ -1375,7 +1378,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } // generate code for class member function Cut() if (!opt.Contains("selector")) { - fprintf(fp,"Int_t %s::Cut(Long64_t entry)\n",classname); + fprintf(fp,"Int_t %s::Cut(Long64_t entry)\n",cppClassName.Data()); fprintf(fp,"{\n"); fprintf(fp,"// This function may be called from Loop.\n"); fprintf(fp,"// returns 1 if entry is accepted.\n"); @@ -1384,22 +1387,22 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fp," return 1;\n"); fprintf(fp,"}\n"); } - fprintf(fp,"#endif // #ifdef %s_cxx\n",classname); + fprintf(fp,"#endif // #ifdef %s_cxx\n",cppClassName.Data()); //======================Generate classname.C===================== if (!opt.Contains("selector")) { // generate code for class member function Loop() - fprintf(fpc,"#define %s_cxx\n",classname); + fprintf(fpc,"#define %s_cxx\n",cppClassName.Data()); fprintf(fpc,"#include \"%s\"\n",thead.Data()); fprintf(fpc,"#include \n"); fprintf(fpc,"#include \n"); fprintf(fpc,"#include \n"); fprintf(fpc,"\n"); - fprintf(fpc,"void %s::Loop()\n",classname); + fprintf(fpc,"void %s::Loop()\n",cppClassName.Data()); fprintf(fpc,"{\n"); fprintf(fpc,"// In a ROOT session, you can do:\n"); - fprintf(fpc,"// root> .L %s.C\n",classname); - fprintf(fpc,"// root> %s t\n",classname); + fprintf(fpc,"// root> .L %s.C\n",fileNameStem.Data()); + fprintf(fpc,"// root> %s t\n",cppClassName.Data()); fprintf(fpc,"// root> t.GetEntry(12); // Fill t data members with entry number 12\n"); fprintf(fpc,"// root> t.Show(); // Show values of entry 12\n"); fprintf(fpc,"// root> t.Show(16); // Read and show values of entry 16\n"); @@ -1432,8 +1435,8 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) } if (opt.Contains("selector")) { // generate usage comments and list of includes - fprintf(fpc,"#define %s_cxx\n",classname); - fprintf(fpc,"// The class definition in %s.h has been generated automatically\n",classname); + fprintf(fpc,"#define %s_cxx\n",cppClassName.Data()); + fprintf(fpc,"// The class definition in %s.h has been generated automatically\n",fileNameStem.Data()); fprintf(fpc,"// by the ROOT utility TTree::MakeSelector(). This class is derived\n"); fprintf(fpc,"// from the ROOT class TSelector. For more information on the TSelector\n" "// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.\n\n"); @@ -1451,9 +1454,9 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fpc,"//\n"); fprintf(fpc,"// To use this file, try the following session on your Tree T:\n"); fprintf(fpc,"//\n"); - fprintf(fpc,"// root> T->Process(\"%s.C\")\n",classname); - fprintf(fpc,"// root> T->Process(\"%s.C\",\"some options\")\n",classname); - fprintf(fpc,"// root> T->Process(\"%s.C+\")\n",classname); + fprintf(fpc,"// root> T->Process(\"%s.C\")\n",fileNameStem.Data()); + fprintf(fpc,"// root> T->Process(\"%s.C\",\"some options\")\n",fileNameStem.Data()); + fprintf(fpc,"// root> T->Process(\"%s.C+\")\n",fileNameStem.Data()); fprintf(fpc,"//\n\n"); fprintf(fpc,"#include \"%s\"\n",thead.Data()); fprintf(fpc,"#include \n"); @@ -1461,7 +1464,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fpc,"\n"); // generate code for class member function Begin fprintf(fpc,"\n"); - fprintf(fpc,"void %s::Begin(TTree * /*tree*/)\n",classname); + fprintf(fpc,"void %s::Begin(TTree * /*tree*/)\n",cppClassName.Data()); fprintf(fpc,"{\n"); fprintf(fpc," // The Begin() function is called at the start of the query.\n"); fprintf(fpc," // When running with PROOF Begin() is only called on the client.\n"); @@ -1472,7 +1475,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fpc,"}\n"); // generate code for class member function SlaveBegin fprintf(fpc,"\n"); - fprintf(fpc,"void %s::SlaveBegin(TTree * /*tree*/)\n",classname); + fprintf(fpc,"void %s::SlaveBegin(TTree * /*tree*/)\n",cppClassName.Data()); fprintf(fpc,"{\n"); fprintf(fpc," // The SlaveBegin() function is called after the Begin() function.\n"); fprintf(fpc," // When running with PROOF SlaveBegin() is called on each slave server.\n"); @@ -1483,7 +1486,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fpc,"}\n"); // generate code for class member function Process fprintf(fpc,"\n"); - fprintf(fpc,"bool %s::Process(Long64_t entry)\n",classname); + fprintf(fpc,"bool %s::Process(Long64_t entry)\n",cppClassName.Data()); fprintf(fpc,"{\n"); fprintf(fpc," // The Process() function is called for each entry in the tree (or possibly\n" " // keyed object in the case of PROOF) to be processed. The entry argument\n" @@ -1501,13 +1504,13 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) " //\n" " // Use fStatus to set the return value of TTree::Process().\n" " //\n" - " // The return value is currently not used.\n\n", classname); + " // The return value is currently not used.\n\n", cppClassName.Data()); fprintf(fpc,"\n"); fprintf(fpc," return true;\n"); fprintf(fpc,"}\n"); // generate code for class member function SlaveTerminate fprintf(fpc,"\n"); - fprintf(fpc,"void %s::SlaveTerminate()\n",classname); + fprintf(fpc,"void %s::SlaveTerminate()\n",cppClassName.Data()); fprintf(fpc,"{\n"); fprintf(fpc," // The SlaveTerminate() function is called after all entries or objects\n" " // have been processed. When running with PROOF SlaveTerminate() is called\n" @@ -1517,7 +1520,7 @@ Int_t TTreePlayer::MakeClass(const char *classname, const char *option) fprintf(fpc,"}\n"); // generate code for class member function Terminate fprintf(fpc,"\n"); - fprintf(fpc,"void %s::Terminate()\n",classname); + fprintf(fpc,"void %s::Terminate()\n",cppClassName.Data()); fprintf(fpc,"{\n"); fprintf(fpc," // The Terminate() function is the last function to be called during\n" " // a query. It always runs on the client, it can be used to present\n" diff --git a/tree/treeplayer/src/TTreeReaderGenerator.cxx b/tree/treeplayer/src/TTreeReaderGenerator.cxx index 2dd53a67e10ed..120889b640b64 100644 --- a/tree/treeplayer/src/TTreeReaderGenerator.cxx +++ b/tree/treeplayer/src/TTreeReaderGenerator.cxx @@ -31,10 +31,20 @@ #include "TObjString.h" #include "TVirtualCollectionProxy.h" #include "TVirtualStreamerInfo.h" +#include "TInterpreter.h" namespace ROOT { namespace Internal { + /** + * @brief Convert a valid TTree branch name or filename into a valid C++ variable name + * @param name a TString with the original name + * @return a TString with the converted name valid to use as C++ variable in a script + */ + TString GetCppName(TString name) { + return gInterpreter->MapCppName(name.Data()); + } + //////////////////////////////////////////////////////////////////////////////// /// Constructor. Analyzes the tree and writes selector. @@ -807,7 +817,11 @@ namespace Internal { //======================Generate classname.h===================== TString thead; - thead.Form("%s.h", fClassname.Data()); + const TString fileNameStem = fClassname; + const TString cppClassName = ROOT::Internal::GetCppName(fClassname); + if (cppClassName != fileNameStem) + Warning("TTreeReaderGenerator::WriteSelector", "The class name provided ('%s') is not a valid C++ identifier and will be converted to '%s', the code produced will likely fail to compile.", fileNameStem.Data(), cppClassName.Data()); + thead.Form("%s.h", fileNameStem.Data()); std::ofstream ofs (thead, std::ofstream::out); if (!ofs) { Error("WriteSelector","cannot open output file %s", thead.Data()); @@ -828,8 +842,8 @@ R"CODE(////////////////////////////////////////////////////////// ofs << R"CODE(////////////////////////////////////////////////////////// -#ifndef )CODE" << fClassname << R"CODE(_h -#define )CODE" << fClassname << R"CODE(_h +#ifndef )CODE" << cppClassName << R"CODE(_h +#define )CODE" << cppClassName << R"CODE(_h #include #include @@ -854,7 +868,7 @@ R"CODE(#include // Generate class declaration with TTreeReaderValues and Arrays ofs << -R"CODE(class )CODE" << fClassname << R"CODE( : public TSelector { +R"CODE(class )CODE" << cppClassName << R"CODE( : public TSelector { public : TTreeReader fReader; //!the tree reader TTree *fChain = 0; //!pointer to the analyzed TTree or TChain @@ -864,17 +878,18 @@ public : next = &fListOfReaders; TTreeReaderDescriptor *descriptor; while ( ( descriptor = (TTreeReaderDescriptor*)next() ) ) { + const TString validName = ROOT::Internal::GetCppName(descriptor->fName); ofs << " TTreeReader" << (descriptor->fType == TTreeReaderDescriptor::ReaderType::kValue ? "Value" : "Array") << "<" << descriptor->fDataType - << "> " << descriptor->fName + << "> " << validName << " = {fReader, \"" << descriptor->fBranchName << "\"};" << std::endl; } // Generate class member functions prototypes ofs << R"CODE( - )CODE" << fClassname << R"CODE((TTree * /*tree*/ =0) { } - ~)CODE" << fClassname << R"CODE(() override { } + )CODE" << cppClassName << R"CODE((TTree * /*tree*/ =0) { } + ~)CODE" << cppClassName << R"CODE(() override { } Int_t Version() const override { return 2; } void Begin(TTree *tree) override; void SlaveBegin(TTree *tree) override; @@ -889,14 +904,14 @@ R"CODE( void SlaveTerminate() override; void Terminate() override; - ClassDefOverride()CODE" << fClassname << R"CODE(,0); + ClassDefOverride()CODE" << cppClassName << R"CODE(,0); }; #endif -#ifdef )CODE" << fClassname << R"CODE(_cxx -void )CODE" << fClassname << R"CODE(::Init(TTree *tree) +#ifdef )CODE" << cppClassName << R"CODE(_cxx +void )CODE" << cppClassName << R"CODE(::Init(TTree *tree) { // The Init() function is called when the selector needs to initialize // a new tree or chain. Typically here the reader is initialized. @@ -908,7 +923,7 @@ void )CODE" << fClassname << R"CODE(::Init(TTree *tree) fReader.SetTree(tree); } -bool )CODE" << fClassname << R"CODE(::Notify() +bool )CODE" << cppClassName << R"CODE(::Notify() { // The Notify() function is called when a new file is opened. This // can be either for a new TTree in a TChain or when when a new TTree @@ -920,13 +935,13 @@ bool )CODE" << fClassname << R"CODE(::Notify() } -#endif // #ifdef )CODE" << fClassname << R"CODE(_cxx +#endif // #ifdef )CODE" << cppClassName << R"CODE(_cxx )CODE"; ofs.close(); //======================Generate classname.C===================== TString tcimp; - tcimp.Form("%s.C", fClassname.Data()); + tcimp.Form("%s.C", fileNameStem.Data()); std::ofstream ofsc (tcimp, std::ofstream::out); if (!ofsc) { Error("WriteSelector","cannot open output file %s", tcimp.Data()); @@ -934,8 +949,8 @@ bool )CODE" << fClassname << R"CODE(::Notify() } ofsc << -R"CODE(#define )CODE" << fClassname << R"CODE(_cxx -// The class definition in )CODE" << fClassname << R"CODE(.h has been generated automatically +R"CODE(#define )CODE" << cppClassName << R"CODE(_cxx +// The class definition in )CODE" << cppClassName << R"CODE(.h has been generated automatically // by the ROOT utility TTree::MakeSelector(). This class is derived // from the ROOT class TSelector. For more information on the TSelector // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual. @@ -965,7 +980,7 @@ R"CODE(#define )CODE" << fClassname << R"CODE(_cxx #include #include -void )CODE" << fClassname << R"CODE(::Begin(TTree * /*tree*/) +void )CODE" << cppClassName << R"CODE(::Begin(TTree * /*tree*/) { // The Begin() function is called at the start of the query. // When running with PROOF Begin() is only called on the client. @@ -974,7 +989,7 @@ void )CODE" << fClassname << R"CODE(::Begin(TTree * /*tree*/) TString option = GetOption(); } -void )CODE" << fClassname << R"CODE(::SlaveBegin(TTree * /*tree*/) +void )CODE" << cppClassName << R"CODE(::SlaveBegin(TTree * /*tree*/) { // The SlaveBegin() function is called after the Begin() function. // When running with PROOF SlaveBegin() is called on each slave server. @@ -984,7 +999,7 @@ void )CODE" << fClassname << R"CODE(::SlaveBegin(TTree * /*tree*/) } -bool )CODE" << fClassname << R"CODE(::Process(Long64_t entry) +bool )CODE" << cppClassName << R"CODE(::Process(Long64_t entry) { // The Process() function is called for each entry in the tree (or possibly // keyed object in the case of PROOF) to be processed. The entry argument @@ -1007,7 +1022,7 @@ bool )CODE" << fClassname << R"CODE(::Process(Long64_t entry) return true; } -void )CODE" << fClassname << R"CODE(::SlaveTerminate() +void )CODE" << cppClassName << R"CODE(::SlaveTerminate() { // The SlaveTerminate() function is called after all entries or objects // have been processed. When running with PROOF SlaveTerminate() is called @@ -1015,7 +1030,7 @@ void )CODE" << fClassname << R"CODE(::SlaveTerminate() } -void )CODE" << fClassname << R"CODE(::Terminate() +void )CODE" << cppClassName << R"CODE(::Terminate() { // The Terminate() function is the last function to be called during // a query. It always runs on the client, it can be used to present