diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp index 81ab0fea69164d37333747c44f1baf62f93c7006..9e981c89a3984b7b9690ba92677e456ae2286ae8 100644 --- a/DDCore/src/plugins/LCDDConverter.cpp +++ b/DDCore/src/plugins/LCDDConverter.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/plugins/LCDDConverter.h b/DDCore/src/plugins/LCDDConverter.h index c56f08be3944c1a53ae60eec5737ffe2221262f5..614dc5c2f8a8b3f68e2d8533aa29987426dc26d0 100644 --- a/DDCore/src/plugins/LCDDConverter.h +++ b/DDCore/src/plugins/LCDDConverter.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/plugins/LCDDFields.cpp b/DDCore/src/plugins/LCDDFields.cpp index 5de3a0d940476f74bcb3c420c3933786c38cc75d..1264decc0dd7957329a74a1aa690e9545e3bba05 100644 --- a/DDCore/src/plugins/LCDDFields.cpp +++ b/DDCore/src/plugins/LCDDFields.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/plugins/PandoraConverter.cpp b/DDCore/src/plugins/PandoraConverter.cpp index 3250b570f0a13feeed3f1420b729a152933a268a..eec6d450051bfcbaf871b0e3f489e659df03c83a 100644 --- a/DDCore/src/plugins/PandoraConverter.cpp +++ b/DDCore/src/plugins/PandoraConverter.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/plugins/PluginInvoker.cpp b/DDCore/src/plugins/PluginInvoker.cpp index 4c461a945dc764dc2e402cd6e77c30b7a430ec25..99a26825211ef79c0a716780dba67e680cf7200e 100644 --- a/DDCore/src/plugins/PluginInvoker.cpp +++ b/DDCore/src/plugins/PluginInvoker.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp index e2a1ee58cdfbe007246570783196156a3c955a4b..1f535d6e638da88263509acfd19926d8a6c15bcf 100644 --- a/DDCore/src/plugins/ShapePlugins.cpp +++ b/DDCore/src/plugins/ShapePlugins.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index 0c6d39486efe2229977b9ed2bd46b9346907e073..86302a9ab94b9b21c24c5361cf101e5016a78808 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -13,22 +13,29 @@ // Framework include files #include "DD4hep/LCDD.h" +#include "DD4hep/Memory.h" #include "DD4hep/DD4hepUI.h" #include "DD4hep/Factories.h" #include "DD4hep/Printout.h" #include "DD4hep/DetectorTools.h" #include "DD4hep/PluginCreators.h" #include "DD4hep/DD4hepRootPersistency.h" +#include "XML/DocumentHandler.h" +#include "XML/XMLElements.h" +#include "XML/XMLTags.h" #include "../LCDDImp.h" // ROOT includes #include "TInterpreter.h" +#include "TGeoElement.h" #include "TGeoManager.h" #include "TGeoVolume.h" #include "TClass.h" #include "TRint.h" // C/C++ include files +#include <cerrno> +#include <cstdlib> #include <fstream> #include <sstream> @@ -119,6 +126,109 @@ static long root_ui(LCDD& lcdd, int /* argc */, char** /* argv */) { } DECLARE_APPLY(DD4hepInteractiveUI,root_ui) +/// Basic entry point to dump the ROOT TGeoElementTable object +/** + * Dump the elment table to stdout or file. + * + * Factory: DD4hepElementTable -format xml/text(default) -output <file-name> + * + * \author M.Frank + * \version 1.0 + * \date 01/04/2014 + */ +static long root_elements(LCDD& lcdd, int argc, char** argv) { + struct ElementPrint { + ElementPrint() = default; + virtual ~ElementPrint() = default; + virtual void operator()(TGeoElement* e) { e->Print(); } + virtual void operator()(TGeoIsotope* i) { i->Print(); } + }; + struct ElementPrintXML : public ElementPrint { + typedef XML::Element elt_h; + elt_h root; + ElementPrintXML(elt_h r) : root(r) {} + virtual ~ElementPrintXML() {} + virtual void operator()(TGeoElement* e) { + elt_h elt = root.addChild(_U(element)); + elt.setAttr(_U(Z),e->Z()); + elt.setAttr(_U(N),e->N()); + elt.setAttr(_U(formula),e->GetName()); + elt.setAttr(_U(name),e->GetName()); + elt_h atom = elt.addChild(_U(atom)); + atom.setAttr(_U(type),"A"); + atom.setAttr(_U(unit),"g/mole"); + atom.setAttr(_U(value),e->A()); + } + virtual void operator()(TGeoIsotope* i) { + elt_h iso = root.addChild(_U(isotope)); + iso.setAttr(_U(Z),i->GetZ()); + iso.setAttr(_U(N),i->GetN()); + iso.setAttr(_U(formula),i->GetName()); + iso.setAttr(_U(name),i->GetName()); + elt_h atom = iso.addChild(_U(atom)); + atom.setAttr(_U(type),"A"); + atom.setAttr(_U(unit),"g/mole"); + atom.setAttr(_U(value),i->GetA()); + } + }; + + string type = "text", output = ""; + for(int i=0; i<argc; ++i) { + if ( argv[i][0] == '-' ) { + char c = ::tolower(argv[i][1]); + if ( c == 't' ) type = argv[++i]; + else if ( c == 'o' ) output = argv[++i]; + else { + ::printf("DD4hepElementTable -opt [-opt] \n" + " -type <string> Output format: text or xml \n" + " -output <file-name> Output file specifier (xml only) \n" + "\n"); + exit(EINVAL); + } + } + } + + XML::Document doc(0); + XML::DocumentHandler docH; + XML::Element element(0); + if ( type == "xml" ) { + const char comment[] = "\n" + " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" + " ++++ Linear collider detector description in C++ ++++\n" + " ++++ DD4hep Detector description generator. ++++\n" + " ++++ ++++\n" + " ++++ Parser:" + XML_IMPLEMENTATION_TYPE + " ++++\n" + " ++++ ++++\n" + " ++++ M.Frank CERN/LHCb ++++\n" + " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n "; + doc = docH.create("materials", comment); + element = doc.root(); + } + dd4hep_ptr<ElementPrint> printer(element + ? new ElementPrintXML(element) + : new ElementPrint()); + TGeoElementTable* table = lcdd.manager().GetElementTable(); + for(Int_t i=0, n=table->GetNelements(); i < n; ++i) + (*printer)(table->GetElement(i)); + + for(Int_t i=0, n=table->GetNelements(); i < n; ++i) { + TGeoElement* elt = table->GetElement(i); + Int_t niso = elt->GetNisotopes(); + if ( niso > 0 ) { + for(Int_t j=0; j < niso; ++j) + (*printer)(elt->GetIsotope(j)); + } + } + if ( element ) { + XML::DocumentHandler dH; + dH.output(doc, output); + } + return 1; +} +DECLARE_APPLY(DD4hepElementTable,root_elements) + /// Basic entry point to interprete an XML document /** * - The file URI to be opened diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt index 252e02b0ec73c7b9ca4096fb80519cc13c7f0769..5059df48760d7eed80ab4fbf276459a4e3b669b0 100644 --- a/examples/ClientTests/CMakeLists.txt +++ b/examples/ClientTests/CMakeLists.txt @@ -29,6 +29,12 @@ dd4hep_configure_scripts( ClientTests DEFAULT_SETUP WITH_TESTS) #--- Testing ------------------------------------------------------------ # # Test readout strings of the form: <id>system:8,barrel:-2</id> +dd4hep_add_test_reg( ClientTests_DumpElements + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" + EXEC_ARGS geoPluginRun -plugin DD4hepElementTable -type xml + REGEX_PASS "formula=\"UUB\" name=\"UUB\"" ) +# +# Test readout strings of the form: <id>system:8,barrel:-2</id> dd4hep_add_test_reg( ClientTests_Bitfield64_BarrelSides COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" EXEC_ARGS geoPluginRun @@ -38,7 +44,6 @@ dd4hep_add_test_reg( ClientTests_Bitfield64_BarrelSides -plugin DD4hepVolumeMgrTest all REGEX_PASS "OK IDS\\(Shell_1\\) vid\\:0000000000000302 system\\: 2 barrel\\:-1" ) # -# # Test readout strings of the form: <id>system:16,barrel:16:-5</id> dd4hep_add_test_reg( ClientTests_Bitfield64_BarrelSides2 COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"