CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
deep_tau::DeepTauCache Class Reference

#include <DeepTauBase.h>

Public Types

using GraphPtr = std::shared_ptr< tensorflow::GraphDef >
 

Public Member Functions

 DeepTauCache (const std::map< std::string, std::string > &graph_names, bool mem_mapped)
 
const tensorflow::GraphDef & getGraph (const std::string &name="") const
 
tensorflow::Session & getSession (const std::string &name="") const
 
 ~DeepTauCache ()
 

Private Attributes

std::map< std::string, GraphPtrgraphs_
 
std::map< std::string, std::unique_ptr< tensorflow::MemmappedEnv > > memmappedEnv_
 
std::map< std::string, tensorflow::Session * > sessions_
 

Detailed Description

Definition at line 40 of file DeepTauBase.h.

Member Typedef Documentation

◆ GraphPtr

using deep_tau::DeepTauCache::GraphPtr = std::shared_ptr<tensorflow::GraphDef>

Definition at line 42 of file DeepTauBase.h.

Constructor & Destructor Documentation

◆ DeepTauCache()

deep_tau::DeepTauCache::DeepTauCache ( const std::map< std::string, std::string > &  graph_names,
bool  mem_mapped 
)

Definition at line 130 of file DeepTauBase.cc.

130  {
131  for (const auto& graph_entry : graph_names) {
132  tensorflow::SessionOptions options;
134 
135  const std::string& entry_name = graph_entry.first;
136  const std::string& graph_file = graph_entry.second;
137  if (mem_mapped) {
138  memmappedEnv_[entry_name] = std::make_unique<tensorflow::MemmappedEnv>(tensorflow::Env::Default());
139  const tensorflow::Status mmap_status = memmappedEnv_.at(entry_name)->InitializeFromFile(graph_file);
140  if (!mmap_status.ok()) {
141  throw cms::Exception("DeepTauCache: unable to initalize memmapped environment for ")
142  << graph_file << ". \n"
143  << mmap_status.ToString();
144  }
145 
146  graphs_[entry_name] = std::make_unique<tensorflow::GraphDef>();
147  const tensorflow::Status load_graph_status =
148  ReadBinaryProto(memmappedEnv_.at(entry_name).get(),
149  tensorflow::MemmappedFileSystem::kMemmappedPackageDefaultGraphDef,
150  graphs_.at(entry_name).get());
151  if (!load_graph_status.ok())
152  throw cms::Exception("DeepTauCache: unable to load graph from ") << graph_file << ". \n"
153  << load_graph_status.ToString();
154 
155  options.config.mutable_graph_options()->mutable_optimizer_options()->set_opt_level(
156  ::tensorflow::OptimizerOptions::L0);
157  options.env = memmappedEnv_.at(entry_name).get();
158 
159  sessions_[entry_name] = tensorflow::createSession(graphs_.at(entry_name).get(), options);
160 
161  } else {
162  graphs_[entry_name].reset(tensorflow::loadGraphDef(graph_file));
163  sessions_[entry_name] = tensorflow::createSession(graphs_.at(entry_name).get(), options);
164  }
165  }
166  }

References tensorflow::createSession(), Default, Exception, graphs_, tensorflow::loadGraphDef(), memmappedEnv_, AlcaSiPixelAliHarvester0T_cff::options, sessions_, tensorflow::setThreading(), btagGenBb_cfi::Status, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ ~DeepTauCache()

deep_tau::DeepTauCache::~DeepTauCache ( )

Definition at line 168 of file DeepTauBase.cc.

168  {
169  for (auto& session_entry : sessions_)
170  tensorflow::closeSession(session_entry.second);
171  }

References tensorflow::closeSession(), and sessions_.

Member Function Documentation

◆ getGraph()

const tensorflow::GraphDef& deep_tau::DeepTauCache::getGraph ( const std::string &  name = "") const
inline

Definition at line 50 of file DeepTauBase.h.

50 { return *graphs_.at(name); }

References graphs_, and Skims_PA_cff::name.

Referenced by DeepTauId::DeepTauId(), and DPFIsolation::DPFIsolation().

◆ getSession()

tensorflow::Session& deep_tau::DeepTauCache::getSession ( const std::string &  name = "") const
inline

Member Data Documentation

◆ graphs_

std::map<std::string, GraphPtr> deep_tau::DeepTauCache::graphs_
private

Definition at line 53 of file DeepTauBase.h.

Referenced by DeepTauCache(), and getGraph().

◆ memmappedEnv_

std::map<std::string, std::unique_ptr<tensorflow::MemmappedEnv> > deep_tau::DeepTauCache::memmappedEnv_
private

Definition at line 55 of file DeepTauBase.h.

Referenced by DeepTauCache().

◆ sessions_

std::map<std::string, tensorflow::Session*> deep_tau::DeepTauCache::sessions_
private

Definition at line 54 of file DeepTauBase.h.

Referenced by DeepTauCache(), getSession(), and ~DeepTauCache().

tensorflow::createSession
Session * createSession(SessionOptions &sessionOptions)
Definition: TensorFlow.cc:85
deep_tau::DeepTauCache::sessions_
std::map< std::string, tensorflow::Session * > sessions_
Definition: DeepTauBase.h:54
tensorflow::setThreading
void setThreading(SessionOptions &sessionOptions, int nThreads=1)
Definition: TensorFlow.cc:17
btagGenBb_cfi.Status
Status
Definition: btagGenBb_cfi.py:4
options
Definition: options.py:1
tensorflow::closeSession
bool closeSession(Session *&session)
Definition: TensorFlow.cc:196
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
deep_tau::DeepTauCache::graphs_
std::map< std::string, GraphPtr > graphs_
Definition: DeepTauBase.h:53
tensorflow::loadGraphDef
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
Exception
Definition: hltDiff.cc:246
Default
#define Default
Definition: vmac.h:110
AlcaSiPixelAliHarvester0T_cff.options
options
Definition: AlcaSiPixelAliHarvester0T_cff.py:42
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
cms::Exception
Definition: Exception.h:70
deep_tau::DeepTauCache::memmappedEnv_
std::map< std::string, std::unique_ptr< tensorflow::MemmappedEnv > > memmappedEnv_
Definition: DeepTauBase.h:55