Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:35:20

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_DIGIPARALLELWORKER_H
0014 #define DDDIGI_DIGIPARALLELWORKER_H
0015 
0016 /// C/C++ include files
0017 #include <cstdint>
0018 
0019 /// Namespace for the AIDA detector description toolkit
0020 namespace dd4hep {
0021 
0022   /// Namespace for the Digitization part of the AIDA detector description toolkit
0023   namespace digi {
0024 
0025     /// Forward declarations
0026     class WorkerPredicate;
0027 
0028     /// Wrapper class to submit bulk actions
0029     /**
0030      *
0031      *  \author  M.Frank
0032      *  \version 1.0
0033      *  \ingroup DD4HEP_DIGITIZATION
0034      */
0035     class ParallelWorker     {
0036     public:
0037       /// Default constructor
0038       ParallelWorker() = default;
0039       ParallelWorker(ParallelWorker&& copy) = default;
0040       ParallelWorker(const ParallelWorker& copy) = default;
0041       ParallelWorker& operator=(ParallelWorker&& copy) = default;
0042       ParallelWorker& operator=(const ParallelWorker& copy) = default;
0043       virtual ~ParallelWorker() = default;
0044       virtual void execute(void* args) const = 0;
0045     };
0046 
0047     /// Wrapper class to submit bulk actions
0048     /**
0049      *
0050      *  \author  M.Frank
0051      *  \version 1.0
0052      *  \ingroup DD4HEP_DIGITIZATION
0053      */
0054     template <typename ACTION_TYPE, typename CALLDATA, typename OPTIONS=std::size_t, typename PREDICATE=std::size_t>
0055       class DigiParallelWorker : public ParallelWorker   {
0056     public:
0057     using action_t = ACTION_TYPE;
0058     using options_t = OPTIONS;
0059     using calldata_t = CALLDATA;
0060     using predicate_t = PREDICATE;
0061 
0062     action_t*        action    { nullptr };
0063     options_t        options   { nullptr };
0064     predicate_t      predicate { nullptr };
0065 
0066     public:
0067     /// Initializing constructor
0068     DigiParallelWorker(action_t* a, const options_t& opts, const predicate_t& p={});
0069     /// Default constructor
0070     DigiParallelWorker() = delete;
0071     /// Move constructor
0072     DigiParallelWorker(DigiParallelWorker&& copy) = default;
0073     /// Inhibit copy constructor
0074     DigiParallelWorker(const DigiParallelWorker& copy) = default;
0075     /// Inhibit move assignment
0076     DigiParallelWorker& operator=(DigiParallelWorker&& copy) = delete;
0077     /// Inhibit copy assignment
0078     DigiParallelWorker& operator=(const DigiParallelWorker& copy) = delete;
0079     /// Default destructor
0080     virtual ~DigiParallelWorker();
0081     /// Access to processor name
0082     const char* name()  const {  return action->name().c_str();   }
0083     /// Callback on data
0084     virtual void execute(void* data) const override;
0085     };
0086 
0087     /// Initializing constructor
0088     template <typename ACTION_TYPE, typename CALLDATA, typename OPTIONS, typename PREDICATE>
0089       DigiParallelWorker<ACTION_TYPE, CALLDATA, OPTIONS, PREDICATE>::DigiParallelWorker(action_t* a, const options_t& o, const predicate_t& p)
0090       : ParallelWorker(), action(a), options(o), predicate(p)
0091     {
0092       if ( action ) action->addRef();
0093     }
0094 
0095     /// Default destructor
0096     template <typename ACTION_TYPE, typename CALLDATA, typename OPTIONS, typename PREDICATE>
0097       DigiParallelWorker<ACTION_TYPE, CALLDATA, OPTIONS, PREDICATE>::~DigiParallelWorker()   {
0098       if ( action )   {
0099     action->release();
0100     action = nullptr;
0101       }
0102     }
0103 
0104     typedef ParallelWorker ParallelCall;
0105   }    // End namespace digi
0106 }      // End namespace dd4hep
0107 
0108 #include <DDDigi/DigiParallelWorkers.h>
0109 #include <DDDigi/DigiParallelWorkerGroup.h>
0110 
0111 #endif // DDDIGI_DIGIPARALLELWORKER_H