Skip to content

Commit

Permalink
[root6] Fix missing declarations in the code interpreted by Cling (#451)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
plexoos authored Feb 7, 2023
1 parent eb260f9 commit d23dce3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
40 changes: 21 additions & 19 deletions StRoot/StBFChain/StBFChain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
TableImpl(Bfc);
ClassImp(StBFChain);

StBFChain *chain = nullptr;

//_____________________________________________________________________________
// Hack constructor.
/*!
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand All @@ -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);
Expand All @@ -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<fNoChainOptions);
Int_t n = strlen(fBFC[k].Opts);
if (n > 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(-k<fNoChainOptions);
if (k < 0 && fBFC[-k].Flag) {
fBFC[-k].Flag = kFALSE;
gMessMgr->QAInfo() << Form(" Switch Off %20s by %s", fBFC[-k].Key, chain) << endm;
gMessMgr->QAInfo() << Form(" Switch Off %20s by %s", fBFC[-k].Key, chainName) << endm;
}
}
}
Expand Down Expand Up @@ -1512,9 +1514,9 @@ Char_t *StBFChain::GetOptionString(const Char_t *Opt)
of the values <tt>vvvvvv</tt> 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;
Expand Down
9 changes: 8 additions & 1 deletion StRoot/macros/bfc.C
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion StarDb/AgMLGeometry/CreateGeometry.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#ifndef __CINT__
#include <TGeoManager.h>

#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;
Expand Down

0 comments on commit d23dce3

Please sign in to comment.