From f4fa1eb609c1856755241a9276c08739825849e5 Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Wed, 12 Oct 2022 10:16:28 +0200 Subject: [PATCH] Use minimal IO library when reading DDG4 input with DDDigi --- DDDigi/CMakeLists.txt | 21 +++++++++++++++++++-- DDDigi/{plugins => ddg4}/DigiDDG4Input.cpp | 0 DDDigi/ddg4/IO.cpp | 21 +++++++++++++++++++++ DDDigi/python/dddigi.py | 6 +++--- DDDigi/src/DigiData.cpp | 7 ++++++- DDEve/DDEve/DDG4IO.C | 10 +++++----- DDG4/include/DDG4/DDG4Dict.h | 4 +--- 7 files changed, 55 insertions(+), 14 deletions(-) rename DDDigi/{plugins => ddg4}/DigiDDG4Input.cpp (100%) create mode 100644 DDDigi/ddg4/IO.cpp diff --git a/DDDigi/CMakeLists.txt b/DDDigi/CMakeLists.txt index cc08ec210..35e7513a9 100644 --- a/DDDigi/CMakeLists.txt +++ b/DDDigi/CMakeLists.txt @@ -53,13 +53,30 @@ dd4hep_add_plugin(DDDigiPlugins USES DD4hep::DDDigi ) +#--------------------------- Plugin library to read input from DDG4 -------------- +if (DD4HEP_USE_GEANT4) + dd4hep_add_dictionary(G__DDDigi_DDG4_IO + SOURCES ../DDCore/include/ROOT/Warnings.h ddg4/IO.cpp + LINKDEF ../DDCore/include/ROOT/LinkDef.h + USES DD4hep::DDG4 + ) + + dd4hep_add_plugin(DDDigi_DDG4_IO + SOURCES ddg4/*.cpp + GENERATED G__DDDigi_DDG4_IO.cxx + USES DD4hep::DDDigi + ) +else() + dd4hep_print( "|++> Geant4 not used. DDDigi will not be able to read DDG4 output.") +endif() + #---Package installation procedure(s) ---------------------------------------------- -set_target_properties(DDDigi DDDigiPlugins PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION}) +set_target_properties(DDDigi DDDigiPlugins DDDigi_DDG4_IO PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION}) file(GLOB DDigi_python python/*.py python/*.C) install(FILES ${DDigi_python} DESTINATION ${DD4HEP_PYTHON_INSTALL_DIR}) -install(TARGETS DDDigi DDDigiPlugins EXPORT DD4hep +install(TARGETS DDDigi DDDigiPlugins DDDigi_DDG4_IO EXPORT DD4hep ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) diff --git a/DDDigi/plugins/DigiDDG4Input.cpp b/DDDigi/ddg4/DigiDDG4Input.cpp similarity index 100% rename from DDDigi/plugins/DigiDDG4Input.cpp rename to DDDigi/ddg4/DigiDDG4Input.cpp diff --git a/DDDigi/ddg4/IO.cpp b/DDDigi/ddg4/IO.cpp new file mode 100644 index 000000000..982035b81 --- /dev/null +++ b/DDDigi/ddg4/IO.cpp @@ -0,0 +1,21 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// \author Markus Frank +// \date 2016-03-10 +// \version 1.0 +// +//========================================================================== + +/// Define this to build a standalonle dictionary: +#define __DDG4_STANDALONE_DICTIONARIES__ + +// C/C++ include files +#include <DDG4/DDG4Dict.h> + diff --git a/DDDigi/python/dddigi.py b/DDDigi/python/dddigi.py index 28d83b237..0702a86db 100644 --- a/DDDigi/python/dddigi.py +++ b/DDDigi/python/dddigi.py @@ -40,10 +40,10 @@ def loadDDDigi(): if result < 0: raise Exception('DDDigi.py: Failed to load the DDDigi library libDDDigiPlugins: ' + gSystem.GetErrorStr()) logger.info('DDDigi.py: Successfully loaded DDDigi plugin library libDDDigiPlugins!') - result = gSystem.Load("libDDG4Plugins") + result = gSystem.Load("libDDDigi_DDG4_IO") if result < 0: - raise Exception('DDDigi.py: Failed to load the DDG4 library libDDG4Plugins: ' + gSystem.GetErrorStr()) - logger.info('DDDigi.py: Successfully loaded DDG4 plugin library libDDG4Plugins!') + raise Exception('DDDigi.py: Failed to load the DDG4 IO library libDDDigi_DDG4_IO: ' + gSystem.GetErrorStr()) + logger.info('DDDigi.py: Successfully loaded DDG4 IO plugin library libDDDigi_DDG4_IO!') from ROOT import dd4hep as module return module diff --git a/DDDigi/src/DigiData.cpp b/DDDigi/src/DigiData.cpp index 2f76d9c13..bf5694852 100644 --- a/DDDigi/src/DigiData.cpp +++ b/DDDigi/src/DigiData.cpp @@ -114,7 +114,12 @@ std::size_t dd4hep::digi::ParticleMapping::merge(ParticleMapping&& updates) { } void dd4hep::digi::ParticleMapping::push(Key::key_type k, Particle&& part) { - auto ret = this->emplace(k, std::move(part)).second; +#if defined(__GNUC__) && (__GNUC__ < 10) + /// Lower compiler version have a bad implementation of std::any + bool ret = false; +#else + bool ret = this->emplace(k, std::move(part)).second; +#endif if ( !ret ) { Key key(k); except("ParticleMapping","Error in particle map. Duplicate ID: mask:%04X Number:%d", diff --git a/DDEve/DDEve/DDG4IO.C b/DDEve/DDEve/DDG4IO.C index d1ead06ce..4620b60c8 100644 --- a/DDEve/DDEve/DDG4IO.C +++ b/DDEve/DDEve/DDG4IO.C @@ -29,8 +29,8 @@ #endif // C/C++ include files -#include "DDG4/DDG4Dict.h" -#include "DDEve/DDEveEventData.h" +#include <DDG4/DDG4Dict.h> +#include <DDEve/DDEveEventData.h> namespace { class DDG4IO {}; } @@ -48,8 +48,8 @@ namespace dd4hep { namespace sim { #include <typeinfo> // ROOT include files -#include "TROOT.h" -#include "TClass.h" +#include <TROOT.h> +#include <TClass.h> namespace { template <typename T> T* _fill(dd4hep::sim::Geant4HitData* ptr, dd4hep::DDEveHit* target) { @@ -119,7 +119,7 @@ namespace { } -#include "DD4hep/Factories.h" +#include <DD4hep/Factories.h> DECLARE_CONSTRUCTOR(DD4hep_DDEve_DDG4HitAccess,_convertHit) DECLARE_CONSTRUCTOR(DD4hep_DDEve_DDG4ParticleAccess,_convertParticle) #endif diff --git a/DDG4/include/DDG4/DDG4Dict.h b/DDG4/include/DDG4/DDG4Dict.h index 68f15ef1a..4b5d3084a 100644 --- a/DDG4/include/DDG4/DDG4Dict.h +++ b/DDG4/include/DDG4/DDG4Dict.h @@ -81,13 +81,11 @@ namespace { class DDG4Dict {}; } #pragma link C++ function operator!=( const std::map<int,dd4hep::sim::Geant4Particle*>::iterator&, const std::map<int,dd4hep::sim::Geant4Particle*>::iterator& ); #endif -//#pragma link C++ class type_info; - /// Dictionaires for basic Hit data structures #pragma link C++ class dd4hep::sim::Geant4HitData+; namespace dd4hep { namespace sim { typedef Geant4HitData* Geant4HitData_ptr_t; }} -#pragma link C++ typedef Geant4HitData_ptr_t; +#pragma link C++ typedef dd4hep::sim::Geant4HitData_ptr_t; #pragma link C++ class std::vector<dd4hep::sim::Geant4HitData_ptr_t>+; #pragma link C++ class std::vector<dd4hep::sim::Geant4HitData*>+; #pragma link C++ class dd4hep::sim::Geant4HitData::Contribution+; -- GitLab