Skip to content
Snippets Groups Projects
Commit 4484186b authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny:
Browse files

Fix use of FullPhysVol as Root/World volume.

Following the inetrface change in the GeoModelIO Write and Read, where I replaced the GeoPhysVol with GeoVPhysVol, now any GeoPhysVol or GeoFullPhysVol can be used as the Root/World volume.
parent 6c5da96c
No related branches found
No related tags found
1 merge request!202Fix write and read of GeoFullPhysVol as root volume
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
#ifndef FSLSDPLUGINLOADER_H_
#define FSLSDPLUGINLOADER_H_
#include "FullSimLight/FSLSensitiveDetectorPlugin.h"
#include "GeoModelKernel/GeoPluginLoader.h"
typedef GeoPluginLoader<FSLSensitiveDetectorPlugin> FSLSDPluginLoader;
#endif
#ifndef MassCalculator_h
#define MassCalculator_h 1
#include "G4Types.hh"
#include "G4String.hh"
#include "G4LogicalVolume.hh"
#include "G4VPhysicalVolume.hh"
#include "G4Material.hh"
#include "G4String.hh"
#include "G4Types.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VSolid.hh"
//#include "GeoModelKernel/GeoBox.h"
// #include "GeoModelKernel/GeoBox.h"
#include "GeoModelKernel/GeoPhysVol.h"
//#include "GeoModelKernel/GeoFullPhysVol.h"
// #include "GeoModelKernel/GeoFullPhysVol.h"
// Units
#include "GeoModelKernel/Units.h"
#define SYSTEM_OF_UNITS GeoModelKernelUnits
#include <vector>
#include <nlohmann/json.hpp>
#include <vector>
using json = nlohmann::json;
......@@ -30,33 +29,40 @@ using json = nlohmann::json;
*/
class MassCalculator {
public:
//static MassCalculator& Instance();
public:
// static MassCalculator& Instance();
MassCalculator(){};
~MassCalculator(){};
MassCalculator(const MassCalculator&) = delete;
MassCalculator& operator=(const MassCalculator&) = delete;
double volume(const PVConstLink& pv);
double exclusiveMass(const PVConstLink& pv);
double inclusiveMass(const PVConstLink& pv);
void calculateMass(G4LogicalVolume* logVol, G4VPhysicalVolume * physVol, std::vector<json>& jlist, double& exclusiveMass, bool writeRep);
void iterateFromWorldMass(G4LogicalVolume* logVolume, std::vector<json>& jlist, double& inclusiveMass, double& exclusiveMass, G4String prefix, G4String material);
void recursiveMassCalculation (G4VPhysicalVolume* worldg4, GeoPhysVol* /*worldgeoModel*/, std::vector<json>& jlist);
void SetPrefixLogicalVolume(const G4String &prefixLV) { fPrefixLogicalVolume = prefixLV; }
void SetMaterial(const G4String &material) { fMaterial = material; }
void SetVerbosity(const int verbosity){ fVerbosityFlag = verbosity; }
void calculateMass(G4LogicalVolume* logVol, G4VPhysicalVolume* physVol,
std::vector<json>& jlist, double& exclusiveMass,
bool writeRep);
void iterateFromWorldMass(G4LogicalVolume* logVolume,
std::vector<json>& jlist, double& inclusiveMass,
double& exclusiveMass, G4String prefix,
G4String material);
void recursiveMassCalculation(G4VPhysicalVolume* worldg4,
GeoVPhysVol* /*worldgeoModel*/,
std::vector<json>& jlist);
void SetPrefixLogicalVolume(const G4String& prefixLV) {
fPrefixLogicalVolume = prefixLV;
}
void SetMaterial(const G4String& material) { fMaterial = material; }
void SetVerbosity(const int verbosity) { fVerbosityFlag = verbosity; }
void printGeometryInfo(G4LogicalVolume* lv, G4int verbosity);
private:
private:
G4String fPrefixLogicalVolume;
G4String fMaterial;
const G4double fDensityThreshold = 0.02 * SYSTEM_OF_UNITS::g/SYSTEM_OF_UNITS::cm3;
G4int fVerbosityFlag;
}; // MassCalculator
const G4double fDensityThreshold =
0.02 * SYSTEM_OF_UNITS::g / SYSTEM_OF_UNITS::cm3;
G4int fVerbosityFlag;
}; // MassCalculator
#endif // MassCalculator_h 1
#endif // MassCalculator_h 1
......@@ -139,7 +139,7 @@ G4VPhysicalVolume *FSLDetectorConstruction::Construct()
{
fTimer.Start();
GeoPhysVol* world = nullptr;
GeoVPhysVol* world = nullptr;
G4LogicalVolume* envelope;
if (fGeometryFileName.contains(".dylib") || fGeometryFileName.contains(".so"))
{
......@@ -152,8 +152,9 @@ G4VPhysicalVolume *FSLDetectorConstruction::Construct()
}
world = nullptr;
world = CreateTheWorld(nullptr);
factory->create(world);
factory->create(dynamic_cast<GeoPhysVol*>(world));
G4cout << "ReadGeoModel::buildGeoModel() done." << G4endl;
fTimer.Stop();
......@@ -218,8 +219,10 @@ G4VPhysicalVolume *FSLDetectorConstruction::Construct()
/* build the GeoModel geometry */
//GeoPhysVol* world = readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory and get an handle to the 'world' volume
world = readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory and get an handle to the 'world' volume
// builds the whole GeoModel tree in memory
// and get an handle to the 'world' volume
world = readInGeo.buildGeoModel();
G4cout << "ReadGeoModel::buildGeoModel() done." << G4endl;
fTimer.Stop();
G4cout << "First step done. GeoModelTree built from the SQLite file." << G4endl;
......
This diff is collapsed.
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
#ifndef GEOGEOMETRYPLUGINLOADER_H_
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
#ifndef GEOMODELKERNEL_GEOVGEOMETRYPLUGIN_H
......@@ -12,50 +12,48 @@
* The geometry plugin builds the raw geometry
*/
#include "GeoModelKernel/GeoVPhysVol.h"
#include "GeoModelKernel/GeoPublisher.h" // to publish lists of FullPhysVol and AlignableTransform nodes in create()
#include <memory> // smart pointers
#include <memory> // smart pointers
#include "GeoModelKernel/GeoPublisher.h" // to publish lists of FullPhysVol and AlignableTransform nodes in create()
#include "GeoModelKernel/GeoVPhysVol.h"
class GeoPhysVol;
class GeoVGeometryPlugin
{
public:
//! Default constructor.
GeoVGeometryPlugin() : m_publisher(nullptr) {}
//! Parametrized constructor for plugins that publish lists of nodes
GeoVGeometryPlugin(std::string name) : m_publisher(std::make_unique<GeoPublisher>()), m_pluginName( name ) { m_publisher->setName(m_pluginName); }
virtual ~GeoVGeometryPlugin() {}
//! Create the system geometry.
/// Note: this is a pure virtual method, so you need to implement it in your derived plugin class
virtual void create ( GeoPhysVol* world, bool publish = false ) = 0;
//! Returns the plugin's name
std::string getName() { return m_pluginName; }
//! Returns the Publisher that publishes the lists of the GeoFullPhysVol and AlignableTransform nodes
GeoPublisher* getPublisher() { return m_publisher.get(); }
protected:
//! A GeoPublisher instance is used to publish lists of nodes.
std::unique_ptr<GeoPublisher> m_publisher;
private:
/// We prohibit copy constructor, and assignment operator
GeoVGeometryPlugin(const GeoVGeometryPlugin &right)=delete;
GeoVGeometryPlugin & operator=(const GeoVGeometryPlugin &right)=delete;
//! The name of the plugin, used to store plugin's published nodes.
std::string m_pluginName;
class GeoVGeometryPlugin {
public:
//! Default constructor.
GeoVGeometryPlugin() : m_publisher(nullptr) {}
//! Parametrized constructor for plugins that publish lists of nodes
GeoVGeometryPlugin(std::string name)
: m_publisher(std::make_unique<GeoPublisher>()), m_pluginName(name) {
m_publisher->setName(m_pluginName);
}
virtual ~GeoVGeometryPlugin() {}
//! Create the system geometry.
/// Note: this is a pure virtual method, so you need to implement it in your
/// derived plugin class
virtual void create(GeoVPhysVol* world, bool publish = false) = 0;
//! Returns the plugin's name
std::string getName() { return m_pluginName; }
//! Returns the Publisher that publishes the lists of the GeoFullPhysVol and
//! AlignableTransform nodes
GeoPublisher* getPublisher() { return m_publisher.get(); }
protected:
//! A GeoPublisher instance is used to publish lists of nodes.
std::unique_ptr<GeoPublisher> m_publisher;
private:
/// We prohibit copy constructor, and assignment operator
GeoVGeometryPlugin(const GeoVGeometryPlugin& right) = delete;
GeoVGeometryPlugin& operator=(const GeoVGeometryPlugin& right) = delete;
//! The name of the plugin, used to store plugin's published nodes.
std::string m_pluginName;
};
#endif
......@@ -31,7 +31,7 @@ class GDMLtoGM : public GeoVGeometryPlugin {
~GDMLtoGM();
// Creation of geometry:
virtual void create(GeoPhysVol *world, bool publish = false ) override;
virtual void create(GeoVPhysVol *world, bool publish = false ) override;
private:
......@@ -43,12 +43,11 @@ class GDMLtoGM : public GeoVGeometryPlugin {
GDMLtoGM::~GDMLtoGM()
{
}
{}
//## Other Operations (implementation)
void GDMLtoGM::create(GeoPhysVol *world, bool /* 'publish' is not used here */)
void GDMLtoGM::create(GeoVPhysVol *world, bool /* 'publish' is not used here */)
{
char* fPath=getenv("GDML_FILE_NAME");
std::string fileName;
......
/*
* Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
*/
* Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoModelKernel/GeoVGeometryPlugin.h"
#include "GeoModelDBManager/GMDBManager.h"
#include "GeoModelRead/ReadGeoModel.h"
#include "GeoModelWrite/WriteGeoModel.h"
#include <stdlib.h> // setenv
#include <unistd.h>
#include "GeoModelKernel/GeoGeometryPluginLoader.h"
#include "GeoModelKernel/GeoVolumeCursor.h"
#include "GeoModelKernel/GeoMaterial.h"
#include "GeoModelKernel/GeoElement.h"
#include "GeoModelKernel/GeoPVLink.h"
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include "GeoModelDBManager/GMDBManager.h"
#include "GeoModelKernel/GeoAccessVolumeAction.h"
#include "GeoModelKernel/GeoBox.h"
#include "GeoModelKernel/GeoCountVolAction.h"
#include "GeoModelKernel/GeoAccessVolumeAction.h"
#include "GeoModelKernel/GeoElement.h"
#include "GeoModelKernel/GeoGeometryPluginLoader.h"
#include "GeoModelKernel/GeoMaterial.h"
#include "GeoModelKernel/GeoNameTag.h"
#include "GeoModelKernel/GeoPVLink.h"
#include "GeoModelKernel/GeoPublisher.h"
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <unistd.h>
#include <stdlib.h> // setenv
#include "GeoModelKernel/GeoVGeometryPlugin.h"
#include "GeoModelKernel/GeoVolumeCursor.h"
#include "GeoModelRead/ReadGeoModel.h"
#include "GeoModelWrite/WriteGeoModel.h"
#ifdef __APPLE__
const std::string shared_obj_extension=".dylib";
const std::string shared_obj_extension = ".dylib";
#else
const std::string shared_obj_extension=".so";
const std::string shared_obj_extension = ".so";
#endif
#define SYSTEM_OF_UNITS GeoModelKernelUnits // --> 'GeoModelKernelUnits::cm'
int main(int argc, char ** argv) {
struct Metadata {
std::string dateString;
std::string geoModelDataBranch;
} metadata;
// Fill metadata;
{
// Ceci n'es pas une pipe:
FILE *ceci=popen("date -Im","r");
if (ceci) {
char buff[1024];
if (fscanf(ceci,"%s",buff)) {
metadata.dateString=buff;
}
pclose(ceci);
#define SYSTEM_OF_UNITS GeoModelKernelUnits // --> 'GeoModelKernelUnits::cm'
int main(int argc, char **argv) {
struct Metadata {
std::string dateString;
std::string geoModelDataBranch;
} metadata;
// Fill metadata;
{
// Ceci n'es pas une pipe:
FILE *ceci = popen("date -Im", "r");
if (ceci) {
char buff[1024];
if (fscanf(ceci, "%s", buff)) {
metadata.dateString = buff;
}
pclose(ceci);
}
}
}
char *geomodel_xml_dir=getenv("GEOMODEL_XML_DIR");
if (geomodel_xml_dir) {
std::string cmd="git -C "+ std::string(geomodel_xml_dir) + " rev-parse --abbrev-ref HEAD";
// Ceci n'es pas une pipe:
FILE *ceci=popen(cmd.c_str(),"r");
if (ceci) {
char buff[1024];
if (fscanf(ceci,"%s",buff)) {
metadata.geoModelDataBranch=buff;
}
pclose(ceci);
char *geomodel_xml_dir = getenv("GEOMODEL_XML_DIR");
if (geomodel_xml_dir) {
std::string cmd = "git -C " + std::string(geomodel_xml_dir) +
" rev-parse --abbrev-ref HEAD";
// Ceci n'es pas une pipe:
FILE *ceci = popen(cmd.c_str(), "r");
if (ceci) {
char buff[1024];
if (fscanf(ceci, "%s", buff)) {
metadata.geoModelDataBranch = buff;
}
pclose(ceci);
}
}
}
//
// Usage message:
//
std::string gmcat= argv[0];
std::string usage= "usage: " + gmcat + " [plugin1"+shared_obj_extension
+ "] [plugin2" + shared_obj_extension
+ "] ...[file1.db] [file2.db].. -o outputFile]";
//
// Print usage message if no args given:
//
if (argc==1) {
std::cerr << usage << std::endl;
return 0;
}
//
// Parse the command line:
//
std::vector<std::string> inputFiles;
std::vector<std::string> inputPlugins;
std::string outputFile;
bool outputFileSet = false;
for (int argi=1;argi<argc;argi++) {
std::string argument=argv[argi];
if (argument.find("-o")!=std::string::npos) {
argi++;
if (argi>=argc) {
std::cerr << usage << std::endl;
return 1;
}
outputFile=argv[argi];
outputFileSet = true;
}
else if (argument.find("-v")!=std::string::npos) {
setenv("GEOMODEL_GEOMODELIO_VERBOSE", "1", 1); // does overwrite
std::cout << "You set the verbosity level to 1" << std::endl;
}
else if (argument.find(shared_obj_extension)!=std::string::npos) {
inputPlugins.push_back(argument);
}
else if (argument.find(".db")!=std::string::npos) {
inputFiles.push_back(argument);
}
else {
std::cerr << "Unrecognized argument " << argument << std::endl;
std::cerr << usage << std::endl;
return 2;
}
}
if( !outputFileSet ) {
std::cerr << "\nERROR! You should set an output file.\n" << std::endl;
std::cerr << usage << std::endl;
return 3;
}
//
// Check that we can access the output file
//
if (access(outputFile.c_str(),F_OK)==0) {
if (!access(outputFile.c_str(),W_OK)) {
if (system(("rm -f "+ outputFile).c_str())) {
std::cerr << "gmcat -- Error, cannot overwrite existing file " << outputFile << std::endl;
return 3;
}
//
// Usage message:
//
std::string gmcat = argv[0];
std::string usage = "usage: " + gmcat + " [plugin1" + shared_obj_extension +
"] [plugin2" + shared_obj_extension +
"] ...[file1.db] [file2.db].. -o outputFile]";
//
// Print usage message if no args given:
//
if (argc == 1) {
std::cerr << usage << std::endl;
return 0;
}
else {
std::cerr << "gmcat -- Error, cannot overwrite existing file " << outputFile << " (permission denied)" << std::endl;
return 4;
//
// Parse the command line:
//
std::vector<std::string> inputFiles;
std::vector<std::string> inputPlugins;
std::string outputFile;
bool outputFileSet = false;
for (int argi = 1; argi < argc; argi++) {
std::string argument = argv[argi];
if (argument.find("-o") != std::string::npos) {
argi++;
if (argi >= argc) {
std::cerr << usage << std::endl;
return 1;
}
outputFile = argv[argi];
outputFileSet = true;
} else if (argument.find("-v") != std::string::npos) {
setenv("GEOMODEL_GEOMODELIO_VERBOSE", "1", 1); // does overwrite
std::cout << "You set the verbosity level to 1" << std::endl;
} else if (argument.find(shared_obj_extension) != std::string::npos) {
inputPlugins.push_back(argument);
} else if (argument.find(".db") != std::string::npos) {
inputFiles.push_back(argument);
} else {
std::cerr << "Unrecognized argument " << argument << std::endl;
std::cerr << usage << std::endl;
return 2;
}
}
}
//
// Create elements and materials for the "World" volume, which is the container:
//
const double gr = SYSTEM_OF_UNITS::gram;
const double mole = SYSTEM_OF_UNITS::mole;
const double cm3 = SYSTEM_OF_UNITS::cm3;
// Define the chemical elements
GeoElement* Nitrogen = new GeoElement ("Nitrogen" ,"N" , 7.0 , 14.0067 *gr/mole);
GeoElement* Oxygen = new GeoElement ("Oxygen" ,"O" , 8.0 , 15.9995 *gr/mole);
GeoElement* Argon = new GeoElement ("Argon" ,"Ar" , 18.0 , 39.948 *gr/mole);
GeoElement* Hydrogen = new GeoElement ("Hydrogen" ,"H" , 1.0 , 1.00797 *gr/mole);
double densityOfAir=0.001214 *gr/cm3;
GeoMaterial *air = new GeoMaterial("Air", densityOfAir);
air->add(Nitrogen , 0.7494);
air->add(Oxygen, 0.2369);
air->add(Argon, 0.0129);
air->add(Hydrogen, 0.0008);
air->lock();
//
// Create a huge world volume made of Air:
//
const GeoBox* worldBox = new GeoBox(2000*SYSTEM_OF_UNITS::cm, 2000*SYSTEM_OF_UNITS::cm, 2500*SYSTEM_OF_UNITS::cm);
const GeoLogVol* worldLog = new GeoLogVol("WorldLog", worldBox, air);
GeoPhysVol *world=new GeoPhysVol(worldLog);
world->ref();
//
// Loop over plugins, create the geometry and put it under the world:
//
std::vector<GeoPublisher*> vecPluginsPublishers; // caches the stores from all plugins
for (const std::string & plugin : inputPlugins) {
GeoGeometryPluginLoader loader;
GeoVGeometryPlugin *factory=loader.load(plugin);
if (!factory) {
std::cerr << "gmcat -- Could not load plugin " << plugin << std::endl;
return 5;
if (!outputFileSet) {
std::cerr << "\nERROR! You should set an output file.\n" << std::endl;
std::cerr << usage << std::endl;
return 3;
}
// NOTE: we want the plugin to publish lits FPV and AXF nodes,
// if it is intended to do that, and store them in the DB.
// For that, we pass a true to the plugin's `create()` method,
// which will use it to publish nodes,
// and then we get from the plugin the pointer to the GeoPublisher instance
// and we cache it for later, to dump the published nodes into the DB.
factory->create(world, true);
if( nullptr != factory->getPublisher() ) {
vecPluginsPublishers.push_back( factory->getPublisher() ); // cache the publisher, if any, for later
}
}
//
// Loop over files, create the geometry and put it under the world:
//
for (const std::string & file : inputFiles) {
GMDBManager* db = new GMDBManager(file);
if (!db->checkIsDBOpen()){
std::cerr << "gmcat -- Error opening the input file: " << file << std::endl;
return 6;
//
// Check that we can access the output file
//
if (access(outputFile.c_str(), F_OK) == 0) {
if (!access(outputFile.c_str(), W_OK)) {
if (system(("rm -f " + outputFile).c_str())) {
std::cerr << "gmcat -- Error, cannot overwrite existing file "
<< outputFile << std::endl;
return 3;
}
} else {
std::cerr << "gmcat -- Error, cannot overwrite existing file "
<< outputFile << " (permission denied)" << std::endl;
return 4;
}
}
/* set the GeoModel reader */
GeoModelIO::ReadGeoModel readInGeo = GeoModelIO::ReadGeoModel(db);
/* build the GeoModel geometry */
GeoPhysVol* dbPhys = readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory
/* get an handle on a Volume Cursor, to traverse the whole set of Volumes */
GeoVolumeCursor aV(dbPhys);
/* loop over the Volumes in the tree */
while (!aV.atEnd()) {
if (aV.getName()!="ANON") {
GeoNameTag *nameTag=new GeoNameTag(aV.getName());
world->add(nameTag);
}
GeoTransform *transform= new GeoTransform(aV.getTransform());
world->add(transform);
world->add((GeoVPhysVol *) &*aV.getVolume());
aV.next();
//
// Create elements and materials for the "World" volume, which is the
// container:
//
const double gr = SYSTEM_OF_UNITS::gram;
const double mole = SYSTEM_OF_UNITS::mole;
const double cm3 = SYSTEM_OF_UNITS::cm3;
// Define the chemical elements
GeoElement *Nitrogen =
new GeoElement("Nitrogen", "N", 7.0, 14.0067 * gr / mole);
GeoElement *Oxygen =
new GeoElement("Oxygen", "O", 8.0, 15.9995 * gr / mole);
GeoElement *Argon = new GeoElement("Argon", "Ar", 18.0, 39.948 * gr / mole);
GeoElement *Hydrogen =
new GeoElement("Hydrogen", "H", 1.0, 1.00797 * gr / mole);
double densityOfAir = 0.001214 * gr / cm3;
GeoMaterial *air = new GeoMaterial("Air", densityOfAir);
air->add(Nitrogen, 0.7494);
air->add(Oxygen, 0.2369);
air->add(Argon, 0.0129);
air->add(Hydrogen, 0.0008);
air->lock();
//
// Create a huge world volume made of Air:
//
const GeoBox *worldBox =
new GeoBox(2000 * SYSTEM_OF_UNITS::cm, 2000 * SYSTEM_OF_UNITS::cm,
2500 * SYSTEM_OF_UNITS::cm);
const GeoLogVol *worldLog = new GeoLogVol("WorldLog", worldBox, air);
GeoPhysVol *world = new GeoPhysVol(worldLog);
world->ref();
//
// Loop over plugins, create the geometry and put it under the world:
//
std::vector<GeoPublisher *>
vecPluginsPublishers; // caches the stores from all plugins
for (const std::string &plugin : inputPlugins) {
GeoGeometryPluginLoader loader;
GeoVGeometryPlugin *factory = loader.load(plugin);
if (!factory) {
std::cerr << "gmcat -- Could not load plugin " << plugin
<< std::endl;
return 5;
}
// NOTE: we want the plugin to publish lits FPV and AXF nodes,
// if it is intended to do that, and store them in the DB.
// For that, we pass a true to the plugin's `create()` method,
// which will use it to publish nodes,
// and then we get from the plugin the pointer to the GeoPublisher
// instance and we cache it for later, to dump the published nodes into
// the DB.
factory->create(world, true);
if (nullptr != factory->getPublisher()) {
vecPluginsPublishers.push_back(
factory->getPublisher()); // cache the publisher, if any, for
// later
}
}
delete db;
}
//
// Open a new database:
//
GMDBManager db(outputFile);
//
// check the DB connection
//
if (!db.checkIsDBOpen()) {
std::cerr << "gmcat -- Error opening the output file: " << outputFile << std::endl;
return 7;
}
//
// Fill the header file with metadata
//
std::vector<std::string> gmcatColNames={"Date", "GeoModelDataBranch"};
std::vector<std::string> gmcatColTypes={"STRING", "STRING" };
std::vector<std::vector<std::variant<int,long,float,double,std::string>>> gmcatData ={{metadata.dateString, metadata.geoModelDataBranch}};
db.createCustomTable("AAHEADER", gmcatColNames,gmcatColTypes,gmcatData);
GeoModelIO::WriteGeoModel dumpGeoModelGraph(db);
world->exec(&dumpGeoModelGraph);
if (vecPluginsPublishers.size() > 0) {
dumpGeoModelGraph.saveToDB(vecPluginsPublishers);
} else {
dumpGeoModelGraph.saveToDB();
}
world->unref();
//
// Loop over files, create the geometry and put it under the world:
//
for (const std::string &file : inputFiles) {
GMDBManager *db = new GMDBManager(file);
if (!db->checkIsDBOpen()) {
std::cerr << "gmcat -- Error opening the input file: " << file
<< std::endl;
return 6;
}
/* set the GeoModel reader */
GeoModelIO::ReadGeoModel readInGeo = GeoModelIO::ReadGeoModel(db);
/* build the GeoModel geometry */
// builds the whole GeoModel tree in memory
GeoVPhysVol *dbPhys = readInGeo.buildGeoModel();
/* get an handle on a Volume Cursor, to traverse the whole set of
* Volumes */
GeoVolumeCursor aV(dbPhys);
/* loop over the Volumes in the tree */
while (!aV.atEnd()) {
if (aV.getName() != "ANON") {
GeoNameTag *nameTag = new GeoNameTag(aV.getName());
world->add(nameTag);
}
GeoTransform *transform = new GeoTransform(aV.getTransform());
world->add(transform);
world->add((GeoVPhysVol *)&*aV.getVolume());
aV.next();
}
delete db;
}
//
// Open a new database:
//
GMDBManager db(outputFile);
//
// check the DB connection
//
if (!db.checkIsDBOpen()) {
std::cerr << "gmcat -- Error opening the output file: " << outputFile
<< std::endl;
return 7;
}
//
// Fill the header file with metadata
//
std::vector<std::string> gmcatColNames = {"Date", "GeoModelDataBranch"};
std::vector<std::string> gmcatColTypes = {"STRING", "STRING"};
std::vector<
std::vector<std::variant<int, long, float, double, std::string>>>
gmcatData = {{metadata.dateString, metadata.geoModelDataBranch}};
db.createCustomTable("AAHEADER", gmcatColNames, gmcatColTypes, gmcatData);
GeoModelIO::WriteGeoModel dumpGeoModelGraph(db);
world->exec(&dumpGeoModelGraph);
if (vecPluginsPublishers.size() > 0) {
dumpGeoModelGraph.saveToDB(vecPluginsPublishers);
} else {
dumpGeoModelGraph.saveToDB();
}
world->unref();
return 0;
return 0;
}
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoModelKernel/GeoVGeometryPlugin.h"
#include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelKernel/GeoNameTag.h"
#include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelKernel/GeoVGeometryPlugin.h"
#include "GeoModelKernel/Units.h"
#define SYSTEM_OF_UNITS GeoModelKernelUnits // so we will get, e.g., 'GeoModelKernelUnits::cm'
#include "GeoModelXml/GmxInterface.h"
#include "GeoModelXml/Gmx2Geo.h"
#define SYSTEM_OF_UNITS \
GeoModelKernelUnits // so we will get, e.g., 'GeoModelKernelUnits::cm'
#include <iostream>
#include <fstream>
#include <iostream>
#include <sstream>
class GMXPlugin : public GeoVGeometryPlugin {
public:
#include "GeoModelXml/Gmx2Geo.h"
#include "GeoModelXml/GmxInterface.h"
// Constructor:
GMXPlugin();
class GMXPlugin : public GeoVGeometryPlugin {
public:
// Constructor:
GMXPlugin();
// Constructor with name to provide to publisher
GMXPlugin(std::string name):GeoVGeometryPlugin(name){}
// Constructor with name to provide to publisher
GMXPlugin(std::string name) : GeoVGeometryPlugin(name) {}
// Destructor:
~GMXPlugin();
// Destructor:
~GMXPlugin();
// Creation of geometry:
virtual void create(GeoPhysVol *world, bool publish) override;
// Creation of geometry:
virtual void create(GeoVPhysVol *world, bool publish) override;
private:
private:
// Illegal operations:
const GMXPlugin &operator=(const GMXPlugin &right) = delete;
GMXPlugin(const GMXPlugin &right) = delete;
// Illegal operations:
const GMXPlugin & operator=(const GMXPlugin &right)=delete;
GMXPlugin(const GMXPlugin &right) = delete;
bool exists(const std::string &name) {
std::ifstream f(name.c_str());
return f.good();
}
bool exists (const std::string& name)
{
std::ifstream f(name.c_str());
return f.good();
}
std::vector<std::string> parseFiles(const std::string s,
std::string delimiter = ";") {
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
std::string token;
std::vector<std::string> res;
std::vector<std::string> parseFiles(const std::string s, std::string delimiter=";")
{
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
std::string token;
std::vector<std::string> res;
while ((pos_end = s.find(delimiter, pos_start)) != std::string::npos) {
token = s.substr(pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
res.push_back(token);
}
while ((pos_end = s.find (delimiter, pos_start)) != std::string::npos) {
token = s.substr (pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
res.push_back (token);
res.push_back(s.substr(pos_start));
return res;
}
res.push_back (s.substr (pos_start));
return res;
}
};
GMXPlugin::GMXPlugin()
{
}
GMXPlugin::~GMXPlugin()
{
}
//## Other Operations (implementation)
void GMXPlugin::create(GeoPhysVol *world, bool publish)
{
std::cout<< "This is GMXPlugin: creating a GeoModelXml detector "<<std::endl;
std::vector<std::string> filesToParse;
char* fPath=getenv("GMX_FILES");
std::string fileName;
if (fPath!=NULL) {
std::cout<<" Environment variable GMX_FILES set to "<<fPath<<std::endl;
fileName=std::string(fPath);
filesToParse=parseFiles(fileName,":");
}
else {
fileName="gmx.xml";
filesToParse.push_back(fileName);
}
char* matManager=getenv("GMX_USE_MATMANAGER");
bool matman=0;
if (matManager!=nullptr)
{
std::cout<<" Environment variable GMX_USE_MATMANAGER set to "<<matManager<<std::endl;
std::istringstream ss(matManager);
ss>>matman;
std::cout<<"matman set to "<<matman<<std::endl;
}
char* levelmaps=getenv("GMX_DUMP_LEVEL_MAPS");
for (auto f: filesToParse)
{
if (!exists(f)) {
std::cout <<"GDMLtoGeo: input file "<<f<<
" does not exist. quitting and returning nicely! "<<std::endl;
return;
GMXPlugin::GMXPlugin() {}
GMXPlugin::~GMXPlugin() {}
// ## Other Operations (implementation)
void GMXPlugin::create(GeoVPhysVol *world, bool publish) {
std::cout << "This is GMXPlugin: creating a GeoModelXml detector "
<< std::endl;
std::vector<std::string> filesToParse;
char *fPath = getenv("GMX_FILES");
std::string fileName;
if (fPath != NULL) {
std::cout << " Environment variable GMX_FILES set to " << fPath
<< std::endl;
fileName = std::string(fPath);
filesToParse = parseFiles(fileName, ":");
} else {
fileName = "gmx.xml";
filesToParse.push_back(fileName);
}
GmxInterface gmxInterface;
//If we want to write the SQLite, pass a publisher through to fill Aux tables
//(needed for ReadoutGeometry)
if(publish) gmxInterface.setPublisher(getPublisher());
if (levelmaps!=nullptr){
std::string mapname = f.substr(0, f.length() - 4);
mapname+="_levelMap.txt";
std::cout<<"Dumping Copy Number Level Map to "<<mapname<<std::endl;
Gmx2Geo gmx2Geo(f, world, gmxInterface, 0 , matman, mapname);
char *matManager = getenv("GMX_USE_MATMANAGER");
bool matman = 0;
if (matManager != nullptr) {
std::cout << " Environment variable GMX_USE_MATMANAGER set to "
<< matManager << std::endl;
std::istringstream ss(matManager);
ss >> matman;
std::cout << "matman set to " << matman << std::endl;
}
else Gmx2Geo gmx2Geo(f, world, gmxInterface, 0 , matman);
}
if (matman) MaterialManager::getManager()->printAll();
char *levelmaps = getenv("GMX_DUMP_LEVEL_MAPS");
for (auto f : filesToParse) {
if (!exists(f)) {
std::cout << "GDMLtoGeo: input file " << f
<< " does not exist. quitting and returning nicely! "
<< std::endl;
return;
}
GmxInterface gmxInterface;
// If we want to write the SQLite, pass a publisher through to fill Aux
// tables (needed for ReadoutGeometry)
if (publish) gmxInterface.setPublisher(getPublisher());
if (levelmaps != nullptr) {
std::string mapname = f.substr(0, f.length() - 4);
mapname += "_levelMap.txt";
std::cout << "Dumping Copy Number Level Map to " << mapname
<< std::endl;
Gmx2Geo gmx2Geo(f, world, gmxInterface, 0, matman, mapname);
} else
Gmx2Geo gmx2Geo(f, world, gmxInterface, 0, matman);
}
if (matman) MaterialManager::getManager()->printAll();
}
extern "C" GMXPlugin *createGMXPlugin() {
return new GMXPlugin("GeoModelXML");
}
extern "C" GMXPlugin *createGMXPlugin() { return new GMXPlugin("GeoModelXML"); }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment