Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:01

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2023 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "ActsExamples/Framework/ProcessCode.hpp"
0012 #include "ActsExamples/Framework/SequenceElement.hpp"
0013 #include <Acts/Utilities/Logger.hpp>
0014 
0015 #include <memory>
0016 #include <string>
0017 
0018 namespace ActsExamples {
0019 struct AlgorithmContext;
0020 
0021 /// Event processing algorithm interface.
0022 ///
0023 /// This class provides default implementations for most interface methods and
0024 /// and adds a default logger that can be used directly in subclasses.
0025 /// Algorithm implementations only need to implement the `execute` method.
0026 class IAlgorithm : public SequenceElement {
0027  public:
0028   /// Constructor
0029   ///
0030   /// @name The algorithm name
0031   /// @level The logging level for this algorithm
0032   IAlgorithm(std::string name,
0033              Acts::Logging::Level level = Acts::Logging::INFO);
0034 
0035   /// The algorithm name.
0036   std::string name() const override;
0037 
0038   /// Execute the algorithm for one event.
0039   ///
0040   /// This function must be implemented by subclasses.
0041   virtual ProcessCode execute(const AlgorithmContext& context) const = 0;
0042 
0043   /// Internal execute method forwards to the algorithm execute method as const
0044   /// @param context The algorithm context
0045   ProcessCode internalExecute(const AlgorithmContext& context) final {
0046     return execute(context);
0047   };
0048 
0049   /// Initialize the algorithm
0050   ProcessCode initialize() override { return ProcessCode::SUCCESS; }
0051   /// Finalize the algorithm
0052   ProcessCode finalize() override { return ProcessCode::SUCCESS; }
0053 
0054  protected:
0055   const Acts::Logger& logger() const { return *m_logger; }
0056 
0057  private:
0058   std::string m_name;
0059   std::unique_ptr<const Acts::Logger> m_logger;
0060 };
0061 }  // namespace ActsExamples