13 #ifndef DD4HEP_DD4HEP_PRIMITIVES_H
14 #define DD4HEP_DD4HEP_PRIMITIVES_H
30 namespace DDSegmentation {
34 typedef long long int CellID;
39 inline unsigned int hash32(
const char* key) {
40 unsigned int hash = 0;
48 hash ^= (hash >> 11); hash += (hash << 15);
51 inline unsigned int hash32(
const std::string& key) {
52 return hash32(key.c_str());
56 long int makeTime(
int year,
int month,
int day,
57 int hour=0,
int minutes=0,
int seconds=0);
60 long int makeTime(
const std::string& date,
const char* fmt=
"%d-%m-%Y %H:%M:%S");
78 std::string
typeName(
const std::type_info& type);
80 void typeinfoCheck(
const std::type_info& typ1,
const std::type_info& typ2,
const std::string& text =
"");
143 typedef std::numeric_limits<value_t>
limits;
171 typedef void* (*cast_t)(
const void*);
173 const std::type_info*
type;
188 template <
typename TYPE>
static void _destroy(
void* p) {
192 template <
typename TYPE>
static void*
_cast(
const void* p) {
194 q =
dynamic_cast<TYPE*
>(q);
198 static ComponentCast c(
typeid(TYPE),_destroy<TYPE>,_cast<TYPE>);
215 typedef DDSegmentation::BitField64 BitField64;
216 typedef DDSegmentation::BitFieldValue BitFieldValue;
220 using DDSegmentation::BitField64;
221 using DDSegmentation::BitFieldValue;
225 template <
typename T>
inline void copyObject(
void* target,
const void* source) {
226 const T*
s = (
const T*)source;
286 void operator()(std::pair<typename M::key_type, typename M::mapped_type> p)
const
289 if ( !
object.empty() ) for_each(
object.begin(),
object.end(),(*
this));
303 void operator()(std::pair<typename M::key_type, typename M::mapped_type> p)
const
306 if ( !
object.empty() ) for_each(
object.begin(),
object.end(),(*
this));
334 void operator()(std::pair<typename M::key_type, typename M::mapped_type> p)
const
337 if ( !
object.empty() ) for_each(
object.begin(),
object.end(),(*
this));
356 if ( p ) p->addRef();
393 template <
typename R,
typename T,
typename A1,
typename A2>
struct ApplyMemFunc2 {
429 template <
typename C,
typename R,
typename T>
433 template <
typename C,
typename R,
typename T>
435 { std::for_each(
object.begin(),
object.end(),ApplyMemFuncConst<R,T>(pmf)); }
437 template <
typename C,
typename R,
typename T,
typename A1>
441 template <
typename C,
typename R,
typename T,
typename A1>
443 { std::for_each(
object.begin(),
object.end(),ApplyMemFuncConst1<R,T,A1>(pmf,a1)); }
446 template <
typename C,
typename R,
typename T,
typename A1,
typename A2>
450 template <
typename C,
typename R,
typename T,
typename A1,
typename A2>
452 { std::for_each(
object.begin(),
object.end(),ApplyMemFuncConst2<R,T,A1,A2>(pmf,a1,a2)); }
460 void operator()(std::pair<typename M::key_type const, typename M::mapped_type>& p)
const
462 void operator()(
const std::pair<typename M::key_type const, typename M::mapped_type>& p)
const
469 template <
typename C,
typename FCN>
void apply1rst(C&
object,
const FCN& func)
472 template <
typename C,
typename R,
typename T>
476 template <
typename C,
typename R,
typename T,
typename A1>
480 template <
typename C,
typename R,
typename T>
481 void apply1rst(C&
object, R (
T::*pmf)()
const)
482 { std::for_each(
object.begin(),
object.end(),
apply__1rst_value(
object,ApplyMemFuncConst<R,T>(pmf))); }
484 template <
typename C,
typename R,
typename T,
typename A1>
485 void apply1rst(C
object, R (
T::*pmf)(A1 a1)
const, A1 a1)
486 { std::for_each(
object.begin(),
object.end(),
apply__1rst_value(
object,ApplyMemFuncConst1<R,T,A1>(pmf,a1))); }
489 template <
typename M,
typename FCN>
class Apply2nd {
493 void operator()(std::pair<typename M::key_type const, typename M::mapped_type>& p)
const
494 { (
func)(p.second); }
495 void operator()(
const std::pair<typename M::key_type const, typename M::mapped_type>& p)
const
496 { (
func)(p.second); }
502 template <
typename C,
typename FCN>
void apply2nd(C&
object,
const FCN& func)
503 { std::for_each(
object.begin(),
object.end(),
apply__2nd_value(
object,func)); }
505 template <
typename C,
typename R,
typename T>
509 template <
typename C,
typename R,
typename T,
typename A1>
513 template <
typename C,
typename R,
typename T>
514 void apply2nd(C&
object, R (
T::*pmf)()
const)
515 { std::for_each(
object.begin(),
object.end(),
apply__2nd_value(
object,ApplyMemFuncConst<R,T>(pmf))); }
517 template <
typename C,
typename R,
typename T,
typename A1>
518 void apply2nd(C
object, R (
T::*pmf)(A1 a1)
const, A1 a1)
519 { std::for_each(
object.begin(),
object.end(),
apply__2nd_value(
object,ApplyMemFuncConst1<R,T,A1>(pmf,a1))); }
545 return (
mask&m) ==
m;
548 return (
mask&m) != 0;
570 #endif // DD4HEP_DD4HEP_PRIMITIVES_H
std::pair< std::string, value_t > string_pair_t
Definition of the string mapped type.
invalid_handle_exception(const invalid_handle_exception &e)
Generic copy constructor.
void operator()(std::pair< typename M::key_type const, typename M::mapped_type > &p) const
Member function call-functor with 2 arguments (const version)
long long int CellID
Useful typedefs to differentiate cell IDs and volume IDs.
R(T::* memfunc_t)(A1 a1) const
std::pair< unsigned long, value_t > ulong_pair_t
Definition of the unsigned long integer mapped type.
ApplyMemFuncConst2(memfunc_t f, A1 &a1, A2 &a2)
R(T::* memfunc_t)(A1 a1, A2 a2)
void deletePtr(T *&p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
void deleteObject(T *p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
void operator()(T *p) const
const result_t & operator()(const arg_t &p) const
Operator function.
void notImplemented(const std::string &msg)
Throw exception when handles are check for validity.
map Functor to delete objects from heap
Functor to release objects from heap and reset the pointer.
void operator()(T &p) const
Generic map Functor to act on first element (key)
void operator()(const T *p) const
static const char * format()
Access to the specific printf format. May be overloaded by users.
ReleaseObject< typename M::value_type > releaseObject(M &)
static void * _cast(const void *p)
Operator to select second element of a pair.
invalid_handle_exception(const std::string &msg)
Initializing constructor.
void apply2nd(C &object, const FCN &func)
const result_t & operator()(const arg_t &p) const
Operator function.
Select2nd< typename T::value_type > select2nd(const T &)
Generator to create Operator to select value elements of a map.
std::map< std::string, value_t > string_map_t
Definition of the string mapped type.
std::string typeName(const std::type_info &type)
ABI information about type names.
static const std::type_info & type()
Access to the RTTI data type.
Member function call-functor with 1 argument (const version)
void(* destroy_t)(void *)
void operator()(T *p) const
ApplyMemFunc2(memfunc_t f, A1 &a1, A2 &a2)
static void _destroy(void *p)
void operator()(std::pair< typename M::key_type, typename M::mapped_type > p) const
std::pair< unsigned int, value_t > uint_pair_t
Definition of the unsigned integer mapped type.
Generic map Functor to act on second element (mapped type)
Data structure to manipulate a bitmask held by reference and represented by an integer.
std::map< unsigned short, value_t > ushort_map_t
Definition of the unsigned short integer mapped type.
ApplyMemFunc1(memfunc_t f, A1 &a1)
void operator()(const T *p) const
ReferenceObject< M > referenceObject(M &)
std::map< int, value_t > int_map_t
Definition of the integer mapped type.
Apply1rst< C, FCN > apply__1rst_value(C &, const FCN &func)
void operator()(const std::pair< typename M::key_type const, typename M::mapped_type > &p) const
void releasePtr(T &p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Functor to delete objects from heap and reset the pointer.
DestroyObjects< M > destroy2nd(M &m)
virtual ~ComponentCast()
Defautl destructor.
std::vector< value_t > vector_t
Definition of the vector type.
Functor to delete objects from heap and reset the pointer.
void operator()(T *p) const
static const char * default_format()
Access to default printf format.
ApplyMemFuncConst1(memfunc_t f, A1 &a1)
void invalidHandleAssignmentError(const std::type_info &from, const std::type_info &to)
Throw exception when handles are badly assigned.
bool anySet(const T &m) const
void copyObject(void *target, const void *source)
Helper to copy objects.
T value_t
Type decribed by th class.
void destroyObjects(M &m)
Member function call-functor with no arguments (const version)
std::map< size_t, value_t > size_map_t
Definition of the size_t mapped type.
void * apply_dynCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
Select1st< typename T::value_type > select1st(const T &)
Generator to create Operator to select key values of a map.
void * apply_downCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
Specialized exception to be thrown if invalid handles are accessed.
std::map< short, value_t > short_map_t
Definition of the short integer mapped type.
std::numeric_limits< value_t > limits
Definition of the limits.
void releaseObjects(M &m)
unsigned int hash(unsigned int initialSeed, unsigned int eventNumber, unsigned int runNumber)
calculate hash from initialSeed, eventID and runID
const std::type_info & type
A bit of support for printing primitives.
void *(* cast_t)(const void *)
std::pair< long, value_t > long_pair_t
Definition of the long integer mapped type.
Member function call-functor with 1 argument.
Functor to delete objects from heap and reset the pointer.
Map Functor to release objects from heap.
Class to perform dynamic casts using unknown pointers.
R(T::* memfunc_t)() const
void apply1rst(C &object, const FCN &func)
long int makeTime(int year, int month, int day, int hour=0, int minutes=0, int seconds=0)
Convert date into epoch time (seconds since 1970)
std::pair< int, value_t > int_pair_t
Definition of the integer mapped type.
result_t operator()(const M &p) const
unsigned int hash32(const char *key)
We need it so often: one-at-time 32 bit hash function.
std::pair< size_t, value_t > size_pair_t
Definition of the size_t mapped type.
R(T::* memfunc_t)(A1 a1, A2 a2) const
void destroyObject(T *&p)
Helper to delete objects from heap and reset the pointer.
Member function call-functor with no arguments.
static ComponentCast & instance()
std::pair< unsigned short, value_t > ushort_pair_t
Definition of the unsigned short integer mapped type.
invalid_handle_exception(const std::exception &e)
Generic copy constructor.
ComponentCast(const std::type_info &t, destroy_t d, cast_t c)
Initializing Constructor.
std::map< long, value_t > long_map_t
Definition of the long integer mapped type.
ApplyMemFuncConst(memfunc_t f)
void operator()(std::pair< typename M::key_type, typename M::mapped_type > p) const
std::map< unsigned long, value_t > ulong_map_t
Definition of the unsigned long integer mapped type.
void operator()(const std::pair< typename M::key_type const, typename M::mapped_type > &p) const
void invalidHandleError(const std::type_info &type)
Throw exception when handles are check for validity.
void operator()(const T *p) const
void * apply_upCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
Member function call-functor with 2 arguments.
static std::string toString(T value)
Auto conversion to string using the default format.
void destructObject(T *p)
Helper to destruct objects. Note: The memory is NOT released!
T & mask
Reference to the data.
Operator to select the first element of a pair.
void typeinfoCheck(const std::type_info &typ1, const std::type_info &typ2, const std::string &text="")
Check type infos for equivalence (dynamic casts) using ABI information.
std::map< unsigned int, value_t > uint_map_t
Definition of the unsigned integer mapped type.
std::pair< short, value_t > short_pair_t
Definition of the short integer mapped type.
virtual ~invalid_handle_exception()=default
Default destructor of specialized exception.
map Functor to delete objects from heap
bool isSet(const T &m) const
bool testBit(int bit) const
void operator()(T &p) const
void call_member_func(C &object, R(T::*pmf)())
ReferenceBitMask(T &m)
Standard constructor.
void operator()(std::pair< typename M::key_type const, typename M::mapped_type > &p) const
ApplyMemFunc(memfunc_t f)
invalid_handle_exception(const char *msg)
Initializing constructor.
ReferenceObjects< typename M::value_type > reference2nd(M &)
void operator()(std::pair< typename M::key_type, typename M::mapped_type > p) const
Apply2nd< C, FCN > apply__2nd_value(C &, const FCN &func)
static std::string type_name()
Access to the RTTI data type.