diff --git a/DDCond/include/DDCond/ConditionsPool.h b/DDCond/include/DDCond/ConditionsPool.h index 9752abe853e9497e0a00e32140bc1ebdac6a21fd..e42e0dd2472e0cf630112230a2d6d031119d0d1d 100644 --- a/DDCond/include/DDCond/ConditionsPool.h +++ b/DDCond/include/DDCond/ConditionsPool.h @@ -147,7 +147,10 @@ namespace dd4hep { enum { PRINT_NONE = 0, PRINT_INSERT = 1<<0, - PRINT_CLEAR = 1<<1 + PRINT_CLEAR = 1<<1, + PRINT_LOAD = 1<<2, + PRINT_COMPUTE= 1<<3, + PRINT_LAST }; /// Processing flags (printout etc.) unsigned int flags = 0; diff --git a/DDCond/src/ConditionsSlice.cpp b/DDCond/src/ConditionsSlice.cpp index 8f0aa1175800d2e6e8eeff807cc6e8a5f196d246..fdbf5d36fcd875ddd16f2c709281a264554e8281 100644 --- a/DDCond/src/ConditionsSlice.cpp +++ b/DDCond/src/ConditionsSlice.cpp @@ -170,13 +170,6 @@ namespace { content.insertKey(c->hash,c->address); return true; } -#if 0 - // test load info access - const ConditionsContent::Conditions& cc=content.conditions(); - auto i = cc.find(c->hash); - string* address = (*i).second->data<string>(); - if ( address ) {} -#endif return true; } /// Return number of conditions selected diff --git a/DDCond/src/Type1/Manager_Type1.cpp b/DDCond/src/Type1/Manager_Type1.cpp index 0b57ba0a8d05bdbc7293184ea8204fb9381004b4..6c4929c24a30a05d1c53c7d785143a6b8c43275e 100644 --- a/DDCond/src/Type1/Manager_Type1.cpp +++ b/DDCond/src/Type1/Manager_Type1.cpp @@ -94,13 +94,13 @@ namespace { template <typename T> void __check_values__(const Manager_Type1* o, Condition::key_type key, const IOV* iov) { if ( !iov ) { - except("ConditionsManager","+++ Invalid IOV to access condition: %16llX. [Null-reference]",key); + except("ConditionsMgr","+++ Invalid IOV to access condition: %16llX. [Null-reference]",key); } const IOVType* typ = check_iov_type<T>(o,iov); if ( !typ ) { // Severe: We have an unknown IOV type. This is not allowed, // because we do not known hot to handle it..... - except("ConditionsManager","+++ Invalid IOV type [%d] to access condition: %16llX.", + except("ConditionsMgr","+++ Invalid IOV type [%d] to access condition: %16llX.", iov->type, key); } } @@ -163,7 +163,7 @@ void Manager_Type1::initialize() { m_loader.reset(createPlugin<ConditionsDataLoader>(typ,m_detDesc,2,argv_loader)); m_updatePool.reset(createPlugin<UpdatePool>(m_updateType,m_detDesc,2,argv_pool)); if ( !m_updatePool.get() ) { - except("ConditionsManager","+++ The update pool of type %s cannot be created. [%s]", + except("ConditionsMgr","+++ The update pool of type %s cannot be created. [%s]", m_updateType.c_str(),Errors::noSys().c_str()); } Ref_t ref(m_updatePool.get()); @@ -182,7 +182,7 @@ pair<bool, const IOVType*> Manager_Type1::registerIOVType(size_t iov_index, cons return make_pair(false,&typ); } else if ( typ.type != 0 && eq_type && !eq_name ) { - except("ConditionsManager","Cannot register IOV %s. Type %d already in use!", + except("ConditionsMgr","Cannot register IOV %s. Type %d already in use!", iov_name.c_str(), iov_index); } typ.name = iov_name; @@ -190,7 +190,7 @@ pair<bool, const IOVType*> Manager_Type1::registerIOVType(size_t iov_index, cons m_rawPool[typ.type] = new ConditionsIOVPool(&typ); return make_pair(true,&typ); } - except("ConditionsManager","Cannot register IOV section %d of type %d. Value out of bounds: [%d,%d]", + except("ConditionsMgr","Cannot register IOV section %d of type %d. Value out of bounds: [%d,%d]", iov_name.c_str(), iov_index, 0, int(m_iovTypes.size())); return make_pair(false,(IOVType*)0); } @@ -201,7 +201,7 @@ const IOVType* Manager_Type1::iovType (size_t iov_index) const { const IOVType& typ = m_iovTypes[iov_index]; if ( typ.type == iov_index ) return &typ; } - except("ConditionsManager","Request to access an unregistered IOV type: %d.", iov_index); + except("ConditionsMgr","Request to access an unregistered IOV type: %d.", iov_index); return 0; } @@ -209,7 +209,7 @@ const IOVType* Manager_Type1::iovType (size_t iov_index) const { const IOVType* Manager_Type1::iovType (const string& iov_name) const { for( const auto& i : m_iovTypes ) if ( i.name == iov_name ) return &i; - except("ConditionsManager","Request to access an unregistered IOV type: %s.", iov_name.c_str()); + except("ConditionsMgr","Request to access an unregistered IOV type: %s.", iov_name.c_str()); return 0; } @@ -231,7 +231,7 @@ ConditionsPool* Manager_Type1::registerIOV(const IOVType& typ, IOV::Key key) { const void* argv_pool[] = {this, iov, 0}; shared_ptr<ConditionsPool> cond_pool(createPlugin<ConditionsPool>(m_poolType,m_detDesc,2,argv_pool)); pool->elements.insert(make_pair(key,cond_pool)); - printout(INFO,"ConditionsManager","Created IOV Pool for:%s",iov->str().c_str()); + printout(INFO,"ConditionsMgr","Created IOV Pool for:%s",iov->str().c_str()); return cond_pool.get(); } @@ -247,14 +247,14 @@ bool Manager_Type1::registerUnlocked(ConditionsPool& pool, Condition cond) { cond->setFlag(Condition::ACTIVE); pool.insert(cond); #if 0 - printout(INFO,"ConditionsManager","Register condition %016lX %s [%s] IOV:%s", + printout(INFO,"ConditionsMgr","Register condition %016lX %s [%s] IOV:%s", cond->hash, cond.name(), cond->address.c_str(), pool.iov->str().c_str()); #endif __callListeners(m_onRegister, &ConditionsListener::onRegisterCondition, cond); return true; } else if ( !cond.isValid() ) - except("ConditionsManager","+++ Invalid condition objects may not be registered. [%s]", + except("ConditionsMgr","+++ Invalid condition objects may not be registered. [%s]", Errors::invalidArg().c_str()); return false; } @@ -297,7 +297,7 @@ void Manager_Type1::__get_checked_pool(const IOV& req_iov, return; } // Invalid IOV type. Throw exception - except("ConditionsManager","+++ Unknown IOV type requested to enable conditions. [%s]", + except("ConditionsMgr","+++ Unknown IOV type requested to enable conditions. [%s]", Errors::invalidArg().c_str()); } @@ -411,20 +411,20 @@ Manager_Type1::get(Condition::key_type key, const IOV& iov) return conditions[0]; } else if ( conditions.empty() ) { - except("ConditionsManager","+++ Condition %16llX for the requested IOV %s do not exist.", + except("ConditionsMgr","+++ Condition %16llX for the requested IOV %s do not exist.", key, iov.str().c_str()); } else if ( conditions.size() > 1 ) { RC::const_iterator start = conditions.begin(); Condition first = *start; - printout(ERROR,"ConditionsManager","+++ Condition %s [%16llX] is ambiguous for IOV %s:", + printout(ERROR,"ConditionsMgr","+++ Condition %s [%16llX] is ambiguous for IOV %s:", first.name(), key, iov.str().c_str()); for(RC::const_iterator i=start; i!=conditions.end(); ++i) { Condition c = *i; - printout(ERROR,"ConditionsManager","+++ %s [%s] = %s", + printout(ERROR,"ConditionsMgr","+++ %s [%s] = %s", c.name(), c->iov->str().c_str(), c->value.c_str()); } - except("ConditionsManager","+++ Condition %s [%16llX] is ambiguous for IOV %s:", + except("ConditionsMgr","+++ Condition %s [%16llX] is ambiguous for IOV %s:", first.name(), key, iov.str().c_str()); } return Condition(); @@ -444,14 +444,14 @@ Manager_Type1::getRange(Condition::key_type key, const IOV& iov) dd4hep_lock_t locked_load(m_updateLock); m_loader->load_range(key, iov, conditions); if ( conditions.empty() ) { - except("ConditionsManager","+++ Conditions %16llX for IOV %s do not exist.", + except("ConditionsMgr","+++ Conditions %16llX for IOV %s do not exist.", key, iov.str().c_str()); } conditions.clear(); } rc = select_range(key, iov, conditions); if ( !rc ) { - except("ConditionsManager","+++ Conditions %16llX for IOV %s do not exist.", + except("ConditionsMgr","+++ Conditions %16llX for IOV %s do not exist.", key, iov.str().c_str()); } return conditions; @@ -478,7 +478,7 @@ std::unique_ptr<UserPool> Manager_Type1::createUserPool(const IOVType* iovT) co return pool; } // Invalid IOV type. Throw exception - except("ConditionsManager","+++ Unknown IOV type requested to enable conditions. [%s]", + except("ConditionsMgr","+++ Unknown IOV type requested to enable conditions. [%s]", Errors::invalidArg().c_str()); return std::unique_ptr<UserPool>(); } diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index 06d07017d8c19bd8aefa858a8f0a64d3f626565a..0a35e377b058b7ba4916e97c46ec9c9267da9283 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -488,7 +488,7 @@ ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, begin(cond_missing), COMP()); long num_cond_miss = last_cond-begin(cond_missing); cond_missing.resize(num_cond_miss); - printout(num_cond_miss==0 ? DEBUG : INFO,"UserPool", + printout((flags&PRINT_LOAD) ? INFO : DEBUG,"UserPool", "%ld conditions out of %ld conditions are MISSING.", num_cond_miss, slice_cond.size()); CalcMissing::iterator last_calc = set_difference(begin(slice_calc), end(slice_calc), @@ -496,15 +496,10 @@ ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, begin(calc_missing), COMP()); long num_calc_miss = last_calc-begin(calc_missing); calc_missing.resize(num_calc_miss); - printout(num_calc_miss==0 ? DEBUG : INFO,"UserPool", + printout((flags&PRINT_COMPUTE) ? INFO : DEBUG,"UserPool", "%ld derived conditions out of %ld conditions are MISSING.", num_calc_miss, slice_calc.size()); -#if 0 - auto iter = begin(calc_missing); - for(auto i=0; i<num_calc_miss; ++i, ++iter) { - printout(INFO,""," Missing derived: %016llX -> %s",(*iter).first,(*iter).second->target.name.c_str()); - } -#endif + result.loaded = 0; result.computed = 0; result.selected = m_conditions.size(); @@ -536,7 +531,7 @@ ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, result.missing = num_load_miss+num_calc_miss; if ( cond_missing.size() != loaded.size() ) { // ERROR! - printout(WARNING,"UserPool","Could not load %ld out of %ld conditions. " + printout(ERROR,"UserPool","Could not load %ld out of %ld conditions. " "[Unhandled error]",cond_missing.size(), slice_cond.size()); } } @@ -608,7 +603,7 @@ ConditionsMappedUserPool<MAPPING>::load(const IOV& required, begin(m_conditions), end(m_conditions), begin(cond_missing), COMP()); long num_cond_miss = last_cond-begin(cond_missing); - printout(num_cond_miss==0 ? DEBUG : INFO,"UserPool", + printout((flags&PRINT_LOAD) ? INFO : DEBUG,"UserPool", "Found %ld missing conditions out of %ld conditions.", num_cond_miss, slice_cond.size()); result.loaded = 0; @@ -677,7 +672,7 @@ ConditionsMappedUserPool<MAPPING>::compute(const IOV& required, begin(m_conditions), end(m_conditions), begin(calc_missing), COMP()); long num_calc_miss = last_calc-begin(calc_missing); - printout(num_calc_miss==0 ? DEBUG : INFO,"UserPool", + printout((flags&PRINT_COMPUTE) ? INFO : DEBUG,"UserPool", "Found %ld missing derived conditions out of %ld conditions.", num_calc_miss, m_conditions.size()); diff --git a/DDCore/include/DD4hep/AlignmentsCalculator.h b/DDCore/include/DD4hep/AlignmentsCalculator.h index c7741ac943a1a6d50bb36ada3645fae4f4a9ee82..3c7b4f7e26b1b96cf794c6914ee5a0d1c872e3a7 100644 --- a/DDCore/include/DD4hep/AlignmentsCalculator.h +++ b/DDCore/include/DD4hep/AlignmentsCalculator.h @@ -46,6 +46,7 @@ namespace dd4hep { public: size_t computed = 0; size_t missing = 0; + size_t multiply = 0; Result() = default; /// Copy constructor Result(const Result& result) = default; @@ -138,6 +139,7 @@ namespace dd4hep { /// Add results inline AlignmentsCalculator::Result& AlignmentsCalculator::Result::operator +=(const Result& result) { + multiply += result.multiply; computed += result.computed; missing += result.missing; return *this; @@ -145,6 +147,7 @@ namespace dd4hep { /// Subtract results inline AlignmentsCalculator::Result& AlignmentsCalculator::Result::operator -=(const Result& result) { + multiply -= result.multiply; computed -= result.computed; missing -= result.missing; return *this; diff --git a/DDCore/include/DD4hep/detail/BasicGrammar_inl.h b/DDCore/include/DD4hep/detail/BasicGrammar_inl.h index 47d8d834723850196a2d0d11073042a3b68b9d92..559840732d9f5e8c2d0ee17acb124d58bc068753 100644 --- a/DDCore/include/DD4hep/detail/BasicGrammar_inl.h +++ b/DDCore/include/DD4hep/detail/BasicGrammar_inl.h @@ -38,8 +38,8 @@ #endif -namespace dd4hep { XmlTools::Evaluator& g4Evaluator(); } -namespace { static XmlTools::Evaluator& s__eval(dd4hep::g4Evaluator()); } +namespace dd4hep { dd4hep::tools::Evaluator& g4Evaluator(); } +namespace { static dd4hep::tools::Evaluator& s__eval(dd4hep::g4Evaluator()); } // C/C++ include files #include <string> @@ -238,7 +238,7 @@ namespace dd4hep { while (val[0] == ' ') val.erase(0, 1); double result = s__eval.evaluate(val.c_str()); - if (s__eval.status() != XmlTools::Evaluator::OK) { + if (s__eval.status() != tools::Evaluator::OK) { return 0; } *ptr = (T)result; diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index 009cbdc55ae85f2e956ba4e10e00abf057d4d4bc..c1cbdab3da0f4e13253e23b8226fc475157d0755 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -105,11 +105,11 @@ std_pair = std.pair #--------------------------------------------------------------------------- core = dd4hep cond = dd4hep.cond +tools = dd4hep.tools align = dd4hep.align detail = dd4hep.detail -import_root('XmlTools') -import_namespace_item('XmlTools','Evaluator') +import_namespace_item('tools','Evaluator') #--------------------------------------------------------------------------- import_namespace_item('core','NamedObject') import_namespace_item('core','run_interpreter') diff --git a/DDCore/src/AlignmentsCalculator.cpp b/DDCore/src/AlignmentsCalculator.cpp index 9100920093d8eb973f70f64f7859d814caa9f36d..b7d4a8d6e344cae4a34e12809235d4784ea47d4c 100644 --- a/DDCore/src/AlignmentsCalculator.cpp +++ b/DDCore/src/AlignmentsCalculator.cpp @@ -134,10 +134,11 @@ Result Calculator::compute(Context& context, Entry& e) const { printout(DEBUG,"ComputeAlignment", "============================== Compute transformation of %s",det.path().c_str()); - e.valid = 1; - e.cond = cond.ptr(); - align.delta = *delta; + e.valid = 1; + e.cond = cond.ptr(); + align.delta = *delta; delta->computeMatrix(transform_for_delta); + result.multiply += 2; DetElement parent_det = det.parent(); AlignmentCondition parent_cond = context.mapping.get(parent_det, Keys::alignmentKey); @@ -157,6 +158,7 @@ Result Calculator::compute(Context& context, Entry& e) const { align.worldTrafo = parent_transform * align.detectorTrafo; align.trToWorld = detail::matrix::_transform(&align.worldTrafo); ++result.computed; + result.multiply += 3; // Update mapping if the condition is freshly created if ( !c.isValid() ) { e.created = 1; diff --git a/DDCore/src/Handle.cpp b/DDCore/src/Handle.cpp index 4f23bbfd2ae6d27f3b6067ecfb35a9700dba48b4..b3769d26719c6448bb447b983a0015c90d719e54 100644 --- a/DDCore/src/Handle.cpp +++ b/DDCore/src/Handle.cpp @@ -26,17 +26,27 @@ #endif namespace dd4hep { - XmlTools::Evaluator& evaluator(); + dd4hep::tools::Evaluator& evaluator(); } namespace { - XmlTools::Evaluator& eval(dd4hep::evaluator()); + dd4hep::tools::Evaluator& eval(dd4hep::evaluator()); } using namespace std; using namespace dd4hep; using namespace dd4hep::detail; +namespace { + void check_evaluation(const string& value, int status) { + if (status != tools::Evaluator::OK) { + stringstream str; + eval.print_error(str); + throw runtime_error("dd4hep: "+str.str()+" : value="+value+" [Evaluation error]"); + } + } +} + namespace dd4hep { short _toShort(const string& value) { @@ -47,11 +57,7 @@ namespace dd4hep { while (s[0] == ' ') s.erase(0, 1); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { - cerr << value << ": "; - eval.print_error(); - throw runtime_error("dd4hep: Severe error during expression evaluation of " + value); - } + check_evaluation(value, eval.status()); return (short) result; } @@ -63,11 +69,7 @@ namespace dd4hep { while (s[0] == ' ') s.erase(0, 1); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { - cerr << value << ": "; - eval.print_error(); - throw runtime_error("dd4hep: Severe error during expression evaluation of " + value); - } + check_evaluation(value, eval.status()); return (int) result; } @@ -79,11 +81,7 @@ namespace dd4hep { while (s[0] == ' ') s.erase(0, 1); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { - cerr << value << ": "; - eval.print_error(); - throw runtime_error("dd4hep: Severe error during expression evaluation of " + value); - } + check_evaluation(value, eval.status()); return (long) result; } @@ -94,22 +92,14 @@ namespace dd4hep { /// String conversions: string to float value float _toFloat(const string& value) { double result = eval.evaluate(value.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { - cerr << value << ": "; - eval.print_error(); - throw runtime_error("dd4hep: Severe error during expression evaluation of " + value); - } + check_evaluation(value, eval.status()); return (float) result; } /// String conversions: string to double value double _toDouble(const string& value) { double result = eval.evaluate(value.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { - cerr << value << ": "; - eval.print_error(); - throw runtime_error("dd4hep: Severe error during expression evaluation of " + value); - } + check_evaluation(value, eval.status()); return result; } @@ -254,11 +244,7 @@ namespace dd4hep { while (v[0] == ' ') v.erase(0, 1); double result = eval.evaluate(v.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { - cerr << value << ": "; - eval.print_error(); - throw runtime_error("dd4hep: Severe error during expression evaluation " + name + "=" + value); - } + check_evaluation(v, eval.status()); eval.setVariable(n.c_str(), result); } } diff --git a/DDCore/src/JSON/Elements.cpp b/DDCore/src/JSON/Elements.cpp index ec56f3ac8180499a95b113aba21e7a8d7ed067e3..94259b0aa5df1260dadfe450b30fa0628b79fe5c 100644 --- a/DDCore/src/JSON/Elements.cpp +++ b/DDCore/src/JSON/Elements.cpp @@ -28,11 +28,11 @@ static const size_t INVALID_NODE = ~0U; // Forward declarations namespace dd4hep { - XmlTools::Evaluator& evaluator(); + dd4hep::tools::Evaluator& evaluator(); } // Static storage namespace { - XmlTools::Evaluator& eval(dd4hep::evaluator()); + dd4hep::tools::Evaluator& eval(dd4hep::evaluator()); string _checkEnviron(const string& env) { string r = getEnviron(env); return r.empty() ? env : r; @@ -150,7 +150,7 @@ long dd4hep::json::_toLong(const char* value) { while (s[0] == ' ') s.erase(0, 1); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -169,7 +169,7 @@ int dd4hep::json::_toInt(const char* value) { while (s[0] == ' ') s.erase(0, 1); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -192,7 +192,7 @@ float dd4hep::json::_toFloat(const char* value) { string s = _toString(value); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -206,7 +206,7 @@ double dd4hep::json::_toDouble(const char* value) { if (value) { string s = _toString(value); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -224,7 +224,7 @@ void dd4hep::json::_toDictionary(const char* name, const char* value) { while (v[0] == ' ') v.erase(0, 1); double result = eval.evaluate(v.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << v << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + v); @@ -258,7 +258,7 @@ string dd4hep::json::getEnviron(const string& env) { else { string v = env.substr(0,id2+1); const char* ret = eval.getEnviron(v.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << env << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during environment lookup of " + env); diff --git a/DDCore/src/RootDictionary.h b/DDCore/src/RootDictionary.h index de986c74e6845299b98e653537821e804a2d5948..c983a6e0b1ce30e73d2bdeae304916c713930824 100644 --- a/DDCore/src/RootDictionary.h +++ b/DDCore/src/RootDictionary.h @@ -52,8 +52,8 @@ namespace dd4hep { TRint app(name.c_str(), &a.first, a.second); app.Run(); } - XmlTools::Evaluator& evaluator(); - XmlTools::Evaluator& g4Evaluator(); + tools::Evaluator& evaluator(); + tools::Evaluator& g4Evaluator(); } namespace dd4hep { namespace Parsers { @@ -71,12 +71,13 @@ namespace dd4hep { namespace Parsers { using namespace std; -#pragma link C++ namespace XmlTools; -#pragma link C++ class XmlTools::Evaluator; +#pragma link C++ namespace dd4hep; + +#pragma link C++ namespace dd4hep::tools; +#pragma link C++ class dd4hep::tools::Evaluator; #pragma link C++ function dd4hep::evaluator; #pragma link C++ function dd4hep::g4Evaluator; -#pragma link C++ namespace dd4hep; #pragma link C++ namespace dd4hep::detail; #pragma link C++ namespace dd4hep::cond; #pragma link C++ namespace dd4hep::align; diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp index 5a356494a328105a77b9ca65e3b0688f0710255f..73496dd90392d50c2cf2d56472f6bb1ab526b158 100644 --- a/DDCore/src/XML/XMLElements.cpp +++ b/DDCore/src/XML/XMLElements.cpp @@ -29,13 +29,13 @@ static const size_t INVALID_NODE = ~0U; // Forward declarations namespace dd4hep { - XmlTools::Evaluator& evaluator(); + dd4hep::tools::Evaluator& evaluator(); } // Static storage namespace { bool s_resolve_environment = true; - XmlTools::Evaluator& eval(dd4hep::evaluator()); + dd4hep::tools::Evaluator& eval(dd4hep::evaluator()); string _checkEnviron(const string& env) { if ( s_resolve_environment ) { string r = getEnviron(env); @@ -293,7 +293,7 @@ long dd4hep::xml::_toLong(const XmlChar* value) { while (s[0] == ' ') s.erase(0, 1); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -312,7 +312,7 @@ int dd4hep::xml::_toInt(const XmlChar* value) { while (s[0] == ' ') s.erase(0, 1); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -335,7 +335,7 @@ float dd4hep::xml::_toFloat(const XmlChar* value) { string s = _toString(value); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -349,7 +349,7 @@ double dd4hep::xml::_toDouble(const XmlChar* value) { if (value) { string s = _toString(value); double result = eval.evaluate(s.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << s << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); @@ -367,7 +367,7 @@ void dd4hep::xml::_toDictionary(const XmlChar* name, const XmlChar* value) { while (v[0] == ' ') v.erase(0, 1); double result = eval.evaluate(v.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << v << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during expression evaluation of " + v); @@ -417,7 +417,7 @@ string dd4hep::xml::getEnviron(const string& env) { else { string v = env.substr(id1,id2-id1+1); const char* ret = eval.getEnviron(v.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { cerr << env << ": "; eval.print_error(); throw runtime_error("dd4hep: Severe error during environment lookup of " + env); diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index b9303ecd09748bb37d049afea21673b1c89beb61..2bfce5d79526dd7d0c969681f4749e6773a550f4 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -1075,7 +1075,8 @@ template <> void Converter<TrackingVolume>::operator()(xml_h element) const { if ( !mother.isValid() ) except("TrackingVolume", - "+++ Cannot identify the mother of the tracking volume: '%s'",path.c_str()); + "++ FAILED Cannot identify the mother of the tracking volume: '%s'", + path.c_str()); if ( pos ) position = Position(pos.x(), pos.y(), pos.z()); if ( rot ) @@ -1087,6 +1088,10 @@ template <> void Converter<TrackingVolume>::operator()(xml_h element) const { Volume par(mother.placement().volume()); PlacedVolume pv; + if ( !par.isValid() ) + except("TrackingVolume", + "++ FAILED Cannot identify the volume of parent: '%s'", + mother.path().c_str()); if ( !trackers.materialStr().empty() ) mat = description.material(trackers.materialStr()); if ( trackers.visStr().empty() ) @@ -1107,7 +1112,7 @@ template <> void Converter<TrackingVolume>::operator()(xml_h element) const { pv = par.placeVolume(vol); if ( !pv.isValid() ) { except("TrackingVolume", - "++ Failed to place the tracking volume inside the mother '%s'",path.c_str()); + "++ FAILED to place the tracking volume inside the mother '%s'",path.c_str()); } } diff --git a/DDParsers/include/Evaluator/Evaluator.h b/DDParsers/include/Evaluator/Evaluator.h index 10f9fdb938fb0c68ac155a0f3b067cd06d105e55..c1f155a6ba9e721ea33f0fb52534de2ac2feb227 100644 --- a/DDParsers/include/Evaluator/Evaluator.h +++ b/DDParsers/include/Evaluator/Evaluator.h @@ -14,263 +14,274 @@ #ifndef XMLTOOLS_EVALUATOR_H #define XMLTOOLS_EVALUATOR_H -/// Namespace containing XML tools. -namespace XmlTools { +#include <ostream> - /// Evaluator of arithmetic expressions with an extendable dictionary. - /** - * Taken from CLHEP 1.9.2.1 - * - * Example: - * @code - * #include "XmlTools/Evaluator.h" - * XmlTools::Evaluator eval; - * eval.setStdMath(); - * double res = eval.evaluate("sin(30*degree)"); - * if (eval.status() != XmlTools::Evaluator::OK) eval.print_error(); - * @endcode - * - * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> - * @ingroup evaluator - */ - class Evaluator { - public: +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + /// Namespace containing XML tools. + namespace tools { + + /// Evaluator of arithmetic expressions with an extendable dictionary. /** - * List of possible statuses. - * Status of the last operation can be obtained with status(). - * In case if status() is an ERROR the corresponding error message - * can be printed with print_error(). + * Taken from CLHEP 1.9.2.1 * - * @see status - * @see error_position - * @see print_error + * Example: + * @code + * #include "XmlTools/Evaluator.h" + * XmlTools::Evaluator eval; + * eval.setStdMath(); + * double res = eval.evaluate("sin(30*degree)"); + * if (eval.status() != XmlTools::Evaluator::OK) eval.print_error(); + * @endcode + * + * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> + * @ingroup evaluator */ - enum { - OK, /**< Everything OK */ - WARNING_EXISTING_VARIABLE, /**< Redefinition of existing variable */ - WARNING_EXISTING_FUNCTION, /**< Redefinition of existing function */ - WARNING_BLANK_STRING, /**< Empty input string */ - ERROR_NOT_A_NAME, /**< Not allowed sysmbol in the name of variable or function */ - ERROR_SYNTAX_ERROR, /**< Systax error */ - ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired parenthesis */ - ERROR_UNEXPECTED_SYMBOL, /**< Unexpected sysbol */ - ERROR_UNKNOWN_VARIABLE, /**< Non-existing variable */ - ERROR_UNKNOWN_FUNCTION, /**< Non-existing function */ - ERROR_EMPTY_PARAMETER, /**< Function call has empty parameter */ - ERROR_CALCULATION_ERROR /**< Error during calculation */ - }; + class Evaluator { + public: - /** - * Constructor. - */ - Evaluator(); + /** + * List of possible statuses. + * Status of the last operation can be obtained with status(). + * In case if status() is an ERROR the corresponding error message + * can be printed with print_error(). + * + * @see status + * @see error_position + * @see print_error + */ + enum { + OK, /**< Everything OK */ + WARNING_EXISTING_VARIABLE, /**< Redefinition of existing variable */ + WARNING_EXISTING_FUNCTION, /**< Redefinition of existing function */ + WARNING_BLANK_STRING, /**< Empty input string */ + ERROR_NOT_A_NAME, /**< Not allowed sysmbol in the name of variable or function */ + ERROR_SYNTAX_ERROR, /**< Systax error */ + ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired parenthesis */ + ERROR_UNEXPECTED_SYMBOL, /**< Unexpected sysbol */ + ERROR_UNKNOWN_VARIABLE, /**< Non-existing variable */ + ERROR_UNKNOWN_FUNCTION, /**< Non-existing function */ + ERROR_EMPTY_PARAMETER, /**< Function call has empty parameter */ + ERROR_CALCULATION_ERROR /**< Error during calculation */ + }; - /** - * Destructor. - */ - ~Evaluator(); + /** + * Constructor. + */ + Evaluator(); - /** - * Evaluates the arithmetic expression given as character string. - * The expression may consist of numbers, variables and functions - * separated by arithmetic (+, - , /, *, ^, **) and logical - * operators (==, !=, >, >=, <, <=, &&, ||). - * - * @param expression input expression. - * @return result of the evaluation. - * @see status - * @see error_position - * @see print_error - */ - double evaluate(const char * expression); + /** + * Destructor. + */ + ~Evaluator(); - /** - * Returns status of the last operation with the evaluator. - */ - int status() const; + /** + * Evaluates the arithmetic expression given as character string. + * The expression may consist of numbers, variables and functions + * separated by arithmetic (+, - , /, *, ^, **) and logical + * operators (==, !=, >, >=, <, <=, &&, ||). + * + * @param expression input expression. + * @return result of the evaluation. + * @see status + * @see error_position + * @see print_error + */ + double evaluate(const char * expression); - /** - * Returns position in the input string where the problem occured. - */ - int error_position() const; + /** + * Returns status of the last operation with the evaluator. + */ + int status() const; - /** - * Prints error message if status() is an ERROR. - */ - void print_error() const; + /** + * Returns position in the input string where the problem occured. + */ + int error_position() const; - /** - * Adds to the dictionary a string constant - * - * @param name name of the variable. - * @param value value assigned to the variable. - */ - void setEnviron(const char* name, const char* value); - /** - * Lookup the dictionary for a string constant - * - * @param name name of the variable. - */ - const char* getEnviron(const char* name); - /** - * Adds to the dictionary a variable with given value. - * If a variable with such a name already exist in the dictionary, - * then status will be set to WARNING_EXISTING_VARIABLE. - * - * @param name name of the variable. - * @param value value assigned to the variable. - */ - void setVariable(const char * name, double value); + /** + * Prints error message if status() is an ERROR. + */ + void print_error(std::ostream& os) const; - /** - * Adds to the dictionary a variable with an arithmetic expression - * assigned to it. - * If a variable with such a name already exist in the dictionary, - * then status will be set to WARNING_EXISTING_VARIABLE. - * - * @param name name of the variable. - * @param expression arithmetic expression. - */ - void setVariable(const char * name, const char * expression); + /** + * Prints error message if status() is an ERROR using std::cerr. + */ + void print_error() const; - /** - * Adds to the dictionary a function without parameters. - * If such a function already exist in the dictionary, - * then status will be set to WARNING_EXISTING_FUNCTION. - * - * @param name function name. - * @param fun pointer to the real function in the user code. - */ - void setFunction(const char * name, double (*fun)()); + /** + * Adds to the dictionary a string constant + * + * @param name name of the variable. + * @param value value assigned to the variable. + */ + void setEnviron(const char* name, const char* value); + /** + * Lookup the dictionary for a string constant + * + * @param name name of the variable. + */ + const char* getEnviron(const char* name); + /** + * Adds to the dictionary a variable with given value. + * If a variable with such a name already exist in the dictionary, + * then status will be set to WARNING_EXISTING_VARIABLE. + * + * @param name name of the variable. + * @param value value assigned to the variable. + */ + void setVariable(const char * name, double value); - /** - * Adds to the dictionary a function with one parameter. - * If such a function already exist in the dictionary, - * then status will be set to WARNING_EXISTING_FUNCTION. - * - * @param name function name. - * @param fun pointer to the real function in the user code. - */ - void setFunction(const char * name, double (*fun)(double)); + /** + * Adds to the dictionary a variable with an arithmetic expression + * assigned to it. + * If a variable with such a name already exist in the dictionary, + * then status will be set to WARNING_EXISTING_VARIABLE. + * + * @param name name of the variable. + * @param expression arithmetic expression. + */ + void setVariable(const char * name, const char * expression); - /** - * Adds to the dictionary a function with two parameters. - * If such a function already exist in the dictionary, - * then status will be set to WARNING_EXISTING_FUNCTION. - * - * @param name function name. - * @param fun pointer to the real function in the user code. - */ - void setFunction(const char * name, double (*fun)(double, double)); + /** + * Adds to the dictionary a function without parameters. + * If such a function already exist in the dictionary, + * then status will be set to WARNING_EXISTING_FUNCTION. + * + * @param name function name. + * @param fun pointer to the real function in the user code. + */ + void setFunction(const char * name, double (*fun)()); - /** - * Adds to the dictionary a function with three parameters. - * If such a function already exist in the dictionary, - * then status will be set to WARNING_EXISTING_FUNCTION. - * - * @param name function name. - * @param fun pointer to the real function in the user code. - */ - void setFunction(const char * name, double (*fun)(double, double, double)); + /** + * Adds to the dictionary a function with one parameter. + * If such a function already exist in the dictionary, + * then status will be set to WARNING_EXISTING_FUNCTION. + * + * @param name function name. + * @param fun pointer to the real function in the user code. + */ + void setFunction(const char * name, double (*fun)(double)); - /** - * Adds to the dictionary a function with four parameters. - * If such a function already exist in the dictionary, - * then status will be set to WARNING_EXISTING_FUNCTION. - * - * @param name function name. - * @param fun pointer to the real function in the user code. - */ - void setFunction(const char * name, double (*fun)(double, double, double, double)); + /** + * Adds to the dictionary a function with two parameters. + * If such a function already exist in the dictionary, + * then status will be set to WARNING_EXISTING_FUNCTION. + * + * @param name function name. + * @param fun pointer to the real function in the user code. + */ + void setFunction(const char * name, double (*fun)(double, double)); - /** - * Adds to the dictionary a function with five parameters. - * If such a function already exist in the dictionary, - * then status will be set to WARNING_EXISTING_FUNCTION. - * - * @param name function name. - * @param fun pointer to the real function in the user code. - */ - void setFunction(const char * name, double (*fun)(double, double, double, double, double)); + /** + * Adds to the dictionary a function with three parameters. + * If such a function already exist in the dictionary, + * then status will be set to WARNING_EXISTING_FUNCTION. + * + * @param name function name. + * @param fun pointer to the real function in the user code. + */ + void setFunction(const char * name, double (*fun)(double, double, double)); - /** - * Finds the variable in the dictionary. - * - * @param name name of the variable. - * @return true if such a variable exists, false otherwise. - */ - bool findVariable(const char * name) const; + /** + * Adds to the dictionary a function with four parameters. + * If such a function already exist in the dictionary, + * then status will be set to WARNING_EXISTING_FUNCTION. + * + * @param name function name. + * @param fun pointer to the real function in the user code. + */ + void setFunction(const char * name, double (*fun)(double, double, double, double)); - /** - * Finds the function in the dictionary. - * - * @param name name of the function to be unset. - * @param npar number of parameters of the function. - * @return true if such a function exists, false otherwise. - */ - bool findFunction(const char * name, int npar) const; + /** + * Adds to the dictionary a function with five parameters. + * If such a function already exist in the dictionary, + * then status will be set to WARNING_EXISTING_FUNCTION. + * + * @param name function name. + * @param fun pointer to the real function in the user code. + */ + void setFunction(const char * name, double (*fun)(double, double, double, double, double)); - /** - * Removes the variable from the dictionary. - * - * @param name name of the variable. - */ - void removeVariable(const char * name); + /** + * Finds the variable in the dictionary. + * + * @param name name of the variable. + * @return true if such a variable exists, false otherwise. + */ + bool findVariable(const char * name) const; - /** - * Removes the function from the dictionary. - * - * @param name name of the function to be unset. - * @param npar number of parameters of the function. - */ - void removeFunction(const char * name, int npar); + /** + * Finds the function in the dictionary. + * + * @param name name of the function to be unset. + * @param npar number of parameters of the function. + * @return true if such a function exists, false otherwise. + */ + bool findFunction(const char * name, int npar) const; - /** - * Clear all settings. - */ - void clear(); + /** + * Removes the variable from the dictionary. + * + * @param name name of the variable. + */ + void removeVariable(const char * name); - /** - * Sets standard mathematical functions and constants. - */ - void setStdMath(); + /** + * Removes the function from the dictionary. + * + * @param name name of the function to be unset. + * @param npar number of parameters of the function. + */ + void removeFunction(const char * name, int npar); - /** - * Sets system of units. Default is the SI system of units. - * To set the CGS (Centimeter-Gram-Second) system of units - * one should call: - * setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0); - * - * To set system of units accepted in the GEANT4 simulation toolkit - * one should call: - * @code - * setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10, - * 1.0, 1.0, 1.0); - * @endcode - * - * The basic units in GEANT4 are: - * @code - * millimeter (millimeter = 1.) - * nanosecond (nanosecond = 1.) - * Mega electron Volt (MeV = 1.) - * positron charge (eplus = 1.) - * degree Kelvin (kelvin = 1.) - * the amount of substance (mole = 1.) - * luminous intensity (candela = 1.) - * radian (radian = 1.) - * steradian (steradian = 1.) - * @endcode - */ - void setSystemOfUnits(double meter = 1.0, double kilogram = 1.0, double second = 1.0, double ampere = 1.0, double kelvin = - 1.0, double mole = 1.0, double candela = 1.0, double radians = 1.0 ); + /** + * Clear all settings. + */ + void clear(); + + /** + * Sets standard mathematical functions and constants. + */ + void setStdMath(); - private: - void * p; // private data - Evaluator(const Evaluator &); // copy constructor is not allowed - Evaluator & operator=(const Evaluator &); // assignment is not allowed - }; + /** + * Sets system of units. Default is the SI system of units. + * To set the CGS (Centimeter-Gram-Second) system of units + * one should call: + * setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0); + * + * To set system of units accepted in the GEANT4 simulation toolkit + * one should call: + * @code + * setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10, + * 1.0, 1.0, 1.0); + * @endcode + * + * The basic units in GEANT4 are: + * @code + * millimeter (millimeter = 1.) + * nanosecond (nanosecond = 1.) + * Mega electron Volt (MeV = 1.) + * positron charge (eplus = 1.) + * degree Kelvin (kelvin = 1.) + * the amount of substance (mole = 1.) + * luminous intensity (candela = 1.) + * radian (radian = 1.) + * steradian (steradian = 1.) + * @endcode + */ + void setSystemOfUnits(double meter = 1.0, double kilogram = 1.0, double second = 1.0, double ampere = 1.0, double kelvin = + 1.0, double mole = 1.0, double candela = 1.0, double radians = 1.0 ); + + private: + void * p; // private data + Evaluator(const Evaluator &); // copy constructor is not allowed + Evaluator & operator=(const Evaluator &); // assignment is not allowed + }; -} // namespace XmlTools + } // namespace tools +} // namespace dd4hep #endif /* XMLTOOLS_EVALUATOR_H */ diff --git a/DDParsers/src/Evaluator/Evaluator.cpp b/DDParsers/src/Evaluator/Evaluator.cpp index fcc6d8743455f9255b7218a93024460187072851..d43a01d9f5b39ae3019f8c99d3e258b05faa113e 100644 --- a/DDParsers/src/Evaluator/Evaluator.cpp +++ b/DDParsers/src/Evaluator/Evaluator.cpp @@ -8,19 +8,20 @@ #include "stack.src" #include "string.src" #include "hash_map.src" -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include <stdlib.h> // for strtod() +#include <sstream> +#include <cstring> +#include <cctype> +#include <cerrno> +#include <cstdlib> // for strtod() // Disable some diagnostics, which we know, but need to ignore #if defined(__GNUC__) && !defined(__APPLE__) && !defined(__llvm__) /* This is OK: -../DDCore/src/Evaluator/Evaluator.cpp: In function 'int engine(pchar, pchar, double&, char*&, const dic_type&)': -../DDCore/src/Evaluator/Evaluator.cpp:164:23: warning: 'pp[3]' may be used uninitialized in this function [-Wmaybe-uninitialized] - result = (*fcn.f4)(pp[3],pp[2],pp[1],pp[0]); -.... - */ + ../DDCore/src/Evaluator/Evaluator.cpp: In function 'int engine(pchar, pchar, double&, char*&, const dic_type&)': + ../DDCore/src/Evaluator/Evaluator.cpp:164:23: warning: 'pp[3]' may be used uninitialized in this function [-Wmaybe-uninitialized] + result = (*fcn.f4)(pp[3],pp[2],pp[1],pp[0]); + .... +*/ #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif @@ -68,10 +69,10 @@ namespace { } //--------------------------------------------------------------------------- -#define EVAL XmlTools::Evaluator +#define EVAL dd4hep::tools::Evaluator -#define REMOVE_BLANKS \ - for(pointer=name;;pointer++) if (!isspace(*pointer)) break; \ +#define REMOVE_BLANKS \ + for(pointer=name;;pointer++) if (!isspace(*pointer)) break; \ for(n=strlen(pointer);n>0;n--) if (!isspace(*(pointer+n-1))) break #define SKIP_BLANKS \ @@ -261,9 +262,9 @@ static int operand(pchar begin, pchar end, double & result, par_end = pointer-1; EVAL_STATUS = engine(par_begin, par_end, value, par_end, dictionary); if (EVAL_STATUS == EVAL::WARNING_BLANK_STRING) - { EVAL_EXIT( EVAL::ERROR_EMPTY_PARAMETER, --par_end ); } + { EVAL_EXIT( EVAL::ERROR_EMPTY_PARAMETER, --par_end ); } if (EVAL_STATUS != EVAL::OK) - { EVAL_EXIT( EVAL_STATUS, par_end ); } + { EVAL_EXIT( EVAL_STATUS, par_end ); } par.push(value); par_begin = pointer + 1; } @@ -281,7 +282,7 @@ static int operand(pchar begin, pchar end, double & result, break; case EVAL::WARNING_BLANK_STRING: if (par.size() != 0) - { EVAL_EXIT( EVAL::ERROR_EMPTY_PARAMETER, --par_end ); } + { EVAL_EXIT( EVAL::ERROR_EMPTY_PARAMETER, --par_end ); } break; default: EVAL_EXIT( EVAL_STATUS, par_end ); @@ -589,228 +590,233 @@ static void setItem(const char * prefix, const char * name, } //--------------------------------------------------------------------------- -namespace XmlTools { +using namespace dd4hep::tools; + +//--------------------------------------------------------------------------- +Evaluator::Evaluator() { + Struct * s = new Struct(); + p = (void *) s; + s->theExpression = 0; + s->thePosition = 0; + s->theStatus = OK; + s->theResult = 0.0; +} - //--------------------------------------------------------------------------- - Evaluator::Evaluator() { - Struct * s = new Struct(); - p = (void *) s; +//--------------------------------------------------------------------------- +Evaluator::~Evaluator() { + Struct * s = reinterpret_cast<Struct*>(p); + if (s->theExpression != 0) { + delete[] s->theExpression; s->theExpression = 0; - s->thePosition = 0; - s->theStatus = OK; - s->theResult = 0.0; } + delete reinterpret_cast<Struct*>(p); +} - //--------------------------------------------------------------------------- - Evaluator::~Evaluator() { - Struct * s = reinterpret_cast<Struct*>(p); - if (s->theExpression != 0) { - delete[] s->theExpression; - s->theExpression = 0; - } - delete reinterpret_cast<Struct*>(p); - } +//--------------------------------------------------------------------------- +double Evaluator::evaluate(const char * expression) { + Struct * s = reinterpret_cast<Struct*>(p); + if (s->theExpression != 0) { delete[] s->theExpression; } + s->theExpression = 0; + s->thePosition = 0; + s->theStatus = WARNING_BLANK_STRING; + s->theResult = 0.0; + if (expression != 0) { + s->theExpression = new char[strlen(expression)+1]; + strcpy(s->theExpression, expression); + s->theStatus = engine(s->theExpression, + s->theExpression+strlen(expression)-1, + s->theResult, + s->thePosition, + s->theDictionary); + } + return s->theResult; +} - //--------------------------------------------------------------------------- - double Evaluator::evaluate(const char * expression) { - Struct * s = reinterpret_cast<Struct*>(p); - if (s->theExpression != 0) { delete[] s->theExpression; } - s->theExpression = 0; - s->thePosition = 0; - s->theStatus = WARNING_BLANK_STRING; - s->theResult = 0.0; - if (expression != 0) { - s->theExpression = new char[strlen(expression)+1]; - strcpy(s->theExpression, expression); - s->theStatus = engine(s->theExpression, - s->theExpression+strlen(expression)-1, - s->theResult, - s->thePosition, - s->theDictionary); - } - return s->theResult; - } +//--------------------------------------------------------------------------- +int Evaluator::status() const { + return (reinterpret_cast<Struct*>(p))->theStatus; +} - //--------------------------------------------------------------------------- - int Evaluator::status() const { - return (reinterpret_cast<Struct*>(p))->theStatus; - } +//--------------------------------------------------------------------------- +int Evaluator::error_position() const { + return (reinterpret_cast<Struct*>(p))->thePosition - (reinterpret_cast<Struct*>(p))->theExpression; +} - //--------------------------------------------------------------------------- - int Evaluator::error_position() const { - return (reinterpret_cast<Struct*>(p))->thePosition - (reinterpret_cast<Struct*>(p))->theExpression; - } +//--------------------------------------------------------------------------- +void Evaluator::print_error() const { + std::stringstream str; + print_error(str); + if ( str.str().empty() ) return; + std::cerr << str.str() << std::endl; +} - //--------------------------------------------------------------------------- - void Evaluator::print_error() const { - char prefix[] = "Evaluator : "; - Struct * s = reinterpret_cast<Struct*>(p); - const char* opt = (s->thePosition ? s->thePosition : ""); - switch (s->theStatus) { - case ERROR_NOT_A_NAME: - std::cerr << prefix << "invalid name : " << opt << std::endl; - return; - case ERROR_SYNTAX_ERROR: - std::cerr << prefix << "systax error" << std::endl; - return; - case ERROR_UNPAIRED_PARENTHESIS: - std::cerr << prefix << "unpaired parenthesis" << std::endl; - return; - case ERROR_UNEXPECTED_SYMBOL: - std::cerr << prefix << "unexpected symbol : " << opt << std::endl; - return; - case ERROR_UNKNOWN_VARIABLE: - std::cerr << prefix << "unknown variable : " << opt << std::endl; - return; - case ERROR_UNKNOWN_FUNCTION: - std::cerr << prefix << "unknown function : " << opt << std::endl; - return; - case ERROR_EMPTY_PARAMETER: - std::cerr << prefix << "empty parameter in function call: " << opt << std::endl; - return; - case ERROR_CALCULATION_ERROR: - std::cerr << prefix << "calculation error" << std::endl; - return; - default: - return; - } +//--------------------------------------------------------------------------- +void Evaluator::print_error(std::ostream& os) const { + static char prefix[] = "Evaluator : "; + Struct * s = reinterpret_cast<Struct*>(p); + const char* opt = (s->thePosition ? s->thePosition : ""); + switch (s->theStatus) { + case ERROR_NOT_A_NAME: + os << prefix << "invalid name : " << opt; + return; + case ERROR_SYNTAX_ERROR: + os << prefix << "systax error" ; + return; + case ERROR_UNPAIRED_PARENTHESIS: + os << prefix << "unpaired parenthesis"; + return; + case ERROR_UNEXPECTED_SYMBOL: + os << prefix << "unexpected symbol : " << opt; + return; + case ERROR_UNKNOWN_VARIABLE: + os << prefix << "unknown variable : " << opt; + return; + case ERROR_UNKNOWN_FUNCTION: + os << prefix << "unknown function : " << opt; + return; + case ERROR_EMPTY_PARAMETER: + os << prefix << "empty parameter in function call: " << opt; + return; + case ERROR_CALCULATION_ERROR: + os << prefix << "calculation error"; + return; + default: + return; } +} - //--------------------------------------------------------------------------- - void Evaluator::setEnviron(const char* name, const char* value) { - Struct* s = reinterpret_cast<Struct*>(p); - string prefix = "${"; - string item_name = prefix + string(name) + string("}"); - dic_type::iterator iter = (s->theDictionary).find(item_name); - Item item; - item.what = Item::STRING; - item.expression = value; - item.function = 0; - item.variable = 0; - //std::cout << " ++++++++++++++++++++++++++++ Saving env:" << name << " = " << value << std::endl; - if (iter != (s->theDictionary).end()) { - iter->second = item; - if (item_name == name) { - s->theStatus = EVAL::WARNING_EXISTING_VARIABLE; - }else{ - s->theStatus = EVAL::WARNING_EXISTING_FUNCTION; - } +//--------------------------------------------------------------------------- +void Evaluator::setEnviron(const char* name, const char* value) { + Struct* s = reinterpret_cast<Struct*>(p); + string prefix = "${"; + string item_name = prefix + string(name) + string("}"); + dic_type::iterator iter = (s->theDictionary).find(item_name); + Item item; + item.what = Item::STRING; + item.expression = value; + item.function = 0; + item.variable = 0; + //std::cout << " ++++++++++++++++++++++++++++ Saving env:" << name << " = " << value << std::endl; + if (iter != (s->theDictionary).end()) { + iter->second = item; + if (item_name == name) { + s->theStatus = EVAL::WARNING_EXISTING_VARIABLE; }else{ - (s->theDictionary)[item_name] = item; - s->theStatus = EVAL::OK; + s->theStatus = EVAL::WARNING_EXISTING_FUNCTION; } + }else{ + (s->theDictionary)[item_name] = item; + s->theStatus = EVAL::OK; } - //--------------------------------------------------------------------------- - const char* Evaluator::getEnviron(const char* name) { - Struct* s = reinterpret_cast<Struct*>(p); - string item_name = name; - //std::cout << " ++++++++++++++++++++++++++++ Try to resolve env:" << name << std::endl; - dic_type::iterator iter = (s->theDictionary).find(item_name); - if (iter != (s->theDictionary).end()) { +} +//--------------------------------------------------------------------------- +const char* Evaluator::getEnviron(const char* name) { + Struct* s = reinterpret_cast<Struct*>(p); + string item_name = name; + //std::cout << " ++++++++++++++++++++++++++++ Try to resolve env:" << name << std::endl; + dic_type::iterator iter = (s->theDictionary).find(item_name); + if (iter != (s->theDictionary).end()) { + s->theStatus = EVAL::OK; + return iter->second.expression.c_str(); + } + if ( ::strlen(item_name.c_str()) > 3 ) { + // Need to remove braces from ${xxxx} for call to getenv() + string env_name(name+2,::strlen(name)-3); + const char* env_str = ::getenv(env_name.c_str()); + if ( 0 != env_str ) { s->theStatus = EVAL::OK; - return iter->second.expression.c_str(); + return env_str; } - if ( ::strlen(item_name.c_str()) > 3 ) { - // Need to remove braces from ${xxxx} for call to getenv() - string env_name(name+2,::strlen(name)-3); - const char* env_str = ::getenv(env_name.c_str()); - if ( 0 != env_str ) { - s->theStatus = EVAL::OK; - return env_str; - } - } - s->theStatus = EVAL::ERROR_UNKNOWN_VARIABLE; - return 0; } + s->theStatus = EVAL::ERROR_UNKNOWN_VARIABLE; + return 0; +} - //--------------------------------------------------------------------------- - void Evaluator::setVariable(const char * name, double value) - { setItem("", name, Item(value), reinterpret_cast<Struct*>(p)); } - - void Evaluator::setVariable(const char * name, const char * expression) - { setItem("", name, Item(expression), reinterpret_cast<Struct*>(p)); } +//--------------------------------------------------------------------------- +void Evaluator::setVariable(const char * name, double value) +{ setItem("", name, Item(value), reinterpret_cast<Struct*>(p)); } - //--------------------------------------------------------------------------- - void Evaluator::setFunction(const char * name,double (*fun)()) { - FCN fcn(fun); - setItem("0", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); - } +void Evaluator::setVariable(const char * name, const char * expression) +{ setItem("", name, Item(expression), reinterpret_cast<Struct*>(p)); } - void Evaluator::setFunction(const char * name,double (*fun)(double)) { - FCN fcn(fun); - setItem("1", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); - } +//--------------------------------------------------------------------------- +void Evaluator::setFunction(const char * name,double (*fun)()) { + FCN fcn(fun); + setItem("0", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); +} - void Evaluator::setFunction(const char * name, double (*fun)(double,double)) { - FCN fcn(fun); - setItem("2", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); - } +void Evaluator::setFunction(const char * name,double (*fun)(double)) { + FCN fcn(fun); + setItem("1", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); +} - void Evaluator::setFunction(const char * name, double (*fun)(double,double,double)) { - FCN fcn(fun); - setItem("3", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); - } +void Evaluator::setFunction(const char * name, double (*fun)(double,double)) { + FCN fcn(fun); + setItem("2", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); +} - void Evaluator::setFunction(const char * name, double (*fun)(double,double,double,double)) { - FCN fcn(fun); - setItem("4", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); - } +void Evaluator::setFunction(const char * name, double (*fun)(double,double,double)) { + FCN fcn(fun); + setItem("3", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); +} - void Evaluator::setFunction(const char * name, double (*fun)(double,double,double,double,double)) { - FCN fcn(fun); - setItem("5", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); - } +void Evaluator::setFunction(const char * name, double (*fun)(double,double,double,double)) { + FCN fcn(fun); + setItem("4", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); +} - //--------------------------------------------------------------------------- - bool Evaluator::findVariable(const char * name) const { - if (name == 0 || *name == '\0') return false; - const char * pointer; int n; REMOVE_BLANKS; - if (n == 0) return false; - Struct * s = reinterpret_cast<Struct*>(p); - return - ((s->theDictionary).find(string(pointer,n)) == (s->theDictionary).end()) ? - false : true; - } +void Evaluator::setFunction(const char * name, double (*fun)(double,double,double,double,double)) { + FCN fcn(fun); + setItem("5", name, Item(fcn.ptr), reinterpret_cast<Struct*>(p)); +} - //--------------------------------------------------------------------------- - bool Evaluator::findFunction(const char * name, int npar) const { - if (name == 0 || *name == '\0') return false; - if (npar < 0 || npar > MAX_N_PAR) return false; - const char * pointer; int n; REMOVE_BLANKS; - if (n == 0) return false; - Struct * s = reinterpret_cast<Struct*>(p); - return ((s->theDictionary).find(sss[npar]+string(pointer,n)) == - (s->theDictionary).end()) ? false : true; - } +//--------------------------------------------------------------------------- +bool Evaluator::findVariable(const char * name) const { + if (name == 0 || *name == '\0') return false; + const char * pointer; int n; REMOVE_BLANKS; + if (n == 0) return false; + Struct * s = reinterpret_cast<Struct*>(p); + return + ((s->theDictionary).find(string(pointer,n)) == (s->theDictionary).end()) ? + false : true; +} - //--------------------------------------------------------------------------- - void Evaluator::removeVariable(const char * name) { - if (name == 0 || *name == '\0') return; - const char * pointer; int n; REMOVE_BLANKS; - if (n == 0) return; - Struct * s = reinterpret_cast<Struct*>(p); - (s->theDictionary).erase(string(pointer,n)); - } +//--------------------------------------------------------------------------- +bool Evaluator::findFunction(const char * name, int npar) const { + if (name == 0 || *name == '\0') return false; + if (npar < 0 || npar > MAX_N_PAR) return false; + const char * pointer; int n; REMOVE_BLANKS; + if (n == 0) return false; + Struct * s = reinterpret_cast<Struct*>(p); + return ((s->theDictionary).find(sss[npar]+string(pointer,n)) == + (s->theDictionary).end()) ? false : true; +} - //--------------------------------------------------------------------------- - void Evaluator::removeFunction(const char * name, int npar) { - if (name == 0 || *name == '\0') return; - if (npar < 0 || npar > MAX_N_PAR) return; - const char * pointer; int n; REMOVE_BLANKS; - if (n == 0) return; - Struct * s = reinterpret_cast<Struct*>(p); - (s->theDictionary).erase(sss[npar]+string(pointer,n)); - } +//--------------------------------------------------------------------------- +void Evaluator::removeVariable(const char * name) { + if (name == 0 || *name == '\0') return; + const char * pointer; int n; REMOVE_BLANKS; + if (n == 0) return; + Struct * s = reinterpret_cast<Struct*>(p); + (s->theDictionary).erase(string(pointer,n)); +} - //--------------------------------------------------------------------------- - void Evaluator::clear() { - Struct * s = reinterpret_cast<Struct*>(p); - s->theDictionary.clear(); - s->theExpression = 0; - s->thePosition = 0; - s->theStatus = OK; - s->theResult = 0.0; - } +//--------------------------------------------------------------------------- +void Evaluator::removeFunction(const char * name, int npar) { + if (name == 0 || *name == '\0') return; + if (npar < 0 || npar > MAX_N_PAR) return; + const char * pointer; int n; REMOVE_BLANKS; + if (n == 0) return; + Struct * s = reinterpret_cast<Struct*>(p); + (s->theDictionary).erase(sss[npar]+string(pointer,n)); +} - //--------------------------------------------------------------------------- -} // namespace XmlTools +//--------------------------------------------------------------------------- +void Evaluator::clear() { + Struct * s = reinterpret_cast<Struct*>(p); + s->theDictionary.clear(); + s->theExpression = 0; + s->thePosition = 0; + s->theStatus = OK; + s->theResult = 0.0; +} diff --git a/DDParsers/src/Evaluator/ExpressionEvaluator.cpp b/DDParsers/src/Evaluator/ExpressionEvaluator.cpp index 4da4bd0f011d9d93257b5fa8be9f205306777d98..577daa2db72b058d1a24e56c7b178bf9d552936a 100644 --- a/DDParsers/src/Evaluator/ExpressionEvaluator.cpp +++ b/DDParsers/src/Evaluator/ExpressionEvaluator.cpp @@ -16,17 +16,17 @@ namespace units = dd4hep; namespace { - void _init(XmlTools::Evaluator& e) { + void _init(dd4hep::tools::Evaluator& e) { // Initialize numerical expressions parser with the standard math functions // and the system of units used by Gaudi (Geant4) e.setStdMath(); } - void _cgsUnits(XmlTools::Evaluator& e) { + void _cgsUnits(dd4hep::tools::Evaluator& e) { // =================================================================================== // CGS units e.setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0); } - void _tgeoUnits(XmlTools::Evaluator& e) { + void _tgeoUnits(dd4hep::tools::Evaluator& e) { // =================================================================================== // DDG4 units (TGeo) 1 sec = 10^9 [nsec] // 1 Coulomb = 1/e As @@ -44,7 +44,7 @@ namespace { units::candela, units::rad ); } - void _g4Units(XmlTools::Evaluator& e) { + void _g4Units(dd4hep::tools::Evaluator& e) { // =================================================================================== // Geant4 units // Geant4: kilogram = joule*s*s/(m*m) 1/e_SI * 1e-6 * 1e9 1e9 / 1e3 / 1e3 = 1. / 1.60217733e-25 @@ -52,12 +52,13 @@ namespace { } } +/// Namespace for the AIDA detector description toolkit namespace dd4hep { - XmlTools::Evaluator& evaluator() { - static XmlTools::Evaluator* e = 0; + tools::Evaluator& evaluator() { + static tools::Evaluator* e = 0; if ( !e ) { - static XmlTools::Evaluator ev; + static tools::Evaluator ev; _init(ev); _tgeoUnits(ev); e = &ev; @@ -66,10 +67,10 @@ namespace dd4hep { } /// Access to G4 evaluator. Note: Uses Geant4 units! - XmlTools::Evaluator& g4Evaluator() { - static XmlTools::Evaluator* e = 0; + tools::Evaluator& g4Evaluator() { + static tools::Evaluator* e = 0; if ( !e ) { - static XmlTools::Evaluator ev; + static tools::Evaluator ev; _init(ev); _g4Units(ev); e = &ev; @@ -78,10 +79,10 @@ namespace dd4hep { } /// Access to G4 evaluator. Note: Uses cgs units! - XmlTools::Evaluator& cgsEvaluator() { - static XmlTools::Evaluator* e = 0; + tools::Evaluator& cgsEvaluator() { + static tools::Evaluator* e = 0; if ( !e ) { - static XmlTools::Evaluator ev; + static tools::Evaluator ev; _init(ev); _cgsUnits(ev); e = &ev; diff --git a/DDParsers/src/Evaluator/setStdMath.cpp b/DDParsers/src/Evaluator/setStdMath.cpp index e0c097e1bbb31f30272c234811dd179c5eb408f9..58f3fa4c82dc2b47801847c33ed7b92c22ed5978 100644 --- a/DDParsers/src/Evaluator/setStdMath.cpp +++ b/DDParsers/src/Evaluator/setStdMath.cpp @@ -7,8 +7,8 @@ /// Utility namespace to support TGeo units. namespace dd4hep { //namespace units { - static const double radian = 1. ; - static const double degree = (3.14159265358979323846/180.0)*radian; + static const double radian = 1. ; + static const double degree = (3.14159265358979323846/180.0)*radian; //} } #else @@ -62,67 +62,71 @@ static double eval_isnan(double a) { return std::isnan(a); } static double eval_isinf(double a) { return std::isinf(a); } static double eval_nearbyint(double a) { return ::nearbyint(a); } -namespace XmlTools { +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { - void Evaluator::setStdMath() { + namespace tools { - // S E T S T A N D A R D C O N S T A N T S + void Evaluator::setStdMath() { - setVariable("pi", 3.14159265358979323846); - setVariable("e", 2.7182818284590452354); - setVariable("gamma", 0.577215664901532861); + // S E T S T A N D A R D C O N S T A N T S + setVariable("pi", 3.14159265358979323846); + setVariable("e", 2.7182818284590452354); + setVariable("gamma", 0.577215664901532861); - // setVariable("radian", 1.0); - // setVariable("rad", 1.0); - // setVariable("degree", 3.14159265358979323846/180.); - // setVariable("deg", 3.14159265358979323846/180.); - setVariable("radian", units::radian ); - setVariable("rad", units::radian ); - setVariable("degree", units::degree ); - setVariable("deg", units::degree ); - // S E T S T A N D A R D F U N C T I O N S + // setVariable("radian", 1.0); + // setVariable("rad", 1.0); + // setVariable("degree", 3.14159265358979323846/180.); + // setVariable("deg", 3.14159265358979323846/180.); + setVariable("radian", units::radian ); + setVariable("rad", units::radian ); + setVariable("degree", units::degree ); + setVariable("deg", units::degree ); - setFunction("abs", eval_abs); - setFunction("fabs", eval_fabs); - setFunction("fmod", eval_fmod); - setFunction("min", eval_min); - setFunction("max", eval_max); - setFunction("sqrt", eval_sqrt); - setFunction("cbrt", eval_cbrt); - setFunction("pow", eval_pow); - setFunction("sin", eval_sin); - setFunction("cos", eval_cos); - setFunction("tan", eval_tan); - setFunction("asin", eval_asin); - setFunction("acos", eval_acos); - setFunction("atan", eval_atan); - setFunction("atan2", eval_atan2); - setFunction("sinh", eval_sinh); - setFunction("cosh", eval_cosh); - setFunction("tanh", eval_tanh); - setFunction("exp", eval_exp); - setFunction("exp2", eval_exp2); - setFunction("exp10", eval_exp10); - setFunction("expm1", eval_expm1); - setFunction("log", eval_log); - setFunction("logb", eval_logb); - setFunction("log10", eval_log10); - setFunction("log1p", eval_log1p); - setFunction("hypot", eval_hypot); - setFunction("erf", eval_erf); - setFunction("erfc", eval_erfc); - setFunction("gamma", eval_gamma); - setFunction("double", eval_double); - setFunction("int", eval_int); - setFunction("nint", eval_nint); - setFunction("floor", eval_floor); - setFunction("round", eval_round); - setFunction("ceil", eval_ceil); - setFunction("isnan", eval_isnan); - setFunction("isinf", eval_isinf); - setFunction("nearbyint", eval_nearbyint); - } + // S E T S T A N D A R D F U N C T I O N S -} // namespace XmlTools + setFunction("abs", eval_abs); + setFunction("fabs", eval_fabs); + setFunction("fmod", eval_fmod); + setFunction("min", eval_min); + setFunction("max", eval_max); + setFunction("sqrt", eval_sqrt); + setFunction("cbrt", eval_cbrt); + setFunction("pow", eval_pow); + setFunction("sin", eval_sin); + setFunction("cos", eval_cos); + setFunction("tan", eval_tan); + setFunction("asin", eval_asin); + setFunction("acos", eval_acos); + setFunction("atan", eval_atan); + setFunction("atan2", eval_atan2); + setFunction("sinh", eval_sinh); + setFunction("cosh", eval_cosh); + setFunction("tanh", eval_tanh); + setFunction("exp", eval_exp); + setFunction("exp2", eval_exp2); + setFunction("exp10", eval_exp10); + setFunction("expm1", eval_expm1); + setFunction("log", eval_log); + setFunction("logb", eval_logb); + setFunction("log10", eval_log10); + setFunction("log1p", eval_log1p); + setFunction("hypot", eval_hypot); + setFunction("erf", eval_erf); + setFunction("erfc", eval_erfc); + setFunction("gamma", eval_gamma); + setFunction("double", eval_double); + setFunction("int", eval_int); + setFunction("nint", eval_nint); + setFunction("floor", eval_floor); + setFunction("round", eval_round); + setFunction("ceil", eval_ceil); + setFunction("isnan", eval_isnan); + setFunction("isinf", eval_isinf); + setFunction("nearbyint", eval_nearbyint); + } + + } // namespace tools +} // namespace dd4hep diff --git a/DDParsers/src/Evaluator/setSystemOfUnits.cpp b/DDParsers/src/Evaluator/setSystemOfUnits.cpp index 42b9bd6bcfeb4027e827d2ac99c6269a3b4b9bc4..487849da3ff7316b168bf94b3a22c6deabf884ec 100644 --- a/DDParsers/src/Evaluator/setSystemOfUnits.cpp +++ b/DDParsers/src/Evaluator/setSystemOfUnits.cpp @@ -3,399 +3,403 @@ #include "Evaluator/Evaluator.h" -namespace XmlTools { - - void Evaluator::setSystemOfUnits(double meter, - double kilogram, - double second, - double ampere, - double kelvin, - double mole, - double candela, - double radians) - { - const double kilo_ = 1.e+03; // chilioi (Greek) "thousand" - const double mega_ = 1.e+06; // megas (Greek) "large" - const double giga_ = 1.e+09; // gigas (Greek) "giant" - const double tera_ = 1.e+12; // teras (Greek) "monster" - const double peta_ = 1.e+15; // pente (Greek) "five" - - const double deci_ = 1.e-01; // decimus (Latin) "tenth" - const double centi_ = 1.e-02; // centum (Latin) "hundred" - const double milli_ = 1.e-03; // mille (Latin) "thousand" - const double micro_ = 1.e-06; // micro (Latin) or mikros (Greek) "small" - const double nano_ = 1.e-09; // nanus (Latin) or nanos (Greek) "dwarf" - const double pico_ = 1.e-12; // pico (Spanish) "bit" - - // ====================================================================== - // - // Base (default) SI units - // for the basic measurable quantities (dimensions): - // - // ====================================================================== - - // Length - // metrum (Latin) and metron (Greek) "measure" - const double m = meter; - setVariable("meter", m); - setVariable("metre", m); - setVariable("m", m); - - // Mass - const double kg = kilogram; - setVariable("kilogram", kg); - setVariable("kg", kg); - - // Time - // minuta secundam (Latin) "second small one" - const double s = second; - setVariable("second", s); - setVariable("s", s); - - // Current - // --- honors Andre-Marie Ampere (1775-1836) of France - const double A = ampere; - setVariable("ampere", A); - setVariable("amp", A); - setVariable("A", A); - - // Temperature - // --- honors William Thomson, 1st Baron Lord Kelvin (1824-1907) of England - const double K = kelvin; - setVariable("kelvin", K); - setVariable("K", K); - - // Amount of substance - const double mol = mole; - setVariable("mole", mol); - setVariable("mol", mol); - - // Luminous intensity - const double cd = candela; - setVariable("candela", cd); - setVariable("cd", cd); - - // ====================================================================== - // - // Supplementary SI units having special symbols: - // - // ====================================================================== - - const double pi = 3.14159265358979323846; - // Plane angle - // const double rad = 1.; // Geant4 (rad units) - //const double rad = pi; // Degree units - - const double rad = radians ; - - setVariable("radian", rad); - setVariable("rad", rad); - setVariable("milliradian", milli_ * rad); - setVariable("mrad", milli_ * rad); - - const double deg = rad*pi/180.; - - setVariable("degree", deg); - setVariable("deg", deg); - - // Solid angle - const double sr = 1.; - setVariable("steradian", sr); - setVariable("sr", sr); - - // ====================================================================== - // - // Derived SI units having special symbols: - // - // ====================================================================== - - // Frequency - // --- honors Heinrich Rudolf Hertz (1857-1894) of Germany - const double Hz = 1./s; - setVariable("hertz", Hz); - setVariable("Hz", Hz); - - // Force - // --- honors Sir Isaac Newton (1642-1727) of England - const double N = m * kg / (s*s); - setVariable("newton", N); - setVariable("N", N); - - // Pressure - // --- honors Blaise Pascal (1623-1662) of France - const double Pa = N / (m*m); - setVariable("pascal", Pa); - setVariable("Pa", Pa); - setVariable("hPa", 100.0*Pa); - - const double atm = 101325. * Pa; - setVariable("atmosphere", atm); - setVariable("atm", atm); - - const double bar = 100000*Pa; - setVariable("bar", bar); - - // Energy - // --- honors James Prescott Joule (1818-1889) of England - const double J = N * m; - setVariable("joule", J); - setVariable("J", J); - - // Power - // --- honors James Watt (1736-1819) of Scotland - const double W = J / s; - setVariable("watt", W); - setVariable("W", W); - - // Electric charge - // --- honors Charles-Augustin de Coulomb (1736-1806) of France - const double C = A * s; - setVariable("coulomb", C); - setVariable("C", C); - - // Electric potential - // --- honors Count Alessandro Volta (1745-1827) of Italy - const double V = J / C; - setVariable("volt", V); - setVariable("V", V); - - // Electric resistance - // --- honors Georg Simon Ohm (1787-1854) of Germany - const double ohm = V / A; - setVariable("ohm", ohm); - - // Electric conductance - // --- honors Ernst Werner von Siemens (1816-1892) or - // his brother Sir William (Karl Wilhelm von) Siemens (1823-1883) - // of Germany (England) - const double S = 1./ ohm; - setVariable("siemens", S); - setVariable("S", S); - - // Electric capacitance - // --- honors Michael Faraday (1791-1867) of England - const double F = C / V; - setVariable("farad", F); - setVariable("F", F); - - // Magnetic flux density - // --- honors Nikola Tesla (1856-1943) of Croatia (United States) - const double T = V * s / (m*m); - setVariable("tesla", T); - setVariable("T", T); - - // --- honors Karl Friedrich Gauss (1777-1855) of Germany - const double Gs = 1.e-4*T; - setVariable("gauss", Gs); - setVariable("Gs", Gs); - - // Magnetic flux - // --- honors Wilhelm Eduard Weber (1804-1891) of Germany - const double Wb = V * s; - setVariable("weber", Wb); - setVariable("Wb", Wb); - - // Inductance - // --- honors Joseph Henry (1797-1878) of the United States - const double H = Wb / A; - setVariable("henry", H); - setVariable("H", H); - - // Luminous flux - const double lm = cd * sr; - setVariable("lumen", lm); - setVariable("lm", lm); - - // Illuminace - const double lx = lm / (m*m); - setVariable("lux", lx); - setVariable("lx", lx); - - // Radioactivity - // --- honors Antoine-Henri Becquerel (1852-1908) of France - const double Bq = 1./s; - setVariable("becquerel", Bq); - setVariable("Bq", Bq); - - // --- honors Pierre Curie (1859-1906) of France - // and Marie Sklodowska Curie (1867-1934) of Poland - setVariable("curie", 3.7e+10 * Bq); - setVariable("Ci", 3.7e+10 * Bq); - - // Specific energy - // --- honors Louis Harold Gray, F.R.S. (1905-1965) of England - const double Gy = J / kg; - setVariable("gray", Gy); - setVariable("Gy", Gy); - - // Dose equivalent - const double Sv = J / kg; - setVariable("sievert", Sv); - setVariable("Sv", Sv); - - // ====================================================================== - // - // Selected units: - // - // ====================================================================== - - // Length - - const double mm = milli_ * m; - setVariable("millimeter", mm); - setVariable("mm", mm); - - const double cm = centi_ * m; - setVariable("centimeter", cm); - setVariable("cm", cm); - - setVariable("decimeter", deci_ * m); - - const double km = kilo_ * m; - setVariable("kilometer", km); - setVariable("km", km); - - setVariable("micrometer", micro_ * m); - setVariable("micron", micro_ * m); - setVariable("nanometer", nano_ * m); - - // --- honors Anders Jonas Angstrom (1814-1874) of Sweden - setVariable("angstrom", 1.e-10 * m); - - // --- honors Enrico Fermi (1901-1954) of Italy - setVariable("fermi", 1.e-15 * m); - - // Length^2 - - setVariable("m2", m*m); - setVariable("mm2", mm*mm); - setVariable("cm2", cm*cm); - setVariable("km2", km*km); - - const double barn = 1.e-28 * m*m; - setVariable("barn", barn); - setVariable("millibarn", milli_ * barn); - setVariable("mbarn", milli_ * barn); - setVariable("microbarn", micro_ * barn); - setVariable("nanobarn", nano_ * barn); - setVariable("picobarn", pico_ * barn); - - // LengthL^3 - - setVariable("m3", m*m*m); - setVariable("mm3", mm*mm*mm); - setVariable("cm3", cm*cm*cm); - setVariable("cc", cm*cm*cm); - setVariable("km3", km*km*km); - - const double L = 1.e-3*m*m*m; - setVariable("liter", L); - setVariable("litre", L); - setVariable("L", L); - setVariable("centiliter", centi_ * L); - setVariable("cL", centi_ * L); - setVariable("milliliter", milli_ * L); - setVariable("mL", milli_ * L); - - // Length^-1 - - const double dpt = 1./m; - setVariable("diopter", dpt); - setVariable("dioptre", dpt); - setVariable("dpt", dpt); - - // Mass - - const double g = 0.001*kg; - setVariable("gram", g); - setVariable("g", g); - setVariable("milligram", milli_ * g); - setVariable("mg", milli_ * g); - - // Time - - setVariable("millisecond", milli_ * s); - setVariable("ms", milli_ * s); - setVariable("microsecond", micro_ * s); - setVariable("nanosecond", nano_ * s); - setVariable("ns", nano_ * s); - setVariable("picosecond", pico_ * s); - - // Current - - setVariable("milliampere", milli_ * A); - setVariable("mA", milli_ * A); - setVariable("microampere", micro_ * A); - setVariable("nanoampere", nano_ * A); - - // Frequency - - setVariable("kilohertz", kilo_ * Hz); - setVariable("kHz", kilo_ * Hz); - setVariable("megahertz", mega_ * Hz); - setVariable("MHz", mega_ * Hz); - - // Force - setVariable("kilonewton", kilo_ * N); - setVariable("kN", kilo_ * N); - - // Pressure - setVariable("kilobar", kilo_ * bar); - setVariable("kbar", kilo_ * bar); - setVariable("millibar", milli_ * bar); - setVariable("mbar", milli_ * bar); - - // Energy - setVariable("kilojoule", kilo_ * J); - setVariable("kJ", kilo_ * J); - setVariable("megajoule", mega_ * J); - setVariable("MJ", mega_ * J); - setVariable("gigajoule", giga_ * J); - setVariable("GJ", giga_ * J); - - const double e_SI = 1.60217733e-19; // positron charge in coulomb - const double ePlus = e_SI * C; // positron charge - const double eV = ePlus * V; - setVariable("electronvolt", eV); - setVariable("eV", eV); - setVariable("kiloelectronvolt", kilo_ * eV); - setVariable("keV", kilo_ * eV); - setVariable("megaelectronvolt", mega_ * eV); - setVariable("MeV", mega_ * eV); - setVariable("gigaelectronvolt", giga_ * eV); - setVariable("GeV", giga_ * eV); - setVariable("teraelectronvolt", tera_ * eV); - setVariable("TeV", tera_ * eV); - setVariable("petaelectronvolt", peta_ * eV); - setVariable("PeV", peta_ * eV); - - // Power - setVariable("kilowatt", kilo_ * W); - setVariable("kW", kilo_ * W); - setVariable("megawatt", mega_ * W); - setVariable("MW", mega_ * W); - setVariable("gigawatt", giga_ * W); - setVariable("GW", giga_ * W); - - // Electric potential - setVariable("kilovolt", kilo_ * V); - setVariable("kV", kilo_ * V); - setVariable("megavolt", mega_ * V); - setVariable("MV", mega_ * V); - - // Electric capacitance - setVariable("millifarad", milli_ * F); - setVariable("mF", milli_ * F); - setVariable("microfarad", micro_ * F); - setVariable("uF", micro_ * F); - setVariable("nanofarad", nano_ * F); - setVariable("nF", nano_ * F); - setVariable("picofarad", pico_ * F); - setVariable("pF", pico_ * F); - - // Magnetic flux density - setVariable("kilogauss", kilo_ * Gs); - setVariable("kGs", kilo_ * Gs); - } - -} // namespace XmlTools +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + namespace tools { + + void Evaluator::setSystemOfUnits(double meter, + double kilogram, + double second, + double ampere, + double kelvin, + double mole, + double candela, + double radians) + { + const double kilo_ = 1.e+03; // chilioi (Greek) "thousand" + const double mega_ = 1.e+06; // megas (Greek) "large" + const double giga_ = 1.e+09; // gigas (Greek) "giant" + const double tera_ = 1.e+12; // teras (Greek) "monster" + const double peta_ = 1.e+15; // pente (Greek) "five" + + const double deci_ = 1.e-01; // decimus (Latin) "tenth" + const double centi_ = 1.e-02; // centum (Latin) "hundred" + const double milli_ = 1.e-03; // mille (Latin) "thousand" + const double micro_ = 1.e-06; // micro (Latin) or mikros (Greek) "small" + const double nano_ = 1.e-09; // nanus (Latin) or nanos (Greek) "dwarf" + const double pico_ = 1.e-12; // pico (Spanish) "bit" + + // ====================================================================== + // + // Base (default) SI units + // for the basic measurable quantities (dimensions): + // + // ====================================================================== + + // Length + // metrum (Latin) and metron (Greek) "measure" + const double m = meter; + setVariable("meter", m); + setVariable("metre", m); + setVariable("m", m); + + // Mass + const double kg = kilogram; + setVariable("kilogram", kg); + setVariable("kg", kg); + + // Time + // minuta secundam (Latin) "second small one" + const double s = second; + setVariable("second", s); + setVariable("s", s); + + // Current + // --- honors Andre-Marie Ampere (1775-1836) of France + const double A = ampere; + setVariable("ampere", A); + setVariable("amp", A); + setVariable("A", A); + + // Temperature + // --- honors William Thomson, 1st Baron Lord Kelvin (1824-1907) of England + const double K = kelvin; + setVariable("kelvin", K); + setVariable("K", K); + + // Amount of substance + const double mol = mole; + setVariable("mole", mol); + setVariable("mol", mol); + + // Luminous intensity + const double cd = candela; + setVariable("candela", cd); + setVariable("cd", cd); + + // ====================================================================== + // + // Supplementary SI units having special symbols: + // + // ====================================================================== + + const double pi = 3.14159265358979323846; + // Plane angle + // const double rad = 1.; // Geant4 (rad units) + //const double rad = pi; // Degree units + + const double rad = radians ; + + setVariable("radian", rad); + setVariable("rad", rad); + setVariable("milliradian", milli_ * rad); + setVariable("mrad", milli_ * rad); + + const double deg = rad*pi/180.; + + setVariable("degree", deg); + setVariable("deg", deg); + + // Solid angle + const double sr = 1.; + setVariable("steradian", sr); + setVariable("sr", sr); + + // ====================================================================== + // + // Derived SI units having special symbols: + // + // ====================================================================== + + // Frequency + // --- honors Heinrich Rudolf Hertz (1857-1894) of Germany + const double Hz = 1./s; + setVariable("hertz", Hz); + setVariable("Hz", Hz); + + // Force + // --- honors Sir Isaac Newton (1642-1727) of England + const double N = m * kg / (s*s); + setVariable("newton", N); + setVariable("N", N); + + // Pressure + // --- honors Blaise Pascal (1623-1662) of France + const double Pa = N / (m*m); + setVariable("pascal", Pa); + setVariable("Pa", Pa); + setVariable("hPa", 100.0*Pa); + + const double atm = 101325. * Pa; + setVariable("atmosphere", atm); + setVariable("atm", atm); + + const double bar = 100000*Pa; + setVariable("bar", bar); + + // Energy + // --- honors James Prescott Joule (1818-1889) of England + const double J = N * m; + setVariable("joule", J); + setVariable("J", J); + + // Power + // --- honors James Watt (1736-1819) of Scotland + const double W = J / s; + setVariable("watt", W); + setVariable("W", W); + + // Electric charge + // --- honors Charles-Augustin de Coulomb (1736-1806) of France + const double C = A * s; + setVariable("coulomb", C); + setVariable("C", C); + + // Electric potential + // --- honors Count Alessandro Volta (1745-1827) of Italy + const double V = J / C; + setVariable("volt", V); + setVariable("V", V); + + // Electric resistance + // --- honors Georg Simon Ohm (1787-1854) of Germany + const double ohm = V / A; + setVariable("ohm", ohm); + + // Electric conductance + // --- honors Ernst Werner von Siemens (1816-1892) or + // his brother Sir William (Karl Wilhelm von) Siemens (1823-1883) + // of Germany (England) + const double S = 1./ ohm; + setVariable("siemens", S); + setVariable("S", S); + + // Electric capacitance + // --- honors Michael Faraday (1791-1867) of England + const double F = C / V; + setVariable("farad", F); + setVariable("F", F); + + // Magnetic flux density + // --- honors Nikola Tesla (1856-1943) of Croatia (United States) + const double T = V * s / (m*m); + setVariable("tesla", T); + setVariable("T", T); + + // --- honors Karl Friedrich Gauss (1777-1855) of Germany + const double Gs = 1.e-4*T; + setVariable("gauss", Gs); + setVariable("Gs", Gs); + + // Magnetic flux + // --- honors Wilhelm Eduard Weber (1804-1891) of Germany + const double Wb = V * s; + setVariable("weber", Wb); + setVariable("Wb", Wb); + + // Inductance + // --- honors Joseph Henry (1797-1878) of the United States + const double H = Wb / A; + setVariable("henry", H); + setVariable("H", H); + + // Luminous flux + const double lm = cd * sr; + setVariable("lumen", lm); + setVariable("lm", lm); + + // Illuminace + const double lx = lm / (m*m); + setVariable("lux", lx); + setVariable("lx", lx); + + // Radioactivity + // --- honors Antoine-Henri Becquerel (1852-1908) of France + const double Bq = 1./s; + setVariable("becquerel", Bq); + setVariable("Bq", Bq); + + // --- honors Pierre Curie (1859-1906) of France + // and Marie Sklodowska Curie (1867-1934) of Poland + setVariable("curie", 3.7e+10 * Bq); + setVariable("Ci", 3.7e+10 * Bq); + + // Specific energy + // --- honors Louis Harold Gray, F.R.S. (1905-1965) of England + const double Gy = J / kg; + setVariable("gray", Gy); + setVariable("Gy", Gy); + + // Dose equivalent + const double Sv = J / kg; + setVariable("sievert", Sv); + setVariable("Sv", Sv); + + // ====================================================================== + // + // Selected units: + // + // ====================================================================== + + // Length + + const double mm = milli_ * m; + setVariable("millimeter", mm); + setVariable("mm", mm); + + const double cm = centi_ * m; + setVariable("centimeter", cm); + setVariable("cm", cm); + + setVariable("decimeter", deci_ * m); + + const double km = kilo_ * m; + setVariable("kilometer", km); + setVariable("km", km); + + setVariable("micrometer", micro_ * m); + setVariable("micron", micro_ * m); + setVariable("nanometer", nano_ * m); + + // --- honors Anders Jonas Angstrom (1814-1874) of Sweden + setVariable("angstrom", 1.e-10 * m); + + // --- honors Enrico Fermi (1901-1954) of Italy + setVariable("fermi", 1.e-15 * m); + + // Length^2 + + setVariable("m2", m*m); + setVariable("mm2", mm*mm); + setVariable("cm2", cm*cm); + setVariable("km2", km*km); + + const double barn = 1.e-28 * m*m; + setVariable("barn", barn); + setVariable("millibarn", milli_ * barn); + setVariable("mbarn", milli_ * barn); + setVariable("microbarn", micro_ * barn); + setVariable("nanobarn", nano_ * barn); + setVariable("picobarn", pico_ * barn); + + // LengthL^3 + + setVariable("m3", m*m*m); + setVariable("mm3", mm*mm*mm); + setVariable("cm3", cm*cm*cm); + setVariable("cc", cm*cm*cm); + setVariable("km3", km*km*km); + + const double L = 1.e-3*m*m*m; + setVariable("liter", L); + setVariable("litre", L); + setVariable("L", L); + setVariable("centiliter", centi_ * L); + setVariable("cL", centi_ * L); + setVariable("milliliter", milli_ * L); + setVariable("mL", milli_ * L); + + // Length^-1 + + const double dpt = 1./m; + setVariable("diopter", dpt); + setVariable("dioptre", dpt); + setVariable("dpt", dpt); + + // Mass + + const double g = 0.001*kg; + setVariable("gram", g); + setVariable("g", g); + setVariable("milligram", milli_ * g); + setVariable("mg", milli_ * g); + + // Time + + setVariable("millisecond", milli_ * s); + setVariable("ms", milli_ * s); + setVariable("microsecond", micro_ * s); + setVariable("nanosecond", nano_ * s); + setVariable("ns", nano_ * s); + setVariable("picosecond", pico_ * s); + + // Current + + setVariable("milliampere", milli_ * A); + setVariable("mA", milli_ * A); + setVariable("microampere", micro_ * A); + setVariable("nanoampere", nano_ * A); + + // Frequency + + setVariable("kilohertz", kilo_ * Hz); + setVariable("kHz", kilo_ * Hz); + setVariable("megahertz", mega_ * Hz); + setVariable("MHz", mega_ * Hz); + + // Force + setVariable("kilonewton", kilo_ * N); + setVariable("kN", kilo_ * N); + + // Pressure + setVariable("kilobar", kilo_ * bar); + setVariable("kbar", kilo_ * bar); + setVariable("millibar", milli_ * bar); + setVariable("mbar", milli_ * bar); + + // Energy + setVariable("kilojoule", kilo_ * J); + setVariable("kJ", kilo_ * J); + setVariable("megajoule", mega_ * J); + setVariable("MJ", mega_ * J); + setVariable("gigajoule", giga_ * J); + setVariable("GJ", giga_ * J); + + const double e_SI = 1.60217733e-19; // positron charge in coulomb + const double ePlus = e_SI * C; // positron charge + const double eV = ePlus * V; + setVariable("electronvolt", eV); + setVariable("eV", eV); + setVariable("kiloelectronvolt", kilo_ * eV); + setVariable("keV", kilo_ * eV); + setVariable("megaelectronvolt", mega_ * eV); + setVariable("MeV", mega_ * eV); + setVariable("gigaelectronvolt", giga_ * eV); + setVariable("GeV", giga_ * eV); + setVariable("teraelectronvolt", tera_ * eV); + setVariable("TeV", tera_ * eV); + setVariable("petaelectronvolt", peta_ * eV); + setVariable("PeV", peta_ * eV); + + // Power + setVariable("kilowatt", kilo_ * W); + setVariable("kW", kilo_ * W); + setVariable("megawatt", mega_ * W); + setVariable("MW", mega_ * W); + setVariable("gigawatt", giga_ * W); + setVariable("GW", giga_ * W); + + // Electric potential + setVariable("kilovolt", kilo_ * V); + setVariable("kV", kilo_ * V); + setVariable("megavolt", mega_ * V); + setVariable("MV", mega_ * V); + + // Electric capacitance + setVariable("millifarad", milli_ * F); + setVariable("mF", milli_ * F); + setVariable("microfarad", micro_ * F); + setVariable("uF", micro_ * F); + setVariable("nanofarad", nano_ * F); + setVariable("nF", nano_ * F); + setVariable("picofarad", pico_ * F); + setVariable("pF", pico_ * F); + + // Magnetic flux density + setVariable("kilogauss", kilo_ * Gs); + setVariable("kGs", kilo_ * Gs); + } + + } // namespace tools +} // namespace dd4hep diff --git a/DDParsers/src/Spirit/Evaluators.cpp b/DDParsers/src/Spirit/Evaluators.cpp index 48e153f0ff6b6fa2dd1761933665b2b77be35b85..43cfc137dfba230f5b12d41934f511e62f3231ba 100755 --- a/DDParsers/src/Spirit/Evaluators.cpp +++ b/DDParsers/src/Spirit/Evaluators.cpp @@ -34,10 +34,10 @@ #include <stdexcept> namespace dd4hep { - XmlTools::Evaluator& g4Evaluator(); + dd4hep::tools::Evaluator& g4Evaluator(); } namespace { - XmlTools::Evaluator& eval(dd4hep::g4Evaluator()); + dd4hep::tools::Evaluator& eval(dd4hep::g4Evaluator()); } //============================================================================== @@ -48,7 +48,7 @@ namespace dd4hep { namespace Parsers { template <> double evaluate_string<double>(const std::string& value) { double result = eval.evaluate(value.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { std::cerr << value << ": "; eval.print_error(); throw std::runtime_error("dd4hep::Properties: Severe error during expression evaluation of " + value); @@ -57,7 +57,7 @@ namespace dd4hep { namespace Parsers { } template <> float evaluate_string<float>(const std::string& value) { double result = eval.evaluate(value.c_str()); - if (eval.status() != XmlTools::Evaluator::OK) { + if (eval.status() != tools::Evaluator::OK) { std::cerr << value << ": "; eval.print_error(); throw std::runtime_error("dd4hep::Properties: Severe error during expression evaluation of " + value); diff --git a/examples/DDDB/include/Detector/DeConditionCallDefs.h b/examples/DDDB/include/Detector/DeConditionCallDefs.h new file mode 100644 index 0000000000000000000000000000000000000000..c2719493a1c474fb0bf949e85c2628dc3c877969 --- /dev/null +++ b/examples/DDDB/include/Detector/DeConditionCallDefs.h @@ -0,0 +1,44 @@ +//============================================================================== +// AIDA Detector description implementation for LHCb +//------------------------------------------------------------------------------ +// 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 Markus Frank +// \date 2018-03-08 +// \version 1.0 +// +//============================================================================== +#ifndef DETECTOR_DECONDITIONCALLDEFS_H +#define DETECTOR_DECONDITIONCALLDEFS_H 1 + +// Framework include files +#include "DD4hep/DetElement.h" +#include "DD4hep/ConditionDerived.h" + +/// Gaudi namespace declaration +namespace gaudi { + + /// Base class to share common type definitions + /** + * + * \author Markus Frank + * \date 2018-03-08 + * \version 1.0 + */ + class DeConditionCallDefs { + public: + typedef dd4hep::DetElement DetElement; + typedef dd4hep::Condition Condition; + typedef dd4hep::ConditionKey ConditionKey; + typedef dd4hep::ConditionKey::KeyMaker KeyMaker; + typedef dd4hep::cond::ConditionResolver Resolver; + typedef dd4hep::cond::ConditionUpdateContext Context; + typedef dd4hep::DDDB::DDDBCatalog Catalog; + }; + +} // End namespace gaudi +#endif // DETECTOR_DECONDITIONCALLDEFS_H diff --git a/examples/DDDB/include/Detector/DeVPConditionCalls.h b/examples/DDDB/include/Detector/DeVPConditionCalls.h index 3c411227f348dbaacd711320aca6521c840598c2..9dc101d05a3e2039f8069875f54c6664176c29c4 100644 --- a/examples/DDDB/include/Detector/DeVPConditionCalls.h +++ b/examples/DDDB/include/Detector/DeVPConditionCalls.h @@ -17,6 +17,7 @@ // Framework include files #include "Detector/DeVP.h" +#include "Detector/DeConditionCallDefs.h" #include "DD4hep/ConditionDerived.h" /// Gaudi namespace declaration @@ -35,24 +36,6 @@ namespace gaudi { dd4hep::Condition alignments_done; }; - /// Base class to share common type definitions - /** - * - * \author Markus Frank - * \date 2018-03-08 - * \version 1.0 - */ - class DeConditionCallDefs { - public: - typedef dd4hep::DetElement DetElement; - typedef dd4hep::Condition Condition; - typedef dd4hep::ConditionKey ConditionKey; - typedef dd4hep::ConditionKey::KeyMaker KeyMaker; - typedef dd4hep::cond::ConditionResolver Resolver; - typedef dd4hep::cond::ConditionUpdateContext Context; - typedef dd4hep::DDDB::DDDBCatalog Catalog; - }; - /// Condition derivation call to build the static Velo-pixel DetElement condition information /** * diff --git a/examples/DDDB/include/Detector/DeVeloConditionCalls.h b/examples/DDDB/include/Detector/DeVeloConditionCalls.h index f9dd6c163ab1f9fef650603a08dd125dad12631b..db3f625d9eb99582d4937bb1d70949f8961d00f9 100644 --- a/examples/DDDB/include/Detector/DeVeloConditionCalls.h +++ b/examples/DDDB/include/Detector/DeVeloConditionCalls.h @@ -12,11 +12,12 @@ // \version 1.0 // //============================================================================== -#ifndef DETECTOR_DEVPCONDITIONCALLS_H -#define DETECTOR_DEVPCONDITIONCALLS_H 1 +#ifndef DETECTOR_DEVELOCONDITIONCALLS_H +#define DETECTOR_DEVELOCONDITIONCALLS_H 1 // Framework include files #include "Detector/DeVelo.h" +#include "Detector/DeConditionCallDefs.h" #include "DD4hep/ConditionDerived.h" /// Gaudi namespace declaration @@ -35,24 +36,6 @@ namespace gaudi { dd4hep::Condition alignments_done; }; - /// Base class to share common type definitions - /** - * - * \author Markus Frank - * \date 2018-03-08 - * \version 1.0 - */ - class DeConditionCallDefs { - public: - typedef dd4hep::DetElement DetElement; - typedef dd4hep::Condition Condition; - typedef dd4hep::ConditionKey ConditionKey; - typedef dd4hep::ConditionKey::KeyMaker KeyMaker; - typedef dd4hep::cond::ConditionResolver Resolver; - typedef dd4hep::cond::ConditionUpdateContext Context; - typedef dd4hep::DDDB::DDDBCatalog Catalog; - }; - /// Condition derivation call to build the static Velo-pixel DetElement condition information /** * @@ -114,4 +97,4 @@ namespace gaudi { }; } // End namespace gaudi -#endif // DETECTOR_DEVPCONDITIONCALLS_H +#endif // DETECTOR_DEVELOCONDITIONCALLS_H diff --git a/examples/DDDB/src/Detector/DeAlignmentCall.cpp b/examples/DDDB/src/Detector/DeAlignmentCall.cpp index 68e3ed1f7886cf94a1054a151837f00c77509fd3..1a20d9271e3748d35d2efb21930bff99ff7e7b8c 100644 --- a/examples/DDDB/src/Detector/DeAlignmentCall.cpp +++ b/examples/DDDB/src/Detector/DeAlignmentCall.cpp @@ -42,7 +42,7 @@ Condition gaudi::DeAlignmentCall::operator()(const ConditionKey& /* key */, ConditionsManager mgr = ctxt.resolver->manager(); cond = Condition(gaudi::Keys::alignmentsComputedKeyName,"Calculator"); Deltas& deltas = cond.bind<Deltas>(); - conditions->print(""); + //conditions->print(""); // Test. Need to be replaced by a special scanner DetectorScanner().scan(AlignmentsCalculator::Scanner(ctxt,deltas),top); AlignmentsCalculator::Result ares = calc.compute(deltas, slice); @@ -52,8 +52,8 @@ Condition gaudi::DeAlignmentCall::operator()(const ConditionKey& /* key */, mgr.registerUnlocked(*iov_pool,c); conditions->insert(c); } - printout(INFO,"Align","Alignments:(C:%ld,M:%ld) IOV:%s", - ares.computed, ares.missing, ctxt.iov->str().c_str()); + printout(INFO,"Align","Alignments:(C:%ld,M:%ld,*:%ld) IOV:%s", + ares.computed, ares.missing, ares.multiply, ctxt.iov->str().c_str()); return cond; } except("DeAlignmentCall","No conditions slice present!"); diff --git a/examples/DDDB/src/Detector/DeVeloConditionCalls.cpp b/examples/DDDB/src/Detector/DeVeloConditionCalls.cpp index 398546201ad94605457ee02d4adf1a9cd0463ea0..ad7c25a5ba67e3c7aa4cb6ace141f102de7c2cdc 100644 --- a/examples/DDDB/src/Detector/DeVeloConditionCalls.cpp +++ b/examples/DDDB/src/Detector/DeVeloConditionCalls.cpp @@ -20,6 +20,14 @@ using namespace std; using namespace gaudi; +namespace { + void _cond_error(const char* func, int line, const std::exception& e) { + dd4hep::printout(dd4hep::ERROR,"Cond-Callback", + "%s:%d Load Condition failed: %s",func,line,e.what()); + } +} +#define LOAD_COND(expr) try{ expr; }catch(const std::exception& e) {_cond_error(__func__,__LINE__,e); throw; } + /// Interface to client Callback in order to update the condition dd4hep::Condition DeVeloStaticConditionCall::operator()(const ConditionKey& key, Context& context) { @@ -54,7 +62,7 @@ void DeVeloStaticConditionCall::resolve(Condition c, Context& context) { for ( const auto& i : elts ) { DetElement de = i.first; KeyMaker key(de.key(), Keys::staticKey); - DeStatic cond = context.condition(key.hash); + DeStatic cond; LOAD_COND(cond = context.condition(key.hash)); const string& path = de.path(); bool left = path.find("/VeloLeft/Module") != string::npos || path.find("/VeloLeft") == path.length()-9; bool right = path.find("/VeloRight/Module") != string::npos || path.find("/VeloRight") == path.length()-10; @@ -141,13 +149,12 @@ void DeVeloIOVConditionCall::resolve(Condition cond, Context& context) { if ( !velo_context->alignments_done.isValid() ) { velo_context->alignments_done = context.condition(Keys::alignmentsComputedKey); } - vector<Condition> conds = context.conditions(det_key); - iov->de_static = context.condition(kstatic.hash); - iov->detectorAlignment = context.condition(kalign.hash); + LOAD_COND(iov->de_static = context.condition(kstatic.hash)); + LOAD_COND(iov->detectorAlignment = context.condition(kalign.hash)); for ( Condition c : conds ) - iov->conditions.insert(make_pair(c.item_key(),c)); - iov->initialize(); + LOAD_COND(iov->conditions.insert(make_pair(c.item_key(),c))); + LOAD_COND(iov->initialize()); } namespace { @@ -180,7 +187,7 @@ namespace { } for (detail::DeVeloGenericStaticObject* i : src->children) { dd4hep::ConditionKey::KeyMaker key(i->detector.key(), Keys::deKey); - DeVeloGeneric child = context.condition(key.hash); + DeVeloGeneric child; LOAD_COND(child = context.condition(key.hash)); gen->children.push_back(child.ptr()); add_sensors(child, DeVeloGenericStatic(i), mapping, context); } @@ -199,7 +206,7 @@ void DeVeloConditionCall::resolve(Condition cond, Context& context) { for ( const auto& i : s->sensors[DeVeloFlags::ALL] ) { if ( i.isValid() ) { KeyMaker key(i->detector.key(), Keys::deKey); - DeVeloSensor sens = context.condition(key.hash); + DeVeloSensor sens; LOAD_COND(sens = context.condition(key.hash)); if ( !sens.isValid() ) { except("DeVelo","Problem Mapping %p ---> %p [%s]", (void*)i.ptr(), (void*)sens.ptr(), i->detector.path().c_str()); @@ -223,7 +230,7 @@ void DeVeloConditionCall::resolve(Condition cond, Context& context) { } for ( auto side : s->sides ) { dd4hep::ConditionKey::KeyMaker key(side->detector.key(), Keys::deKey); - DeVeloGeneric child = context.condition(key.hash); + DeVeloGeneric child; LOAD_COND(child = context.condition(key.hash)); vp->sides.push_back(child); add_sensors(child, side, sensorMapping, context); } diff --git a/examples/DDDB/src/plugins/CondDB2DDDB.cpp b/examples/DDDB/src/plugins/CondDB2DDDB.cpp index 063490940bd27ec9fda676ff0b8134d38c57d369..72ab66b35b06ff2ef364bf94b7fddab44ad71089 100644 --- a/examples/DDDB/src/plugins/CondDB2DDDB.cpp +++ b/examples/DDDB/src/plugins/CondDB2DDDB.cpp @@ -29,6 +29,7 @@ #include "Math/Polar2D.h" // C/C++ include files +#include <climits> using namespace std; using namespace dd4hep; @@ -174,11 +175,14 @@ namespace dd4hep { bool print_catalog = false; bool print_catalog_ref = false; bool print_tabprop = false; - + bool print_tree_on_error = true; + bool print_eval_error = true; /// Default constructor DDDBContext() = default; /// Initializing constructor DDDBContext(Detector* d); + /// Default destructor + ~DDDBContext() = default; /** Printout helpers */ void print(const DDDBIsotope* obj) const { if ( print_materials ) dddb_print(obj); } @@ -250,12 +254,15 @@ namespace dd4hep { convert(element); } catch(const exception& e) { - printout(INFO,typeName(typeid(T)),"Failed to convert XML object: %s", e.what()); - xml::dump_tree(element.parent()); + bool eval_err = ::strstr(e.what(),"error during expression evaluation"); + if ( !eval_err ) eval_err = ::strstr(e.what(),"Evaluator : unknown variable"); + if ( !eval_err || (eval_err && s_config.print_eval_error) ) + printout(INFO,typeName(typeid(T)),"Failed to convert XML object: %s", e.what()); + if ( s_config.print_tree_on_error ) xml::dump_tree(element.parent()); } catch(...) { printout(INFO,typeName(typeid(T)),"Failed to convert XML object."); - xml::dump_tree(element.parent()); + if ( s_config.print_tree_on_error ) xml::dump_tree(element.parent()); } } }; @@ -274,11 +281,11 @@ namespace dd4hep { } catch(const exception& e) { printout(INFO,typeName(typeid(T)),"Failed to convert object: %s",e.what()); - xml::dump_tree(element.parent()); + //xml::dump_tree(element.parent()); } catch(...) { printout(INFO,typeName(typeid(T)),"Failed to convert object."); - xml::dump_tree(element.parent()); + //xml::dump_tree(element.parent()); } } void convert(xml::Handle_t element, DDDBShape*& ptr_shape) const; @@ -764,7 +771,7 @@ namespace dd4hep { /// Specialized conversion of <param/> entities template <> void Conv<DDDBConfig>::convert(xml_h element) const { - DDDBContext* ctx = &s_config; + DDDBContext* ctx = _param<DDDBContext>(); for(xml_coll_t c(element,_U(param)); c; ++c) { xml_dim_t p = c; if ( p.nameStr() == "print_file_load" ) @@ -799,6 +806,10 @@ namespace dd4hep { ctx->print_catalog_ref = p.attr<bool>(_U(value)); else if ( p.nameStr() == "print_tabprop" ) ctx->print_tabprop = p.attr<bool>(_U(value)); + else if ( p.nameStr() == "print_tree_on_error" ) + ctx->print_tree_on_error = p.attr<bool>(_U(value)); + else if ( p.nameStr() == "print_eval_error" ) + ctx->print_eval_error = p.attr<bool>(_U(value)); } } @@ -900,7 +911,7 @@ namespace dd4hep { if ( i == context->geo->materials.end() ) { printout(ERROR,"MaterialRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); } - if ( catalog ) { + else if ( catalog ) { DDDBMaterial* m = (*i).second; string path = object_path(context,m->name); context->collectPath(path, m); @@ -1429,10 +1440,18 @@ namespace dd4hep { DDDBContext* context = _param<DDDBContext>(); string name = element.attr<string>(_U(name)); string value = element.attr<string>(_U(value)); - _toDictionary(name,value); if ( context->print_params ) { printout(INFO,"Parameter","++ %s = %s",name.c_str(),value.c_str()); } + try { + _toDictionary(name,value); + } + catch(const exception& e) { + if ( context->print_eval_error ) { + printout(ERROR,"DDDBParameter","++ FAILED %s = %s [%s]",name.c_str(),value.c_str(),e.what()); + } + throw; + } } /// Specialized conversion of <detelemref/> entities @@ -1607,6 +1626,7 @@ namespace dd4hep { DDDBCatalog* catalog = 0; DDDBContext* context = _param<DDDBContext>(); xml_coll_t(e, _LBU(block)).for_each(Conv<DDDBBlock>(description,context,catalog)); + xml_coll_t(e, _U(config)).for_each(Conv<DDDBConfig>(description,&s_config,catalog)); xml_coll_t(e, _U(config)).for_each(Conv<DDDBConfig>(description,context,catalog)); xml_coll_t(e, _U(parameter)).for_each(Conv<DDDBParameter>(description,context,catalog)); xml_coll_t(e, _U(isotope)).for_each(Conv<DDDBIsotope>(description,context,catalog)); @@ -1809,7 +1829,7 @@ namespace dd4hep { xml_doc->context.doc = xml_doc->id; xml_doc->context.event_time = ctx->event_time; xml_doc->context.valid_since = 0;//ctx->valid_since; - xml_doc->context.valid_until = 0;//ctx->valid_until; + xml_doc->context.valid_until = LONG_MAX;//ctx->valid_until; docs.insert(make_pair(doc_path,xml_doc->addRef())); if ( !rdr->isBlocked(doc_path) ) { @@ -1818,7 +1838,7 @@ namespace dd4hep { xml_h e = doc.root(); context->print(xml_doc); printout(context->print_file_load ? INFO : DEBUG, - "load_dddb","Loading document: %s IOV: %ld [%ld,%ld]", + "load_dddb","Loaded document: %s IOV: %ld [%ld,%ld]", xml_doc->id.c_str(), xml_doc->context.event_time, xml_doc->context.valid_since, @@ -1843,6 +1863,7 @@ namespace dd4hep { context->print_condition = prt; if ( prt || context->print_xml ) xml::dump_tree(e); converter(e); + return; } return; } @@ -1862,7 +1883,7 @@ namespace dd4hep { DDDBHelper* hlp, const std::string& doc_path, const std::string& obj_path) { - xml::UriReader* rdr = hlp->reader<xml::UriReader>(); + xml::UriReader* rdr = hlp->reader<xml::UriReader>(); DDDBReaderContext* ctx = (DDDBReaderContext*)rdr->context(); DDDBDocument* doc = new DDDBDocument(); doc->name = obj_path; diff --git a/examples/DDDB/src/plugins/DDDB2Objects.cpp b/examples/DDDB/src/plugins/DDDB2Objects.cpp index 4f7aa6d5139f5db7b9e3b784ac25800b088b4c67..b6e4bfd6e9682e742f7952fc184955f48b51788c 100644 --- a/examples/DDDB/src/plugins/DDDB2Objects.cpp +++ b/examples/DDDB/src/plugins/DDDB2Objects.cpp @@ -59,12 +59,27 @@ namespace dd4hep { typedef cond::ConditionsPool ConditionsPool; typedef cond::AbstractMap AbstractMap; + /// Printout steering for debugging + struct PrintFlags { + bool materials = false; + bool volumes = false; + bool logvol = false; + bool shapes = false; + bool physvol = false; + bool params = false; + bool detelem = false; + bool conditions = false; + bool vis = false; + }; + static PrintFlags s_printFlags; + /// Helper class to facilitate conversion. Purely local. struct Context { typedef set<string> StringSet; Context(Detector& l, DDDB::DDDBHelper* h) : description(l), geo(h->detectorDescription()), helper(h) { reader = h->reader<DDDB::DDDBReader>(); + print = s_printFlags; } ~Context() { //printout(INFO,"Context","Destructor calling...."); @@ -103,22 +118,14 @@ namespace dd4hep { Volume lvDummy; ConditionsManager manager; const IOVType* epoch = 0; + PrintFlags print; int max_volume_depth = 9999; int unmatched_deltas = 0; int delta_conditions = 0; int matched_conditions = 0; int unmatched_conditions = 0; int badassigned_conditions = 0; - bool print_materials = false; - bool print_volumes = false; - bool print_logvol = false; - bool print_shapes = false; - bool print_physvol = false; - bool print_params = false; - bool print_detelem = false; - bool print_conditions = false; - bool print_vis = false; - bool conditions_only = false; + bool conditions_only = false; static PlacedVolume placement(DetElement de) { if ( de.isValid() ) { @@ -273,7 +280,7 @@ namespace dd4hep { iso = TGeoIsotope::FindIsotope(o->c_name()); if ( !iso ) iso = new TGeoIsotope(o->c_name(),o->Z,o->A,o->density); context->isotopes.insert(make_pair(o,iso)); - if ( context->print_materials ) dddb_print(iso); + if ( context->print.materials ) dddb_print(iso); } return iso; } @@ -306,7 +313,7 @@ namespace dd4hep { except("Cnv<Element>","Failed to insert Element: %s into table!", nam); return 0; } - if ( context->print_materials ) dddb_print(e); + if ( context->print.materials ) dddb_print(e); } DDDBMaterial* material = Context::find(context->geo->materials,string(nam)); if ( !material ) { @@ -401,7 +408,7 @@ namespace dd4hep { medium->SetUniqueID(unique_mat_id); } context->materials.insert(make_pair(object,medium)); - if ( context->print_materials ) dddb_print(medium); + if ( context->print.materials ) dddb_print(medium); } return medium; } @@ -422,11 +429,13 @@ namespace dd4hep { mat = Context::find(context->geo->materials,mat_name); } if ( !mat ) { - printout(ERROR,"Cnv<Material>", - "++ Failed to find component material: %s " - "---> Matrial table dump.", material_name.c_str()); - for(auto im=context->geo->materials.begin(); im != context->geo->materials.end(); ++im) - dddb_print((*im).second); + if ( context->print.materials ) { + printout(ERROR,"Cnv<Material>", + "++ Failed to find component material: %s " + "---> Material table dump.", material_name.c_str()); + for(auto im=context->geo->materials.begin(); im != context->geo->materials.end(); ++im) + dddb_print((*im).second); + } except("Materials","++ Undefined material %s",material_name.c_str()); } TGeoMedium* medium = (TGeoMedium*)CNV<DDDBMaterial>(context->description,context).convert(mat); @@ -546,7 +555,7 @@ namespace dd4hep { object->c_id(), object->type); } shape->SetTitle(object->path.c_str()); - if ( context->print_shapes ) { + if ( context->print.shapes ) { printout(INFO,"Cnv<Shape>","++ Converted shape: %s",object->c_id()); } context->shapes.insert(make_pair(object, shape)); @@ -597,7 +606,7 @@ namespace dd4hep { mother->SetTitle(object->path.c_str()); VisAttr vis = context->helper->visAttr(object->path); if ( vis.isValid() ) { - if ( context->print_vis ) { + if ( context->print.vis ) { printout(INFO,"Cnv<LogVol>","++ Vol:%s Vis:%s",mother->GetTitle(), vis.name()); } mother.setVisAttributes(vis); @@ -711,7 +720,7 @@ namespace dd4hep { break; } context->placements.insert(make_pair(pv, place.ptr())); - if ( context->print_physvol ) { + if ( context->print.physvol ) { Position pos; pv->trafo.GetTranslation(pos); printout(INFO,"Cnv<PhysVol>","++ Converted physVol: depth:%d typ:%d places:%d [%p lv:%p] %s", @@ -722,7 +731,7 @@ namespace dd4hep { } } } - if ( context->print_logvol ) { + if ( context->print.logvol ) { printout(INFO,"Cnv<LogVol>","++ Converted logVol: [%p -> %p] %s NDau:%d", (void*)object, (void*)mother.ptr(), object->path.c_str(), mother->GetNdaughters()); @@ -751,9 +760,11 @@ namespace dd4hep { lv = (*iv).second; return lv; } +#if 0 for(iv = c->logvols.begin(); iv != c->logvols.end(); ++iv) printout(WARNING,"Cnv<LogVol>","++ %s --volume--> %s", c->id.c_str(), (*iv).second->name.c_str()); +#endif } printout(WARNING,"Cnv<LogVol>","++ Undefined logical volume: %s", nam.c_str()); return 0; @@ -779,7 +790,7 @@ namespace dd4hep { Volume vol; DDDBCatalog* support = 0; DetElement det, parent_element; - if ( context->print_detelem ) { + if ( context->print.detelem ) { printout(INFO,"CNV<Catalog>","++ Starting catalog %p %s [cref:%d/%d lref:%d/%d lv:%s sup:%s np:%s] Cond:%s ", (void*)object, object->path.c_str(), @@ -859,12 +870,11 @@ namespace dd4hep { if ( !object->npath.empty() ) { PlacedVolume place = context->supportPlacement(parent_element, object->npath); if ( !place.isValid() ) { - char txt[64]; - ::snprintf(txt,sizeof(txt),"++ %%%lds %%s %%s",long(object->path.length())); - printout(WARNING,"CNV<DetElem>",txt, - object->path.c_str(), "Placement: ", object->logvol.c_str()); - printout(WARNING,"CNV<DetElem>",txt," --> INVALID PLACEMENT...", - "Vol.N-path:", object->npath.c_str()); + printout(WARNING,"CNV<DetElem>","++ %s Placement: %s", + object->path.c_str(), object->logvol.c_str()); + printout(WARNING,"CNV<DetElem>", + "++ --> INVALID PLACEMENT... Vol.N-path: %s", + object->npath.c_str()); } else { det.setPlacement(place); @@ -926,7 +936,7 @@ namespace dd4hep { } } } - if ( context->print_detelem ) { + if ( context->print.detelem ) { printout(INFO,"CNV<Catalog>","++ Converting catalog %p -> %p [cref:%d/%d lref:%d/%d lv:%s [%p] sup:%s np:%s] %s ", (void*)object, det.ptr(), int(object->catalogrefs.size()), @@ -1057,15 +1067,15 @@ namespace dd4hep { DDDBHelper* helper = description.extension<DDDBHelper>(false); if ( helper ) { Context context(description, helper); - context.print_materials = false; - context.print_logvol = false; - context.print_shapes = false; - context.print_physvol = false; - context.print_volumes = false; - context.print_params = false; - context.print_detelem = false; - context.print_conditions = false; - context.print_vis = false; + context.print.materials = false; + context.print.logvol = false; + context.print.shapes = false; + context.print.physvol = false; + context.print.volumes = false; + context.print.params = false; + context.print.detelem = false; + context.print.conditions = false; + context.print.vis = false; context.max_volume_depth = 11; CNV<dddb> cnv(description,&context); @@ -1098,7 +1108,7 @@ namespace dd4hep { DDDBHelper* helper = description.extension<DDDBHelper>(false); if ( helper ) { Context context(description, helper); - context.print_conditions = false; + context.print.conditions = false; context.conditions_only = true; CNV<dddb> cnv(description,&context); cnv(make_pair(string(),context.geo));