Back to home page

EIC code displayed by LXR

 
 

    


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

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_VOLUMEPROCESSOR_H
0014 #define DD4HEP_VOLUMEPROCESSOR_H
0015 
0016 // Framework includes
0017 #include <DD4hep/DetElement.h>
0018 #include <DD4hep/Volumes.h>
0019 
0020 // C/C++ include files
0021 #include <memory>
0022 
0023 /// Namespace for the AIDA detector description toolkit
0024 namespace dd4hep {
0025 
0026   /// Generic PlacedVolume processor
0027   /**
0028    *   Please note that the principle of locality applies:
0029    *   The object is designed for stack allocation and configuration.
0030    *   It may NOT be shared across threads!
0031    *
0032    *   \author  M.Frank
0033    *   \version 1.0
0034    *   \date    31/05/2017
0035    *   \ingroup DD4HEP_CORE
0036    */
0037   class PlacedVolumeProcessor {
0038   public:
0039     /// Initializing constructor
0040     PlacedVolumeProcessor() = default;
0041     /// R-value copy from a temporary (Since processor is reference)
0042     PlacedVolumeProcessor(PlacedVolumeProcessor&& copy) = default;
0043     /// Default copy constructor
0044     PlacedVolumeProcessor(const PlacedVolumeProcessor& copy) = default;
0045     /// Default destructor
0046     virtual ~PlacedVolumeProcessor() noexcept(false);
0047     /// Default assignment
0048     PlacedVolumeProcessor& operator=(const PlacedVolumeProcessor& copy) = default;
0049     /// Callback to output PlacedVolume information of an single Placement
0050     virtual int operator()(PlacedVolume pv, int level) = 0;
0051     /// Callback to output PlacedVolume information of an entire Placement
0052     virtual int process(PlacedVolume pv, int level, bool recursive);
0053   };
0054 
0055   /// PlacedVolume scanner using a Processor object
0056   /**
0057    *   Please see the documentation of the
0058    *   PlacedVolumeProcessor base class for further information.
0059    *   The only requirement to the object is to fullfill the callback signature.
0060    *
0061    *   \author  M.Frank
0062    *   \version 1.0
0063    *   \date    31/05/2017
0064    *   \ingroup DD4HEP_CORE
0065    */
0066   template <typename T> class PlacementProcessor : virtual public PlacedVolumeProcessor  {
0067   public:
0068     /// Reference to execution object implementing operator()(PlacedVolume pv, int level)
0069     T& processor;
0070   public:
0071     /// Default constructor
0072     PlacementProcessor() = delete;
0073     /// Default constructor
0074     PlacementProcessor(T& p) : processor(p) {}
0075     /// Default move constructor is disabled
0076     PlacementProcessor(T&& p) = delete;
0077     /// R-value copy from a temporary (Since processor is reference)
0078     PlacementProcessor(PlacementProcessor&& copy) = default;
0079     /// Default copy constructor
0080     PlacementProcessor(const PlacementProcessor& copy) = default;
0081     /// Default destructor
0082     virtual ~PlacementProcessor() = default;
0083     /// Default assignment
0084     PlacementProcessor& operator=(const PlacementProcessor& copy) = default;
0085     /// Callback to output detector information of an single placement
0086     virtual int operator()(PlacedVolume pv, int level)  final
0087     {   return (processor)(pv, level);         }
0088   };
0089 
0090   /// Instantiation helper
0091   template <typename T> inline
0092   PlacementProcessor<typename std::remove_reference<T>::type> placementProcessor(T&& proc)
0093   { return PlacementProcessor<typename std::remove_reference<T>::type>(std::forward<T>(proc)); }
0094 
0095   /// Wrapper to call objects in the form of a PlacedVolume processor.
0096   /**
0097    *   \author  M.Frank
0098    *   \version 1.0
0099    *   \date    31/05/2017
0100    *   \ingroup DD4HEP_CORE
0101    */
0102   template <typename T> class PlacementProcessorShared : public PlacedVolumeProcessor {
0103   public:
0104     /// Reference to execution object implementing operator()(PlacedVolume pv, int level)
0105     std::shared_ptr<T> processor;
0106   public:
0107     /// Default constructor
0108     PlacementProcessorShared() = delete;
0109     /// Default constructor
0110     PlacementProcessorShared(std::shared_ptr<T>& p) : processor(p) {}
0111     /// Default copy constructor
0112     PlacementProcessorShared(const PlacementProcessorShared& copy) = default;
0113     /// Default destructor
0114     virtual ~PlacementProcessorShared() = default;
0115     /// Default assignment
0116     PlacementProcessorShared& operator=(const PlacementProcessorShared& copy) = default;
0117     /// Callback to output detector information of an single DetElement
0118     virtual int operator()(PlacedVolume pv, int level)  final
0119     {  return (*processor)(pv, level);                 }
0120   };
0121 
0122   /// Helper to run placement scan through volume hierarchies scans
0123   /**
0124    *   This wrapper converts any object, which has the signature
0125    *   int operator()(DetElement de, int level) const
0126    *   The object is automatically wrapped to a PlacedVolumeProcessor
0127    *   and the PlacedVolume tree is scanned depending on the scanning
0128    *   arguments.
0129    *  
0130    *   \author  M.Frank
0131    *   \version 1.0
0132    *   \date    01/04/2016
0133    *   \ingroup DD4HEP_CORE
0134    */
0135   class PlacedVolumeScanner  {
0136   public:
0137     /// Default constructor
0138     PlacedVolumeScanner() = default;
0139     /// Copy constructor
0140     PlacedVolumeScanner(const PlacedVolumeScanner& copy) = default;
0141     /// Assignment operator
0142     PlacedVolumeScanner& operator=(const PlacedVolumeScanner& copy) = default;
0143 
0144     /// Constructor performing the scan internally
0145     template <typename Q>
0146     PlacedVolumeScanner(Q& proc, DetElement start, int level=0, bool recursive=true)
0147     {  scan(proc, start.placement(), level, recursive);     }
0148 
0149     /// Constructor performing the scan internally
0150     template <typename Q>
0151     PlacedVolumeScanner(const Q& proc, DetElement start, int level=0, bool recursive=true)
0152     {  scan(proc, start.placement(), level, recursive);     }
0153 
0154     /// Constructor performing the scan internally
0155     template <typename Q>
0156     PlacedVolumeScanner(Q& proc, PlacedVolume start, int level=0, bool recursive=true)
0157     {  scan(proc, start, level, recursive);     }
0158 
0159     /// Constructor performing the scan internally
0160     template <typename Q>
0161     PlacedVolumeScanner(const Q& proc, PlacedVolume start, int level=0, bool recursive=true)
0162     {  scan(proc, start, level, recursive);     }
0163 
0164     /// PlacedVolume element tree scanner using wrapped PlacedVolumeProcessor objects
0165     int scanPlacements(PlacedVolumeProcessor& proc, PlacedVolume start, int level=0, bool recursive=true)  const {
0166       return proc.process(start, level, recursive);
0167     }
0168     /// PlacedVolume element tree scanner using wrapped PlacedVolumeProcessor objects
0169     template <typename Q>
0170     int scan(Q& p, PlacedVolume start, int level=0, bool recursive=true)  const {
0171       auto proc = placementProcessor(p);
0172       return proc.process(start, level, recursive);
0173     }
0174     /// PlacedVolume element tree scanner using wrapped PlacedVolumeProcessor objects
0175     template <typename Q>
0176     int scan(const Q& p, PlacedVolume start, int level=0, bool recursive=true) const {
0177       auto proc = placementProcessor(p);
0178       return proc.process(start, level, recursive);
0179     }
0180   };
0181 }      /* End namespace dd4hep               */
0182 #endif // DD4HEP_VOLUMEPROCESSOR_H