Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Multiple commits. See release notes. #1021

Merged
merged 26 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
274edb1
Release some code exclusions for gcc < 10
MarkusFrankATcernch Oct 31, 2022
abe81d0
Release some code exclusions for gcc < 10
MarkusFrankATcernch Oct 31, 2022
43dfc0d
Check MC history tracking
MarkusFrankATcernch Nov 1, 2022
031ccce
Improve VolumeManager functionality
MarkusFrankATcernch Nov 4, 2022
663d464
Fix python style errors
MarkusFrankATcernch Nov 4, 2022
ce6763c
Improve deposit smearing in DDDigi
MarkusFrankATcernch Nov 4, 2022
66a27df
Fix python style errors
MarkusFrankATcernch Nov 4, 2022
b2a81b4
Have consistent callback signatures for container and segmenation cal…
MarkusFrankATcernch Nov 6, 2022
d23fe60
Fix segmentation selection mechanism in DDDigi
MarkusFrankATcernch Nov 6, 2022
851a94a
use std::function/std::bind instead of self made callbacks
MarkusFrankATcernch Nov 7, 2022
44d94c5
Export DDG4 UI manager with example examples/DDG4/scripts/TestUserCom…
MarkusFrankATcernch Nov 18, 2022
f007b27
Fic ctest and python style errors
MarkusFrankATcernch Nov 18, 2022
91a818b
Fix ctest and python style errors
MarkusFrankATcernch Nov 18, 2022
9f86dd4
Fix Geant4Particle charges. Remove python style errors. Fix DDDigi fr…
MarkusFrankATcernch Nov 18, 2022
18c227e
Fix particle charge
MarkusFrankATcernch Nov 18, 2022
9222737
Undo fix to propagate Geant4Particle charge. Must be done in the outp…
MarkusFrankATcernch Nov 18, 2022
ace2d81
Remove interpreter error
MarkusFrankATcernch Nov 18, 2022
9d1ea59
Fix instantiation problem for dictionaries
MarkusFrankATcernch Nov 19, 2022
6cb1130
Fix instantiation problem for dictionaries
MarkusFrankATcernch Nov 19, 2022
0e44f3e
Fix instantiation problem for dictionaries
MarkusFrankATcernch Nov 19, 2022
71da5f4
Test properties in DDDigi
MarkusFrankATcernch Nov 21, 2022
7db6ef5
Test properties in DDDigi
MarkusFrankATcernch Nov 21, 2022
ffa8b44
Test properties in DDDigi
MarkusFrankATcernch Nov 21, 2022
9b99060
Simplify and fix late grammars in component properties
MarkusFrankATcernch Nov 21, 2022
3239eeb
Simplify and fix late grammars in component properties
MarkusFrankATcernch Nov 21, 2022
543ff0a
Remove compiler warning
MarkusFrankATcernch Nov 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions DDCore/include/DD4hep/Callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ namespace dd4hep {
: par(p), call(0) {
func.first = func.second = 0;
}
/// Constructor with object initialization
Callback(const void* p)
: par((void*)p), call(0) {
func.first = func.second = 0;
}
/// Initializing constructor
Callback(void* p, void* mf, func_t c)
: par(p), call(c) {
Expand Down
77 changes: 15 additions & 62 deletions DDCore/include/DD4hep/ComponentProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <algorithm>
#include <stdexcept>
#include <typeinfo>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
Expand All @@ -29,53 +30,6 @@ namespace dd4hep {

class Property;
class BasicGrammar;
class PropertyGrammar;

/// Interface class to configure properties in components
/**
* Placeholder interface.
*
* \author M.Frank
* \version 1.0
* \ingroup DD4HEP_CORE
*/
class PropertyConfigurator {
protected:
/// Default destructor
virtual ~PropertyConfigurator();
public:
virtual void set(const PropertyGrammar& setter, const std::string&, const std::string&, void* ptr) const = 0;
};


/// Class describing the grammar representation of a given data type
/**
* Note: This class cannot be saved to a ROOT file!
*
* \author M.Frank
* \version 1.0
* \ingroup DD4HEP_CORE
*/
class PropertyGrammar {
protected:
friend class Property;
const BasicGrammar& m_grammar; //! This member is not ROOT persistent as the entire class is not.
public:
/// Default constructor
PropertyGrammar(const BasicGrammar& g);
/// Default destructor
virtual ~PropertyGrammar();
/// Error callback on invalid conversion
static void invalidConversion(const std::type_info& from, const std::type_info& to);
/// Error callback on invalid conversion
static void invalidConversion(const std::string& value, const std::type_info& to);
/// Access to the type information
virtual const std::type_info& type() const;
/// Serialize an opaque value to a string
virtual std::string str(const void* ptr) const;
/// Set value from serialized string. On successful data conversion TRUE is returned.
virtual bool fromString(void* ptr, const std::string& value) const;
};

/// The property class to assign options to actions.
/**
Expand All @@ -94,9 +48,9 @@ namespace dd4hep {
class Property {
protected:
/// Pointer to the data location
void* m_par = 0;
void* m_par { nullptr };
/// Reference to the grammar of this property (extended type description)
const PropertyGrammar* m_hdl = 0;
const BasicGrammar* m_hdl { nullptr };

public:
/// Default constructor
Expand All @@ -114,7 +68,7 @@ namespace dd4hep {
/// Property type name
std::string type() const;
/// Access grammar object
const PropertyGrammar& grammar() const;
const BasicGrammar& grammar() const;
/// Conversion to string value
std::string str() const;
/// Conversion from string value
Expand All @@ -138,18 +92,19 @@ namespace dd4hep {
};

/// User constructor
template <typename TYPE> Property::Property(TYPE& val) : m_par(&val), m_hdl(0) {
static PropertyGrammar grammar(BasicGrammar::instance<TYPE>());
m_hdl = &grammar;
}
template <typename TYPE> Property::Property(TYPE& val)
: m_par(&val), m_hdl(0)
{
m_hdl = &BasicGrammar::get(typeid(TYPE));
}

/// Set value of this property
template <typename TYPE> void Property::set(const TYPE& val) {
const PropertyGrammar& grm = grammar();
const auto& grm = grammar();
if (grm.type() == typeid(TYPE))
*(TYPE*) m_par = val;
else if (!grm.fromString(m_par, BasicGrammar::instance< TYPE >().str(&val)))
PropertyGrammar::invalidConversion(typeid(TYPE), grm.type());
BasicGrammar::invalidConversion(typeid(TYPE), grm.type());
}

/// Assignment operator / set new balue
Expand All @@ -160,11 +115,11 @@ namespace dd4hep {

/// Retrieve value from stack (large values e.g. vectors etc.)
template <typename TYPE> void Property::value(TYPE& val) const {
const PropertyGrammar& grm = grammar();
const auto& grm = grammar();
if (grm.type() == typeid(TYPE))
val = *(TYPE*) m_par;
else if (!BasicGrammar::instance< TYPE >().fromString(&val, this->str()))
PropertyGrammar::invalidConversion(grm.type(), typeid(TYPE));
BasicGrammar::invalidConversion(grm.type(), typeid(TYPE));
}

/// Retrieve value
Expand Down Expand Up @@ -196,7 +151,7 @@ namespace dd4hep {
/// Equality operator
bool operator==(const TYPE& val) const { return val == data; }
/// Access grammar object
const PropertyGrammar& grammar() const { return this->Property::grammar(); }
const BasicGrammar& grammar() const { return this->Property::grammar(); }
/// Conversion to string value
std::string str() const { return this->Property::str(); }
/// Retrieve value with data conversion
Expand Down Expand Up @@ -258,8 +213,6 @@ namespace dd4hep {
template <typename T> void add(const std::string& name, T& value) {
add(name, Property(value));
}
/// Bulk set of all properties
void set(const std::string& component_name, PropertyConfigurator& setup);
/// Apply functor on properties
template <typename FUNCTOR> void for_each(FUNCTOR& func) {
std::for_each(m_properties.begin(), m_properties.end(), func);
Expand All @@ -268,7 +221,7 @@ namespace dd4hep {
template <typename FUNCTOR> void for_each(const FUNCTOR& func) {
std::for_each(m_properties.begin(), m_properties.end(), func);
}
/// Export properties of another instance
/// Import properties of another instance
void adopt(const PropertyManager& copy);
/// Dump string values
void dump() const;
Expand Down
1 change: 1 addition & 0 deletions DDCore/include/DD4hep/Grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// C/C++ include files
#include <string>
#include <iostream>
#include <typeinfo>

// Forward declarations
Expand Down
67 changes: 50 additions & 17 deletions DDCore/include/DD4hep/GrammarParsed.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,35 @@ namespace dd4hep {
std::pair<int,double> grammar_evaluate_item(std::string val);

/// PropertyGrammar overload: Retrieve value from string
template <typename TYPE> bool grammar_fromString(const BasicGrammar& gr, void* ptr, const std::string& string_val) {
template <typename TYPE> bool grammar_fromString(const BasicGrammar& gr, void* ptr, const std::string& val) {
int sc = 0;
TYPE temp;
try {
sc = ::dd4hep::Parsers::parse(temp,string_val);
#ifdef DD4HEP_DEBUG_PROPERTIES
std::cout << "Parsing " << val << std::endl;
#endif
sc = ::dd4hep::Parsers::parse(temp, val);
if ( sc ) {
*(TYPE*)ptr = temp;
return true;
}
}
catch (...) {
}
if ( !sc ) sc = gr.evaluate(&temp,string_val);
#if 0
std::cout << "Sc=" << sc << " Converting value: " << string_val
#ifdef DD4HEP_DEBUG_PROPERTIES
std::cout << "Parsing " << val << "FAILED" << std::endl;
#endif
if ( !sc ) sc = gr.evaluate(&temp,val);
#ifdef DD4HEP_DEBUG_PROPERTIES
std::cout << "Sc=" << sc << " Converting value: " << val
<< " to type " << typeid(TYPE).name()
<< std::endl;
#endif
if ( sc ) {
*(TYPE*)ptr = temp;
return true;
}
BasicGrammar::invalidConversion(string_val, typeid(TYPE));
BasicGrammar::invalidConversion(val, typeid(TYPE));
return false;
}

Expand All @@ -84,17 +94,30 @@ namespace dd4hep {
}

/// Item evaluator
template <typename T> inline int eval_item(T* ptr, std::string val) {
template <typename T> inline int eval_item(T* ptr, const std::string& val) {
/// First try to parse the value with spirit.
try {
T temp;
int sc = ::dd4hep::Parsers::parse(temp,val);
if ( sc ) {
*ptr = temp;
return 1;
}
}
catch (...) {
}
/// If this failed: try to evaluate it with the expression parser
auto result = grammar_evaluate_item(val);
if (result.first != tools::Evaluator::OK) {
return 0;
if (result.first == tools::Evaluator::OK) {
*ptr = (T)result.second;
return 1;
}
*ptr = (T)result.second;
return 1;
/// This also failed: Return error.
return 0;
}

/// String evaluator
template <> inline int eval_item<std::string>(std::string* ptr, std::string val) {
/// String evaluator: Nothing to do!
template <> inline int eval_item<std::string>(std::string* ptr, const std::string& val) {
*ptr = val;
return 1;
}
Expand Down Expand Up @@ -270,10 +293,20 @@ namespace dd4hep {

#define DD4HEP_DEFINE_PARSER_GRAMMAR_EVAL(xx,func) \
namespace dd4hep { namespace detail { \
template<> int grammar_eval<xx>(const BasicGrammar&, void* _p, const std::string& _v) { return func ((xx*)_p,_v); }}}

#define DD4HEP_DEFINE_PARSER_GRAMMAR_INSTANCE(serial,xx) namespace dd4hep { template class Grammar< xx >; } \
namespace DD4HEP_PARSER_GRAMMAR_CNAME(serial,0) { static auto s_reg = ::dd4hep::GrammarRegistry::pre_note< xx >(); }
template<> int grammar_eval<xx>(const BasicGrammar&, void* _p, const std::string& _v) {\
return func ((xx*)_p,_v); \
}}}


#define DD4HEP_DEFINE_PARSER_GRAMMAR_INSTANCE(serial,xx) \
namespace dd4hep { \
template class Grammar< xx >; \
template BasicGrammar const& BasicGrammar::instance< xx >(); \
template const GrammarRegistry& GrammarRegistry::pre_note<xx>(int); \
} \
namespace DD4HEP_PARSER_GRAMMAR_CNAME(serial,0) { \
static auto s_reg = ::dd4hep::GrammarRegistry::pre_note< xx >(1); \
}

#define DD4HEP_DEFINE_PARSER_GRAMMAR_SERIAL(serial,ctxt,xx,func) \
DD4HEP_DEFINE_PARSER_GRAMMAR_EVAL(xx,func) \
Expand Down
14 changes: 14 additions & 0 deletions DDCore/include/DD4hep/VolumeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ namespace dd4hep {
Position localToWorld(const double local[3]) const;
/// Transform local coordinates to the world coordinates
Position localToWorld(const Position& local) const;

/// Transform world coordinates to the DetElement coordinates
Position worldToElement(const Position& world) const;
/// Transform world coordinates to the DetElement coordinates
Position worldToElement(const double world[3]) const;
/// Transform world coordinates to the DetElement coordinates
void worldToElement(const double world[3], double element[3]) const;

/// Transform world coordinates to the local coordinates
Position worldToLocal(const Position& world) const;
/// Transform world coordinates to the local coordinates
Position worldToLocal(const double world[3]) const;
/// Transform world coordinates to the local coordinates
void worldToLocal(const double world[3], double local[3]) const;
};

/// Class to support the retrieval of detector elements and volumes given a valid identifier
Expand Down
10 changes: 10 additions & 0 deletions DDCore/include/Parsers/Primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ namespace dd4hep {
/// Definition of the vector type
typedef std::vector<value_t> vector_t;

/// Definition of the bool mapped type
typedef std::pair<bool,value_t> bool_pair_t;
/// Definition of the char mapped type
typedef std::pair<char,value_t> char_pair_t;
/// Definition of the unsigned char mapped type
typedef std::pair<unsigned char,value_t> uchar_pair_t;
/// Definition of the short integer mapped type
typedef std::pair<short,value_t> short_pair_t;
/// Definition of the unsigned short integer mapped type
Expand All @@ -226,6 +232,10 @@ namespace dd4hep {
/// Definition of the unsigned long integer mapped type
typedef std::pair<unsigned long,value_t> ulong_pair_t;
/// Definition of the size_t mapped type
typedef std::pair<float,value_t> float_pair_t;
/// Definition of the size_t mapped type
typedef std::pair<double,value_t> double_pair_t;
/// Definition of the size_t mapped type
typedef std::pair<size_t,value_t> size_pair_t;
/// Definition of the string mapped type
typedef std::pair<std::string,value_t> string_pair_t;
Expand Down
14 changes: 13 additions & 1 deletion DDCore/include/Parsers/Printout.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ namespace dd4hep {
WARNING = 4,
ERROR = 5,
FATAL = 6,
ALWAYS = 7
ALWAYS = 7,

/// Forced printout levels if the output level is handled
/// e.g. by a Geant4Action or DigiAction. These always pass
/// The default DD4hep print level restrictions.
FORCE_LEVEL = 0x10,
FORCE_VERBOSE = FORCE_LEVEL + 1,
FORCE_DEBUG = FORCE_LEVEL + 2,
FORCE_INFO = FORCE_LEVEL + 3,
FORCE_WARNING = FORCE_LEVEL + 4,
FORCE_ERROR = FORCE_LEVEL + 5,
FORCE_FATAL = FORCE_LEVEL + 6,
FORCE_ALWAYS = FORCE_LEVEL + 7
};

#ifndef __CINT__
Expand Down
11 changes: 10 additions & 1 deletion DDCore/python/dd4hep_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ def unicode_2_string(value):


OutputLevel = _Levels()
VERBOSE = OutputLevel.VERBOSE
DEBUG = OutputLevel.DEBUG
INFO = OutputLevel.INFO
WARNING = OutputLevel.WARNING
ERROR = OutputLevel.ERROR
FATAL = OutputLevel.FATAL


# ------------------------Generic STL stuff can be accessed using std: -----
#
# -- e.g. Create an instance of std::vector<dd4hep::sim::Geant4Vertex*>:
Expand All @@ -149,7 +157,8 @@ def unicode_2_string(value):
import_namespace_item('core', 'run_interpreter')
#
import_namespace_item('detail', 'interp')
import_namespace_item('detail', 'eval')
# No: This inhibits the usage of native python eval!
# import_namespace_item('detail', 'eval')

# ---------------------------------------------------------------------------
# def run_interpreter(name): detail.interp.run(name)
Expand Down
Loading