ATLAS Offline Software
VNetworkBase.h
Go to the documentation of this file.
1 
18 #ifndef VNETWORKBASE_H
19 #define VNETWORKBASE_H
20 
21 // For conversion to ostream
22 #include <iostream>
23 #include <map>
24 
25 // For reading and writing
26 #include "TFile.h"
27 #include "TTree.h"
28 
29 // For messaging
31 
39 public:
45  VNetworkBase();
46 
47  // explicit = Don't let this do implicit type conversion
59  explicit VNetworkBase(const std::string &inputFile);
60 
71  VNetworkBase(const VNetworkBase &copy_from);
72 
73  // virtual destructor, to ensure that it is always called, even
74  // when a base class is deleted via a pointer to a derived class
75  virtual ~VNetworkBase();
76 
77  // same as for lwtnn
90  typedef std::map<std::string, std::map<std::string, double>> NetworkInputs;
100  typedef std::map<std::string, double> NetworkOutputs;
101 
112  static std::string representNetworkInputs(NetworkInputs const &inputs,
113  int maxValues = 3);
114 
125  static std::string representNetworkOutputs(NetworkOutputs const &outputs,
126  int maxValues = 3);
127 
128  // pure virtual, derived classes must impement this
141  virtual NetworkOutputs compute(NetworkInputs const &inputs) const = 0;
142 
143  // Conversion to ostream
144  // It's not possible to have a virtual friend function
145  // so instead, have a friend function that calls a virtual protected method
154  friend std::ostream &operator<<(std::ostream &strm,
155  const VNetworkBase &vNetworkBase) {
156  vNetworkBase.print(strm);
157  return strm;
158  }
159 
168  virtual void writeNetToTTree(TTree &tree) = 0;
169 
173  inline static const std::string m_defaultTreeName = "onnxruntime_session";
174 
184  void writeNetToTTree(TFile &root_file,
185  std::string const &tree_name = m_defaultTreeName);
186 
196  void writeNetToTTree(std::string const &root_name,
197  std::string const &tree_name = m_defaultTreeName);
198 
207  virtual std::vector<std::string> getOutputLayers() const = 0;
208 
218  static bool isFile(std::string const &inputFile);
219 
229  bool isFile() const;
230 
239  virtual void deleteAllButNet() = 0;
240 
241 protected:
245  std::string m_inputFile;
246 
256  virtual void setupPersistedVariables() = 0;
257 
267  virtual void setupNet() = 0;
268 
277  virtual void print(std::ostream &strm) const;
278 
289  bool isRootFile(std::string const &filename = "") const;
290 
297 
303  void removePrefixes(std::vector<std::string> &output_names) const;
304 
305 private:
306  // Suppling a ClassDef for writing to file.
308 };
309 
310 #endif
VNetworkBase::NetworkOutputs
std::map< std::string, double > NetworkOutputs
Format for network outputs.
Definition: VNetworkBase.h:100
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
VNetworkBase::VNetworkBase
VNetworkBase()
VNetworkBase default constructor.
Definition: VNetworkBase.cxx:16
VNetworkBase::representNetworkOutputs
static std::string representNetworkOutputs(NetworkOutputs const &outputs, int maxValues=3)
String representation of network outputs.
Definition: VNetworkBase.cxx:57
tree
TChain * tree
Definition: tile_monitor.h:30
VNetworkBase::setupPersistedVariables
virtual void setupPersistedVariables()=0
Perform actions that prep data to create the net.
VNetworkBase::NetworkInputs
std::map< std::string, std::map< std::string, double > > NetworkInputs
Format for network inputs.
Definition: VNetworkBase.h:90
VNetworkBase::m_defaultTreeName
static const std::string m_defaultTreeName
Default name for the TTree to save in.
Definition: VNetworkBase.h:173
VNetworkBase::isFile
bool isFile() const
Check if the argument inputFile is the path of a file on disk.
Definition: VNetworkBase.cxx:117
VNetworkBase::compute
virtual NetworkOutputs compute(NetworkInputs const &inputs) const =0
Function to pass values to the network.
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
VNetworkBase::operator<<
friend std::ostream & operator<<(std::ostream &strm, const VNetworkBase &vNetworkBase)
Put-to operator to facilitate printing.
Definition: VNetworkBase.h:154
VNetworkBase::getOutputLayers
virtual std::vector< std::string > getOutputLayers() const =0
List the names of the outputs.
python.CreateTierZeroArgdict.outputs
outputs
Definition: CreateTierZeroArgdict.py:189
VNetworkBase::removePrefixes
void removePrefixes(NetworkOutputs &outputs) const
Remove any common prefix from the outputs.
Definition: VNetworkBase.cxx:151
VNetworkBase
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
Definition: VNetworkBase.h:38
VNetworkBase::representNetworkInputs
static std::string representNetworkInputs(NetworkInputs const &inputs, int maxValues=3)
String representation of network inputs.
Definition: VNetworkBase.cxx:37
VNetworkBase::setupNet
virtual void setupNet()=0
Perform actions that prepare network for use.
VNetworkBase::~VNetworkBase
virtual ~VNetworkBase()
Definition: VNetworkBase.cxx:34
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
VNetworkBase::isRootFile
bool isRootFile(std::string const &filename="") const
Check if a string is possibly a root file path.
Definition: VNetworkBase.cxx:101
VNetworkBase::writeNetToTTree
virtual void writeNetToTTree(TTree &tree)=0
Save the network to a TTree.
VNetworkBase::m_inputFile
std::string m_inputFile
Path to the file describing the network, including filename.
Definition: VNetworkBase.h:245
VNetworkBase::deleteAllButNet
virtual void deleteAllButNet()=0
Get rid of any memory objects that arn't needed to run the net.
MLogging.h
VNetworkBase::print
virtual void print(std::ostream &strm) const
Write a short description of this net to the string stream.
Definition: VNetworkBase.cxx:73
VNetworkBase::ClassDef
ClassDef(VNetworkBase, 1)