CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Attributes
VariablePlotter Class Reference

#include <Plotter.h>

Inheritance diagram for VariablePlotter:
Plotter

Classes

class  Directory
 
class  SubDirectory
 

Public Member Functions

void complete () override
 
void fill (std::string subDir, const edm::Event &iEvent) override
 
void setDir (std::string dir) override
 
 VariablePlotter (const edm::ParameterSet &iConfig)
 
 ~VariablePlotter () override
 
- Public Member Functions inherited from Plotter
 Plotter ()
 
 Plotter (const edm::ParameterSet &iConfig)
 
virtual ~Plotter ()
 

Private Types

typedef std::map< std::string, DirectoryDirectories
 
typedef std::map< std::string, ConfigurableHisto * > DirectoryHistos
 
typedef std::map< std::string, SubDirectorySubDirectories
 

Private Attributes

std::string currentDir_
 
Directories directories_
 
DirectoryHistos master_
 

Detailed Description

Definition at line 29 of file Plotter.h.

Member Typedef Documentation

typedef std::map<std::string, Directory> VariablePlotter::Directories
private

Definition at line 211 of file Plotter.h.

typedef std::map<std::string, ConfigurableHisto*> VariablePlotter::DirectoryHistos
private

Definition at line 192 of file Plotter.h.

typedef std::map<std::string, SubDirectory> VariablePlotter::SubDirectories
private

Definition at line 202 of file Plotter.h.

Constructor & Destructor Documentation

VariablePlotter::VariablePlotter ( const edm::ParameterSet iConfig)
inline

Definition at line 31 of file Plotter.h.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSetNames(), ConfigurableHisto::h1, ConfigurableHisto::h2, ConfigurableHisto::prof, cms::dd::split(), and AlCaHLTBitMon_QueryRunRegistry::string.

31  : currentDir_("youDidNotSetDirectoryFirst") {
32  //create the master copy, never filled, just to make copies
33 
34  // make TH1
35  edm::ParameterSet th1 = iConfig.getParameter<edm::ParameterSet>("TH1s");
36  std::vector<std::string> th1Names;
37  th1.getParameterSetNames(th1Names);
38  for (unsigned int iH = 0; iH != th1Names.size(); ++iH) {
39  std::string hname = th1Names[iH];
41  if (hPset.exists("name"))
42  hname = hPset.getParameter<std::string>("name");
43  bool split = hPset.exists("splitter") || hPset.exists("splitters");
44  if (split)
45  master_[hname] = new SplittingConfigurableHisto(ConfigurableHisto::h1, hname, hPset);
46  else
47  master_[hname] = new ConfigurableHisto(ConfigurableHisto::h1, hname, hPset);
48  }
49 
50  // make profiles
51  edm::ParameterSet tprof = iConfig.getParameter<edm::ParameterSet>("TProfiles");
52  std::vector<std::string> tprofNames;
53  tprof.getParameterSetNames(tprofNames);
54  for (unsigned int iH = 0; iH != tprofNames.size(); ++iH) {
55  std::string hname = tprofNames[iH];
56  edm::ParameterSet hPset = tprof.getParameter<edm::ParameterSet>(hname);
57  bool split = hPset.exists("splitter") || hPset.exists("splitters");
58  if (hPset.exists("name"))
59  hname = hPset.getParameter<std::string>("name");
60  if (split)
62  else
63  master_[hname] = new ConfigurableHisto(ConfigurableHisto::prof, hname, hPset);
64  }
65 
66  // make TH2
67  edm::ParameterSet th2 = iConfig.getParameter<edm::ParameterSet>("TH2s");
68  std::vector<std::string> th2Names;
69  th2.getParameterSetNames(th2Names);
70  for (unsigned int iH = 0; iH != th2Names.size(); ++iH) {
71  std::string hname = th2Names[iH];
73  if (hPset.exists("name"))
74  hname = hPset.getParameter<std::string>("name");
75  bool split = hPset.exists("splitter") || hPset.exists("splitters");
76  if (split)
77  master_[hname] = new SplittingConfigurableHisto(ConfigurableHisto::h2, hname, hPset);
78  else
79  master_[hname] = new ConfigurableHisto(ConfigurableHisto::h2, hname, hPset);
80  }
81  }
std::vector< std::string_view > split(std::string_view, const char *)
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
DirectoryHistos master_
Definition: Plotter.h:193
std::string currentDir_
Definition: Plotter.h:213
size_t getParameterSetNames(std::vector< std::string > &output, bool trackiness=true) const
VariablePlotter::~VariablePlotter ( )
inlineoverride

Definition at line 144 of file Plotter.h.

144  {
145  // CANNOT DO THAT because of TFileService holding the histograms
146  /* //loop over all subdirectories and delete all ConfigurableHistograms
147  Directories::iterator dir_It = directories_.begin();
148  Directories::iterator dir_It_end = directories_.end();
149  // loop directories
150  for (;dir_It!=dir_It_end;++dir_It){
151  Directory & currentDirectory=dir_It->second;
152  SubDirectories & currentSetOfSubDirectories=currentDirectory.subDir;
153  SubDirectories::iterator subDir_It = currentSetOfSubDirectories.begin();
154  SubDirectories::iterator subDir_It_end = currentSetOfSubDirectories.end();
155  //loop subdirectories
156  for (;subDir_It!=subDir_It_end;++subDir_It){
157  DirectoryHistos::iterator histogramIterator=subDir_It->second.histos.begin();
158  DirectoryHistos::iterator histogramIterator_end=subDir_It->second.histos.end();
159  //loop configurable histograms
160  for(; histogramIterator!=histogramIterator_end;++histogramIterator){
161  // by doing that you are removing the histogram from the TFileService too. and this will crash
162  // delete histogramIterator->second;
163  }
164  }
165  }
166  */
167  }

Member Function Documentation

void VariablePlotter::complete ( )
inlineoverridevirtual

Implements Plotter.

Definition at line 168 of file Plotter.h.

References VariablePlotter::Directory::subDir.

168  {
169  //loop over all subdirectories and call complete() on all ConfigurableHistograms
170 
171  Directories::iterator dir_It = directories_.begin();
172  Directories::iterator dir_It_end = directories_.end();
173  // loop directories
174  for (; dir_It != dir_It_end; ++dir_It) {
175  Directory& currentDirectory = dir_It->second;
176  SubDirectories& currentSetOfSubDirectories = currentDirectory.subDir;
177  SubDirectories::iterator subDir_It = currentSetOfSubDirectories.begin();
178  SubDirectories::iterator subDir_It_end = currentSetOfSubDirectories.end();
179  //loop subdirectories
180  for (; subDir_It != subDir_It_end; ++subDir_It) {
181  DirectoryHistos::iterator histogramIterator = subDir_It->second.histos.begin();
182  DirectoryHistos::iterator histogramIterator_end = subDir_It->second.histos.end();
183  //loop configurable histograms
184  for (; histogramIterator != histogramIterator_end; ++histogramIterator) {
185  histogramIterator->second->complete();
186  }
187  }
188  }
189  }
Directories directories_
Definition: Plotter.h:214
std::map< std::string, SubDirectory > SubDirectories
Definition: Plotter.h:202
void VariablePlotter::fill ( std::string  subDir,
const edm::Event iEvent 
)
inlineoverridevirtual

Implements Plotter.

Definition at line 97 of file Plotter.h.

References VariablePlotter::SubDirectory::dir, VariablePlotter::Directory::dir, VariablePlotter::SubDirectory::dirName, VariablePlotter::SubDirectory::histos, TFileDirectory::mkdir(), PostProcessorHcalIsoTrack_cfi::subDir, and VariablePlotter::Directory::subDir.

97  {
98  //what is the current directory
99  Directory& currentDirectory = directories_[currentDir_];
100 
101  //what is the current set of sub directories for this
102  SubDirectories& currentSetOfSubDirectories = currentDirectory.subDir;
103 
104  //find the subDirectory requested:
105  SubDirectory* subDirectoryToUse = nullptr;
106  SubDirectories::iterator subDirectoryFindIterator = currentSetOfSubDirectories.find(subDir);
107 
108  //not found? insert a new directory with this name
109  if (subDirectoryFindIterator == currentSetOfSubDirectories.end()) {
110  edm::LogInfo("VariablePlotter") << " gonna clone histograms for :" << subDir << " in " << currentDir_;
111  SubDirectory& insertedDir = currentSetOfSubDirectories[subDir];
112  subDirectoryToUse = &insertedDir;
113  if (!insertedDir.dir) {
114  insertedDir.dir = new TFileDirectory(currentDirectory.dir->mkdir(subDir));
115  insertedDir.dirName = subDir;
116  }
117 
118  //create a copy from the master copy
119  DirectoryHistos::iterator masterHistogramIterator = master_.begin();
120  DirectoryHistos::iterator masterHistogramIterator_end = master_.end();
121  for (; masterHistogramIterator != masterHistogramIterator_end; ++masterHistogramIterator) {
122  //clone does not book histogram
123  insertedDir.histos[masterHistogramIterator->first] = masterHistogramIterator->second->clone();
124  }
125 
126  //book all copies of the histos
127  DirectoryHistos::iterator clonedHistogramIterator = insertedDir.histos.begin();
128  DirectoryHistos::iterator clonedHistogramIterator_end = insertedDir.histos.end();
129  for (; clonedHistogramIterator != clonedHistogramIterator_end; ++clonedHistogramIterator) {
130  clonedHistogramIterator->second->book(insertedDir.dir);
131  }
132  } else {
133  subDirectoryToUse = &subDirectoryFindIterator->second;
134  }
135 
136  //now that you have the subdirectory: fill histograms for this sub directory
137  DirectoryHistos::iterator histogramIterator = subDirectoryToUse->histos.begin();
138  DirectoryHistos::iterator histogramIterator_end = subDirectoryToUse->histos.end();
139  for (; histogramIterator != histogramIterator_end; ++histogramIterator) {
140  histogramIterator->second->fill(iEvent);
141  }
142  }
Directories directories_
Definition: Plotter.h:214
DirectoryHistos master_
Definition: Plotter.h:193
std::string currentDir_
Definition: Plotter.h:213
std::map< std::string, SubDirectory > SubDirectories
Definition: Plotter.h:202
void VariablePlotter::setDir ( std::string  dir)
inlineoverridevirtual

Implements Plotter.

Definition at line 83 of file Plotter.h.

References DeadROC_duringRun::dir, VariablePlotter::Directory::dir, VariablePlotter::Directory::dirName, and eostools::mkdir().

83  {
84  //insert a new one
85  Directory& insertedDirectory = directories_[dir];
86 
87  //create the actual directory in TFile: name is <dir>
88  if (!insertedDirectory.dir) {
89  insertedDirectory.dir = new TFileDirectory(edm::Service<TFileService>()->mkdir(dir));
90  insertedDirectory.dirName = dir;
91  }
92 
93  //remember which directory name this is
94  currentDir_ = dir;
95  }
Directories directories_
Definition: Plotter.h:214
def mkdir(path)
Definition: eostools.py:251
std::string currentDir_
Definition: Plotter.h:213

Member Data Documentation

std::string VariablePlotter::currentDir_
private

Definition at line 213 of file Plotter.h.

Directories VariablePlotter::directories_
private

Definition at line 214 of file Plotter.h.

DirectoryHistos VariablePlotter::master_
private

Definition at line 193 of file Plotter.h.