CMS 3D CMS Logo

TrainerMonitoring.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 #include <memory>
4 #include <ostream>
5 
6 #include <TFile.h>
7 #include <TDirectory.h>
8 #include <TObject.h>
9 
11 
13 
14 namespace { // anonymous
15 
16 class ROOTContextSentinel {
17  public:
18  ROOTContextSentinel() : dir(gDirectory), file(gFile) {}
19  ~ROOTContextSentinel() { gDirectory = dir; gFile = file; }
20 
21  private:
22  TDirectory *dir;
23  TFile *file;
24 };
25 
26 } // anonymous namespace
27 
28 namespace PhysicsTools {
29 
30 TrainerMonitoring::TrainerMonitoring(const std::string &fileName)
31 {
32  ROOTContextSentinel ctx;
33 
34  rootFile.reset(TFile::Open(fileName.c_str(), "RECREATE"));
35 }
36 
37 TrainerMonitoring::~TrainerMonitoring()
38 {
39 }
40 
42 {
43  ROOTContextSentinel ctx;
44 
45  typedef std::map<std::string, std::shared_ptr<Module> > Map;
46  for(Map::const_iterator iter = modules.begin();
47  iter != modules.end(); ++iter) {
48  rootFile->cd();
49  TDirectory *dir = rootFile->mkdir(iter->first.c_str());
50  dir->cd();
51  iter->second->write(dir);
52  }
53 }
54 
56 {
57 }
58 
59 TrainerMonitoring::Module::~Module()
60 {
61 }
62 
64 {
65  typedef std::map<std::string, std::shared_ptr<Object> > Map;
66  for(Map::const_iterator iter = data.begin();
67  iter != data.end(); ++iter)
68  iter->second->write(dir);
69 }
70 
72 {
73  std::shared_ptr<Object> ptr(object);
74  if (!data.insert(std::make_pair(object->getName(), ptr)).second)
75  throw cms::Exception("DuplicateNode")
76  << "Node \"" << object->getName() << "\" already"
77  " exists." << std::endl;
78 }
79 
80 TrainerMonitoring::Module *TrainerMonitoring::book(const std::string &name)
81 {
82  std::shared_ptr<Module> module(new Module);
83  if (!modules.insert(std::make_pair(name, module)).second)
84  throw cms::Exception("DuplicateModule")
85  << "Module \"" << name << "\" already"
86  " exists." << std::endl;
87 
88  return module.get();
89 }
90 
91 } // namespace PhysicsTools
const std::string & getName() const
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
#define Module(md)
Definition: vmac.h:203
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
dbl *** dir
Definition: mlp_gen.cc:35
def write(self, setup)
Definition: vlib.h:208