Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for XML processing of files relative to xml tag location #1181

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading