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 48 of file DeepTauBase.h.

Member Typedef Documentation

◆ GraphPtr

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

Definition at line 50 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 210 of file DeepTauBase.cc.

210  {
211  for (const auto& graph_entry : graph_names) {
212  tensorflow::SessionOptions options;
214 
215  const std::string& entry_name = graph_entry.first;
216  const std::string& graph_file = graph_entry.second;
217  if (mem_mapped) {
218  memmappedEnv_[entry_name] = std::make_unique<tensorflow::MemmappedEnv>(tensorflow::Env::Default());
219  const tensorflow::Status mmap_status = memmappedEnv_.at(entry_name)->InitializeFromFile(graph_file);
220  if (!mmap_status.ok()) {
221  throw cms::Exception("DeepTauCache: unable to initalize memmapped environment for ")
222  << graph_file << ". \n"
223  << mmap_status.ToString();
224  }
225 
226  graphs_[entry_name] = std::make_unique<tensorflow::GraphDef>();
227  const tensorflow::Status load_graph_status =
228  ReadBinaryProto(memmappedEnv_.at(entry_name).get(),
229  tensorflow::MemmappedFileSystem::kMemmappedPackageDefaultGraphDef,
230  graphs_.at(entry_name).get());
231  if (!load_graph_status.ok())
232  throw cms::Exception("DeepTauCache: unable to load graph from ") << graph_file << ". \n"
233  << load_graph_status.ToString();
234 
235  options.config.mutable_graph_options()->mutable_optimizer_options()->set_opt_level(
236  ::tensorflow::OptimizerOptions::L0);
237  options.env = memmappedEnv_.at(entry_name).get();
238 
239  sessions_[entry_name] = tensorflow::createSession(graphs_.at(entry_name).get(), options);
240 
241  } else {
242  graphs_[entry_name].reset(tensorflow::loadGraphDef(graph_file));
243  sessions_[entry_name] = tensorflow::createSession(graphs_.at(entry_name).get(), options);
244  }
245  }
246  }

References tensorflow::createSession(), 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 248 of file DeepTauBase.cc.

248  {
249  for (auto& session_entry : sessions_)
250  tensorflow::closeSession(session_entry.second);
251  }

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 58 of file DeepTauBase.h.

58 { 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 61 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 63 of file DeepTauBase.h.

Referenced by DeepTauCache().

◆ sessions_

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

Definition at line 62 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:62
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:198
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
deep_tau::DeepTauCache::graphs_
std::map< std::string, GraphPtr > graphs_
Definition: DeepTauBase.h:61
tensorflow::loadGraphDef
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
Exception
Definition: hltDiff.cc:245
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:63