diff --git a/DDCore/include/JSON/Elements.h b/DDCore/include/JSON/Elements.h index 1c86b75820f4ae2354d44844be72bffcd8c3ad14..1734f2b96c9a5784c7554c144c73df38ed5e35ed 100644 --- a/DDCore/include/JSON/Elements.h +++ b/DDCore/include/JSON/Elements.h @@ -422,11 +422,13 @@ namespace DD4hep { }; /// Forward declarations - class DocumentHandler; - - + class DocumentHandler; #undef INLINE + + void dumpTree(Handle_t elt); + void dumpTree(Element elt); + void dumpTree(const JsonElement* elt); - } /* End namespace XML */ + } /* End namespace JSON */ } /* End namespace DD4hep */ #endif /* DDCORE_DD4HEP_JSON_ELEMENTS_H */ diff --git a/DDCore/src/JSON/DocumentHandler.cpp b/DDCore/src/JSON/DocumentHandler.cpp index b38aa4eb87bd2b9151f621b82daf1a3a924e10af..1dffafcb6def449c8cdab63b88f310861a553374 100644 --- a/DDCore/src/JSON/DocumentHandler.cpp +++ b/DDCore/src/JSON/DocumentHandler.cpp @@ -34,9 +34,9 @@ DocumentHandler::~DocumentHandler() { Document DocumentHandler::load(const string& fname) const { string fn = fname; if ( fname.find("://") != string::npos ) fn = fname.substr(fname.find("://")+3); - string cmd = "cat "+fn; - ::printf("\n\n+++++ Dump json file: %s\n\n\n",fn.c_str()); - ::system(cmd.c_str()); + //string cmd = "cat "+fn; + //::printf("\n\n+++++ Dump json file: %s\n\n\n",fn.c_str()); + //::system(cmd.c_str()); unique_ptr<JsonElement> doc(new JsonElement(fn, ptree())); boost::property_tree::read_json(fn,doc->second); return doc.release(); diff --git a/DDCore/src/JSON/Elements.cpp b/DDCore/src/JSON/Elements.cpp index 8b740290a002922200b34d6da7b42dcd336dd7b3..24079d656ceca7bfc0e710776a577b56f2273ec1 100644 --- a/DDCore/src/JSON/Elements.cpp +++ b/DDCore/src/JSON/Elements.cpp @@ -518,3 +518,24 @@ void Collection_t::operator++(int) const { void Collection_t::operator--(int) const { --(*this); } + +void DD4hep::JSON::dumpTree(Handle_t elt) { + dumpTree(elt.ptr()); +} + +void DD4hep::JSON::dumpTree(Element elt) { + dumpTree(elt.ptr()); +} + +void DD4hep::JSON::dumpTree(const JsonElement* elt) { + struct Dump { + void operator()(const JsonElement* elt, const string& tag) const { + string t = tag+" "; + printout(INFO,"DumpTree","+++ %s %s: %s",tag.c_str(), elt->first.c_str(), elt->second.data().c_str()); + for(auto i=elt->second.begin(); i!=elt->second.end(); ++i) + (*this)(&(*i), t); + } + } _dmp; + _dmp(elt," "); +} + diff --git a/examples/ClientTests/compact/MiniTel.json b/examples/ClientTests/compact/MiniTel.json index d0746cffa31452e33cfc153e2afe92b6310b980f..d56a9c81cb22aec85133bcabc07a954132bae324 100644 --- a/examples/ClientTests/compact/MiniTel.json +++ b/examples/ClientTests/compact/MiniTel.json @@ -1,15 +1,3 @@ -//========================================================================== -// AIDA Detector description implementation for LCD -//-------------------------------------------------------------------------- -// 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 : M.Frank -// -//========================================================================== { "detector": { "id": 1, diff --git a/examples/ClientTests/src_boost/JsonTest.cpp b/examples/ClientTests/src_boost/JsonTest.cpp index 456940aa1cdee081800073cc4acd094bff8059d1..13cb089d9c07955b318c4463d6509a4adb495b13 100644 --- a/examples/ClientTests/src_boost/JsonTest.cpp +++ b/examples/ClientTests/src_boost/JsonTest.cpp @@ -22,34 +22,13 @@ using namespace DD4hep; using namespace DD4hep::JSON; using namespace DD4hep::Geometry; -static long json_dump(LCDD& lcdd, int argc, char** argv) { +static long json_dump(LCDD& /* lcdd */, int argc, char** argv) { if ( argc < 1 ) { - return 0; + ::printf("DD4hep_JsonDumper <file> \n"); + exit(EINVAL); } DocumentHolder doc(JSON::DocumentHandler().load(argv[0])); - Element elt = doc.root(); - - for( boost::property_tree::ptree::value_type const& rowPair : elt.ptr()->second.get_child( "" ) ) - { - cout << "1--" << rowPair.first << ": " << endl; - cout << rowPair.second.get_value<string>() << " " << endl; - - for( boost::property_tree::ptree::value_type const& itemPair : rowPair.second ) - { - cout << "\t2--" << itemPair.first << " " << endl; - - for( boost::property_tree::ptree::value_type const& node : itemPair.second ) - { - cout << "\t\t3--" << node.first << "=" << node.second.get_value<string>() << endl; - } - - cout << endl; - - } - - cout << endl; - } - + dumpTree(doc.root()); return 1; }