Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:54

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 // DDDB is a detector description convention developed by the LHCb experiment.
0015 // For further information concerning the DTD, please see:
0016 // http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf
0017 //
0018 //==========================================================================
0019 #ifndef EXAMPLES_DDDB_SRC_PLUGINS_DETSERVICE_H
0020 #define EXAMPLES_DDDB_SRC_PLUGINS_DETSERVICE_H
0021 
0022 // Framework includes
0023 #include "Detector/IDetService.h"
0024 #include "DD4hep/ComponentProperties.h"
0025 
0026 // C/C++ includes
0027 #include <mutex>
0028 
0029 /// Gaudi namespace declaration
0030 namespace gaudi  {
0031 
0032   /// Example gaudi-like service to access dd4hep conditions
0033   /**
0034      *  \author  M.Frank
0035      *  \version 1.0
0036      *  \date    01/04/2014
0037      */
0038   class DetService : virtual public IDetService,
0039                     public dd4hep::PropertyConfigurable
0040   {
0041     /// Cache entry definition
0042     class CacheEntry
0043     {
0044     public:
0045       Slice slice;
0046       dd4hep::IOV iov{0};
0047       int age = 0;
0048       CacheEntry() = default;
0049       CacheEntry(CacheEntry &&) = delete;
0050       CacheEntry(const CacheEntry &) = delete;
0051       CacheEntry &operator=(const CacheEntry &) = delete;
0052     };
0053 
0054     /// Short-cut to the ConditionsManager
0055     typedef dd4hep::cond::ConditionsManager ConditionsManager;
0056     /// Short-cut to the cache slices
0057     typedef std::vector<CacheEntry *> CachedSlices;
0058     /// Short-cut to the content cache
0059     typedef std::pair<std::string, Content> ContentEntry;
0060     /// Cached content container
0061     typedef std::vector<ContentEntry> CachedContents;
0062 
0063     /// Main object lock for content manipulation
0064     std::mutex m_contentLock;
0065     /// Main object lock for slice manipulation
0066     std::mutex m_sliceLock;
0067     /// Reference to the conditions manager object
0068     ConditionsManager m_manager;
0069     /// Container of active content objects
0070     CachedContents m_activeContents;
0071     /// Container of content objects being edited
0072     CachedContents m_openContents;
0073     /// The slice cache of re-usable slices
0074     CachedSlices m_cache;
0075     /// The maximum age limit
0076     int m_ageLimit;
0077 
0078   protected:
0079     /// Age all slices and check for slices which have expired.
0080     void _age();
0081     /// Find a conditions slice in the cache
0082     Slice _find(Content &content, const IOVType *typ, EventStamp stamp);
0083     /// Project a newly created conditions slice.
0084     Slice _create(Content &content, Context *ctx, const IOVType *typ, EventStamp stamp);
0085     /// Project a new conditions slice. If a free cached slice is availible, it shall be re-used
0086     Slice _project(Content &content, Context *ctx, const IOVType *typ, EventStamp stamp);
0087     /// Remove content from cache
0088     bool _remove(CachedContents &cache, Content &content);
0089     /// Add a condition address to the content. Condition is identified by its global key
0090     bool _addContent(Content &content, Condition::key_type key, const std::string &address);
0091 
0092   public:
0093     /// Default constructor
0094     DetService() = delete;
0095     /// Initializing constructor
0096     DetService(ConditionsManager m);
0097     /// Initializing constructor
0098     DetService(const DetService &copy) = delete;
0099     /// Default destructor
0100     virtual ~DetService() = default;
0101     /// Assignment operator
0102     DetService &operator=(const DetService &copy) = delete;
0103 
0104     /// Initialize the service
0105     virtual int initialize();
0106     /// Finalize the service
0107     virtual int finalize();
0108 
0109     /** General accessors to manipulate the conditions   */
0110     /// Accessor: get refernece to the conditions manager
0111     virtual ConditionsManager manager() const override;
0112 
0113     /// Accessor: Access IOV Type from conditions manager
0114     virtual const IOVType *iovType(const std::string &identifier) const override;
0115 
0116     /// Open content creation context
0117     virtual Content openContent(const std::string &name) override;
0118 
0119     /// Open content creation context and copy items from registered object
0120     virtual Content getContent(const std::string &name) override;
0121 
0122     /// Add a condition address to the content. Condition is identified by its global key
0123     virtual void addContent(Content &content,
0124                             Condition::key_type key,
0125                             const std::string &address) override;
0126 
0127     /// Add a condition address to the content
0128     virtual void addContent(Content &content,
0129                             DetElement det,
0130                             const std::string &item,
0131                             const std::string &address) override;
0132 
0133     /// Add a condition functor for a derived condition to the content
0134     virtual void addContent(Content &content, Dependency *call) override;
0135 
0136     /// Close content creation context
0137     virtual void closeContent(Content &content) override;
0138 
0139     /// Remove content object from cache.
0140     virtual bool removeContent(Content &content) override;
0141 
0142     /// Project a new conditions slice. If a free cached slice is availible, it shall be re-used
0143     virtual Slice project(Content &content,
0144                           Context *ctx,
0145                           const IOVType *typ,
0146                           EventStamp stamp) override;
0147     /// Project a new conditions slice. If a free cached slice is availible, it shall be re-used
0148     virtual Slice project(Content &content,
0149                           Context *ctx,
0150                           const std::string &typ,
0151                           EventStamp stamp) override;
0152     /// Project a new conditions slice. If a free cached slice is availible, it shall be re-used
0153     virtual Slice project(const std::string &content,
0154                           Context *ctx,
0155                           const std::string &typ,
0156                           EventStamp stamp) override;
0157     /// Invoke slice cleanup
0158     virtual void cleanup(const Cleanup &cleaner)  override;
0159   };
0160 }
0161 #endif // EXAMPLES_DDDB_SRC_PLUGINS_DETSERVICE_H