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_DIGIKERNEL_H
0014 #define DDDIGI_DIGIKERNEL_H
0015 
0016 /// Framework include files
0017 #include <DDDigi/DigiActionSequence.h>
0018 #include <DDDigi/DigiParallelWorker.h>
0019 
0020 /// C/C++ include files
0021 #include <mutex>
0022 #include <memory>
0023 
0024 /// Forward declarations
0025 class TH1;
0026 
0027 /// Namespace for the AIDA detector description toolkit
0028 namespace dd4hep {
0029 
0030   /// Namespace for the Digitization part of the AIDA detector description toolkit
0031   namespace digi {
0032 
0033     /// Forward declarations
0034     class DigiAction;
0035     class DigiActionSequence;
0036     
0037     /// Class, which allows all DigiAction derivatives to access the DDG4 kernel structures.
0038     /**
0039      *  To implement access to a user specified framework please see class DigiContext.
0040      *
0041      *  \author  M.Frank
0042      *  \version 1.0
0043      *  \ingroup DD4HEP_DIGITIZATION
0044      */
0045     class DigiKernel : public DigiAction   {
0046     public:
0047       typedef std::map<std::string,int>                 ClientOutputLevels;
0048       typedef std::pair<void*, const std::type_info*>   UserFramework;
0049 
0050     private:
0051       class Internals;
0052       class Processor;
0053       template <typename ACTION, typename ARGUMENT> class Wrapper;
0054 
0055       /// Internal only data structures;
0056       Internals*            internals   { nullptr };
0057       
0058     protected:
0059       /// Detector description object
0060       Detector*             m_detDesc         { nullptr };
0061       /// Reference to the user framework
0062       mutable UserFramework m_userFramework;
0063       
0064       /// Execute one single event
0065       virtual void executeEvent(std::unique_ptr<DigiContext>&& context);
0066       /// Notify kernel that the execution of one single event finished
0067       void notify(std::unique_ptr<DigiContext>&& context);
0068       /// Notify kernel that the execution of one single event finished
0069       void notify(std::unique_ptr<DigiContext>&&, const std::exception& e);
0070       
0071     protected:
0072       /// Define standard assignments and constructors
0073       DDDIGI_DEFINE_ACTION_CONSTRUCTORS(DigiKernel);
0074 
0075     public:
0076       /// Standard constructor for the master instance
0077       DigiKernel(Detector& description);
0078 
0079     public:
0080       /// Default destructor
0081       virtual ~DigiKernel();
0082 
0083 #ifndef __CINT__
0084       /// Instance accessor
0085       static DigiKernel& instance(Detector& description);
0086 #endif
0087       /// Access to detector description
0088       Detector& detectorDescription() const     {        return *m_detDesc;        }
0089       /// Generic framework access
0090       UserFramework& userFramework() const      {        return m_userFramework;   }
0091       /// Set the framework context to the kernel object
0092       template <typename T> void setUserFramework(T* object)   {
0093         m_userFramework = UserFramework(object,&typeid(T));
0094       }
0095 
0096       /// Have a shared initializer lock
0097       std::mutex& initializer_lock()  const;
0098 
0099       /// Have a global I/O lock (e.g. for ROOT)
0100       std::mutex& global_io_lock()   const;
0101 
0102       /// Have a global output log lock
0103       std::mutex& global_output_lock()   const;
0104       
0105       /** Property access                            */
0106       /// Print the property values
0107       virtual void printProperties() const  override;
0108 
0109       /** Client output level settings               */
0110       /// Fill cache with the global output level of a named object. Must be set before instantiation
0111       void setOutputLevel(const std::string object, PrintLevel new_level);
0112       /// Retrieve the global output level of a named object.
0113       PrintLevel getOutputLevel(const std::string object) const;
0114 
0115       /// Access current number of events still to process
0116       std::size_t events_todo()  const;
0117       /// Access current number of events already processed
0118       std::size_t events_done()  const;
0119       /// Access current number of events processing (events in flight)
0120       std::size_t events_processing()  const;
0121 
0122       /// Register configure callback. Signature:   (function)()
0123       void register_configure(const std::function<void()>& callback)   const;
0124       /// Register initialize callback. Signature:  (function)()
0125       void register_initialize(const std::function<void()>& callback)   const;
0126       /// Register terminate callback. Signature:   (function)()
0127       void register_terminate(const std::function<void()>& callback)   const;
0128       /// Register start event callback. Signature: (function)(DigiContext*)
0129       void register_start_event(const std::function<void(DigiContext&)>& callback)   const;
0130       /// Register end event callback. Signature:   (function)(DigiContext*)
0131       void register_end_event(const std::function<void(DigiContext&)>& callback)   const;
0132 
0133       /// Registration of monitoring objects eventually saved by the handler
0134       void register_monitor(DigiAction* action, TNamed* histo)  const;
0135 
0136       /// Construct detector geometry using description plugin
0137       virtual void loadGeometry(const std::string& compact_file);
0138       /// Load XML file 
0139       virtual void loadXML(const char* fname);
0140 
0141       /// Configure the digitization: call all registered configurators
0142       virtual int configure();
0143       /// Initialize the digitization: call all registered initializers
0144       virtual int initialize();
0145       /// Run the digitization sequence over the requested number of events
0146       virtual int run();
0147       /// Terminate the digitization: call all registered terminators and release the allocated resources
0148       virtual int terminate();
0149 
0150       /// Access to the main input action sequence from the kernel object
0151       DigiActionSequence& inputAction() const;
0152       /// Access to the main event action sequence from the kernel object
0153       DigiActionSequence& eventAction() const;
0154       /// Access to the main output action sequence from the kernel object
0155       DigiActionSequence& outputAction() const;
0156 
0157       /// Submit a bunch of actions to be executed in parallel
0158       virtual void submit (DigiContext& context, ParallelCall*const algorithms[], std::size_t count, void* data, bool parallel=true)  const;
0159 
0160       /// Submit a bunch of actions to be executed in parallel
0161       virtual void submit (DigiContext& context, const std::vector<ParallelCall*>& algorithms, void* data, bool parallel=true)  const;
0162 
0163       /// If running multithreaded: wait until the thread-group finished execution
0164       virtual void wait(DigiContext& context)   const;
0165 
0166     };
0167   }    // End namespace digi
0168 }      // End namespace dd4hep
0169 #endif // DDDIGI_DIGIKERNEL_H