CMS 3D CMS Logo

Classes | Public Member Functions | Private Types | Private Attributes

VariablePlotter Class Reference

#include <Plotter.h>

Inheritance diagram for VariablePlotter:
Plotter

List of all members.

Classes

class  Directory
class  SubDirectory

Public Member Functions

void complete ()
void fill (std::string subDir, const edm::Event &iEvent)
void setDir (std::string dir)
 VariablePlotter (edm::ParameterSet iConfig)
 ~VariablePlotter ()

Private Types

typedef std::map< std::string,
Directory
Directories
typedef std::map< std::string,
ConfigurableHisto * > 
DirectoryHistos
typedef std::map< std::string,
SubDirectory
SubDirectories

Private Attributes

std::string currentDir_
Directories directories_
DirectoryHistos master_

Detailed Description

Definition at line 31 of file Plotter.h.


Member Typedef Documentation

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

Definition at line 209 of file Plotter.h.

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

Definition at line 190 of file Plotter.h.

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

Definition at line 200 of file Plotter.h.


Constructor & Destructor Documentation

VariablePlotter::VariablePlotter ( edm::ParameterSet  iConfig) [inline]

Definition at line 33 of file Plotter.h.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSetNames(), ConfigurableHisto::h1, ConfigurableHisto::h2, master_, ConfigurableHisto::prof, and split.

                                           : currentDir_("youDidNotSetDirectoryFirst") {
    //create the master copy, never filled, just to make copies

    //    make TH1
    edm::ParameterSet th1=iConfig.getParameter<edm::ParameterSet>("TH1s");
    std::vector<std::string> th1Names;
    th1.getParameterSetNames(th1Names);
    for (unsigned int iH=0;iH!=th1Names.size();++iH){
      std::string hname = th1Names[iH];
      edm::ParameterSet hPset=th1.getParameter<edm::ParameterSet>(hname);
      bool split=hPset.exists("splitter") || hPset.exists("splitters");
      if (split)
        master_[hname]=new SplittingConfigurableHisto(ConfigurableHisto::h1, hname, hPset);
      else
        master_[hname]=new ConfigurableHisto(ConfigurableHisto::h1, hname, hPset);
    }

    //    make profiles
    edm::ParameterSet tprof=iConfig.getParameter<edm::ParameterSet>("TProfiles");
    std::vector<std::string> tprofNames;
    tprof.getParameterSetNames(tprofNames);
    for (unsigned int iH=0;iH!=tprofNames.size();++iH){
      std::string hname = tprofNames[iH];
      edm::ParameterSet hPset=tprof.getParameter<edm::ParameterSet>(hname);
      bool split=hPset.exists("splitter") || hPset.exists("splitters");
      if (split)
        master_[hname]=new SplittingConfigurableHisto(ConfigurableHisto::prof, hname, hPset);
      else
        master_[hname]=new ConfigurableHisto(ConfigurableHisto::prof, hname, hPset);
    }
    
    //    make TH2
    edm::ParameterSet th2=iConfig.getParameter<edm::ParameterSet>("TH2s");
    std::vector<std::string> th2Names;
    th2.getParameterSetNames(th2Names);
    for (unsigned int iH=0;iH!=th2Names.size();++iH){
      std::string hname = th2Names[iH];
      edm::ParameterSet hPset=th2.getParameter<edm::ParameterSet>(hname);
      bool split=hPset.exists("splitter") || hPset.exists("splitters");
      if (split)
        master_[hname]=new SplittingConfigurableHisto(ConfigurableHisto::h2, hname, hPset);
      else
        master_[hname]=new ConfigurableHisto(ConfigurableHisto::h2, hname, hPset);
    }
  }
VariablePlotter::~VariablePlotter ( ) [inline]

Definition at line 142 of file Plotter.h.

                    {
    // CANNOT DO THAT because of TFileService holding the histograms
    /*    //loop over all subdirectories and delete all ConfigurableHistograms
          Directories::iterator dir_It = directories_.begin();
          Directories::iterator dir_It_end = directories_.end();
          // loop directories
          for (;dir_It!=dir_It_end;++dir_It){
          Directory & currentDirectory=dir_It->second;
          SubDirectories & currentSetOfSubDirectories=currentDirectory.subDir;
          SubDirectories::iterator subDir_It = currentSetOfSubDirectories.begin();
          SubDirectories::iterator subDir_It_end = currentSetOfSubDirectories.end();
          //loop subdirectories
          for (;subDir_It!=subDir_It_end;++subDir_It){
          DirectoryHistos::iterator histogramIterator=subDir_It->second.histos.begin();
          DirectoryHistos::iterator histogramIterator_end=subDir_It->second.histos.end();
          //loop configurable histograms
          for(; histogramIterator!=histogramIterator_end;++histogramIterator){
          // by doing that you are removing the histogram from the TFileService too. and this will crash
          //      delete histogramIterator->second;
          }
          }
          }
    */
  }

Member Function Documentation

void VariablePlotter::complete ( ) [inline, virtual]

Implements Plotter.

Definition at line 166 of file Plotter.h.

References directories_, and VariablePlotter::Directory::subDir.

                 {
    
    //loop over all subdirectories and call complete() on all ConfigurableHistograms
    
    Directories::iterator dir_It = directories_.begin();
    Directories::iterator dir_It_end = directories_.end();
    // loop directories
    for (;dir_It!=dir_It_end;++dir_It){
      Directory & currentDirectory=dir_It->second;
      SubDirectories & currentSetOfSubDirectories=currentDirectory.subDir;
      SubDirectories::iterator subDir_It = currentSetOfSubDirectories.begin();
      SubDirectories::iterator subDir_It_end = currentSetOfSubDirectories.end();
      //loop subdirectories
      for (;subDir_It!=subDir_It_end;++subDir_It){
        DirectoryHistos::iterator histogramIterator=subDir_It->second.histos.begin();
        DirectoryHistos::iterator histogramIterator_end=subDir_It->second.histos.end();
        //loop configurable histograms
        for(; histogramIterator!=histogramIterator_end;++histogramIterator)
          { histogramIterator->second->complete(); }
      }
    }
  }
void VariablePlotter::fill ( std::string  subDir,
const edm::Event iEvent 
) [inline, virtual]

Implements Plotter.

Definition at line 93 of file Plotter.h.

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

                                                    {
    //what is the current directory
    Directory & currentDirectory= directories_[currentDir_];

    //what is the current set of sub directories for this
    SubDirectories & currentSetOfSubDirectories=currentDirectory.subDir;
    
    //find the subDirectory requested:
    SubDirectory * subDirectoryToUse=0;
    SubDirectories::iterator subDirectoryFindIterator=currentSetOfSubDirectories.find(subDir);

    //not found? insert a new directory with this name
    if (subDirectoryFindIterator==currentSetOfSubDirectories.end()){
      edm::LogInfo("VariablePlotter")<<" gonna clone histograms for :"<<subDir<<" in "<<currentDir_;
      SubDirectory & insertedDir = currentSetOfSubDirectories[subDir];
      subDirectoryToUse = &insertedDir;
      if (!insertedDir.dir){
        insertedDir.dir=new TFileDirectory(currentDirectory.dir->mkdir(subDir));
        insertedDir.dirName=subDir;
      }

      //create a copy from the master copy
      DirectoryHistos::iterator masterHistogramIterator=master_.begin();
      DirectoryHistos::iterator masterHistogramIterator_end=master_.end();
      for (; masterHistogramIterator!=masterHistogramIterator_end;++masterHistogramIterator)
        {
          //clone does not book histogram
          insertedDir.histos[masterHistogramIterator->first]=masterHistogramIterator->second->clone();
        }
      
      //book all copies of the histos
      DirectoryHistos::iterator clonedHistogramIterator=insertedDir.histos.begin();
      DirectoryHistos::iterator clonedHistogramIterator_end=insertedDir.histos.end();
      for (; clonedHistogramIterator!=clonedHistogramIterator_end;++clonedHistogramIterator)
        {
          clonedHistogramIterator->second->book(insertedDir.dir);
        }
    }
    else{
      subDirectoryToUse=&subDirectoryFindIterator->second;
    }
    
    //now that you have the subdirectory: fill histograms for this sub directory
    DirectoryHistos::iterator histogramIterator=subDirectoryToUse->histos.begin();
    DirectoryHistos::iterator histogramIterator_end=subDirectoryToUse->histos.end();
    for(; histogramIterator!=histogramIterator_end;++histogramIterator)
      { histogramIterator->second->fill(iEvent); }
  }
void VariablePlotter::setDir ( std::string  dir) [inline, virtual]

Implements Plotter.

Definition at line 79 of file Plotter.h.

References currentDir_, dir, VariablePlotter::Directory::dir, directories_, and VariablePlotter::Directory::dirName.

                            {
    //insert a new one
    Directory & insertedDirectory = directories_[dir];

    //create the actual directory in TFile: name is <dir>
    if (!insertedDirectory.dir){
      insertedDirectory.dir=new TFileDirectory(edm::Service<TFileService>()->mkdir(dir));
      insertedDirectory.dirName=dir;
    }

    //remember which directory name this is
    currentDir_=dir;
  }

Member Data Documentation

std::string VariablePlotter::currentDir_ [private]

Definition at line 211 of file Plotter.h.

Referenced by fill(), and setDir().

Definition at line 212 of file Plotter.h.

Referenced by complete(), fill(), and setDir().

Definition at line 191 of file Plotter.h.

Referenced by fill(), and VariablePlotter().