|
| 1 | +#include <TGeoManager.h> |
| 2 | + |
| 3 | +#include "StBFChain/StBFChain.h" |
| 4 | +#include "StarVMC/StarAgmlLib/AgModule.h" |
| 5 | +#include "StarVMC/StarAgmlLib/StarTGeoStacker.h" |
| 6 | +#include "StarVMC/StarGeometry/StarGeo.h" |
| 7 | + |
| 8 | +extern StBFChain* chain; |
| 9 | + |
| 10 | +/** |
| 11 | + * Adapted from StarDb/VmcGeometry/CreateGeometry.h |
| 12 | + */ |
| 13 | +TDataSet *CreateGeometry(const Char_t *name="y2011") { |
| 14 | + TObjectSet *geom = 0; |
| 15 | + if ( gGeoManager ) { |
| 16 | + cout << "AgML geometry: Existing TGeoManager " << gGeoManager->GetName() |
| 17 | + << " detected, ignoring request for " |
| 18 | + << name << endl; |
| 19 | + return geom; |
| 20 | + } |
| 21 | + |
| 22 | + // Cache geometry to a TFile. Geometry will be restored from TFile on subsequent calls. |
| 23 | + TString filename = ""; |
| 24 | + if (chain) { filename = chain->GetFileOut(); if ( filename=="" ) filename = chain->GetFileIn(); } |
| 25 | + else { filename = name; } |
| 26 | + |
| 27 | + // Strip out @ symbol |
| 28 | + filename = filename.ReplaceAll("@",""); |
| 29 | + // Strip off the last extention in the filename |
| 30 | + filename = filename( 0, filename.Last('.') ); |
| 31 | + // Append geom.root to the extentionless filename |
| 32 | + filename+=".geom.root"; |
| 33 | + |
| 34 | + // Detect second call to the system |
| 35 | + if ( AgModule::Find("HALL") ) { |
| 36 | + if ( chain->GetOption("Sti") || |
| 37 | + chain->GetOption("StiCA") || |
| 38 | + chain->GetOption("StiVMC") ){ |
| 39 | + cout << "AgML geometry: HALL exists. Restore from cache file " |
| 40 | + << filename.Data() << endl; |
| 41 | + gGeoManager = 0; |
| 42 | + assert(0); |
| 43 | + TGeoManager::Import( filename ); |
| 44 | + assert(gGeoManager); |
| 45 | + } |
| 46 | + return geom; |
| 47 | + } |
| 48 | + |
| 49 | + cout << "AgML: Building geometry " << name << " " << endl; |
| 50 | + |
| 51 | + // Create the geometry using TGeo |
| 52 | + AgBlock::SetStacker( new StarTGeoStacker() ); |
| 53 | + |
| 54 | + Geometry *build = new Geometry(); |
| 55 | + |
| 56 | + // Suppress copious ROOT warnings |
| 57 | + Long_t save = gErrorIgnoreLevel; gErrorIgnoreLevel = 9999; |
| 58 | + build->ConstructGeometry(name); |
| 59 | + gErrorIgnoreLevel = save; |
| 60 | + |
| 61 | + if ( gGeoManager ) |
| 62 | + { |
| 63 | + gGeoManager->CloseGeometry(); |
| 64 | + geom = new TObjectSet("Geometry",gGeoManager, false ); |
| 65 | + geom -> SetTitle( Form("AgML Geometry: %s",name) ); |
| 66 | + |
| 67 | + TFile *file = new TFile( filename, "recreate" ); |
| 68 | + file->cd(); |
| 69 | + gGeoManager->Write(); |
| 70 | + file->Close(); |
| 71 | + delete file; |
| 72 | + } |
| 73 | + |
| 74 | + return (TDataSet *)geom; |
| 75 | +} |
0 commit comments