diff --git a/DDCore/include/DD4hep/ComponentProperties.h b/DDCore/include/DD4hep/ComponentProperties.h index 178cbe4740d3b40127422d4bdcdb82ac4a9df796..bfb150e89adb900a705d74a47979b69603aa1343 100644 --- a/DDCore/include/DD4hep/ComponentProperties.h +++ b/DDCore/include/DD4hep/ComponentProperties.h @@ -30,14 +30,17 @@ namespace DD4hep { class BasicGrammar; class PropertyGrammar; - /// Heler class to configure properties + /// Interface class to configure properties in components /** + * Placeholder interface. + * * \author M.Frank * \version 1.0 * \ingroup DD4HEP_SIMULATION */ class PropertyConfigurator { protected: + /// Default destructor virtual ~PropertyConfigurator(); public: virtual void set(const PropertyGrammar& setter, const std::string&, const std::string&, void* ptr) const = 0; diff --git a/DDCore/include/DD4hep/ConditionsData.h b/DDCore/include/DD4hep/ConditionsData.h index 97010d646dd1bbf7576ef38d6f6fc5199a12345b..48145942731f9bbb71e73a6b620e9919ebf28a81 100644 --- a/DDCore/include/DD4hep/ConditionsData.h +++ b/DDCore/include/DD4hep/ConditionsData.h @@ -70,6 +70,10 @@ namespace DD4hep { template <typename T> T* option() const { return static_cast<T*>(clientData); } + /// Access the number of contained blocks + size_t size() const { + return params.size(); + } /// Simplify access to first item of the parameter list (const access) const Params::value_type& firstParam() const { Params::const_iterator i=std::begin(params); diff --git a/DDCore/include/XML/DocumentHandler.h b/DDCore/include/XML/DocumentHandler.h index 64e4386aa7f19c09853aa51dff41d01f1e1f9daa..b8d09e7621fa1d82ee2e6785973bec5a93c53d92 100644 --- a/DDCore/include/XML/DocumentHandler.h +++ b/DDCore/include/XML/DocumentHandler.h @@ -16,7 +16,6 @@ // Framework include files #include "XML/XMLElements.h" -#include "DD4hep/Memory.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { diff --git a/DDCore/include/XML/Layering.h b/DDCore/include/XML/Layering.h index 896017c274389d186063c40c2d84174816a6d9b9..50597abcbd06ea6a79de9ac89884c6939491b4d8 100644 --- a/DDCore/include/XML/Layering.h +++ b/DDCore/include/XML/Layering.h @@ -11,8 +11,8 @@ // //========================================================================== -#ifndef DD4hep_LAYERING_H -#define DD4hep_LAYERING_H +#ifndef DD4HEP_DDCORE_LAYERING_H +#define DD4HEP_DDCORE_LAYERING_H // Framework include files #include "XML/XMLElements.h" @@ -179,8 +179,6 @@ namespace DD4hep { inline LayeringCnv::LayeringCnv(Element e) : Element(e) { } - } - -} /* End namespace DD4hep */ -#endif /* DD4hep_LAYERING_H */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DDCORE_LAYERING_H */ diff --git a/DDCore/include/XML/Printout.h b/DDCore/include/XML/Printout.h new file mode 100644 index 0000000000000000000000000000000000000000..01c16994333b3a1604866ca4288255a3bfa9e61d --- /dev/null +++ b/DDCore/include/XML/Printout.h @@ -0,0 +1,24 @@ +//========================================================================== +// 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 +// +//========================================================================== +#ifndef DD4HEP_DDCORE_XML_PRINTOUT_H +#define DD4HEP_DDCORE_XML_PRINTOUT_H + +// Forwarding printout functionality to DD4hep +/** Note: This is necessary to use the XML functionality as a standalone + * utility without the need to externalize the world. + * + * See the externalized header in doc/externalize for details. + */ +#include "DD4hep/Printout.h" + +#endif /* DD4HEP_DDCORE_XML_PRINTOUT_H */ diff --git a/DDCore/include/XML/XML.h b/DDCore/include/XML/XML.h new file mode 100644 index 0000000000000000000000000000000000000000..25f983d51c42787b491d108e31f4be6281943ba4 --- /dev/null +++ b/DDCore/include/XML/XML.h @@ -0,0 +1,31 @@ +//========================================================================== +// 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 +// +//========================================================================== + +#ifndef DD4HEP_DDCORE_XML_TYPES_H +#define DD4HEP_DDCORE_XML_TYPES_H + +#include "XML/XMLTags.h" +#include "XML/XMLDimension.h" +#include "XML/DocumentHandler.h" + +typedef DD4hep::XML::Handle_t xml_h; +typedef DD4hep::XML::Tag_t xml_tag_t; +typedef DD4hep::XML::Attribute xml_attr_t; +typedef DD4hep::XML::Collection_t xml_coll_t; +typedef DD4hep::XML::Element xml_elt_t; +typedef DD4hep::XML::RefElement xml_ref_t; +typedef DD4hep::XML::Dimension xml_dim_t; +typedef DD4hep::XML::Document xml_doc_t; +typedef DD4hep::XML::Strng_t Unicode; + +#endif // DD4HEP_DDCORE_XML_TYPES_H diff --git a/DDCore/include/XML/XMLElements.h b/DDCore/include/XML/XMLElements.h index 9366bece936df565f74a9836b58376695fb60ccb..f2922d66601727cc0feda74485d02aa3949a0ae1 100644 --- a/DDCore/include/XML/XMLElements.h +++ b/DDCore/include/XML/XMLElements.h @@ -21,7 +21,7 @@ // Framework include files #include "XML/config.h" -#include "DD4hep/Primitives.h" +//#include "DD4hep/Primitives.h" #ifndef RAD_2_DEGREE #define RAD_2_DEGREE 57.295779513082320876798154814105 @@ -195,7 +195,7 @@ namespace DD4hep { } /// String length in native representation size_t length() const { - return XmlString::length(m_xml); + return XmlString::length(m_xml); } /// Assignment opertor from ascii string Strng_t& operator=(const char* s); @@ -314,6 +314,15 @@ namespace DD4hep { return c == b.m_str; } + /// Convert Strng_t to std::string + std::string _toString(const Strng_t& s); + /// Convert Tag_t to std::string + std::string _toString(const Tag_t& s); + /// Helper function to populate the evaluator dictionary \ingroup DD4HEP_XML + void _toDictionary(const XmlChar* name, const Strng_t& s); + /// Helper function to populate the evaluator dictionary \ingroup DD4HEP_XML + void _toDictionary(const XmlChar* name, const Tag_t& t); + /// Class describing a list of XML nodes /** * Definition of a "list" of xml elements hanging of the parent. diff --git a/DDCore/src/ComponentProperties.cpp b/DDCore/src/ComponentProperties.cpp index 677d526d6128b201bbbc1784bec8ae2e2a0a76bb..bcca31f8305a1e540883d64eae9c4407ee57dbab 100644 --- a/DDCore/src/ComponentProperties.cpp +++ b/DDCore/src/ComponentProperties.cpp @@ -25,6 +25,10 @@ using namespace std; using namespace DD4hep; +/// Default destructor +PropertyConfigurator::~PropertyConfigurator() { +} + /// Default constructor PropertyGrammar::PropertyGrammar(const BasicGrammar& g) : m_grammar(g) { } diff --git a/DDCore/src/Evaluator/ExpressionEvaluator.cpp b/DDCore/src/Evaluator/ExpressionEvaluator.cpp index 101a57614fea9a853635618dc83f22f15716b168..e00e73dcbe436bd3c70d3a5d95cc9907f62ffb8e 100644 --- a/DDCore/src/Evaluator/ExpressionEvaluator.cpp +++ b/DDCore/src/Evaluator/ExpressionEvaluator.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/Evaluator/setStdMath.cpp b/DDCore/src/Evaluator/setStdMath.cpp index e88a784c6d72b7a1a10c813439f8cb10742e96b2..6cb9ab28a358a9c253e1619b9e47e0f0f99d3701 100644 --- a/DDCore/src/Evaluator/setStdMath.cpp +++ b/DDCore/src/Evaluator/setStdMath.cpp @@ -3,7 +3,16 @@ // ---------------------------------------------------------------------- #include "XML/Evaluator.h" + +#ifdef DD4HEP_NONE +/// Utility namespace to support TGeo units. +namespace dd4hep { + static const double radian = 1. ; + static const double degree = (3.14159265358979323846/180.0)*radian; +} +#else #include "DD4hep/DD4hepUnits.h" +#endif #include <cmath> // for sqrt and pow #include <math.h> @@ -66,10 +75,10 @@ namespace XmlTools { // setVariable("rad", 1.0); // setVariable("degree", 3.14159265358979323846/180.); // setVariable("deg", 3.14159265358979323846/180.); - setVariable("radian", dd4hep::rad ); - setVariable("rad", dd4hep::rad ); - setVariable("degree", dd4hep::deg ); - setVariable("deg", dd4hep::deg ); + setVariable("radian", dd4hep::radian ); + setVariable("rad", dd4hep::radian ); + setVariable("degree", dd4hep::degree ); + setVariable("deg", dd4hep::degree ); // S E T S T A N D A R D F U N C T I O N S diff --git a/DDCore/src/XML/DocumentHandler.cpp b/DDCore/src/XML/DocumentHandler.cpp index a0aa7afce07994e9e804163cdbdaa973ceff2eea..f363b559c1a5fd7f25e322e8ccd48230cdbc6248 100644 --- a/DDCore/src/XML/DocumentHandler.cpp +++ b/DDCore/src/XML/DocumentHandler.cpp @@ -12,13 +12,12 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" +#include "XML/Printout.h" #include "XML/UriReader.h" #include "XML/DocumentHandler.h" -#include "TUri.h" -#include "TUrl.h" // C/C++ include files +#include <memory> #include <iostream> #include <stdexcept> #include <sys/types.h> @@ -221,6 +220,19 @@ namespace DD4hep { } } +#ifdef DD4HEP_NONE +/// System ID of a given XML entity +string DocumentHandler::system_path(Handle_t base, const string& fn) { + string path = system_path(base); + string dir = ::dirname((char*)path.c_str()); + return dir+fn; +} +#else + +#include "TUri.h" +#include "TUrl.h" +#endif + /// System ID of a given XML entity string DocumentHandler::system_path(Handle_t base, const string& fn) { string path, dir = system_path(base); @@ -304,7 +316,7 @@ Document DocumentHandler::load(const string& fname, UriReader* reader) const { } catch(...) { } - dd4hep_ptr < XercesDOMParser > parser(make_parser(reader)); + unique_ptr < XercesDOMParser > parser(make_parser(reader)); try { if ( !path.empty() ) { parser->parse(path.c_str()); @@ -336,7 +348,7 @@ Document DocumentHandler::load(const string& fname, UriReader* reader) const { /// Parse a standalong XML string into a document. Document DocumentHandler::parse(const char* bytes, size_t length, const char* sys_id, UriReader* rdr) const { - dd4hep_ptr < XercesDOMParser > parser(make_parser(rdr)); + unique_ptr < XercesDOMParser > parser(make_parser(rdr)); MemBufInputSource src((const XMLByte*)bytes, length, sys_id, false); parser->parse(src); DOMDocument* doc = parser->adoptDocument(); @@ -465,9 +477,9 @@ Document DocumentHandler::load(const std::string& fname, UriReader* reader) cons doc->ErrorDesc()); printout(FATAL,"DocumentHandler","+++ Document:%s Location Line:%d Column:%d", doc->Value(), doc->ErrorRow(), doc->ErrorCol()); - except("DD4hep: file:%s error:%s",clean.c_str(),doc->ErrorDesc()); + except("DD4hep:XML","++ file:%s error:%s",clean.c_str(),doc->ErrorDesc()); } - except("DD4hep: Unknown error (TinyXML) while parsing:%s",fname.c_str()); + except("DD4hep:XML","++ Unknown error (TinyXML) while parsing:%s",fname.c_str()); } } catch(exception& e) { diff --git a/DDCore/src/XML/Layering.cpp b/DDCore/src/XML/Layering.cpp index 9619ebbb209fbab5ec8cfe814d4dbfd0ad697a3d..67bea2dc4d5caa1d84e630e38143903e036e119f 100644 --- a/DDCore/src/XML/Layering.cpp +++ b/DDCore/src/XML/Layering.cpp @@ -12,6 +12,7 @@ //========================================================================== // Framework include files +#include "DD4hep/Primitives.h" #include "XML/XMLDetector.h" #include "XML/Layering.h" #include "XML/XMLTags.h" diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp index 84fac499c337f2f8ef52cf76cdee1f458c489eb0..057a9f82905e1a2d3cec12ee191e38870e2e82b5 100644 --- a/DDCore/src/XML/XMLElements.cpp +++ b/DDCore/src/XML/XMLElements.cpp @@ -12,7 +12,7 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" +#include "XML/Printout.h" #include "XML/Evaluator.h" #include "XML/XMLElements.h" #include "XML/XMLTags.h" @@ -181,6 +181,7 @@ namespace { } } +/// Convert XML char to std::string string DD4hep::XML::_toString(const XmlChar *toTranscode) { char *buff = XmlString::transcode(toTranscode); string tmp(buff == 0 ? "" : buff); @@ -261,6 +262,15 @@ string DD4hep::XML::_toString(double v, const char* fmt) { return __to_string(v, fmt); } +/// Convert Strng_t to std::string +string DD4hep::XML::_toString(const Strng_t& s) { + return _toString(Tag_t(s)); +} +/// Convert Tag_t to std::string +string DD4hep::XML::_toString(const Tag_t& s) { + return s.str(); +} + /// Format pointer to string with arbitrary format string DD4hep::XML::_ptrToString(const void* v, const char* fmt) { return __to_string(v, fmt); @@ -360,6 +370,16 @@ void DD4hep::XML::_toDictionary(const XmlChar* name, const XmlChar* value) { eval.setVariable(n.c_str(), result); } +/// Helper function to populate the evaluator dictionary \ingroup DD4HEP_XML +void DD4hep::XML::_toDictionary(const XmlChar* name, const Strng_t& s) { + return _toDictionary(name, s.ptr()); +} + +/// Helper function to populate the evaluator dictionary \ingroup DD4HEP_XML +void DD4hep::XML::_toDictionary(const XmlChar* name, const Tag_t& t) { + return _toDictionary(name, t.ptr()); +} + template <typename T> void DD4hep::XML::_toDictionary(const XmlChar* name, T value) { Strng_t item = _toString(value); @@ -370,6 +390,8 @@ void DD4hep::XML::_toDictionary(const XmlChar* name, T value) { #ifndef DD4HEP_USE_TINYXML template void DD4hep::XML::_toDictionary(const XmlChar* name, const char* value); #endif +template void DD4hep::XML::_toDictionary(const XmlChar* name, const Tag_t& value); +template void DD4hep::XML::_toDictionary(const XmlChar* name, const Strng_t& value); template void DD4hep::XML::_toDictionary(const XmlChar* name, const string& value); template void DD4hep::XML::_toDictionary(const XmlChar* name, unsigned long value); template void DD4hep::XML::_toDictionary(const XmlChar* name, unsigned int value); diff --git a/DDCore/src/parsers/ParserStandardList_Mapint_bool.cpp b/DDCore/src/parsers/ParserStandardList_Mapint_bool.cpp index 09812a49be43e9b387d875d0da7874299cf051e8..bdf1712ea128a4ba84110f98df67f74fd814e885 100644 --- a/DDCore/src/parsers/ParserStandardList_Mapint_bool.cpp +++ b/DDCore/src/parsers/ParserStandardList_Mapint_bool.cpp @@ -1,4 +1,3 @@ -// $Id: ParserStandardList_Mapint_bool.cpp 2166 2016-03-17 16:37:06Z /DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=sailer/CN=683529/CN=Andre Sailer $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/parsers/ParserStandardList_Mapint_double.cpp b/DDCore/src/parsers/ParserStandardList_Mapint_double.cpp index 1fe4237749a2ec124d811bf1aa563fc80d3cf679..d00e0a973973527f62fc4989b746f2858a151c9c 100644 --- a/DDCore/src/parsers/ParserStandardList_Mapint_double.cpp +++ b/DDCore/src/parsers/ParserStandardList_Mapint_double.cpp @@ -1,4 +1,3 @@ -// $Id: ParserStandardList_Mapint_double.cpp 2166 2016-03-17 16:37:06Z /DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=sailer/CN=683529/CN=Andre Sailer $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/parsers/ParsersFactory.h b/DDCore/src/parsers/ParsersFactory.h index c1d6b07dac2828524b7e5c6877889bacdbfcb2d5..5080ff88f407c116f9308df13aa04bbd802af2da 100644 --- a/DDCore/src/parsers/ParsersFactory.h +++ b/DDCore/src/parsers/ParsersFactory.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -60,5 +59,12 @@ namespace DD4hep { }/* Parsers */ } /* DD4hep */ //============================================================================= + +// ============================================================================ +#define PARSERS_DEF_FOR_SINGLE(Type) \ + int DD4hep::Parsers::parse(Type& result, const std::string& input) \ + { return DD4hep::Parsers::parse_(result, input); } +// ============================================================================ + #endif // DD4HEPPROPERTYPARSERS_PARSERSGENERATOR_H diff --git a/DDCore/src/parsers/ParsersStandardListCommon.h b/DDCore/src/parsers/ParsersStandardListCommon.h index 2231bd8e5910d57f545b1cdb6f2ad353cf203fba..76470c0fea8321d72f3722e474efb64c6a1c7c9a 100644 --- a/DDCore/src/parsers/ParsersStandardListCommon.h +++ b/DDCore/src/parsers/ParsersStandardListCommon.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/parsers/ParsersStandardMisc5.cpp b/DDCore/src/parsers/ParsersStandardMisc5.cpp index cd9874f2332b880350a58211860402801ee2fa8d..ab449db2bd6751421bdf216c2e8bd1f13842b8e8 100644 --- a/DDCore/src/parsers/ParsersStandardMisc5.cpp +++ b/DDCore/src/parsers/ParsersStandardMisc5.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/parsers/ParsersStandardMiscCommon.h b/DDCore/src/parsers/ParsersStandardMiscCommon.h index 757abf0d9c1621f0e2e0fe08bae26ccb1eea393b..b8fa5392c1d141db024d41d7976a4202040913f8 100644 --- a/DDCore/src/parsers/ParsersStandardMiscCommon.h +++ b/DDCore/src/parsers/ParsersStandardMiscCommon.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/parsers/ParsersStandardSingle.cpp b/DDCore/src/parsers/ParsersStandardSingle.cpp index e6046c4e3e4668b270b9867b0373c98e7ae91ad9..4722847f81612e9746aff14639a08a41b61c2f9a 100644 --- a/DDCore/src/parsers/ParsersStandardSingle.cpp +++ b/DDCore/src/parsers/ParsersStandardSingle.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -10,11 +9,6 @@ // //========================================================================== #include "ParsersFactory.h" -// ============================================================================ -#define PARSERS_DEF_FOR_SINGLE(Type) \ - int DD4hep::Parsers::parse(Type& result, const std::string& input) \ - { return DD4hep::Parsers::parse_(result, input); } -// ============================================================================ PARSERS_DEF_FOR_SINGLE(bool) PARSERS_DEF_FOR_SINGLE(int) diff --git a/DDDB/src/CondDB2DDDB.cpp b/DDDB/src/CondDB2DDDB.cpp index d980df0522bb25fd8acb459f53bdc42cd9aad346..319b08cbaf43cd576a4d0f418d11c71a84d3b965 100644 --- a/DDDB/src/CondDB2DDDB.cpp +++ b/DDDB/src/CondDB2DDDB.cpp @@ -620,7 +620,12 @@ namespace DD4hep { xml_coll_t(element,_LBU(paramVector)).for_each(conv); pair<ConditionParams::iterator,bool> res = d.params.insert(block); if ( !res.second ) { - printout(INFO,"ParamVector","++ Failed to insert condition parameter:%s",name.c_str()); + printout(INFO,"Condition","++ Failed to insert condition parameter:%s",name.c_str()); + } + if ( d.size() > 1 ) { + printout(WARNING,"Condition", + "++ Found ALIGNMENT condition block with MULTIPLE entries [%d]: %s", + int(d.size()), name.c_str()); } ++num_align; } @@ -644,10 +649,10 @@ namespace DD4hep { printout(INFO,"ParamMap","++ Condition:%s -> %s",path.c_str(),nam.c_str()); } if ( d.classID == AbstractMap::ALIGNMENT ) { continue; } - if ( tag == "param" ) { ++num_param; continue; } - if ( tag == "paramVector" ) { ++num_vector; continue; } - if ( tag == "map" ) { ++num_map; continue; } - if ( tag == "specific" ) { ++num_spec; continue; } + if ( tag == "param" ) { ++num_param; continue; } + if ( tag == "paramVector" ) { ++num_vector; continue; } + if ( tag == "map" ) { ++num_map; continue; } + if ( tag == "specific" ) { ++num_spec; continue; } printout(INFO,"Condition","++ Unknown conditions tag:%s obj:%s id:%s", tag.c_str(), path.c_str(), id.c_str()); } diff --git a/doc/externalize/ExpressionEvaluator.cpp b/doc/externalize/ExpressionEvaluator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..460f2b8c972c42c820f071004e9405cf51c981e7 --- /dev/null +++ b/doc/externalize/ExpressionEvaluator.cpp @@ -0,0 +1,42 @@ +//========================================================================== +// 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 +// +//========================================================================== + +#include "XML/Evaluator.h" + +namespace { + void _init(XmlTools::Evaluator& e) { + // Initialize numerical expressions parser with the standard math functions + // and the system of units used by Gaudi (Geant4) + e.setStdMath(); + } + void _g4Units(XmlTools::Evaluator& e) { + // =================================================================================== + // Geant4 units + // Geant4: kilogram = joule*s*s/(m*m) 1/e_SI * 1e-6 * 1e9 1e9 / 1e3 / 1e3 = 1. / 1.60217733e-25 + e.setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10, 1.0, 1.0, 1.0); + } +} + +namespace DD4hep { + XmlTools::Evaluator& evaluator() { + static XmlTools::Evaluator* e = 0; + if ( !e ) { + static XmlTools::Evaluator ev; + _init(ev); + _g4Units(ev); + e = &ev; + } + return *e; + } +} + diff --git a/doc/externalize/PluginManager.cpp b/doc/externalize/PluginManager.cpp index cbb014f9cb3ea7e6e2ec4442317f4a3fbdd2b350..f5f3480d7d5b647bdddc935103121076d7ae3358 100644 --- a/doc/externalize/PluginManager.cpp +++ b/doc/externalize/PluginManager.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -11,8 +10,6 @@ // Author : M.Frank // //========================================================================== -#pragma push_macro("Gaudi") -#undef Gaudi #include <string> #include <sstream> #include <map> @@ -20,12 +17,23 @@ #include <typeinfo> #include <utility> +#define Gaudi DD4hep_Flavor + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wkeyword-macro" +#endif + #define private public // This define will give us a version of the gaudi plugin manager, // which will NOT clash with Gaudi! It of course has a correspondance in the // compiler options of the GaudiPluginService package. -//#define Gaudi DD4hep_Flavor #include "Gaudi/PluginService.h" +#undef private + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif extern "C" { /// Access debug level @@ -47,5 +55,4 @@ extern "C" { Gaudi::PluginService::Details::Registry::instance().add(id,stub,sig,ret,id); } } -#pragma pop_macro("Gaudi") diff --git a/doc/externalize/Printout.cpp b/doc/externalize/Printout.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8205beb90a829c62235781fadb26b068a67b9da9 --- /dev/null +++ b/doc/externalize/Printout.cpp @@ -0,0 +1,96 @@ +//========================================================================== +// 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 "XML/Printout.h" +#include <stdexcept> + +// Disable some diagnostics for ROOT dictionaries +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wvarargs" +#endif + +using namespace std; + +namespace { + string print_fmt = "%-16s %5s %s"; + DD4hep::PrintLevel print_lvl = DD4hep::INFO; + const char* print_level(DD4hep::PrintLevel lvl) { + switch(lvl) { + case DD4hep::NOLOG: return "NOLOG"; + case DD4hep::VERBOSE: return "VERB "; + case DD4hep::DEBUG: return "DEBUG"; + case DD4hep::INFO: return "INFO "; + case DD4hep::WARNING: return "WARN "; + case DD4hep::ERROR: return "ERROR"; + case DD4hep::FATAL: return "FATAL"; + case DD4hep::ALWAYS: return " "; + default: + if ( lvl> DD4hep::ALWAYS ) + return print_level(DD4hep::ALWAYS); + return print_level(DD4hep::NOLOG); + } + } +} + +/** Calls the display action + * \arg severity [int,read-only] Display severity flag + * \arg src [string,read-only] Information source (component, etc.) + * \arg fmt [string,read-only] Format string for ellipsis args + * \return Status code indicating success or failure + */ +int DD4hep::printout(PrintLevel severity, const char* src, const char* fmt, ...) { + if (severity >= print_lvl) { + va_list args; + va_start(args, fmt); + printout(severity, src, fmt, args); + va_end(args); + } + return 1; +} + +/** Calls the display action + * \arg severity [int,read-only] Display severity flag + * \arg src [string,read-only] Information source (component, etc.) + * \arg fmt [string,read-only] Format string for ellipsis args + * \return Status code indicating success or failure + */ +int DD4hep::printout(PrintLevel severity, const string& src, const char* fmt, ...) { + if (severity >= print_lvl) { + va_list args; + va_start(args, fmt); + printout(severity, src.c_str(), fmt, args); + va_end(args); + } + return 1; +} + +/** Calls the display action with ERROR and throws an std::runtime_error exception + * \arg src [string,read-only] Information source (component, etc.) + * \arg fmt [string,read-only] Format string for ellipsis args + * \return Status code indicating success or failure + */ +int DD4hep::except(const char* src, const char* fmt, ...) { + char str[4096]; + va_list args; + va_start(args, fmt); + size_t len1 = ::snprintf(str, sizeof(str), "%s: ", src); + size_t len2 = ::vsnprintf(str + len1, sizeof(str) - len1, fmt, args); + if ( len2 > sizeof(str) - len1 ) { + len2 = sizeof(str) - len1 - 1; + str[sizeof(str)-1] = 0; + } + printout(FATAL,src,fmt,args); + va_end(args); + throw runtime_error(str); +} diff --git a/doc/externalize/Printout.h b/doc/externalize/Printout.h new file mode 100644 index 0000000000000000000000000000000000000000..9939ae122a4c9599763cf557b76816db7efbebf8 --- /dev/null +++ b/doc/externalize/Printout.h @@ -0,0 +1,58 @@ +//========================================================================== +// 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 +// +//========================================================================== +#ifndef DD4HEP_DDCORE_XML_PRINTOUT_H +#define DD4HEP_DDCORE_XML_PRINTOUT_H + +// C/C++ include files +#include <cstdarg> +#include <string> + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + enum PrintLevel { + NOLOG = 0, + VERBOSE = 1, + DEBUG = 2, + INFO = 3, + WARNING = 4, + ERROR = 5, + FATAL = 6, + ALWAYS = 7 + }; + /// Calls the display action with a given severity level + /** + * @arg severity [int,read-only] Display severity flag (see enum) + * @arg src [string,read-only] Information source (component, etc.) + * @arg fmt [string,read-only] Format string for ellipsis args + * @return Status code indicating success or failure + */ + int printout(PrintLevel severity, const char* src, const char* fmt, ...); + + /// Calls the display action with a given severity level + /** + * @arg severity [int,read-only] Display severity flag (see enum) + * @arg src [string,read-only] Information source (component, etc.) + * @arg fmt [string,read-only] Format string for ellipsis args + * @return Status code indicating success or failure + */ + int printout(PrintLevel severity, const std::string& src, const char* fmt, ...); + /// Calls the display action with ERROR and throws an std::runtime_error exception + /** + * @arg src [string,read-only] Information source (component, etc.) + * @arg fmt [string,read-only] Format string for ellipsis args + * @return Status code indicating success or failure + */ + int except(const char* src, const char* fmt, ...); +} + +#endif /* DD4HEP_DDCORE_XML_PRINTOUT_H */ diff --git a/doc/externalize/README.txt b/doc/externalize/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..7cf9d454d4a254559e2b17428b74a92ce6452670 --- /dev/null +++ b/doc/externalize/README.txt @@ -0,0 +1,17 @@ + +DD4hep externalizations +======================= + +From time to time is is useful to import some pieces of other frameworks in new projects. +DD4hep has currently the following components, which can be used also standalone outside: + +- The XML parsing framework including the expression evaluator. +- The property mechanism uing the boost::spirit parsers. + +The two scripts internally show which files are required to be imported in other +projects. + + +For details, and in the event of problems, please contact me. + +Markus Frank diff --git a/doc/externalize/externalize_properties.sh b/doc/externalize/externalize_properties.sh new file mode 100755 index 0000000000000000000000000000000000000000..9c48e0c1b182c099011300d5eaa6b8d1a20a17b4 --- /dev/null +++ b/doc/externalize/externalize_properties.sh @@ -0,0 +1,46 @@ +#!/bin/bash +#========================================================================== +# 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. +# +#========================================================================== +# +copy_files() { + target=${1}; + cd DDCore/include/DD4hep + echo "+++ Copy header files from `pwd` to: ${target}/DD4hep ...."; + scp BasicGrammar.h ComponentProperties.h Exceptions.h Plugins.h Printout.h \ + BasicGrammar_inl.h ComponentProperties_inl.h Parsers.h Primitives.h ToStream.h \ + ${target}/DD4hep; + cd -; + cd DDCore/src; + echo "+++ Copy source files from `pwd` to: ${target}/src/DD4hep ...."; + scp -r parsers BasicGrammar.cpp ComponentProperties.cpp Plugins.cpp Printout.cpp \ + BasicGrammarTypes.cpp Exceptions.cpp Primitives.cpp ToStream.cpp \ + ${target}/src/DD4hep/; + cd -; + scp doc/externalize/PluginManager.cpp ${target}/src/DD4hep/; +} + +TARGET=${1}; +if test "" = "${TARGET}"; then + cat <<EOF + Usage: bash ${0} <scp-target-directory> + e.g. ${USER}/cmtuser/Online_vxry/Online/Dataflow + This script extracts the DD4hep property mechanism so that + it can be used without DD4hep. + + Note: to use the properties and the parsers, you also MUST + externalize the Evaluator. + +EOF + exit 1; +fi; + +echo "+++ Copy property files to target location: ${TARGET}"; +copy_files ${TARGET}; diff --git a/doc/externalize/externalize_xml.sh b/doc/externalize/externalize_xml.sh new file mode 100755 index 0000000000000000000000000000000000000000..9a6c6957c7e6080042672ba80cbcf187f084026c --- /dev/null +++ b/doc/externalize/externalize_xml.sh @@ -0,0 +1,50 @@ +#!/bin/bash +#========================================================================== +# 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. +# +#========================================================================== +# +# +copy_files() { + target=${1}; + cd DDCore/include/XML + echo "+++ Copy header files from `pwd` to: ${target}/XML ...."; + scp config.h DocumentHandler.h tinyxml.h UriReader.h XMLChildValue.h \ + XMLDimension.h XMLElements.h Evaluator.h tinystr.h UnicodeValues.h \ + XMLDimension.inl XMLTags.h XML.h ${target}/XML/; + cd -; + cd DDCore/src/XML; + echo "+++ Copy source files from `pwd` to: ${target}/src ...."; + scp DocumentHandler.cpp tinyxmlerror_inl.h tinyxml_inl.h tinyxmlparser_inl.h \ + UriReader.cpp XMLChildValue.cpp XMLDimension.cpp \ + XMLElements.cpp XMLTags.cpp ${target}/src/; + cd -; + cd DDCore/src/Evaluator; + echo "+++ Copy source files from `pwd` to: ${target}/Evaluator ...."; + scp Evaluator.cpp hash_map.src setStdMath.cpp setSystemOfUnits.cpp stack.src string.src \ + ${target}/Evaluator/; + cd -; + scp doc/externalize/Printout.h ${target}/XML/; + scp doc/externalize/Printout.cpp ${target}/src/; + scp doc/externalize/ExpressionEvaluator.cpp ${target}/src/; +} + +TARGET=${1}; +if test "" = "${TARGET}"; then + cat <<EOF + Usage: bash ${0} <scp-target-directory> + e.g. ${USER}/cmtuser/Online_vxry/Online/Dataflow + This script extracts the DD4hep XML interface so that + it can be used without DD4hep. +EOF + exit 1; +fi; + +echo "+++ Copy property files to target location: ${TARGET}"; +copy_files ${TARGET};