Skip to content

Commit

Permalink
Allow for XML processing of files relative to xml tag location (See i…
Browse files Browse the repository at this point in the history
…ssue AIDASoft#1180 for details)
  • Loading branch information
MarkusFrankATcernch committed Oct 18, 2023
1 parent 8e1d0be commit 1aee5b0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
33 changes: 28 additions & 5 deletions DDCore/src/plugins/Compact2Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
#include <TMath.h>

// C/C++ include files
#include <climits>
#include <filesystem>
#include <iostream>
#include <iomanip>
#include <climits>
#include <set>

using namespace std;
Expand Down Expand Up @@ -1443,17 +1444,38 @@ template <> void Converter<IncludeFile>::operator()(xml_h element) const {
template <> void Converter<JsonFile>::operator()(xml_h element) const {
string base = xml::DocumentHandler::system_directory(element);
string file = element.attr<string>(_U(ref));
vector<char*> argv{&file[0],&base[0]};
vector<char*> argv{&file[0], &base[0]};
description.apply("DD4hep_JsonProcessor",int(argv.size()), &argv[0]);
}

/// Read alignment entries from a seperate file in one of the include sections of the geometry
template <> void Converter<XMLFile>::operator()(xml_h element) const {
PrintLevel level = s_debug.includes ? ALWAYS : DEBUG;
string fname = element.attr<string>(_U(ref));
if ( s_debug.includes ) {
printout(ALWAYS, "Compact","++ Processing xml document %s.", fname.c_str());
size_t idx = fname.find("://");
std::error_code ec;

if ( idx == string::npos && filesystem::exists(fname, ec) ) {
// Regular file without protocol specification
printout(level, "Compact","++ Processing xml document %s.", fname.c_str());
this->description.fromXML(fname);
}
else if ( idx == string::npos ) {
// File relative to location of xml tag (protocol specification not possible)
string location = xml::DocumentHandler::system_path(element, fname);
printout(level, "Compact","++ Processing xml document %s.", location.c_str());
this->description.fromXML(location);
}
else if ( idx > 0 ) {
// File with protocol specification: must trust the location and the parser capabilities
printout(level, "Compact","++ Processing xml document %s.", fname.c_str());
this->description.fromXML(fname);
}
else {
// Are there any other possibilities ?
printout(level, "Compact","++ Processing xml document %s.", fname.c_str());
this->description.fromXML(fname);
}
this->description.fromXML(fname);
}

/// Read material entries from a seperate file in one of the include sections of the geometry
Expand Down Expand Up @@ -1716,6 +1738,7 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
}
xml_coll_t(compact, _U(plugins)).for_each(_U(plugin), Converter<Plugin> (description));
xml_coll_t(compact, _U(plugins)).for_each(_U(include), Converter<XMLFile> (description));
xml_coll_t(compact, _U(plugins)).for_each(_U(xml), Converter<XMLFile> (description));
}

#ifdef _WIN32
Expand Down
4 changes: 4 additions & 0 deletions examples/ClientTests/compact/IncludePlugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<plugins>
<include ref="${DD4hepExamplesINSTALL}/examples/ClientTests/compact/ExamplePlugins.xml"/>
</plugins>
<!-- This here is parsed at the very end -->
<plugins>
<include ref="ExamplePlugins.xml"/>
</plugins>


</lccdd>

0 comments on commit 1aee5b0

Please sign in to comment.