ATLAS Offline Software
METNetHandler.h
Go to the documentation of this file.
1 /*
3  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4 */
5 // Author: Bill Balunas <balunas@cern.ch>, based on earlier implementation by M. Leigh
7 
8 #ifndef METUTILITIES_MET_METNETHANDLER_H
9 #define METUTILITIES_MET_METNETHANDLER_H
10 
11 // STL includes
12 #include <string>
13 
14 // ONNX Library
15 #include <onnxruntime_cxx_api.h>
16 
17 // For ATLAS_THREAD_SAFE
19 
20 namespace met {
21 
22  class METNetHandler {
23 
24  public:
25 
26  // Constructor with parameters
27  METNetHandler(const std::string& modelName);
28 
29  // Destructor
30  virtual ~METNetHandler() = default;
31 
32  // Public methods
33  int initialize();
34  unsigned int getReqSize() const;
35  void predict(std::vector<float>& outputs, std::vector<float>& inputs) const;
36 
37  private:
38 
39  // Default constructor
40  METNetHandler() = delete;
41 
42  // Class properties
43  std::string m_modelName; // Path to the onnx file
44  std::string m_modelPath; // Output of the path resolver
45 
46  // Features of the network structure
47  size_t m_numInputs;
48  size_t m_numOutputs;
49  std::vector<int64_t> m_inputDims;
50  std::vector<int64_t> m_outputDims;
51  std::vector<const char *> m_graphInputNames;
52  std::vector<const char *> m_graphOutputNames;
53 
54  // ONNX session objects
55  Ort::Env m_onnxEnv;
56  Ort::SessionOptions m_onnxSessionOptions;
57  Ort::AllocatorWithDefaultOptions m_onnxAllocator;
58  mutable std::unique_ptr<Ort::Session> m_onnxSession ATLAS_THREAD_SAFE {nullptr};
59  mutable std::mutex m_onnxMutex ATLAS_THREAD_SAFE;
60  };
61 
62 }
63 
64 #endif
met::METNetHandler::m_modelName
std::string m_modelName
Definition: METNetHandler.h:43
met::METNetHandler::m_onnxAllocator
Ort::AllocatorWithDefaultOptions m_onnxAllocator
Definition: METNetHandler.h:57
met::METNetHandler::m_numInputs
size_t m_numInputs
Definition: METNetHandler.h:47
met::METNetHandler::ATLAS_THREAD_SAFE
std::unique_ptr< Ort::Session > m_onnxSession ATLAS_THREAD_SAFE
Definition: METNetHandler.h:58
met::METNetHandler::m_graphOutputNames
std::vector< const char * > m_graphOutputNames
Definition: METNetHandler.h:52
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
met::METNetHandler::m_modelPath
std::string m_modelPath
Definition: METNetHandler.h:44
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
met::METNetHandler::m_numOutputs
size_t m_numOutputs
Definition: METNetHandler.h:48
met::METNetHandler::m_onnxEnv
Ort::Env m_onnxEnv
Definition: METNetHandler.h:55
met
Definition: IMETSignificance.h:24
met::METNetHandler::initialize
int initialize()
Definition: METNetHandler.cxx:24
met::METNetHandler::getReqSize
unsigned int getReqSize() const
Definition: METNetHandler.cxx:40
met::METNetHandler
Definition: METNetHandler.h:22
python.CreateTierZeroArgdict.outputs
outputs
Definition: CreateTierZeroArgdict.py:189
met::METNetHandler::m_outputDims
std::vector< int64_t > m_outputDims
Definition: METNetHandler.h:50
met::METNetHandler::m_inputDims
std::vector< int64_t > m_inputDims
Definition: METNetHandler.h:49
met::METNetHandler::~METNetHandler
virtual ~METNetHandler()=default
met::METNetHandler::m_graphInputNames
std::vector< const char * > m_graphInputNames
Definition: METNetHandler.h:51
met::METNetHandler::predict
void predict(std::vector< float > &outputs, std::vector< float > &inputs) const
Definition: METNetHandler.cxx:45
met::METNetHandler::m_onnxSessionOptions
Ort::SessionOptions m_onnxSessionOptions
Definition: METNetHandler.h:56
checker_macros.h
Define macros for attributes used to control the static checker.
met::METNetHandler::ATLAS_THREAD_SAFE
std::mutex m_onnxMutex ATLAS_THREAD_SAFE
Definition: METNetHandler.h:59
met::METNetHandler::METNetHandler
METNetHandler()=delete