Back to home page

EIC code displayed by LXR

 
 

    


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

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 EXAMPLES_CONDITIONS_SRC_CONDITIONEXAMPLEOBJECTS_H
0014 #define EXAMPLES_CONDITIONS_SRC_CONDITIONEXAMPLEOBJECTS_H
0015 
0016 // Framework include files
0017 #include "DD4hep/Detector.h"
0018 #include "DD4hep/Printout.h"
0019 #include "DD4hep/Conditions.h"
0020 #include "DD4hep/ConditionsMap.h"
0021 #include "DD4hep/ConditionDerived.h"
0022 #include "DD4hep/ConditionsPrinter.h"
0023 #include "DD4hep/ConditionsProcessor.h"
0024 #include "DD4hep/DetectorProcessor.h"
0025 
0026 #include "DDCond/ConditionsSlice.h"
0027 #include "DDCond/ConditionsManager.h"
0028 
0029 /// Namespace for the AIDA detector description toolkit
0030 namespace dd4hep {
0031 
0032   /// Namespace for conditions examples
0033   namespace ConditionExamples {
0034 
0035     using cond::UserPool;
0036     using cond::ConditionsPool;
0037     using cond::ConditionsSlice;
0038     using cond::ConditionsContent;
0039     using cond::ConditionsPrinter;
0040     using cond::ConditionsManager;
0041     using cond::ConditionUpdateCall;
0042     using cond::ConditionUpdateContext;
0043     using cond::conditionsCollector;
0044     
0045     /// Helper to reduce the number of lines of code
0046     /**
0047      *  \author  M.Frank
0048      *  \version 1.0
0049      *  \ingroup DD4HEP_CONDITIONS
0050      */
0051     class OutputLevel {
0052     public:
0053       /// Output level
0054       PrintLevel printLevel = DEBUG;
0055       /// Default constructor
0056       OutputLevel() = default;
0057       /// Initializing constructor
0058       OutputLevel(PrintLevel p) : printLevel(p) {}
0059       /// Default destructor
0060       virtual ~OutputLevel() = default;
0061     };
0062 
0063     /// Specialized condition only offering non-default ctor
0064     /**
0065      *  \author  M.Frank
0066      *  \version 1.0
0067      *  \ingroup DD4HEP_CONDITIONS
0068      */
0069     class NonDefaultCtorCond  {
0070     private:
0071       /// Inhibit default constructor
0072       NonDefaultCtorCond() = delete;
0073       /// Inhibit move constructor
0074       NonDefaultCtorCond(NonDefaultCtorCond&& copy) = delete;
0075       /// Inhibit copy constructor
0076       NonDefaultCtorCond(const NonDefaultCtorCond& copy) = delete;
0077       /// Inhibit move assignment
0078       NonDefaultCtorCond& operator=(NonDefaultCtorCond&& copy) = delete;
0079       /// Inhibit copy assignment
0080       NonDefaultCtorCond& operator=(const NonDefaultCtorCond& copy) = delete;
0081     public:
0082       int a, b, c, d;
0083       /// Initializing constructor only
0084       NonDefaultCtorCond(int aa, int bb, int cc);
0085       /// Default descructor
0086       virtual ~NonDefaultCtorCond();
0087       /// Set data member
0088       void set(int val);
0089     };
0090     
0091     /// Specialized conditions update callback 
0092     /**
0093      *  Used by clients to update a condition.
0094      *
0095      *  \author  M.Frank
0096      *  \version 1.0
0097      *  \ingroup DD4HEP_CONDITIONS
0098      */
0099     class ConditionNonDefaultCtorUpdate1 : public ConditionUpdateCall, public OutputLevel  {
0100     public:
0101       /// Initializing constructor
0102       ConditionNonDefaultCtorUpdate1(PrintLevel p) : OutputLevel(p) {    }
0103       /// Default destructor
0104       virtual ~ConditionNonDefaultCtorUpdate1() = default;
0105       /// Interface to client Callback in order to update the condition
0106       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override  final;
0107       /// Interface to client Callback in order to update the condition
0108       virtual void resolve(Condition condition, ConditionUpdateContext& context) override  final;
0109     };
0110 
0111     /// Specialized conditions update callback with an unresolvable reference
0112     /**
0113      *  Used by clients to update a condition.
0114      *
0115      *  \author  M.Frank
0116      *  \version 1.0
0117      *  \ingroup DD4HEP_CONDITIONS
0118      */
0119     class ConditionUpdateUnresolved : public ConditionUpdateCall, public OutputLevel  {
0120     public:
0121       /// Initializing constructor
0122       ConditionUpdateUnresolved(PrintLevel p) : OutputLevel(p) {    }
0123       /// Default destructor
0124       virtual ~ConditionUpdateUnresolved() = default;
0125       /// Interface to client Callback in order to update the condition
0126       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override  final;
0127       /// Interface to client Callback in order to update the condition
0128       virtual void resolve(Condition condition, ConditionUpdateContext& context) override  final;
0129     };
0130 
0131     /// Specialized conditions update callback 
0132     /**
0133      *  Used by clients to update a condition.
0134      *
0135      *  \author  M.Frank
0136      *  \version 1.0
0137      *  \ingroup DD4HEP_CONDITIONS
0138      */
0139     class ConditionUpdate1 : public ConditionUpdateCall, public OutputLevel  {
0140     public:
0141       /// Initializing constructor
0142       ConditionUpdate1(PrintLevel p) : OutputLevel(p) {    }
0143       /// Default destructor
0144       virtual ~ConditionUpdate1() = default;
0145       /// Interface to client Callback in order to update the condition
0146       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override  final;
0147       /// Interface to client Callback in order to update the condition
0148       virtual void resolve(Condition condition, ConditionUpdateContext& context) override  final;
0149     };
0150 
0151     /// Specialized conditions update callback 
0152     /**
0153      *  Used by clients to update a condition.
0154      *
0155      *  \author  M.Frank
0156      *  \version 1.0
0157      *  \ingroup DD4HEP_CONDITIONS
0158      */
0159     class ConditionUpdate2 : public ConditionUpdateCall, public OutputLevel  {
0160     public:
0161       /// Initializing constructor
0162       ConditionUpdate2(PrintLevel p) : OutputLevel(p) {    }
0163       /// Default destructor
0164       virtual ~ConditionUpdate2() = default;
0165       /// Interface to client Callback in order to update the condition
0166       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override   final;
0167       /// Interface to client Callback in order to update the condition
0168       virtual void resolve(Condition condition, ConditionUpdateContext& context) override  final;
0169     };
0170 
0171     /// Specialized conditions update callback 
0172     /**
0173      *  Used by clients to update a condition.
0174      *
0175      *  \author  M.Frank
0176      *  \version 1.0
0177      *  \ingroup DD4HEP_CONDITIONS
0178      */
0179     class ConditionUpdate3 : public ConditionUpdateCall, public OutputLevel  {
0180     public:
0181       /// Initializing constructor
0182       ConditionUpdate3(PrintLevel p) : OutputLevel(p) {    }
0183       /// Default destructor
0184       virtual ~ConditionUpdate3() = default;
0185       /// Interface to client Callback in order to update the condition
0186       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override  final;
0187       /// Interface to client Callback in order to update the condition
0188       virtual void resolve(Condition condition, ConditionUpdateContext& context) override  final;
0189     };
0190     
0191     /// Specialized conditions update callback 
0192     /**
0193      *  Used by clients to update a condition.
0194      *
0195      *  \author  M.Frank
0196      *  \version 1.0
0197      *  \ingroup DD4HEP_CONDITIONS
0198      */
0199     class ConditionUpdate4 : public ConditionUpdateCall, public OutputLevel  {
0200     public:
0201       /// Initializing constructor
0202       ConditionUpdate4(PrintLevel p) : OutputLevel(p) {    }
0203       /// Default destructor
0204       virtual ~ConditionUpdate4() = default;
0205       /// Interface to client Callback in order to update the condition
0206       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override  final;
0207     };
0208     
0209     /// Specialized conditions update callback 
0210     /**
0211      *  Used by clients to update a condition.
0212      *
0213      *  \author  M.Frank
0214      *  \version 1.0
0215      *  \ingroup DD4HEP_CONDITIONS
0216      */
0217     class ConditionUpdate5 : public ConditionUpdateCall, public OutputLevel  {
0218     public:
0219       /// Initializing constructor
0220       ConditionUpdate5(PrintLevel p) : OutputLevel(p) {    }
0221       /// Default destructor
0222       virtual ~ConditionUpdate5() = default;
0223       /// Interface to client Callback in order to update the condition
0224       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override  final;
0225     };
0226     
0227     /// Specialized conditions update callback 
0228     /**
0229      *  Used by clients to update a condition.
0230      *
0231      *  \author  M.Frank
0232      *  \version 1.0
0233      *  \ingroup DD4HEP_CONDITIONS
0234      */
0235     class ConditionUpdate6 : public ConditionUpdateCall, public OutputLevel  {
0236     public:
0237       size_t max_deps = 0;
0238       size_t min_deps = 999999999999UL;
0239       size_t num_deps = 0;
0240       size_t call_count = 0;
0241       /// Initializing constructor
0242       ConditionUpdate6(PrintLevel p) : OutputLevel(p) {    }
0243       /// Default destructor
0244       virtual ~ConditionUpdate6();
0245       /// Interface to client Callback in order to update the condition
0246       virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override  final;
0247     };
0248     
0249     /// This is important, otherwise the register and forward calls won't find them!
0250     /**
0251      *  \author  M.Frank
0252      *  \version 1.02
0253      *  \date    01/04/2016
0254      */
0255     class ConditionsKeys : public OutputLevel {
0256     public:
0257       /// Content object to be filled
0258       ConditionsContent& content;
0259       /// Constructor
0260       ConditionsKeys(ConditionsContent& c, PrintLevel p) : OutputLevel(p), content(c) {}
0261       /// Callback to process a single detector element
0262       virtual int operator()(DetElement de, int level) const final;
0263     };
0264 
0265     /// Example how to populate the detector description with derived conditions
0266     /**
0267      *  This is simply a DetElement crawler...
0268      *
0269      *  \author  M.Frank
0270      *  \version 1.0
0271      *  \date    01/04/2016
0272      */
0273     struct ConditionsDependencyCreator : public OutputLevel  {
0274       /// Content object to be filled
0275       ConditionsContent&   content;
0276       /// Three different update call types
0277       std::shared_ptr<ConditionUpdateCall> scall1, call1, call2, call3, call4, call5, call6, callUnresolved;
0278       /// Flag for special setup for ROOT persistency
0279       bool persist_conditions;
0280       /// Flag to indicate increased complexity
0281       int  extended;
0282       /// Constructor
0283       ConditionsDependencyCreator(ConditionsContent& c, PrintLevel p, bool persist=false, int extended=0);
0284       /// Destructor
0285       virtual ~ConditionsDependencyCreator() = default;
0286       /// Callback to process a single detector element
0287       virtual int operator()(DetElement de, int level) const final;
0288     };
0289 
0290     /// Example how to populate the detector description with conditions constants
0291     /**
0292      *  This is simply a DetElement crawler...
0293      *
0294      *  \author  M.Frank
0295      *  \version 1.0
0296      *  \date    01/04/2016
0297      */
0298     struct ConditionsCreator  : public OutputLevel  {
0299       /// Content object for which conditions are supposedly created
0300       ConditionsSlice& slice;
0301       /// Conditions pool the created conditions are inserted to (not equals user pool!)
0302       ConditionsPool&  pool;
0303       /// Constructor
0304       ConditionsCreator(ConditionsSlice& s, ConditionsPool& p, PrintLevel l=DEBUG)
0305         : OutputLevel(l), slice(s), pool(p)  {}
0306       /// Destructor
0307       virtual ~ConditionsCreator() = default;
0308       /// Callback to process a single detector element
0309       virtual int operator()(DetElement de, int level)  const final;
0310       template<typename T>
0311       Condition make_condition(DetElement de,
0312                    const std::string& name,
0313                    const T& val)  const;
0314       template<typename T, typename... Args>
0315       Condition make_condition_args(DetElement de,
0316                     const std::string& name,
0317                     Args... args)  const;
0318     };
0319 
0320     /// Example how to access the conditions constants from a detector element
0321     /**
0322      *  \author  M.Frank
0323      *  \version 1.0
0324      *  \date    01/04/2016
0325      */
0326     struct ConditionsDataAccess : public OutputLevel   {
0327       /// Reference to the IOV to be checked
0328       const IOV&     iov;
0329       /// Reference to the conditions map to access conditions
0330       ConditionsMap& map;
0331 
0332       /// Constructor
0333       ConditionsDataAccess(const IOV& i, ConditionsMap& m, PrintLevel l=DEBUG)
0334         : OutputLevel(l), iov(i), map(m) {}
0335       /// Destructor
0336       virtual ~ConditionsDataAccess() = default;
0337       /// Callback to process a single detector element
0338       virtual int operator()(DetElement de, int level)  const;
0339       /// Common call to access selected conditions
0340       virtual int accessConditions(DetElement de,
0341                                    const std::vector<Condition>& conditions)  const;
0342     };
0343 
0344     /// Helper to run DetElement scans
0345     typedef DetectorScanner Scanner;
0346     
0347     /// Install the consitions and the conditions manager
0348     ConditionsManager installManager(Detector& description);
0349   }       /* End namespace condExamples             */
0350 }         /* End namespace dd4hep                         */
0351 #endif // EXAMPLES_CONDITIONS_SRC_CONDITIONEXAMPLEOBJECTS_H