Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:14

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 
0014 // Framework include files
0015 #include <DD4hep/Detector.h>
0016 #include <DD4hep/Plugins.h>
0017 #include <DD4hep/Printout.h>
0018 
0019 #include <DDDigi/DigiHandle.h>
0020 #include <DDDigi/DigiKernel.h>
0021 #include <DDDigi/DigiInputAction.h>
0022 #include <DDDigi/DigiEventAction.h>
0023 #include <DDDigi/DigiSignalProcessor.h>
0024 
0025 // C/C++ include files
0026 #include <stdexcept>
0027 
0028 using namespace dd4hep::digi;
0029 
0030 /// Namespace for the AIDA detector description toolkit
0031 namespace dd4hep {
0032 
0033   /// Namespace for the Digitization part of the AIDA detector description toolkit
0034   namespace digi {
0035  
0036     template <typename TYPE> static inline TYPE* checked_value(TYPE* p) {
0037       if (p) {
0038         return p;
0039       }
0040       except("DigiHandle","Attempt to access an invalid object of type:%s!",
0041              typeName(typeid(TYPE)).c_str());
0042       return 0;
0043     }
0044 
0045     template <typename TYPE> DigiHandle<TYPE>::DigiHandle(TYPE* typ) : value(typ)  {
0046       if (value)
0047         value->addRef();
0048     }
0049 
0050     template <typename TYPE> DigiHandle<TYPE>::DigiHandle(const DigiHandle<TYPE>& handle) : value(handle.get())
0051     {
0052       if (value)
0053         value->addRef();
0054     }
0055 
0056     template <typename TYPE> DigiHandle<TYPE>::DigiHandle(DigiHandle<TYPE>&& handle) : value(handle.get())
0057     {
0058       handle.value = 0;
0059     }
0060 
0061     template <typename T> T* _raw_create(const std::string& t, const DigiKernel& kernel, const std::string& n)    {
0062       DigiEventAction* object = PluginService::Create<DigiEventAction*>(t, &kernel, n);
0063       return object ? dynamic_cast<T*>(object) : nullptr;
0064     }
0065 
0066     template <> DigiAction* _raw_create<DigiAction>(const std::string& t, const DigiKernel& kernel, const std::string& n)    {
0067       return PluginService::Create<DigiAction*>(t, &kernel, n);
0068     }
0069 
0070     template <> DigiSignalProcessor* _raw_create<DigiSignalProcessor>(const std::string& t, const DigiKernel& kernel, const std::string& n)    {
0071       return PluginService::Create<DigiSignalProcessor*>(t, &kernel, n);
0072     }
0073 
0074     template <typename TYPE> TYPE* _create_object(const DigiKernel& kernel, const TypeName& typ)    {
0075       TYPE* object = _raw_create<TYPE>(typ.first, kernel, typ.second);
0076       if (!object && typ.first == typ.second) {
0077         std::string _t = typeName(typeid(TYPE));
0078         printout(DEBUG, "DigiHandle", "Object factory for %s not found. Try out %s",
0079                  typ.second.c_str(), _t.c_str());
0080         object = _raw_create<TYPE>(_t, kernel, typ.second);
0081         if (!object) {
0082           size_t idx = _t.rfind(':');
0083           if (idx != std::string::npos)
0084             _t = std::string(_t.substr(idx + 1));
0085           printout(DEBUG, "DigiHandle", "Try out object factory for %s",_t.c_str());
0086           object = _raw_create<TYPE>(_t, kernel, typ.second);
0087         }
0088       }
0089       if (object)  {
0090         return object;
0091       }
0092       except("DigiHandle", "Failed to create object of type %s!", typ.first.c_str());
0093       return nullptr;
0094     }
0095 
0096     template <typename TYPE> 
0097     DigiHandle<TYPE>::DigiHandle(const DigiKernel& kernel, const std::string& type_name)  {
0098       value = _create_object<TYPE>(kernel,TypeName::split(type_name));
0099     }
0100 
0101     template <typename TYPE> 
0102     DigiHandle<TYPE>::DigiHandle(const DigiKernel& kernel, const char* type_name_char)  {
0103       value = _create_object<TYPE>(kernel,TypeName::split(type_name_char ? type_name_char : "????"));
0104     }
0105 
0106     template <typename TYPE> DigiHandle<TYPE>::~DigiHandle() {
0107       if (value)
0108         value->release();
0109       value = 0;
0110     }
0111 
0112     template <typename TYPE> TYPE* DigiHandle<TYPE>::release() {
0113       TYPE* temp = value;
0114       value = 0;
0115       return temp;
0116     }
0117 
0118     template <typename TYPE> void DigiHandle<TYPE>::checked_assign(TYPE* p) {
0119       if (value)
0120         value->release();
0121       value = checked_value(p);
0122       if (value)
0123         value->addRef();
0124     }
0125 
0126     template <typename TYPE> Property& DigiHandle<TYPE>::operator[](const std::string& property_name) const {
0127       PropertyManager& pm = checked_value(value)->properties();
0128       return pm[property_name];
0129     }
0130 
0131     template <typename TYPE> DigiHandle<TYPE>::operator TYPE*() const {
0132       return checked_value(value);
0133     }
0134 
0135     template <typename TYPE> bool DigiHandle<TYPE>::operator!() const {
0136       return 0 == value;
0137     }
0138 
0139     template <typename TYPE> TYPE* DigiHandle<TYPE>::get() const {
0140       return checked_value(value);
0141     }
0142 
0143     template <typename TYPE> TYPE* DigiHandle<TYPE>::operator->() const {
0144       return checked_value(value);
0145     }
0146 
0147     template <typename TYPE> DigiAction* DigiHandle<TYPE>::action() const {
0148       return checked_value(value);
0149     }
0150 
0151     /// Assignment operator
0152     template <typename TYPE> DigiHandle<TYPE>& DigiHandle<TYPE>::operator=(const DigiHandle& handle) {
0153       if ( &handle != this )  {
0154         TYPE* point = value;
0155         value = handle.get();
0156         if ( value ) value->addRef();
0157         if ( point ) point->release();
0158       }
0159       return *this;
0160     }
0161 
0162     /// Assignment move operator
0163     template <typename TYPE> DigiHandle<TYPE>& DigiHandle<TYPE>::operator=(DigiHandle&& handle) {
0164       if ( value ) value->release();
0165       value = handle.get();
0166       handle.value = 0;
0167       return *this;
0168     }
0169 
0170     template <typename TYPE> DigiHandle<TYPE>& DigiHandle<TYPE>::operator=(TYPE* pointer) {
0171       if ( pointer != value )  {
0172         TYPE* point = value;
0173         value = pointer;
0174         if ( value ) value->addRef();
0175         if ( point ) point->release();
0176       }
0177       return *this;
0178     }
0179 
0180     KernelHandle::KernelHandle()  {
0181       value = &DigiKernel::instance(Detector::getInstance());
0182     }
0183 
0184     KernelHandle::KernelHandle(DigiKernel* k) : value(k)  {
0185     }
0186 
0187     Property& KernelHandle::operator[](const std::string& property_name) const {
0188       PropertyManager& pm = checked_value(value)->properties();
0189       return pm[property_name];
0190     }
0191 
0192   }
0193 }
0194 
0195 #include <DDDigi/DigiSynchronize.h>
0196 #include <DDDigi/DigiActionSequence.h>
0197 
0198 /// Namespace for the AIDA detector description toolkit
0199 namespace dd4hep {
0200   /// Namespace for the Digitization part of the AIDA detector description toolkit
0201   namespace digi {
0202 
0203     template class DigiHandle<DigiAction>;
0204     template class DigiHandle<DigiInputAction>;
0205     template class DigiHandle<DigiEventAction>;
0206     template class DigiHandle<DigiSynchronize>;
0207     template class DigiHandle<DigiActionSequence>;
0208     template class DigiHandle<DigiSignalProcessor>;
0209   }
0210 }