Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:05

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DDCOND_CONDITIONSSELECTORS_H
0014 #define DDCOND_CONDITIONSSELECTORS_H
0015 
0016 // Framework include files
0017 #include "DD4hep/Conditions.h"
0018 #include "DD4hep/detail/ConditionsInterna.h"
0019 
0020 /// Namespace for the AIDA detector description toolkit
0021 namespace dd4hep {
0022 
0023   /// Namespace for implementation details of the AIDA detector description toolkit
0024   namespace cond {
0025 
0026     /// Namespace for condition operators to avoid clashes
0027     namespace Operators {
0028 
0029       /// Definition of the selector object base class to cover type definitions
0030       /**
0031        *  \author  M.Frank
0032        *  \version 1.0
0033        *  \ingroup DD4HEP_CONDITIONS
0034        */
0035       class Cond__Oper {
0036       public:
0037         typedef Condition cond_t;
0038         typedef Condition::Object object_t;
0039         typedef std::pair<const Condition::key_type,Condition> mapentry_t;
0040         typedef std::pair<const Condition::key_type,object_t*> ptr_mapentry_t;
0041       };
0042 
0043       /// Sequential container select operator for conditions mappings
0044       /**
0045        *  \author  M.Frank
0046        *  \version 1.0
0047        *  \ingroup DD4HEP_CONDITIONS
0048        */
0049       template <typename T> struct SequenceSelect : public Cond__Oper  {
0050         T& mapping;
0051         SequenceSelect(T& o) : mapping(o) {                                            }
0052         bool operator()(Condition::Object* o)  const
0053         { mapping.emplace(mapping.end(), o); return true;                              }
0054       };
0055 
0056       /// Mapped container selection operator for conditions mappings
0057       /**
0058        *  \author  M.Frank
0059        *  \version 1.0
0060        *  \ingroup DD4HEP_CONDITIONS
0061        */
0062      template <typename T> struct MapSelect : public Cond__Oper   {
0063         T& mapping;
0064         MapSelect(T& o) : mapping(o) {                                               }
0065         bool operator()(Condition::Object* o)  const
0066         { return mapping.emplace(o->hash,o).second;                                  }
0067       };
0068 
0069       /// Helper to collect conditions using a ConditionsSelect base class
0070       /** 
0071        *  \author  M.Frank
0072        *  \version 1.0
0073        *  \ingroup DD4HEP_CONDITIONS
0074        */
0075       template <typename T> struct MapConditionsSelect : public ConditionsSelect  {
0076         T& mapping;
0077         MapConditionsSelect(T& o) : mapping(o) {                                     }
0078         virtual bool operator()(Condition::Object* o)  const
0079         { return mapping.emplace(o->hash,o).second;                                  }
0080         virtual size_t size() const  { return mapping.size();                        }
0081       };
0082       
0083       /// Helper to insert objects into a conditions pool
0084       /** 
0085        *  \author  M.Frank
0086        *  \version 1.0
0087        *  \ingroup DD4HEP_CONDITIONS
0088        */
0089       template <typename T> struct PoolSelect : public Cond__Oper  {
0090         T& pool;
0091         PoolSelect(T& o) : pool(o)                           {                         }
0092         bool operator()(Condition::Object* o)  const         { return pool.insert(o);  }
0093       };
0094 
0095       /// Helper to remove objects from a conditions pool. The removed condition is deleted.
0096       /** 
0097        *  \author  M.Frank
0098        *  \version 1.0
0099        *  \ingroup DD4HEP_CONDITIONS
0100        */
0101       template <typename T> struct PoolRemove : public Cond__Oper  {
0102         T& pool;
0103         PoolRemove(T& o) : pool(o)         {                                           }
0104         bool operator()(object_t* o) const { pool.onRemove(o); delete(o); return true; }
0105       };
0106     
0107       /// Container select operator for conditions mappings with conditions flagged active
0108       /**
0109        *  \author  M.Frank
0110        *  \version 1.0
0111        *  \ingroup DD4HEP_CONDITIONS
0112        */
0113       template <typename T> struct ActiveSelect : public Cond__Oper {
0114       public:
0115         T& collection;
0116         ActiveSelect(T& p) : collection(p) {}
0117         bool operator()(object_t* o)  const   {
0118           if ( (o->flags & Condition::ACTIVE) )  {
0119             collection.emplace(collection.end(),o);
0120             return true;
0121           }
0122           return false;
0123         }
0124       };
0125 
0126       /// Helper to select keyed objects from a conditions pool
0127       /** 
0128        *  \author  M.Frank
0129        *  \version 1.0
0130        *  \ingroup DD4HEP_CONDITIONS
0131        */
0132       template<typename collection_type> class KeyedSelect : public Cond__Oper  {
0133         cond_t::key_type key;
0134         collection_type& collection;
0135       public:
0136         KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) {  }
0137         bool operator()(object_t* o) const {
0138           if ( o->hash == key )  {
0139             collection.emplace(collection.end(),o);
0140             return true;
0141           }
0142           return false;
0143         }
0144       };
0145 
0146       /// Helper to select condition objects by hash key from a conditions pool
0147       /** 
0148        *  \author  M.Frank
0149        *  \version 1.0
0150        *  \ingroup DD4HEP_CONDITIONS
0151        */
0152       class KeyFind : public Cond__Oper  {
0153         cond_t::key_type hash;
0154       public:
0155         KeyFind(cond_t::key_type h) : hash(h)  {                   }
0156         bool operator()(const object_t* o) const       {  return o->hash == hash;      }
0157       };
0158 
0159       /// Helper to wrap another object and make it copyable
0160       /** 
0161        *  \author  M.Frank
0162        *  \version 1.0
0163        *  \ingroup DD4HEP_CONDITIONS
0164        */
0165       template <typename OPER> class OperatorWrapper : public Cond__Oper  {
0166       public:
0167         typedef OPER operator_t;
0168         typedef OperatorWrapper<operator_t> wrapper_t;
0169         operator_t& oper;
0170       public:
0171         OperatorWrapper(operator_t& o) : oper(o)       {                               }
0172         bool operator()(object_t* o) const             { return oper(o);               }
0173         bool operator()(const cond_t& o) const         { return oper(o.ptr());         }
0174         bool operator()(const mapentry_t& o) const     { return oper(o.second.ptr());  }
0175         bool operator()(const ptr_mapentry_t& o) const { return oper(o.second);        }
0176       };
0177 
0178       /// Arbitrary wrapper for user defined conditions operators
0179       /** 
0180        *  \author  M.Frank
0181        *  \version 1.0
0182        *  \ingroup DD4HEP_CONDITIONS
0183        */
0184       template <typename OPER> class ConditionsOperation : public Cond__Oper  {
0185       public:
0186         typedef OPER operator_t;
0187         typedef ConditionsOperation<operator_t> wrapper_t;
0188         operator_t oper;
0189       public:
0190         ConditionsOperation(const operator_t& o) : oper(o)     {                       }
0191         bool operator()(object_t* o) const             { return oper(o);               }
0192         bool operator()(const cond_t& o) const         { return oper(o.ptr());         }
0193         bool operator()(const mapentry_t& o) const     { return oper(o.second.ptr());  }
0194         bool operator()(const ptr_mapentry_t& o) const { return oper(o.second);        }
0195       };
0196     
0197       /// Helper function to create a OperatorWrapper<T> object from the argument type
0198       /** 
0199        *  \author  M.Frank
0200        *  \version 1.0
0201        *  \ingroup DD4HEP_CONDITIONS
0202        */
0203       template <typename oper_type> OperatorWrapper<oper_type> operatorWrapper(oper_type& oper) {
0204         return OperatorWrapper<oper_type>(oper);
0205       }
0206 
0207       /// Helper to create functor to remove objects from a conditions pool
0208       /** 
0209        *  \author  M.Frank
0210        *  \version 1.0
0211        *  \ingroup DD4HEP_CONDITIONS
0212        */
0213       template <typename P> inline ConditionsOperation<PoolRemove<P> > poolRemove(P& pool)
0214       { return ConditionsOperation<PoolRemove<P> >(PoolRemove<P>(pool));  }
0215 
0216       /// Helper to create functor to insert objects into a conditions pool
0217       /** 
0218        *  \author  M.Frank
0219        *  \version 1.0
0220        *  \ingroup DD4HEP_CONDITIONS
0221        */
0222       template <typename P> inline ConditionsOperation<PoolSelect<P> > poolSelect(P& pool)
0223       { return ConditionsOperation<PoolSelect<P> >(PoolSelect<P>(pool));  }
0224 
0225       /// Helper to create functor to collect conditions using a ConditionsSelect base class
0226       /** 
0227        *  \author  M.Frank
0228        *  \version 1.0
0229        *  \ingroup DD4HEP_CONDITIONS
0230        */
0231       template <typename T> inline MapConditionsSelect<T> mapConditionsSelect(T& collection)
0232       {  return MapConditionsSelect<T>(collection);      }
0233 
0234       /// Helper to create functor to select objects from a conditions pool into a sequential container
0235       /** 
0236        *  \author  M.Frank
0237        *  \version 1.0
0238        *  \ingroup DD4HEP_CONDITIONS
0239        */
0240       template <typename C> inline 
0241       ConditionsOperation<SequenceSelect<C> > sequenceSelect(C& coll) {
0242         typedef SequenceSelect<C> operator_t;
0243         return ConditionsOperation<operator_t>(operator_t(coll));
0244       }
0245 
0246       /// Helper to create functor to select objects from a conditions pool into a mapped container
0247       /** 
0248        *  \author  M.Frank
0249        *  \version 1.0
0250        *  \ingroup DD4HEP_CONDITIONS
0251        */
0252       template <typename C> inline 
0253       ConditionsOperation<SequenceSelect<C> > mapSelect(C& coll) {
0254         typedef MapSelect<C> operator_t;
0255         return ConditionsOperation<operator_t>(operator_t(coll));
0256       }
0257 
0258       /// Helper to select active objects from a conditions pool
0259       /** 
0260        *  \author  M.Frank
0261        *  \version 1.0
0262        *  \ingroup DD4HEP_CONDITIONS
0263        */
0264       template <typename C> inline ConditionsOperation<ActiveSelect<C> > activeSelect(C& coll)
0265       { return ConditionsOperation<ActiveSelect<C> >(ActiveSelect<C>(coll)); }
0266 
0267       /// Helper to create functor to select keyed objects from a conditions pool
0268       /** 
0269        *  \author  M.Frank
0270        *  \version 1.0
0271        *  \ingroup DD4HEP_CONDITIONS
0272        */
0273       template <typename C> inline 
0274       ConditionsOperation<KeyedSelect<C> > keyedSelect(Condition::key_type key, C& coll)
0275       { return ConditionsOperation<KeyedSelect<C> >(KeyedSelect<C>(key, coll)); }
0276 
0277       /// Helper to create functor to find conditions objects by hash key
0278       /** 
0279        *  \author  M.Frank
0280        *  \version 1.0
0281        *  \ingroup DD4HEP_CONDITIONS
0282        */
0283       ConditionsOperation<KeyFind> inline  keyFind(Condition::key_type key)
0284       { return ConditionsOperation<KeyFind>(KeyFind(key)); }
0285 
0286     }        /* End namespace Operators            */
0287   }          /* End namespace cond           */
0288 }            /* End namespace dd4hep               */
0289 #endif // DDCOND_CONDITIONSSELECTORS_H