Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:38:24

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #pragma once
0012 
0013 #include <Gaudi/Property.h>
0014 #include <Gaudi/Sequence.h>
0015 #include <mutex>
0016 
0017 namespace Gaudi {
0018   /** A Sequencer is essentially a list of Algorithms and is responsible
0019    *  for their management. Note that Sequences may themselves contain other
0020    *  Sequences. The default execute() implementation loops over the
0021    *  members of the sequence, calling their execute() methods. However, this
0022    *  can be modified if a member is disabled, has already been executed, or a
0023    *  member indicates that it's filter fails. The the former two cases the
0024    *  execution of the member is bypassed. In the latter case, the loop is
0025    *  terminated and the Sequencer assumes the same filtered state as the
0026    *  last member.
0027    */
0028   class GAUDI_API Sequencer : public Gaudi::Sequence {
0029   public:
0030     using Gaudi::Sequence::Sequence;
0031 
0032     /** Initialization of a sequencer.
0033      *
0034      * Typically things like histogram creation,
0035      * setting up of data structures etc, should be done here. If a sequence
0036      * has properties specified in the job options file, they will be set to
0037      * the requested values BEFORE the initialize() method is invoked.
0038      */
0039     StatusCode initialize() override;
0040 
0041     /// Sequencer Reinitialization.
0042     StatusCode reinitialize() override;
0043 
0044     /// Sequencer finalization.
0045     StatusCode start() override;
0046 
0047     /// The actions to be performed by the sequencer on an event.
0048     StatusCode execute( const EventContext& ctx ) const override;
0049 
0050     /// Sequencer stop.
0051     StatusCode stop() override;
0052 
0053     /// Sequencer finalization.
0054     StatusCode finalize() override;
0055 
0056     /// Was the branch filter passed for the last event?
0057     bool branchFilterPassed( const EventContext& ctx ) const;
0058 
0059     /// Set the branch filter passed flag for the last event
0060     void setBranchFilterPassed( const EventContext& ctx, bool state ) const;
0061 
0062     /// Append an algorithm to the sequencer.
0063     StatusCode append( Gaudi::Algorithm* pAlgorithm );
0064 
0065     /// Append an algorithm to the sequencer branch
0066     StatusCode appendToBranch( Gaudi::Algorithm* pAlgorithm );
0067 
0068     /** Create a algorithm and append it to the sequencer.
0069      *
0070      *  A call to this method
0071      *  creates a child algorithm object. Note that the returned pointer is
0072      *  to Algorithm (as opposed to IAlgorithm), and thus the methods of
0073      *  IProperty are also available for the direct setting of the algorithm's
0074      *  properties. Using this mechanism instead of creating algorithms
0075      *  directly via the new operator is preferred since then the framework
0076      *  may take care of all of the necessary book-keeping.
0077      */
0078     StatusCode createAndAppend( const std::string& type,      // The concrete algorithm class of the algorithm
0079                                 const std::string& name,      // The name to be given to the algorithm
0080                                 Gaudi::Algorithm*& pAlgorithm // Set to point to the newly created algorithm object
0081     );
0082 
0083     /** Create a algorithm and append it to the sequencer branch.
0084      *
0085      *  A call to this method creates a child algorithm object. Note that the returned pointer is
0086      *  to Algorithm (as opposed to IAlgorithm), and thus the methods of
0087      *  IProperty are also available for the direct setting of the algorithm's
0088      *  properties. Using this mechanism instead of creating algorithms
0089      *  directly via the new operator is preferred since then the framework
0090      *  may take care of all of the necessary book-keeping.
0091      */
0092     StatusCode createAndAppendToBranch( const std::string& type,      // The concrete algorithm class of the algorithm
0093                                         const std::string& name,      // The name to be given to the algorithm
0094                                         Gaudi::Algorithm*& pAlgorithm // Set to point to the newly created algorithm
0095                                                                       // object
0096     );
0097 
0098     /// Remove the specified algorithm from the sequencer
0099     StatusCode remove( Gaudi::Algorithm* pAlgorithm );
0100     StatusCode remove( const std::string& name );
0101     StatusCode removeFromBranch( Gaudi::Algorithm* pAlgorithm );
0102     StatusCode removeFromBranch( const std::string& name );
0103 
0104     /** List of branch algorithms.
0105      *
0106      *  These are the algorithms
0107      *  that would get executed if a filter algorithm indicated
0108      *  a failure. The branch is located within the main sequence
0109      *  by the first element, which is the filter algorithm.
0110      */
0111     const std::vector<Gaudi::Algorithm*>& branchAlgorithms() const;
0112     std::vector<Gaudi::Algorithm*>&       branchAlgorithms();
0113 
0114     /// Decode Member Name list
0115     StatusCode decodeMemberNames();
0116 
0117     /// Decode branch member name list
0118     StatusCode decodeBranchMemberNames();
0119 
0120   protected:
0121     /**
0122      ** Append an algorithm to the sequencer.
0123      **/
0124     StatusCode append( Gaudi::Algorithm* pAlgorithm, std::vector<Gaudi::Algorithm*>& theAlgs );
0125 
0126     /**
0127      ** Create a algorithm and append it to the sequencer. A call to this method
0128      ** creates a child algorithm object. Note that the returned pointer is
0129      ** to Algorithm (as opposed to IAlgorithm), and thus the methods of
0130      ** IProperty are also available for the direct setting of the algorithm's
0131      ** properties. Using this mechanism instead of creating algorithms
0132      ** directly via the new operator is preferred since then the framework
0133      ** may take care of all of the necessary book-keeping.
0134      **/
0135     StatusCode createAndAppend( const std::string& type,       // The concrete algorithm class of the algorithm
0136                                 const std::string& name,       // The name to be given to the algorithm
0137                                 Gaudi::Algorithm*& pAlgorithm, // Set to point to the newly created algorithm object
0138                                 std::vector<Gaudi::Algorithm*>& theAlgs );
0139 
0140     /**
0141      ** Decode algorithm names, creating or appending algorithms as appropriate
0142      **/
0143     StatusCode decodeNames( Gaudi::Property<std::vector<std::string>>& theNames,
0144                             std::vector<Gaudi::Algorithm*>& theAlgs, std::vector<bool>& theLogic );
0145 
0146     /**
0147      ** Execute the members in the specified list
0148      **/
0149     StatusCode execute( const EventContext& ctx, const std::vector<Gaudi::Algorithm*>& theAlgs,
0150                         const std::vector<bool>& theLogic, Gaudi::Algorithm*& lastAlgorithm,
0151                         std::size_t first = 0 ) const;
0152 
0153     /**
0154      ** Execute member algorithm
0155      **/
0156     StatusCode executeMember( Gaudi::Algorithm* theAlgorithm, const EventContext& context ) const;
0157 
0158     /**
0159      ** Remove the specified algorithm from the sequencer
0160      **/
0161 
0162     StatusCode remove( const std::string& algname, std::vector<Gaudi::Algorithm*>& theAlgs );
0163 
0164     // NO COPY / ASSIGNMENT  ALLOWED
0165     Sequencer( const Sequencer& a )              = delete;
0166     Sequencer& operator=( const Sequencer& rhs ) = delete;
0167 
0168   public:
0169     /// Produce string representation of the control flow expression.
0170     std::ostream& toControlFlowExpression( std::ostream& os ) const override;
0171 
0172   private:
0173     Gaudi::Property<std::vector<std::string>> m_names{ this,
0174                                                        "Members",
0175                                                        {},
0176                                                        [this]( auto& ) {
0177                                                          if ( this->isInitialized() )
0178                                                            this->decodeMemberNames().ignore();
0179                                                        },
0180                                                        "member names",
0181                                                        "vector<Algorithm>" };
0182     Gaudi::Property<std::vector<std::string>> m_branchNames{ this,
0183                                                              "BranchMembers",
0184                                                              {},
0185                                                              [this]( auto& ) {
0186                                                                if ( this->isInitialized() )
0187                                                                  this->decodeBranchMemberNames().ignore();
0188                                                              },
0189                                                              "branch member names",
0190                                                              "vector<Algorithm>" };
0191 
0192     Gaudi::Property<bool> m_shortCircuit{ this, "ShortCircuit", true, "stop processing as soon as possible" };
0193     Gaudi::Property<bool> m_sequential{ this, "Sequential", false, "execute members one at a time" };
0194     Gaudi::Property<bool> m_modeOR{ this, "ModeOR", false, "use OR logic instead of AND" };
0195     Gaudi::Property<bool> m_ignoreFilter{ this, "IgnoreFilterPassed", false, "always continue" };
0196     Gaudi::Property<bool> m_invert{ this, "Invert", false, "invert the logic result of the sequencer" };
0197 
0198     Gaudi::Property<std::vector<std::string>> m_vetoObjs{
0199         this, "VetoObjects", {}, "skip execute if one or more of these TES objects exist" };
0200     Gaudi::Property<std::vector<std::string>> m_requireObjs{
0201         this, "RequireObjects", {}, "execute only if one or more of these TES objects exist" };
0202 
0203     std::vector<bool>              m_isInverted;       // Member logic inverted list
0204     std::vector<Gaudi::Algorithm*> m_branchAlgs;       // Branch algorithms
0205     std::vector<bool>              m_isBranchInverted; // Branch Member logic inverted list
0206 
0207     mutable std::mutex                                m_branchFilterMutex;
0208     mutable std::map<EventContext::ContextID_t, bool> m_branchFilterPassed; // Branch filter passed flag
0209   };
0210 } // namespace Gaudi