Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:21

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 DDDIGI_DIGISEGMENTSPLITTER_H
0014 #define DDDIGI_DIGISEGMENTSPLITTER_H
0015 
0016 // Framework include files
0017 #include <DDDigi/DigiEventAction.h>
0018 #include <DDDigi/DigiParallelWorker.h>
0019 #include <DDDigi/DigiSegmentationTool.h>
0020 #include <DDDigi/DigiContainerProcessor.h>
0021 
0022 /// Namespace for the AIDA detector description toolkit
0023 namespace dd4hep {
0024 
0025   /// Namespace for the Digitization part of the AIDA detector description toolkit
0026   namespace digi {
0027 
0028     /// Segmentation split context
0029     /**
0030      *  
0031      *  
0032      *
0033      *  \author  M.Frank
0034      *  \version 1.0
0035      *  \ingroup DD4HEP_DIGITIZATION
0036      */
0037     class DigiSegmentProcessContext : public DigiSegmentContext  {
0038     public:
0039       using predicate_t = DigiContainerProcessor::predicate_t;
0040       predicate_t predicate;
0041 
0042     public:
0043       /// Default constructor
0044       DigiSegmentProcessContext() = default;
0045       /// Default copy constructor
0046       DigiSegmentProcessContext(const DigiSegmentContext& copy);
0047       /// Default move constructor
0048       DigiSegmentProcessContext(DigiSegmentProcessContext&& copy) = default;
0049       /// Default copy constructor
0050       DigiSegmentProcessContext(const DigiSegmentProcessContext& copy) = default;
0051       /// Default destructor
0052       virtual ~DigiSegmentProcessContext() = default;
0053       /// Default move assignment
0054       DigiSegmentProcessContext& operator=(const DigiSegmentContext& copy);
0055       /// Default move assignment
0056       DigiSegmentProcessContext& operator=(DigiSegmentProcessContext&& copy) = default;
0057       /// Default copy assignment
0058       DigiSegmentProcessContext& operator=(const DigiSegmentProcessContext& copy) = default;
0059 
0060       /// Full identifier (field + id)
0061       std::string identifier()  const;
0062       /// Check a given cell id if it matches this selection
0063       //bool matches(uint64_t cell)  const  {
0064       //  return this->split_id(cell) == this->predicate.id;
0065       //}
0066       /// Check a given cell id if it matches this selection
0067       bool matches(CellID cell)  const  {
0068         return this->split_id(cell) == this->predicate.id;
0069       }
0070 
0071       /// Check if a deposit should be processed
0072       bool use_depo(const std::pair<const CellID, EnergyDeposit>& deposit)   const   {
0073     return this->matches(deposit.first);
0074       }
0075       void enable(uint32_t split_id);
0076     };
0077 
0078     /// Predicate function to accept a subset of segment entries
0079     /**
0080      *
0081      *  \author  M.Frank
0082      *  \version 1.0
0083      *  \ingroup DD4HEP_DIGITIZATION
0084      */
0085     struct accept_segment_t : public DigiContainerProcessor::predicate_t  {
0086       accept_segment_t(const DigiSegmentContext* s, uint32_t i)
0087     : predicate_t(std::bind(&accept_segment_t::use_depo, this, std::placeholders::_1), i, s) {
0088       }
0089       /// Check if a deposit should be processed
0090       bool use_depo(const deposit_t& deposit)   const   {
0091     return this->segmentation->split_id(deposit.first) == this->id;
0092       }
0093     };
0094 
0095     /// Default base class for all Digitizer actions and derivates thereof.
0096     /**
0097      *  This is a utility class supporting properties, output and access to
0098      *  event and run objects through the context.
0099      *
0100      *  \author  M.Frank
0101      *  \version 1.0
0102      *  \ingroup DD4HEP_DIGITIZATION
0103      */
0104     class DigiSegmentSplitter : public DigiContainerProcessor   {
0105     protected:
0106 
0107       /**  Local use definitions                      */
0108       using self_t      = DigiSegmentSplitter;
0109       using tool_t      = DigiSegmentationTool;
0110       using splits_t    = std::set<uint32_t>;
0111       using segment_t   = DigiSegmentProcessContext;
0112       using processor_t = DigiContainerProcessor;
0113 
0114       using worker_t    = DigiParallelWorker<processor_t, work_t, segment_t>;
0115       using workers_t   = DigiParallelWorkers<worker_t>;
0116       friend class DigiParallelWorker<processor_t, work_t, segment_t>;
0117 
0118     protected:
0119 
0120       /**  Object properties                          */
0121       /// Property: Split element of the ID descriptor
0122       std::string          m_processor_type;
0123       /// Property: Name of the subdetector to be handed
0124       std::string          m_detector_name;
0125       /// Property: Splitter field in the segmentation description
0126       std::string          m_split_by;
0127       /// Property to steer parallel processing
0128       bool                 m_parallel          { false };
0129       /// Property: Flag if processors should be shared
0130       bool                 m_share_processor   { true };
0131 
0132       /**  Member variables                           */
0133       /// Data keys from the readout collection names
0134       std::vector<Key>   m_keys;
0135       /// Segmentation split context
0136       segment_t          m_split_context;
0137       /// Split elements used to parallelize the processing
0138       splits_t           m_splits;
0139       /// Array of sub-workers
0140       workers_t          m_workers;
0141 
0142       /// Lock for output merging
0143       mutable std::mutex m_output_lock;
0144       /// Segmentation too instance
0145       mutable tool_t     m_split_tool;
0146 
0147     protected:
0148       /// Default destructor
0149       virtual ~DigiSegmentSplitter();
0150 
0151       /// Initialization function
0152       void initialize();
0153 
0154     public:
0155       /// Adopt new parallel worker handling single split identifier
0156       virtual void adopt_segment_processor(DigiContainerProcessor* action, int split_id);
0157       /// Adopt new parallel worker handling multiple split-identifiers
0158       virtual void adopt_segment_processor(DigiContainerProcessor* action, const std::vector<int>&  ids);
0159 
0160     public:
0161       /// Standard constructor
0162       DigiSegmentSplitter(const kernel_t& kernel, const std::string& name);
0163       /// Access the readout collection keys
0164       std::vector<std::string> collection_names()   const;
0165       /// Main functional callback
0166       virtual void execute(context_t& context, work_t& work, const predicate_t& predicate)  const  override;
0167     };
0168   }    // End namespace digi
0169 }      // End namespace dd4hep
0170 #endif // DDDIGI_DIGISEGMENTSPLITTER_H