diff --git a/StRoot/StBFChain/StBFChain.cxx b/StRoot/StBFChain/StBFChain.cxx index 566db07be1f..242449e3e18 100644 --- a/StRoot/StBFChain/StBFChain.cxx +++ b/StRoot/StBFChain/StBFChain.cxx @@ -18,6 +18,7 @@ #include "StEnumerations.h" #include "TTree.h" #include "TEnv.h" +#include "StarVMC/StarGeometry/CreateGeometry.h" #define STAR_LOGGER 1 // PLease, preserve the comment after = { . It is used for documentation formatting // @@ -1023,21 +1024,7 @@ Int_t StBFChain::Init() { if (GetOption("VmcGeo")) { path = "./StarDb/VmcGeo:$STAR/StarDb/VmcGeo"; } - TString geom("Geometry."); - geom += DbAlias[i].geometry; - geom += ".C"; - Char_t *file = gSystem->Which(path.Data(),geom,kReadPermission); - if (file) { - LOG_INFO << "StBFChain::Init force load of " << file << endm; - TString command = ".L "; command += file; - gInterpreter->ProcessLine(command); - gInterpreter->Calc("CreateTable()"); - command.ReplaceAll(".L ",".U "); - gInterpreter->ProcessLine(command); - delete [] file; - } else { - LOG_INFO << "StBFChain::Init file for geometry tag " << geom << " has not been found in path" << path << endm; - } + CreateGeometry(DbAlias[i].geometry); break; } } diff --git a/StarVMC/StarGeometry/CreateGeometry.cxx b/StarVMC/StarGeometry/CreateGeometry.cxx new file mode 100644 index 00000000000..593482a2bc2 --- /dev/null +++ b/StarVMC/StarGeometry/CreateGeometry.cxx @@ -0,0 +1,75 @@ +#include + +#include "StBFChain/StBFChain.h" +#include "StarVMC/StarAgmlLib/AgModule.h" +#include "StarVMC/StarAgmlLib/StarTGeoStacker.h" +#include "StarVMC/StarGeometry/StarGeo.h" + +extern StBFChain* chain; + +/** + * Adapted from StarDb/VmcGeometry/CreateGeometry.h + */ +TDataSet *CreateGeometry(const Char_t *name="y2011") { + TObjectSet *geom = 0; + if ( gGeoManager ) { + cout << "AgML geometry: Existing TGeoManager " << gGeoManager->GetName() + << " detected, ignoring request for " + << name << endl; + return geom; + } + + // Cache geometry to a TFile. Geometry will be restored from TFile on subsequent calls. + TString filename = ""; + if (chain) { filename = chain->GetFileOut(); if ( filename=="" ) filename = chain->GetFileIn(); } + else { filename = name; } + + // Strip out @ symbol + filename = filename.ReplaceAll("@",""); + // Strip off the last extention in the filename + filename = filename( 0, filename.Last('.') ); + // Append geom.root to the extentionless filename + filename+=".geom.root"; + + // Detect second call to the system + if ( AgModule::Find("HALL") ) { + if ( chain->GetOption("Sti") || + chain->GetOption("StiCA") || + chain->GetOption("StiVMC") ){ + cout << "AgML geometry: HALL exists. Restore from cache file " + << filename.Data() << endl; + gGeoManager = 0; + assert(0); + TGeoManager::Import( filename ); + assert(gGeoManager); + } + return geom; + } + + cout << "AgML: Building geometry " << name << " " << endl; + + // Create the geometry using TGeo + AgBlock::SetStacker( new StarTGeoStacker() ); + + Geometry *build = new Geometry(); + + // Suppress copious ROOT warnings + Long_t save = gErrorIgnoreLevel; gErrorIgnoreLevel = 9999; + build->ConstructGeometry(name); + gErrorIgnoreLevel = save; + + if ( gGeoManager ) + { + gGeoManager->CloseGeometry(); + geom = new TObjectSet("Geometry",gGeoManager, false ); + geom -> SetTitle( Form("AgML Geometry: %s",name) ); + + TFile *file = new TFile( filename, "recreate" ); + file->cd(); + gGeoManager->Write(); + file->Close(); + delete file; + } + + return (TDataSet *)geom; +} diff --git a/StarVMC/StarGeometry/CreateGeometry.h b/StarVMC/StarGeometry/CreateGeometry.h new file mode 100644 index 00000000000..e19384992f6 --- /dev/null +++ b/StarVMC/StarGeometry/CreateGeometry.h @@ -0,0 +1,3 @@ +class TDataSet; + +TDataSet *CreateGeometry(const char *name="y2011");