: Adds functionality to TFile to ease building and navigation of TFiles containing DQM histograms. More...
#include <SiStripTFile.h>
Inherits ROOT::TFile.
Public Types | |
typedef std::vector< TH1 * > | Histos |
typedef std::map< std::string, Histos > | HistosMap |
Public Member Functions | |
void | addDevice (unsigned int key) |
TDirectory * | addPath (const std::string &) |
void | dirContent (TDirectory *, std::vector< TDirectory * > *, std::map< std::string, std::vector< TH1 * > > *) |
TDirectory * | dqmTop () |
void | findHistos (TDirectory *, std::map< std::string, std::vector< TH1 * > > *) |
bool | queryDQMFormat () |
TDirectory * | readDQMFormat () |
sistrip::RunType & | runType () |
TDirectory * | setDQMFormat (sistrip::RunType, sistrip::View) |
SiStripTFile (const char *fname, Option_t *option="UPDATE", const char *ftitle="", Int_t compress=1) | |
TDirectory * | sistripTop () |
TDirectory * | top () |
sistrip::View & | View () |
virtual | ~SiStripTFile () |
Private Attributes | |
bool | dqmFormat_ |
TDirectory * | dqmTop_ |
sistrip::RunType | runType_ |
TDirectory * | sistripTop_ |
TDirectory * | top_ |
sistrip::View | view_ |
: Adds functionality to TFile to ease building and navigation of TFiles containing DQM histograms.
Definition at line 22 of file SiStripTFile.h.
typedef std::vector<TH1*> SiStripTFile::Histos |
Definition at line 38 of file SiStripTFile.h.
typedef std::map< std::string, Histos > SiStripTFile::HistosMap |
Definition at line 41 of file SiStripTFile.h.
SiStripTFile::SiStripTFile | ( | const char * | fname, |
Option_t * | option = "UPDATE" , |
||
const char * | ftitle = "" , |
||
Int_t | compress = 1 |
||
) |
Constructor
Definition at line 15 of file SiStripTFile.cc.
References readDQMFormat().
: TFile(fname,option,ftitle,compress), runType_(sistrip::UNKNOWN_RUN_TYPE), view_(sistrip::UNKNOWN_VIEW), top_(gDirectory), dqmTop_(0), sistripTop_(0), dqmFormat_(false) { readDQMFormat(); }
SiStripTFile::~SiStripTFile | ( | ) | [virtual] |
void SiStripTFile::addDevice | ( | unsigned int | key | ) |
Adds the directory paths for the device of given key. Must use dqmFormat() before this method.
Definition at line 156 of file SiStripTFile.cc.
References addPath(), sistrip::CONTROL_VIEW, dqmFormat_, sistrip::dqmRoot_, sistrip::mlDqmClient_, SiStripKey::path(), setDQMFormat(), sistrip::UNKNOWN_RUN_TYPE, and view_.
{ if (view_ == sistrip::CONTROL_VIEW) { if (!dqmFormat_) setDQMFormat(sistrip::UNKNOWN_RUN_TYPE, sistrip::CONTROL_VIEW); SiStripFecKey control_path(key); std::string directory_path = control_path.path(); cd(sistrip::dqmRoot_); addPath(directory_path); } else { edm::LogWarning(mlDqmClient_) << "[CommissioningFile::addDevice]: Currently only implemented for Control View." << std::endl; } }
TDirectory * SiStripTFile::addPath | ( | const std::string & | path | ) |
Adds a path to the file. Any directories within the path that already exist are not recreated.
Definition at line 176 of file SiStripTFile.cc.
References dir, and sistrip::dir_.
Referenced by addDevice(), and setDQMFormat().
{ // std::string path = dir; // std::string root = sistrip::dqmRoot_+"/"+sistrip::root_+"/"; // if ( path.find( root ) == std::string::npos ) { // cerr << "Did not find \"" << root << "\" root in path: " << dir; // path = root + dir; // } std::vector<std::string> directories; directories.reserve(10); //fill std::vector std::string::const_iterator it, previous_dir, latest_dir; if (*(path.begin()) == std::string(sistrip::dir_)) { it = previous_dir = latest_dir = path.begin();} else {it = previous_dir = latest_dir = path.begin()-1;} while (it != path.end()) { it++; if (*it == std::string(sistrip::dir_)) { previous_dir = latest_dir; latest_dir = it; directories.push_back(std::string(previous_dir+1, latest_dir)); } } if (latest_dir != (path.end()-1)) { directories.push_back(std::string(latest_dir+1, path.end()));} //update file TDirectory* child = gDirectory; for (std::vector<std::string>::const_iterator dir = directories.begin(); dir != directories.end(); dir++) { if (!dynamic_cast<TDirectory*>(child->Get(dir->c_str()))) { child = child->mkdir(dir->c_str()); child->cd();} else {child->Cd(dir->c_str()); child = gDirectory;} } return child; }
void SiStripTFile::dirContent | ( | TDirectory * | dir, |
std::vector< TDirectory * > * | dirs, | ||
std::map< std::string, std::vector< TH1 * > > * | histos | ||
) |
Finds histos and sub-dirs found within given directory. Updates map with found histos, indexed by dir path.
Definition at line 235 of file SiStripTFile.cc.
References begin, end, newFWLiteAna::found, python::cmstools::loop(), and VarParsing::obj.
Referenced by findHistos().
{ TList* keylist = dir->GetListOfKeys(); if (keylist) { TObject* obj = keylist->First(); // the object (dir or histo) if ( obj ) { bool loop = true; while (loop) { if (obj == keylist->Last()) {loop = false;} if (dynamic_cast<TDirectory*>(dir->Get(obj->GetName()))) { TDirectory* child = dynamic_cast<TDirectory*>(dir->Get(obj->GetName())); //update record of directories dirs->push_back(child); } TH1* his = dynamic_cast<TH1*>( dir->Get(obj->GetName()) ); if ( his ) { bool found = false; std::vector<TH1*>::iterator ihis = (*histos)[std::string(dir->GetPath())].begin(); for ( ; ihis != (*histos)[std::string(dir->GetPath())].end(); ihis++ ) { if ( (*ihis)->GetName() == his->GetName() ) { found = true; } } if ( !found ) { (*histos)[std::string(dir->GetPath())].push_back(his); } } obj = keylist->After(obj); } } } }
TDirectory * SiStripTFile::dqmTop | ( | ) |
Returns the dqm directory
Definition at line 121 of file SiStripTFile.cc.
References dqmFormat_, dqmTop_, and sistrip::mlDqmClient_.
{ if (!dqmFormat_) { edm::LogWarning(mlDqmClient_) << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format." << std::endl; return 0; } return dqmTop_;}
void SiStripTFile::findHistos | ( | TDirectory * | dir, |
std::map< std::string, std::vector< TH1 * > > * | histos | ||
) |
Finds TH1 histograms, iterating through sub-directories. Fills a map, indexed by the histogram path.
Definition at line 218 of file SiStripTFile.cc.
References dirContent(), and mergeVDriftHistosByStation::histos.
{ std::vector< TDirectory* > dirs; dirs.reserve(20000); dirs.push_back(dir); //loop through all directories and record tprofiles (matching label taskId_) contained within them. while ( !dirs.empty() ) { dirContent(dirs[0], &dirs, histos); dirs.erase(dirs.begin()); } }
bool SiStripTFile::queryDQMFormat | ( | ) |
Checks to see if the file complies with DQM format requirements.
Definition at line 110 of file SiStripTFile.cc.
References dqmFormat_.
{ return dqmFormat_; }
TDirectory * SiStripTFile::readDQMFormat | ( | ) |
Checks file complies with DQM format requirements. If so, updates record directory "top-level" directory structure and of readout view and commissioning RunType.
Definition at line 71 of file SiStripTFile.cc.
References sistrip::CONTROL_VIEW, sistrip::controlView_, dqmFormat_, sistrip::dqmRoot_, dqmTop_, spr::find(), python::cmstools::loop(), VarParsing::obj, sistrip::root_, runType(), runType_, sistripTop_, sistrip::taskId_, top_, and view_.
Referenced by SiStripTFile().
{ //check directory structure and find readout view dqmTop_ = GetDirectory(sistrip::dqmRoot_); if (dqmTop_) sistripTop_ = dqmTop_->GetDirectory(sistrip::root_); if (sistripTop_) top_ = sistripTop_->GetDirectory(sistrip::controlView_); if (top_!=gDirectory) view_ = sistrip::CONTROL_VIEW; //does file conform with DQM Format requirements? if (dqmTop_ && sistripTop_ && top_) { dqmFormat_ = true;} // Search for commissioning run_type if (sistripTop_) { TList* keylist = sistripTop_->GetListOfKeys(); if (keylist) { TObject* obj = keylist->First(); //the object if (obj) { bool loop = true; while (loop) { if (obj == keylist->Last()) {loop = false;} if ( std::string(obj->GetName()).find(sistrip::taskId_) != std::string::npos ) { runType_ = SiStripEnumsAndStrings::runType( std::string(obj->GetTitle()).substr(2,std::string::npos) ); // cout << " name: " << std::string(obj->GetName()) // << " title: " << std::string(obj->GetTitle()) // << " runType: " << SiStripEnumsAndStrings::runType( runType_ ) // << std::endl; } obj = keylist->After(obj); } } } } return top_; }
sistrip::RunType & SiStripTFile::runType | ( | ) |
Get Method
Definition at line 146 of file SiStripTFile.cc.
References runType_.
Referenced by readDQMFormat(), and setDQMFormat().
{ return runType_;}
TDirectory * SiStripTFile::setDQMFormat | ( | sistrip::RunType | run_type, |
sistrip::View | view | ||
) |
Formats the commissioning file with the correct "top-level" directory structure. Inserts string defining commissioning RunType in sistrip::root_ directory
Definition at line 36 of file SiStripTFile.cc.
References addPath(), sistrip::CONTROL_VIEW, sistrip::controlView_, sistrip::dir_, dqmFormat_, sistrip::dqmRoot_, dqmTop_, sistrip::mlDqmClient_, sistrip::root_, runType(), runType_, sistrip::sep_, sistripTop_, sistrip::taskId_, top_, and view_.
Referenced by addDevice().
{ view_ = view; runType_ = run_type; if (view == sistrip::CONTROL_VIEW) { std::stringstream ss(""); ss << sistrip::dqmRoot_ << sistrip::dir_ << sistrip::root_ << sistrip::dir_ << sistrip::controlView_; top_ = addPath( ss.str() ); dqmTop_ = GetDirectory(sistrip::dqmRoot_); sistripTop_ = dqmTop_->GetDirectory(sistrip::root_); dqmFormat_ = true; //TNamed defining commissioning runType std::stringstream run_type_label; std::stringstream run_type_title; run_type_label << sistrip::taskId_ << sistrip::sep_ << SiStripEnumsAndStrings::runType(runType_); run_type_title << "s=" << SiStripEnumsAndStrings::runType(runType_); TNamed run_type_description(run_type_label.str().c_str(),run_type_title.str().c_str()); sistripTop_->WriteTObject(&run_type_description); } else { edm::LogWarning(mlDqmClient_) << "[CommissioningFile::setDQMFormat]: Currently only implemented for Control View." << std::endl; return 0; } return top_; }
TDirectory * SiStripTFile::sistripTop | ( | ) |
Returns the sistrip::root_ directory
Definition at line 134 of file SiStripTFile.cc.
References dqmFormat_, sistrip::mlDqmClient_, and sistripTop_.
{ if (!dqmFormat_) { edm::LogWarning(mlDqmClient_) << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format." << std::endl; return 0; } return sistripTop_;}
TDirectory * SiStripTFile::top | ( | ) |
Returns the "top" directory (describing the readout view)
Definition at line 116 of file SiStripTFile.cc.
References top_.
{ return top_;}
sistrip::View & SiStripTFile::View | ( | ) |
bool SiStripTFile::dqmFormat_ [private] |
True if dqmFormat() operation has been performed
Definition at line 105 of file SiStripTFile.h.
Referenced by addDevice(), dqmTop(), queryDQMFormat(), readDQMFormat(), setDQMFormat(), and sistripTop().
TDirectory* SiStripTFile::dqmTop_ [private] |
dqm directory
Definition at line 99 of file SiStripTFile.h.
Referenced by dqmTop(), readDQMFormat(), and setDQMFormat().
sistrip::RunType SiStripTFile::runType_ [private] |
RunType
Definition at line 90 of file SiStripTFile.h.
Referenced by readDQMFormat(), runType(), and setDQMFormat().
TDirectory* SiStripTFile::sistripTop_ [private] |
sistrip::root_ directory
Definition at line 102 of file SiStripTFile.h.
Referenced by readDQMFormat(), setDQMFormat(), and sistripTop().
TDirectory* SiStripTFile::top_ [private] |
Readout view directory
Definition at line 96 of file SiStripTFile.h.
Referenced by readDQMFormat(), setDQMFormat(), and top().
sistrip::View SiStripTFile::view_ [private] |
Logical view.
Definition at line 93 of file SiStripTFile.h.
Referenced by addDevice(), readDQMFormat(), setDQMFormat(), and View().