|
||||
File indexing completed on 2025-01-18 09:55: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_DIGICONTEXT_H 0014 #define DDDIGI_DIGICONTEXT_H 0015 0016 // Framework incloude files 0017 #include <DD4hep/Primitives.h> 0018 #include <DDDigi/DigiData.h> 0019 #include <DDDigi/DigiRandomGenerator.h> 0020 0021 /// C/C++ include files 0022 #include <memory> 0023 #include <mutex> 0024 0025 /// Namespace for the AIDA detector description toolkit 0026 namespace dd4hep { 0027 0028 // Forward declarations 0029 class Detector; 0030 class DetElement; 0031 0032 /// Namespace for the Digitization part of the AIDA detector description toolkit 0033 namespace digi { 0034 0035 /// Forward declarations 0036 class DigiActionSequence; 0037 class DigiKernel; 0038 0039 /// Generic context to extend user, run and event information 0040 /** 0041 * A valid instance of the DigiContext is passed to every instance of a DigiAction at 0042 * creation time. 0043 * 0044 * The DigiContext is the main thread specific accessor to the dd4hep, DDG4 and 0045 * the user framework. 0046 * - The access to the dd4hep objects is via the DigiContext::detectorDescription() call, 0047 * - the access to DDG4 as a whole is supported via DigiContext::kernel() and 0048 * - the access to the user gframework using a specialized implementation of: 0049 * template <typename T> T& userFramework() const; 0050 * 0051 * A user defined implementations must be specialized somewhere in a compilation unit 0052 * of the user framework, not in a header file. The framework object could host 0053 * e.g. references for histogramming, logging, data access etc. 0054 * 0055 * This way any experiment/user related data processing framework can exhibit 0056 * its essential tools to DDG4 actions. 0057 * 0058 * A possible specialized implementations would look like the following: 0059 * 0060 * struct Gaudi { 0061 * IMessageSvc* msg; 0062 * IHistogramSvc* histos; 0063 * .... 0064 * }; 0065 * 0066 * template<> Gaudi& DigiContext::userFramework<Gaudi>() const { 0067 * UserFramework& fw = m_kernel->userFramework(); 0068 * if ( fw.first && &typeid(T) == fw.second ) return *(T*)fw.first; 0069 * throw std::runtime_error("No user specified framework context present!"); 0070 * } 0071 * 0072 * To access the user framework then use the following call: 0073 * Gaudi* fw = context->userFramework<Gaudi>(); 0074 * 0075 * of course after having initialized it: 0076 * Gaudi * fw = ...; 0077 * GaudiKernel& kernel = ...; 0078 * kernel.setUserFramework(fw); 0079 * 0080 * \author M.Frank 0081 * \version 1.0 0082 * \ingroup DD4HEP_DIGITIZATION 0083 */ 0084 class DigiContext { 0085 friend class DigiKernel; 0086 public: 0087 typedef std::pair<void*, const std::type_info*> UserFramework; 0088 0089 public: 0090 /// Reference to the thread context 0091 const DigiKernel& kernel; 0092 /// Transient context variable - depending on the thread context: event reference 0093 std::unique_ptr<DigiEvent> event { }; 0094 0095 protected: 0096 /// Reference to the random engine for this event 0097 std::shared_ptr<DigiRandomGenerator> m_random; 0098 /// Set the random generator 0099 void set_random_generator(std::shared_ptr<DigiRandomGenerator>& rndm) { 0100 m_random = rndm; 0101 } 0102 0103 protected: 0104 /// Inhibit default constructor 0105 DigiContext() = delete; 0106 /// Inhibit move constructor 0107 DigiContext(DigiContext&&) = delete; 0108 /// Inhibit copy constructor 0109 DigiContext(const DigiContext&) = delete; 0110 0111 public: 0112 0113 /// Initializing constructor 0114 DigiContext(const DigiKernel& kernel, std::unique_ptr<DigiEvent>&& event); 0115 /// Default destructor 0116 virtual ~DigiContext(); 0117 0118 /// Have a shared initializer lock 0119 std::mutex& initializer_lock() const; 0120 /// Have a global I/O lock (e.g. for ROOT) 0121 std::mutex& global_io_lock() const; 0122 /// Have a global output log lock 0123 std::mutex& global_output_lock() const; 0124 0125 /// Access to the random engine for this event 0126 DigiRandomGenerator& randomGenerator() const { return *m_random; } 0127 /// Access to the user framework. Specialized function to be implemented by the client 0128 template <typename T> T& framework() const; 0129 /// Generic framework access 0130 UserFramework& userFramework() const; 0131 /// Access to detector description 0132 Detector& detectorDescription() const; 0133 /// Access to the main input action sequence from the kernel object 0134 DigiActionSequence& inputAction() const; 0135 /// Access to the main event action sequence from the kernel object 0136 DigiActionSequence& eventAction() const; 0137 /// Access to the main output action sequence from the kernel object 0138 DigiActionSequence& outputAction() const; 0139 }; 0140 0141 } // End namespace digi 0142 } // End namespace dd4hep 0143 0144 #endif // DDDIGI_DIGICONTEXT_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |