From d23dce318178c384897c1c9e13d8edfecf5d6490 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Tue, 7 Feb 2023 18:49:54 -0500 Subject: [PATCH] [root6] Fix missing declarations in the code interpreted by Cling (#451) This should have been a part of #448 as the changes are closely related but unfortunately that PR was merged before I had a chance to update it. A couple of issues seen in the ROOT6 CI tests are taken care of: 1. Include missing definitions when interpreting AgMLGeometry. Unlike `rootcint`, `rootcling` needs to see explicit definitions of the types used in an interpreted code. ``` LoadTable: .L /star-sw/StarDb/AgMLGeometry/Geometry.y2021a.C In file included from input_line_732:1: In file included from /star-sw/StarDb/AgMLGeometry/Geometry.y2021a.C:2: /star-sw/StarDb/AgMLGeometry/CreateGeometry.h:10:8: error: use of undeclared identifier 'gGeoManager' if ( gGeoManager ) { ^ ``` 2. StBFChain: Declare global pointer to `chain` in compiled code. It appears that the ROOT6 interpreter prefers to see the declaration of the main StBFChain in the compiled code over the one in the `bfc.C` macro. ``` LoadTable: .L /star-sw/StarDb/AgMLGeometry/Geometry.y2021a.C IncrementalExecutor::executeFunction: symbol 'chain' unresolved while linking [cling interface function]! root4star: .sl79_gcc485/OBJ/StRoot/St_db_Maker/St_db_Maker.cxx:934: virtual TDataSet* St_db_Maker::LoadTable(TDataSet*): Assertion `!ee' failed. ``` Could it be that global variables in interpreted code are not visible in other interpreted scripts? From the C++ point of view, the error actually makes sense because of the `extern StBFChain* chain;` statement in `StarDb/AgMLGeometry/CreateGeometry.h` As suggested during the review, local variables were renamed to avoid confusion with global name `chain` --- StRoot/StBFChain/StBFChain.cxx | 40 +++++++++++++++------------- StRoot/macros/bfc.C | 9 ++++++- StarDb/AgMLGeometry/CreateGeometry.h | 7 ++++- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/StRoot/StBFChain/StBFChain.cxx b/StRoot/StBFChain/StBFChain.cxx index 32e7e87e828..008f2509850 100644 --- a/StRoot/StBFChain/StBFChain.cxx +++ b/StRoot/StBFChain/StBFChain.cxx @@ -42,6 +42,8 @@ TableImpl(Bfc); ClassImp(StBFChain); +StBFChain *chain = nullptr; + //_____________________________________________________________________________ // Hack constructor. /*! @@ -56,15 +58,15 @@ ClassImp(StBFChain); */ void StBFChain::Setup(Int_t mode) { static const Char_t *path = "./StRoot/StBFChain:$STAR/StRoot/StBFChain"; - TString chain("BFC.C"); - Char_t *file = gSystem->Which(path,chain,kReadPermission); + TString fileName("BFC.C"); + Char_t *file = gSystem->Which(path,fileName,kReadPermission); #ifdef STAR_LOGGER - if (! file) { LOG_FATAL << Form("StBFChain::Setup\tFile %s has not been found in path %s",chain.Data(),path) << endm; } - else { LOG_WARN << Form("StBFChain::Setup\tFile %s has been found as %s",chain.Data(),file) << endm; } + if (! file) { LOG_FATAL << Form("StBFChain::Setup\tFile %s has not been found in path %s",fileName.Data(),path) << endm; } + else { LOG_WARN << Form("StBFChain::Setup\tFile %s has been found as %s",fileName.Data(),file) << endm; } #else - if (! file) Fatal("StBFChain::Setup","File %s has not been found in path %s",chain.Data(),path); - else Warning("StBFChain::Setup","File %s has been found as %s",chain.Data(),file); + if (! file) Fatal("StBFChain::Setup","File %s has not been found in path %s",fileName.Data(),path); + else Warning("StBFChain::Setup","File %s has been found as %s",fileName.Data(),file); #endif TString cmd(".L "); cmd += file; @@ -1099,13 +1101,13 @@ Int_t StBFChain::ParseString (const TString &tChain, TObjArray &Opt, Bool_t Sort for (k = 0; k < nParsed; k++) {if (obj->At(k)) {if (k != N) obj->AddAt(obj->At(k),N); N++;}} nParsed = N; // sort options - StBFChain *chain = (StBFChain *) StMaker::GetChain(); - if (chain && Sort) {// sort options + StBFChain *curChain = (StBFChain *) StMaker::GetChain(); + if (curChain && Sort) {// sort options TArrayI idT(nParsed); Int_t *idx = idT.GetArray(); TArrayI kdT(nParsed); Int_t *kdx = kdT.GetArray(); for (k = 0; k < nParsed; k++) { TString string = ((TObjString *) obj->At(k))->GetString(); - kdx[k] = TMath::Abs(chain->kOpt(string,kFALSE)); + kdx[k] = TMath::Abs(curChain->kOpt(string,kFALSE)); } TMath::Sort(nParsed,kdx,idx,0); TString sChain; @@ -1114,7 +1116,7 @@ Int_t StBFChain::ParseString (const TString &tChain, TObjArray &Opt, Bool_t Sort if (k == 0) sChain = ((TObjString *)Opt[k])->GetString(); else {sChain += ","; sChain += ((TObjString *)Opt[k])->GetString();} } - if (N > 1 && chain->Debug() > 2) { + if (N > 1 && curChain->Debug() > 2) { gMessMgr->QAInfo() << "Requested chain is :\t" << tChain.Data() << endm; gMessMgr->QAInfo() << "Sorted chain is :\t" << sChain.Data() << endm; } @@ -1211,7 +1213,7 @@ Int_t StBFChain::kOpt (const TString *tag, Bool_t Check) const { return 0; } //_____________________________________________________________________ -void StBFChain::SetOptions(const Char_t *options, const Char_t *chain) { +void StBFChain::SetOptions(const Char_t *options, const Char_t *chainName) { TString tChain(options); TObjArray Opts; Int_t nParsed = ParseString(tChain,Opts,kTRUE); @@ -1240,7 +1242,7 @@ void StBFChain::SetOptions(const Char_t *options, const Char_t *chain) { // printf ("Chain %s\n",tChain.Data()); kgo = kOpt(Tag.Data(),kFALSE); if (kgo != 0) { - SetOption(kgo,chain); + SetOption(kgo,chainName); if (kgo > 0) { TString Comment(fBFC[kgo].Comment); TString Opts(fBFC[kgo].Opts); @@ -1395,7 +1397,7 @@ void StBFChain::SetOptions(const Char_t *options, const Char_t *chain) { } else { // Check for predefined db time stamps ? kgo = kOpt(Tag.Data(),kFALSE); if (kgo != 0){ - SetOption(kgo,chain); + SetOption(kgo,chainName); } else { // Check that option can be library name or / and Maker static const Char_t *path = ".:.$STAR_HOST_SYS/lib::.$STAR_HOST_SYS/LIB:$STAR/.$STAR_HOST_SYS/lib:$STAR/.$STAR_HOST_SYS/LIB"; @@ -1414,7 +1416,7 @@ void StBFChain::SetOptions(const Char_t *options, const Char_t *chain) { } kgo = kOpt(Tag.Data(),kFALSE); if (kgo != 0) { - SetOption(kgo,chain); + SetOption(kgo,chainName); } else { gMessMgr->QAInfo() << " Invalid Option " << Tag.Data() << ". !! ABORT !! " << endm; abort(); //assert(1); @@ -1429,20 +1431,20 @@ void StBFChain::SetOptions(const Char_t *options, const Char_t *chain) { } //_____________________________________________________________________ /// Enable/disable valid command line options -void StBFChain::SetOption(const Int_t k, const Char_t *chain) { +void StBFChain::SetOption(const Int_t k, const Char_t *chainName) { if (k > 0) { assert(k 0) SetOptions(fBFC[k].Opts,fBFC[k].Key); if (!fBFC[k].Flag) { fBFC[k].Flag = kTRUE; - gMessMgr->QAInfo() << Form(" Switch On %20s by %s", fBFC[k].Key, chain) << endm; + gMessMgr->QAInfo() << Form(" Switch On %20s by %s", fBFC[k].Key, chainName) << endm; } } else { assert(-kQAInfo() << Form(" Switch Off %20s by %s", fBFC[-k].Key, chain) << endm; + gMessMgr->QAInfo() << Form(" Switch Off %20s by %s", fBFC[-k].Key, chainName) << endm; } } } @@ -1512,9 +1514,9 @@ Char_t *StBFChain::GetOptionString(const Char_t *Opt) of the values vvvvvv must be clearly added to the documentation */ -void StBFChain::SetFlags(const Char_t *Chain) +void StBFChain::SetFlags(const Char_t *chainOpts) { - TString tChain(Chain); + TString tChain(chainOpts); Int_t mode = 1; Setup(mode); Int_t k=0; diff --git a/StRoot/macros/bfc.C b/StRoot/macros/bfc.C index a874bff8829..3c7538fb0eb 100644 --- a/StRoot/macros/bfc.C +++ b/StRoot/macros/bfc.C @@ -29,7 +29,14 @@ class StMessMgr; #include "TAttr.h" #include "Rtypes.h" #endif -StBFChain *chain=0; + +#if !defined(__CINT__) || defined(__CLING__) +// 'chain' is defined in StBFChain library (see StRoot/StBFChain.cxx) +extern StBFChain* chain; +#else +StBFChain* chain = 0; +#endif + //_____________________________________________________________________ //_________________ Prototypes _______________________________________________ void Usage(); diff --git a/StarDb/AgMLGeometry/CreateGeometry.h b/StarDb/AgMLGeometry/CreateGeometry.h index 125fbb0ff06..7deee16ed76 100644 --- a/StarDb/AgMLGeometry/CreateGeometry.h +++ b/StarDb/AgMLGeometry/CreateGeometry.h @@ -1,5 +1,10 @@ -#ifndef __CINT__ +#include + +#if !defined(__CINT__) || defined(__CLING__) #include "StBFChain/StBFChain.h" +#include "StarVMC/StarAgmlLib/AgModule.h" +#include "StarVMC/StarAgmlLib/StarTGeoStacker.h" +#include "StarVMC/StarGeometry/StarGeo.h" #endif extern StBFChain* chain;