CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends

TH1Store Class Reference

#include <TH1Store.h>

List of all members.

Public Types

typedef std::map< std::string,
std::string > 
SSMap
typedef SSMap::const_iterator SSMapConstIter
typedef std::map< std::string,
TH1 * > 
STH1PtrMap
typedef STH1PtrMap::const_iterator STH1PtrMapConstIter
typedef STH1PtrMap::iterator STH1PtrMapIter
typedef std::vector< std::string > SVec

Public Member Functions

void add (TH1 *histPtr, const std::string &directory="")
TH1 * hist (const std::string &name)
TH1 * hist (const char *name)
TH1 * hist (const TString &name)
void setDeleteOnDestruction (bool deleteOnDestruction=true)
 TH1Store ()
void write (const std::string &filename, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
void write (TFile *filePtr, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
 ~TH1Store ()

Static Public Member Functions

static void setVerbose (bool verbose=true)

Static Public Attributes

static const SVec kEmptyVec

Private Member Functions

TDirectory * _createDir (const std::string &dirname, TFile *filePtr) const

Private Attributes

bool m_deleteOnDestruction
SSMap m_nameDirMap
STH1PtrMap m_ptrMap

Static Private Attributes

static bool sm_verbose = false

Friends

std::ostream & operator<< (std::ostream &o_stream, const TH1Store &rhs)

Detailed Description

Definition at line 15 of file TH1Store.h.


Member Typedef Documentation

typedef std::map< std::string, std::string > TH1Store::SSMap

Definition at line 24 of file TH1Store.h.

typedef SSMap::const_iterator TH1Store::SSMapConstIter

Definition at line 26 of file TH1Store.h.

typedef std::map< std::string, TH1* > TH1Store::STH1PtrMap

Definition at line 25 of file TH1Store.h.

typedef STH1PtrMap::const_iterator TH1Store::STH1PtrMapConstIter

Definition at line 28 of file TH1Store.h.

typedef STH1PtrMap::iterator TH1Store::STH1PtrMapIter

Definition at line 27 of file TH1Store.h.

typedef std::vector< std::string > TH1Store::SVec

Definition at line 23 of file TH1Store.h.


Constructor & Destructor Documentation

TH1Store::TH1Store ( )

Definition at line 21 of file TH1Store.cc.

                   : m_deleteOnDestruction (false)
{
}
TH1Store::~TH1Store ( )

Definition at line 25 of file TH1Store.cc.

References m_deleteOnDestruction, and m_ptrMap.

{
   if (m_deleteOnDestruction)
   {
      for (STH1PtrMapIter iter = m_ptrMap.begin();
           m_ptrMap.end() != iter;
           ++iter)
      {
         delete iter->second;
      } // for iter
   } // if destroying pointers
}

Member Function Documentation

TDirectory * TH1Store::_createDir ( const std::string &  dirname,
TFile *  filePtr 
) const [private]

Definition at line 131 of file TH1Store.cc.

References TrackerOfflineValidation_Dqm_cff::dirName.

Referenced by write().

{
   // do we have this one already
   TDirectory *dirPtr = filePtr->GetDirectory (dirName.c_str());
   if (dirPtr)
   {
      dirPtr->cd();
      return dirPtr;
   }
   // if we're here, then this directory doesn't exist.  Is this
   // directory a subdirectory?
   const boost::regex subdirRE ("(.+?)/([^/]+)");
   boost::smatch matches;
   TDirectory *parentDir = 0;
   string useName = dirName;
   if( boost::regex_match (dirName, matches, subdirRE) )
   {
      parentDir = _createDir (matches[1], filePtr);
      useName = matches[2];
   } else {
      // This is not a subdirectory, so we're golden
      parentDir = filePtr;
   }
   dirPtr = parentDir->mkdir (useName.c_str());
   dirPtr->cd();
   return dirPtr;
}
void TH1Store::add ( TH1 *  histPtr,
const std::string &  directory = "" 
)

Definition at line 39 of file TH1Store.cc.

References benchmark_cfg::cerr, gather_cfg::cout, createBeamHaloJobs::directory, m_nameDirMap, m_ptrMap, mergeVDriftHistosByStation::name, and sm_verbose.

{
   // Do we have a histogram with this name already?
   string name = histPtr->GetName();
   if (m_ptrMap.end() != m_ptrMap.find (name))
   {
      //  D'oh
      cerr << "TH1Store::add() Error: '" << name 
           << "' already exists.  Aborting." << endl;
      assert (0);
   } // if already exists
   if (sm_verbose)
   {
      cout << "THStore::add() : Adding " << name << endl;
   }   
   m_ptrMap[name] = histPtr;
   histPtr->SetDirectory(0);
   if (directory.length())
   {
      m_nameDirMap[name] = directory;
   }
}
TH1* TH1Store::hist ( const char *  name) [inline]

Definition at line 68 of file TH1Store.h.

References hist().

Referenced by hist().

      { return hist( (const std::string) name ); }
TH1* TH1Store::hist ( const TString &  name) [inline]

Definition at line 70 of file TH1Store.h.

References hist().

Referenced by hist().

      { return hist( (const char*) name ); }
TH1* TH1Store::hist ( const std::string &  name)
void TH1Store::setDeleteOnDestruction ( bool  deleteOnDestruction = true) [inline]

Definition at line 56 of file TH1Store.h.

References m_deleteOnDestruction.

      { m_deleteOnDestruction = deleteOnDestruction; }
static void TH1Store::setVerbose ( bool  verbose = true) [inline, static]

Definition at line 87 of file TH1Store.h.

References sm_verbose, and validate_alignment_devdb10_cfg::verbose.

void TH1Store::write ( const std::string &  filename,
const SVec argsVec = kEmptyVec,
const SVec inputFilesVec = kEmptyVec 
) const
void TH1Store::write ( TFile *  filePtr,
const SVec argsVec = kEmptyVec,
const SVec inputFilesVec = kEmptyVec 
) const

Definition at line 93 of file TH1Store.cc.

References _createDir(), gather_cfg::cout, dir, m_nameDirMap, and m_ptrMap.

{
   filePtr->cd();
   // write out all histograms
   for (STH1PtrMapConstIter iter = m_ptrMap.begin();
        m_ptrMap.end() != iter;
        ++iter)
   {
      SSMapConstIter nameDirIter = m_nameDirMap.find (iter->first);
      if (m_nameDirMap.end() != nameDirIter)
      {
         // we want a subdirectory for this one
         _createDir (nameDirIter->second, filePtr);
      } else {
         // we don't need a subdirectory, just save this in the main
         // directory.
         filePtr->cd();         
      }
      iter->second->Write();
   } // for iter
   // Write out command line arguments.  Save information in directory
   // called provenance.
   TDirectory *dir = _createDir ("args", filePtr);
   if (argsVec.size())
   {
      dir->WriteObject (&argsVec, "argsVec");
   }
   if (inputFilesVec.size())
   {
      dir->WriteObject (&inputFilesVec, "inputFiles");
   }
   cout << "TH1Store::write(): Successfully written to '"
        << filePtr->GetName() << "'." << endl;
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o_stream,
const TH1Store rhs 
) [friend]

Member Data Documentation

Definition at line 30 of file TH1Store.h.

Definition at line 105 of file TH1Store.h.

Referenced by setDeleteOnDestruction(), and ~TH1Store().

Definition at line 107 of file TH1Store.h.

Referenced by add(), and write().

Definition at line 106 of file TH1Store.h.

Referenced by add(), write(), and ~TH1Store().

bool TH1Store::sm_verbose = false [static, private]

Definition at line 113 of file TH1Store.h.

Referenced by add(), and setVerbose().