From 98e50bdca0056a7042f2e55d68375b1d3ced1a51 Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Wed, 28 Sep 2016 18:58:08 +0200 Subject: [PATCH] Allow properties to be externalized to other projects --- .../DD4hep/{objects => }/BasicGrammar_inl.h | 7 +- DDCore/include/DD4hep/ComponentProperties.h | 2 - DDCore/src/AlignmentData.cpp | 2 +- DDCore/src/BasicGrammarTypes.cpp | 12 +- DDCore/src/ComponentProperties.cpp | 2 +- DDCore/src/ConditionsData.cpp | 2 +- DDCore/src/ObjectPrintout.cpp | 142 ++++++++++++++++++ DDCore/src/Printout.cpp | 120 --------------- DDCore/src/ToStream.cpp | 13 ++ DDCore/src/parsers/UsedParser.h | 8 +- 10 files changed, 175 insertions(+), 135 deletions(-) rename DDCore/include/DD4hep/{objects => }/BasicGrammar_inl.h (99%) create mode 100644 DDCore/src/ObjectPrintout.cpp diff --git a/DDCore/include/DD4hep/objects/BasicGrammar_inl.h b/DDCore/include/DD4hep/BasicGrammar_inl.h similarity index 99% rename from DDCore/include/DD4hep/objects/BasicGrammar_inl.h rename to DDCore/include/DD4hep/BasicGrammar_inl.h index 997e3635a..4d9fba2c4 100644 --- a/DDCore/include/DD4hep/objects/BasicGrammar_inl.h +++ b/DDCore/include/DD4hep/BasicGrammar_inl.h @@ -26,17 +26,20 @@ #include "DD4hep/Primitives.h" #include "DD4hep/BasicGrammar.h" +#include "XML/Evaluator.h" + #ifdef DD4HEP_USE_BOOST #include "DD4hep/Parsers.h" #include "DD4hep/ToStream.h" -#include "XML/Evaluator.h" namespace DD4hep { XmlTools::Evaluator& g4Evaluator(); } -namespace { static XmlTools::Evaluator& s__eval(DD4hep::g4Evaluator()); } #endif +namespace { static XmlTools::Evaluator& s__eval(DD4hep::g4Evaluator()); } +#ifndef DD4HEP_PARSERS_NO_ROOT #include "Math/Point3D.h" #include "Math/Vector3D.h" #include "Math/Vector4D.h" +#endif // C/C++ include files #include <string> diff --git a/DDCore/include/DD4hep/ComponentProperties.h b/DDCore/include/DD4hep/ComponentProperties.h index bef20e83c..8640787ac 100644 --- a/DDCore/include/DD4hep/ComponentProperties.h +++ b/DDCore/include/DD4hep/ComponentProperties.h @@ -16,8 +16,6 @@ #define DD4HEP_DDG4_COMPONENTPROPERTIES_H // Framework include files -//#include "DD4hep/Primitives.h" -//#include "DD4hep/Exceptions.h" // C/C++ include files #include <algorithm> diff --git a/DDCore/src/AlignmentData.cpp b/DDCore/src/AlignmentData.cpp index 53310d0e9..15d9a4d05 100644 --- a/DDCore/src/AlignmentData.cpp +++ b/DDCore/src/AlignmentData.cpp @@ -206,6 +206,6 @@ Alignment AlignmentData::nominal() const { DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(Delta) DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(AlignmentData) -#include "DD4hep/objects/BasicGrammar_inl.h" +#include "DD4hep/BasicGrammar_inl.h" DD4HEP_DEFINE_PARSER_GRAMMAR(Delta,eval_none<Delta>) DD4HEP_DEFINE_PARSER_GRAMMAR(AlignmentData,eval_none<AlignmentData>) diff --git a/DDCore/src/BasicGrammarTypes.cpp b/DDCore/src/BasicGrammarTypes.cpp index cf4d61373..1197a5b4d 100644 --- a/DDCore/src/BasicGrammarTypes.cpp +++ b/DDCore/src/BasicGrammarTypes.cpp @@ -13,7 +13,9 @@ //========================================================================== // Framework include files -#include "DD4hep/objects/BasicGrammar_inl.h" +#include "DD4hep/BasicGrammar_inl.h" + +#ifndef DD4HEP_PARSERS_NO_ROOT namespace ROOT { namespace Math { @@ -41,6 +43,10 @@ namespace ROOT { template struct std::less<ROOT::Math::XYZPoint>; template struct std::less<ROOT::Math::XYZVector>; template struct std::less<ROOT::Math::PxPyPzEVector>; +DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(ROOT::Math::XYZPoint,eval_obj) +DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(ROOT::Math::XYZVector,eval_obj) +DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(ROOT::Math::PxPyPzEVector,eval_obj) +#endif #if defined(DD4HEP_HAVE_ALL_PARSERS) DD4HEP_DEFINE_PARSER_GRAMMAR_U_CONT(char) @@ -54,7 +60,3 @@ DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(bool,eval_item) DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(float,eval_item) DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(double,eval_item) DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(std::string,eval_item) - -DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(ROOT::Math::XYZPoint,eval_obj) -DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(ROOT::Math::XYZVector,eval_obj) -DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(ROOT::Math::PxPyPzEVector,eval_obj) diff --git a/DDCore/src/ComponentProperties.cpp b/DDCore/src/ComponentProperties.cpp index 6734afc0b..5dcdcb839 100644 --- a/DDCore/src/ComponentProperties.cpp +++ b/DDCore/src/ComponentProperties.cpp @@ -257,7 +257,7 @@ namespace DD4hep { #include "Math/Vector3D.h" #include "Math/Vector4D.h" -#include "DD4hep/objects/BasicGrammar_inl.h" +#include "DD4hep/BasicGrammar_inl.h" #include "DD4hep/ComponentProperties_inl.h" DD4HEP_DEFINE_PARSER_GRAMMAR_TYPE(Property) diff --git a/DDCore/src/ConditionsData.cpp b/DDCore/src/ConditionsData.cpp index d0e2d5207..d20d82ec8 100644 --- a/DDCore/src/ConditionsData.cpp +++ b/DDCore/src/ConditionsData.cpp @@ -74,6 +74,6 @@ AbstractMap& AbstractMap::operator=(const AbstractMap& c) { #include "DD4hep/objects/ConditionsInterna.h" DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(AbstractMap) -#include "DD4hep/objects/BasicGrammar_inl.h" +#include "DD4hep/BasicGrammar_inl.h" DD4HEP_DEFINE_PARSER_GRAMMAR(AbstractMap,eval_none<AbstractMap>) diff --git a/DDCore/src/ObjectPrintout.cpp b/DDCore/src/ObjectPrintout.cpp new file mode 100644 index 000000000..198278224 --- /dev/null +++ b/DDCore/src/ObjectPrintout.cpp @@ -0,0 +1,142 @@ +// $Id: $ +//========================================================================== +// 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 +// +//========================================================================== + +// Framework include files +#include "DD4hep/LCDD.h" +#include "DD4hep/Objects.h" +#include "DD4hep/Conditions.h" +#include "DD4hep/objects/ObjectsInterna.h" +#include "DD4hep/Printout.h" + +// C/C++ include files +#include <cstdarg> +#include <stdexcept> + +using namespace std; + +#include "TMap.h" +#include "TROOT.h" +#include "TColor.h" +using namespace std; +namespace DD4hep { + using namespace Geometry; + using Conditions::Condition; + + template <typename T> void PrintMap<T>::operator()() const { + Printer < T > p(lcdd, os); + os << "++" << endl << "++ " << text << endl << "++" << endl; + for (LCDD::HandleMap::const_iterator i = cont.begin(); i != cont.end(); ++i) + p((*i).second); + } + + template <> void Printer<Handle<NamedObject> >::operator()(const Handle<NamedObject>& val) const { + printout(INFO, "Printer", "++ %s Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle()); + } + template <> void Printer<Handle<TNamed> >::operator()(const Handle<TNamed>& val) const { + printout(INFO, "Printer", "++ %s Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle()); + } + + template <> void Printer<Constant>::operator()(const Constant& val) const { + printout(INFO, "Printer", "++ %s Constant:%s %s", prefix.c_str(), val->GetName(), val.toString().c_str()); + } + + template <> void Printer<Material>::operator()(const Material& val) const { + printout(INFO, "Printer", "++ %s Material:%s %s", prefix.c_str(), val->GetName(), val.toString().c_str()); + } + + template <> void Printer<VisAttr>::operator()(const VisAttr& val) const { + printout(INFO, "Printer", "++ %s VisAttr: %s", prefix.c_str(), val.toString().c_str()); + } + + template <> void Printer<Readout>::operator()(const Readout& val) const { + printout(INFO, "Printer", "++ %s Readout: %s of type %s", prefix.c_str(), val->GetName(), val->GetTitle()); + } + + template <> void Printer<Region>::operator()(const Region& val) const { + printout(INFO, "Printer", "++ %s Region: %s of type %s", prefix.c_str(), val->GetName(), val->GetTitle()); + } + + template <> void Printer<RotationZYX>::operator()(const RotationZYX& val) const { + printout(INFO, "Printer", "++ %s ZYXRotation: phi: %7.3 rad theta: %7.3 rad psi: %7.3 rad", prefix.c_str(), val.Phi(), + val.Theta(), val.Psi()); + } + + template <> void Printer<Position>::operator()(const Position& val) const { + printout(INFO, "Printer", "++ %s Position: x: %9.3 mm y: %9.3 mm z: %9.3 mm", prefix.c_str(), val.X(), val.Y(), val.Z()); + } + template <> void Printer<Condition>::operator()(const Condition& val) const { + int flg = Condition::WITH_IOV|Condition::WITH_ADDRESS; + printout(INFO, "Printer", "++ %s %s", prefix.c_str(), val.str(flg).c_str()); + } +#if 0 + template <> void Printer<LimitSet>::operator()(const LimitSet& val) const { + const set<Limit>& o = val.limits(); + printout(INFO, "Printer", "++ %s LimitSet: %s", prefix.c_str(), val.name()); + val->TNamed::Print(); + for (set<Limit>::const_iterator i = o.begin(); i != o.end(); ++i) { + os << "++ Limit:" << (*i).name << " " << (*i).particles << " [" << (*i).unit << "] " << (*i).content << " " + << (*i).value << endl; + } + } + + template <> void Printer<DetElement>::operator()(const DetElement& val) const { + DetElement::Object* obj = val.data<DetElement::Object>(); + if (obj) { + char text[256]; + const DetElement& sd = val; + PlacedVolume plc = sd.placement(); + bool vis = plc.isValid(); + bool env = plc.isValid(); + bool mat = plc.isValid(); + ::snprintf(text, sizeof(text), "ID:%-3d Combine Hits:%3s Material:%s Envelope:%s VisAttr:%s", sd.id(), + yes_no(sd.combineHits()), mat ? plc.material().name() : yes_no(mat), + env ? plc.motherVol()->GetName() : yes_no(env), yes_no(vis)); + os << prefix << "+= DetElement: " << val.name() << " " << val.type() << endl; + os << prefix << "| " << text << endl; + + if (vis) { + VisAttr attr = plc.volume().visAttributes(); + VisAttr::Object* v = attr.data<VisAttr::Object>(); + TColor* col = gROOT->GetColor(v->color); + char text[256]; + ::snprintf(text, sizeof(text), " RGB:%-8s [%d] %7.2f Style:%d %d ShowDaughters:%3s Visible:%3s", col->AsHexString(), + v->color, col->GetAlpha(), int(v->drawingStyle), + int(v->lineStyle), yes_no(v->showDaughters), + yes_no(v->visible)); + os << prefix << "| VisAttr: " << setw(32) << left << attr.name() << text << endl; + } + if (plc.isValid()) { + Volume vol = plc.volume(); + Solid s = vol.solid(); + Material m = vol.material(); + ::snprintf(text, sizeof(text), "Volume:%s Shape:%s Material:%s", vol->GetName(), s.isValid() ? s.name() : "Unknonw", + m.isValid() ? m->GetName() : "Unknown"); + os << prefix << "+------------- " << text << endl; + } + const DetElement::Children& ch = sd.children(); + for (DetElement::Children::const_iterator i = ch.begin(); i != ch.end(); ++i) + Printer < DetElement > (lcdd, os, prefix + "| ")((*i).second); + return; + } + } +#endif + template <> void Printer<const LCDD*>::operator()(const LCDD* const &) const { + //Header(lcdd.header()).fromCompact(doc,compact.child(Tag_info),Strng_t("In memory")); + PrintMap < Constant > (lcdd, os, lcdd->constants(), "List of Constants")(); + //PrintMap < VisAttr > (lcdd, os, lcdd->visAttributes(), "List of Visualization attributes")(); + //PrintMap < LimitSet > (lcdd, os, lcdd->readouts(), "List of Readouts")(); + //PrintMap < Region > (lcdd, os, lcdd->regions(), "List of Regions")(); + //PrintMap < DetElement > (lcdd, os, lcdd->detectors(), "List of DetElements")(); + } +} diff --git a/DDCore/src/Printout.cpp b/DDCore/src/Printout.cpp index 4f191a166..02af783b3 100644 --- a/DDCore/src/Printout.cpp +++ b/DDCore/src/Printout.cpp @@ -13,9 +13,6 @@ //========================================================================== // Framework include files -#include "DD4hep/LCDD.h" -#include "DD4hep/Objects.h" -#include "DD4hep/objects/ObjectsInterna.h" #include "DD4hep/Printout.h" // C/C++ include files @@ -300,120 +297,3 @@ void DD4hep::setPrinter(void* arg, output_function_t fcn) { print_arg = arg; print_func = fcn; } -#include "DD4hep/Conditions.h" - -#include "TMap.h" -#include "TROOT.h" -#include "TColor.h" -using namespace std; -namespace DD4hep { - using namespace Geometry; - using Conditions::Condition; - - template <typename T> void PrintMap<T>::operator()() const { - Printer < T > p(lcdd, os); - os << "++" << endl << "++ " << text << endl << "++" << endl; - for (LCDD::HandleMap::const_iterator i = cont.begin(); i != cont.end(); ++i) - p((*i).second); - } - - template <> void Printer<Handle<NamedObject> >::operator()(const Handle<NamedObject>& val) const { - printout(INFO, "Printer", "++ %s Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle()); - } - template <> void Printer<Handle<TNamed> >::operator()(const Handle<TNamed>& val) const { - printout(INFO, "Printer", "++ %s Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle()); - } - - template <> void Printer<Constant>::operator()(const Constant& val) const { - printout(INFO, "Printer", "++ %s Constant:%s %s", prefix.c_str(), val->GetName(), val.toString().c_str()); - } - - template <> void Printer<Material>::operator()(const Material& val) const { - printout(INFO, "Printer", "++ %s Material:%s %s", prefix.c_str(), val->GetName(), val.toString().c_str()); - } - - template <> void Printer<VisAttr>::operator()(const VisAttr& val) const { - printout(INFO, "Printer", "++ %s VisAttr: %s", prefix.c_str(), val.toString().c_str()); - } - - template <> void Printer<Readout>::operator()(const Readout& val) const { - printout(INFO, "Printer", "++ %s Readout: %s of type %s", prefix.c_str(), val->GetName(), val->GetTitle()); - } - - template <> void Printer<Region>::operator()(const Region& val) const { - printout(INFO, "Printer", "++ %s Region: %s of type %s", prefix.c_str(), val->GetName(), val->GetTitle()); - } - - template <> void Printer<RotationZYX>::operator()(const RotationZYX& val) const { - printout(INFO, "Printer", "++ %s ZYXRotation: phi: %7.3 rad theta: %7.3 rad psi: %7.3 rad", prefix.c_str(), val.Phi(), - val.Theta(), val.Psi()); - } - - template <> void Printer<Position>::operator()(const Position& val) const { - printout(INFO, "Printer", "++ %s Position: x: %9.3 mm y: %9.3 mm z: %9.3 mm", prefix.c_str(), val.X(), val.Y(), val.Z()); - } - template <> void Printer<Condition>::operator()(const Condition& val) const { - int flg = Condition::WITH_IOV|Condition::WITH_ADDRESS; - printout(INFO, "Printer", "++ %s %s", prefix.c_str(), val.str(flg).c_str()); - } -#if 0 - template <> void Printer<LimitSet>::operator()(const LimitSet& val) const { - const set<Limit>& o = val.limits(); - printout(INFO, "Printer", "++ %s LimitSet: %s", prefix.c_str(), val.name()); - val->TNamed::Print(); - for (set<Limit>::const_iterator i = o.begin(); i != o.end(); ++i) { - os << "++ Limit:" << (*i).name << " " << (*i).particles << " [" << (*i).unit << "] " << (*i).content << " " - << (*i).value << endl; - } - } - - template <> void Printer<DetElement>::operator()(const DetElement& val) const { - DetElement::Object* obj = val.data<DetElement::Object>(); - if (obj) { - char text[256]; - const DetElement& sd = val; - PlacedVolume plc = sd.placement(); - bool vis = plc.isValid(); - bool env = plc.isValid(); - bool mat = plc.isValid(); - ::snprintf(text, sizeof(text), "ID:%-3d Combine Hits:%3s Material:%s Envelope:%s VisAttr:%s", sd.id(), - yes_no(sd.combineHits()), mat ? plc.material().name() : yes_no(mat), - env ? plc.motherVol()->GetName() : yes_no(env), yes_no(vis)); - os << prefix << "+= DetElement: " << val.name() << " " << val.type() << endl; - os << prefix << "| " << text << endl; - - if (vis) { - VisAttr attr = plc.volume().visAttributes(); - VisAttr::Object* v = attr.data<VisAttr::Object>(); - TColor* col = gROOT->GetColor(v->color); - char text[256]; - ::snprintf(text, sizeof(text), " RGB:%-8s [%d] %7.2f Style:%d %d ShowDaughters:%3s Visible:%3s", col->AsHexString(), - v->color, col->GetAlpha(), int(v->drawingStyle), - int(v->lineStyle), yes_no(v->showDaughters), - yes_no(v->visible)); - os << prefix << "| VisAttr: " << setw(32) << left << attr.name() << text << endl; - } - if (plc.isValid()) { - Volume vol = plc.volume(); - Solid s = vol.solid(); - Material m = vol.material(); - ::snprintf(text, sizeof(text), "Volume:%s Shape:%s Material:%s", vol->GetName(), s.isValid() ? s.name() : "Unknonw", - m.isValid() ? m->GetName() : "Unknown"); - os << prefix << "+------------- " << text << endl; - } - const DetElement::Children& ch = sd.children(); - for (DetElement::Children::const_iterator i = ch.begin(); i != ch.end(); ++i) - Printer < DetElement > (lcdd, os, prefix + "| ")((*i).second); - return; - } - } -#endif - template <> void Printer<const LCDD*>::operator()(const LCDD* const &) const { - //Header(lcdd.header()).fromCompact(doc,compact.child(Tag_info),Strng_t("In memory")); - PrintMap < Constant > (lcdd, os, lcdd->constants(), "List of Constants")(); - //PrintMap < VisAttr > (lcdd, os, lcdd->visAttributes(), "List of Visualization attributes")(); - //PrintMap < LimitSet > (lcdd, os, lcdd->readouts(), "List of Readouts")(); - //PrintMap < Region > (lcdd, os, lcdd->regions(), "List of Regions")(); - //PrintMap < DetElement > (lcdd, os, lcdd->detectors(), "List of DetElements")(); - } -} diff --git a/DDCore/src/ToStream.cpp b/DDCore/src/ToStream.cpp index f809e2505..65f1f2e4a 100644 --- a/DDCore/src/ToStream.cpp +++ b/DDCore/src/ToStream.cpp @@ -13,7 +13,17 @@ //========================================================================== // Framework include files +#if defined(DD4HEP_PARSER_HEADER) +// This is the case, if the parsers are externalized +// and the DD4hep namespace is renamed! +#include DD4HEP_PARSER_HEADER + +#else + +// Standard DD4hep parser handling #include "DD4hep/ToStream.h" + +#endif #include "XML/Evaluator.h" // C/C++ include files @@ -53,6 +63,8 @@ namespace DD4hep { namespace Parsers { } } +#ifndef DD4HEP_PARSERS_NO_ROOT + // ============================================================================ // print XYZ-point std::ostream& DD4hep::Utils::toStream(const ROOT::Math::XYZPoint& obj, std::ostream& s) { @@ -91,3 +103,4 @@ std::ostream& DD4hep::Utils::toStream(const ROOT::Math::PxPyPzEVector& obj, std: s << " )"; return s; } +#endif diff --git a/DDCore/src/parsers/UsedParser.h b/DDCore/src/parsers/UsedParser.h index 96c417a3b..f83260325 100644 --- a/DDCore/src/parsers/UsedParser.h +++ b/DDCore/src/parsers/UsedParser.h @@ -13,12 +13,14 @@ #define DD4HEP_DDCORE_PARSERS_USEDPARSERS_H -#if defined(DD4hep) - -#include "Parsers/UsedParser.h" +#if defined(DD4HEP_PARSER_HEADER) +// This is the case, if the parsers are externalized +// and the DD4hep namespace is renamed! +#include DD4HEP_PARSER_HEADER #else +// Standard DD4hep parser handling #include "DD4hep/Parsers.h" #include "DD4hep/ToStream.h" -- GitLab