Back to home page

EIC code displayed by LXR

 
 

    


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

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 DD4HEP_CONDITIONSPROCESSOR_H
0014 #define DD4HEP_CONDITIONSPROCESSOR_H
0015 
0016 // Framework include files
0017 #include <DD4hep/DetElement.h>
0018 #include <DD4hep/Conditions.h>
0019 #include <DD4hep/ConditionsMap.h>
0020 
0021 // C/C++ include files
0022 #include <memory>
0023 
0024 /// Namespace for the AIDA detector description toolkit
0025 namespace dd4hep {
0026 
0027   /// Namespace for the conditions part of the AIDA detector description toolkit
0028   namespace cond   {
0029 
0030 
0031     /// Generic condition processor facade for the Conditons::Processor object
0032     /**
0033      *  This wrapper converts any object, which has the signature
0034      *  int operator()(Condition cond) const
0035      *  The object is automatically wrapped to a Condition::Processor object
0036      *  and allows to scan trees using e.g. DetElementProcessors etc.
0037      *  
0038      *  \author  M.Frank
0039      *  \version 1.0
0040      *  \date    01/04/2016
0041      */
0042     template <typename T> class ConditionsProcessor : public Condition::Processor  {
0043       /// Reference to the actual processor
0044       T& processor;
0045     public:
0046       /// Default constructor
0047       ConditionsProcessor() = delete;
0048       /// Initializing constructor
0049       ConditionsProcessor(T& p) : processor(p) {}
0050       /// This move constructor is disabled to void temporary references.
0051       ConditionsProcessor(T&& p) = delete;
0052       /// R-value copy from a temporary copy (Since processor is reference)
0053       ConditionsProcessor(ConditionsProcessor&& copy) = default;
0054       /// Copy constructor
0055       ConditionsProcessor(const ConditionsProcessor& copy) = default;
0056       /// Default destructor
0057       virtual ~ConditionsProcessor() = default;
0058       /// Assignment operator
0059       ConditionsProcessor& operator=(const ConditionsProcessor& copy) = default;
0060       /// Processing callback
0061       virtual int process(Condition condition)  const override  {
0062         return (processor)(condition);
0063       }
0064     };
0065     /// Creator utility function for ConditionsProcessor objects
0066     template <typename T> inline
0067     ConditionsProcessor<typename std::remove_reference<T>::type> conditionsProcessor(T&& obj)
0068     { return ConditionsProcessor<typename std::remove_reference<T>::type>(obj);   }
0069 
0070     /// Generic condition processor facade for the Conditons::Processor object
0071     /**
0072      *  This wrapper converts any object, which has the signature
0073      *  int operator()(Condition cond) const
0074      *  The object is automatically wrapped to a Condition::Processor object
0075      *  and allows to scan trees using e.g. DetElementProcessors etc.
0076      *
0077      *  
0078      *  \author  M.Frank
0079      *  \version 1.0
0080      *  \date    01/04/2016
0081      */
0082     template <typename T> class ConditionsProcessorWrapper : public Condition::Processor  {
0083       std::unique_ptr<T> processor;
0084     public:
0085       /// Default constructor
0086       ConditionsProcessorWrapper() = default;
0087       /// Initializing constructor
0088       ConditionsProcessorWrapper(T* p) : processor(p) {}
0089       /// Copy constructor
0090       ConditionsProcessorWrapper(const ConditionsProcessorWrapper& copy) = delete;
0091       /// Default destructor
0092       virtual ~ConditionsProcessorWrapper() = default;
0093       /// Assignment operator
0094       ConditionsProcessorWrapper& operator=(const ConditionsProcessorWrapper& copy) = delete;
0095       /// Processing callback
0096       virtual int process(Condition c)  const override  {
0097         return (*(processor.get()))(c);
0098       }
0099     };
0100     /// Creator utility function for ConditionsProcessorWrapper objects
0101     template <typename T> inline ConditionsProcessorWrapper<T>* createProcessorWrapper(T* obj)  {
0102       return new ConditionsProcessorWrapper<T>(obj);
0103     }
0104     /// Creator utility function for ConditionsProcessorWrapper objects
0105     template <typename T> inline ConditionsProcessorWrapper<T> processorWrapper(T* obj)  {
0106       return ConditionsProcessorWrapper<T>(obj);
0107     }
0108 
0109     /// Generic condition collector keyed by detector elements
0110     /**
0111      *   To be used with utilities like DetElementProcessor etc.
0112      *
0113      *  
0114      *  \author  M.Frank
0115      *  \version 1.0
0116      *  \date    01/04/2016
0117      */
0118     template <typename T> class ConditionsCollector  {
0119     public:
0120       /// Reference to the user pool
0121       ConditionsMap& mapping;
0122       /// Collection container
0123       T&             conditions;
0124     public:
0125       /// Default constructor
0126       ConditionsCollector(ConditionsMap& m, T& d) : mapping(m), conditions(d) {}
0127       /// Default move constructor is disabled
0128       ConditionsCollector(ConditionsMap& m, T&& p) = delete;
0129       /// R-value copy from a temporary
0130       ConditionsCollector(ConditionsCollector&& copy) = default;
0131       /// Copy constructor
0132       ConditionsCollector(const ConditionsCollector& copy) = default;
0133       /// Default destructor
0134       ~ConditionsCollector() = default;
0135       /// Assignment operator
0136       ConditionsCollector& operator=(const ConditionsCollector& copy) = default;
0137       /// Callback to output conditions information
0138       /** Note: Valid implementations exist for the container types:
0139        *        std::list<Condition>
0140        *        std::vector<Condition>
0141        *        std::map<DetElement,Condition>
0142        *        std::multimap<DetElement,Condition>
0143        *        std::map<std::string,Condition>        key = DetElement.path()
0144        *        std::multimap<std::string,Condition>   key = DetElement.path()
0145        */
0146       virtual int operator()(DetElement de, int level=0)  const final;
0147     };
0148     /// Creator utility function for ConditionsCollector objects
0149     template <typename T> inline
0150     ConditionsCollector<typename std::remove_reference<T>::type> conditionsCollector(ConditionsMap& m, T&& conditions)
0151     {  return ConditionsCollector<typename std::remove_reference<T>::type>(m, conditions); }
0152     
0153 
0154   }       /* End namespace cond               */
0155 }         /* End namespace dd4hep                   */
0156 #endif // DD4HEP_CONDITIONSPROCESSOR_H