#include <DQM/SiStripCommissioningClients/interface/SiStripTFile.h>
Public Types | |
typedef std::vector< TH1 * > | Histos |
typedef std::map< std::string, Histos > | HistosMap |
Public Member Functions | |
void | addDevice (unsigned int key) |
Adds the directory paths for the device of given key. | |
TDirectory * | addPath (const std::string &) |
Adds a path to the file. | |
void | dirContent (TDirectory *, std::vector< TDirectory * > *, std::map< std::string, std::vector< TH1 * > > *) |
Finds histos and sub-dirs found within given directory. | |
TDirectory * | dqmTop () |
Returns the dqm directory. | |
void | findHistos (TDirectory *, std::map< std::string, std::vector< TH1 * > > *) |
Finds TH1 histograms, iterating through sub-directories. | |
bool | queryDQMFormat () |
Checks to see if the file complies with DQM format requirements. | |
TDirectory * | readDQMFormat () |
Checks file complies with DQM format requirements. | |
sistrip::RunType & | runType () |
Get Method. | |
TDirectory * | setDQMFormat (sistrip::RunType, sistrip::View) |
Formats the commissioning file with the correct "top-level" directory structure. | |
SiStripTFile (const char *fname, Option_t *option="UPDATE", const char *ftitle="", Int_t compress=1) | |
Constructor. | |
TDirectory * | sistripTop () |
Returns the sistrip::root_ directory. | |
TDirectory * | top () |
Returns the "top" directory (describing the readout view). | |
sistrip::View & | View () |
Get Method. | |
virtual | ~SiStripTFile () |
Destructor. | |
Private Attributes | |
bool | dqmFormat_ |
True if dqmFormat() operation has been performed. | |
TDirectory * | dqmTop_ |
dqm directory | |
sistrip::RunType | runType_ |
RunType. | |
TDirectory * | sistripTop_ |
sistrip::root_ directory | |
TDirectory * | top_ |
Readout view directory. | |
sistrip::View | view_ |
Logical 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().
00018 : 00019 TFile(fname,option,ftitle,compress), 00020 runType_(sistrip::UNKNOWN_RUN_TYPE), 00021 view_(sistrip::UNKNOWN_VIEW), 00022 top_(gDirectory), 00023 dqmTop_(0), 00024 sistripTop_(0), 00025 dqmFormat_(false) 00026 { 00027 readDQMFormat(); 00028 }
SiStripTFile::~SiStripTFile | ( | ) | [virtual] |
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_, lat::endl(), sistrip::mlDqmClient_, SiStripKey::path(), setDQMFormat(), sistrip::UNKNOWN_RUN_TYPE, and view_.
00156 { 00157 00158 if (view_ == sistrip::CONTROL_VIEW) { 00159 if (!dqmFormat_) setDQMFormat(sistrip::UNKNOWN_RUN_TYPE, sistrip::CONTROL_VIEW); 00160 SiStripFecKey control_path(key); 00161 std::string directory_path = control_path.path(); 00162 cd(sistrip::dqmRoot_.c_str()); 00163 addPath(directory_path); 00164 } 00165 00166 else { 00167 edm::LogWarning(mlDqmClient_) 00168 << "[CommissioningFile::addDevice]: Currently only implemented for Control View." 00169 << std::endl; 00170 } 00171 00172 }
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, sistrip::dir_, and it.
Referenced by addDevice(), and setDQMFormat().
00176 { 00177 00178 // std::string path = dir; 00179 // std::string root = sistrip::dqmRoot_+"/"+sistrip::root_+"/"; 00180 // if ( path.find( root ) == std::string::npos ) { 00181 // cerr << "Did not find \"" << root << "\" root in path: " << dir; 00182 // path = root + dir; 00183 // } 00184 00185 std::vector<std::string> directories; directories.reserve(10); 00186 00187 //fill std::vector 00188 std::string::const_iterator it, previous_dir, latest_dir; 00189 if (*(path.begin()) == sistrip::dir_) { 00190 it = previous_dir = latest_dir = path.begin();} 00191 else {it = previous_dir = latest_dir = path.begin()-1;} 00192 00193 while (it != path.end()) { 00194 it++; 00195 if (*it == sistrip::dir_) { 00196 previous_dir = latest_dir; 00197 latest_dir = it; 00198 directories.push_back(std::string(previous_dir+1, latest_dir)); 00199 } 00200 } 00201 00202 if (latest_dir != (path.end()-1)) { 00203 directories.push_back(std::string(latest_dir+1, path.end()));} 00204 00205 //update file 00206 TDirectory* child = gDirectory; 00207 for (std::vector<std::string>::const_iterator dir = directories.begin(); dir != directories.end(); dir++) { 00208 if (!dynamic_cast<TDirectory*>(child->Get(dir->c_str()))) { 00209 child = child->mkdir(dir->c_str()); 00210 child->cd();} 00211 else {child->Cd(dir->c_str()); child = gDirectory;} 00212 } 00213 return child; 00214 }
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, python::cmstools::loop(), and VarParsing::obj.
Referenced by findHistos().
00237 { 00238 00239 TList* keylist = dir->GetListOfKeys(); 00240 if (keylist) { 00241 00242 TObject* obj = keylist->First(); // the object (dir or histo) 00243 00244 if ( obj ) { 00245 bool loop = true; 00246 while (loop) { 00247 if (obj == keylist->Last()) {loop = false;} 00248 00249 if (dynamic_cast<TDirectory*>(dir->Get(obj->GetName()))) { 00250 TDirectory* child = dynamic_cast<TDirectory*>(dir->Get(obj->GetName())); 00251 00252 //update record of directories 00253 dirs->push_back(child); 00254 } 00255 00256 TH1* his = dynamic_cast<TH1*>( dir->Get(obj->GetName()) ); 00257 if ( his ) { 00258 bool found = false; 00259 std::vector<TH1*>::iterator ihis = (*histos)[std::string(dir->GetPath())].begin(); 00260 for ( ; ihis != (*histos)[std::string(dir->GetPath())].end(); ihis++ ) { 00261 if ( (*ihis)->GetName() == his->GetName() ) { found = true; } 00262 } 00263 if ( !found ) { (*histos)[std::string(dir->GetPath())].push_back(his); } 00264 } 00265 obj = keylist->After(obj); 00266 } 00267 } 00268 } 00269 00270 }
TDirectory * SiStripTFile::dqmTop | ( | ) |
Returns the dqm directory.
Definition at line 121 of file SiStripTFile.cc.
References dqmFormat_, dqmTop_, lat::endl(), and sistrip::mlDqmClient_.
00121 { 00122 if (!dqmFormat_) { 00123 edm::LogWarning(mlDqmClient_) 00124 << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format." 00125 << std::endl; 00126 return 0; 00127 } 00128 00129 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 combine::histos.
00218 { 00219 00220 std::vector< TDirectory* > dirs; 00221 dirs.reserve(20000); 00222 dirs.push_back(dir); 00223 00224 //loop through all directories and record tprofiles (matching label taskId_) contained within them. 00225 00226 while ( !dirs.empty() ) { 00227 dirContent(dirs[0], &dirs, histos); 00228 dirs.erase(dirs.begin()); 00229 } 00230 }
bool SiStripTFile::queryDQMFormat | ( | ) |
Checks to see if the file complies with DQM format requirements.
Definition at line 110 of file SiStripTFile.cc.
References dqmFormat_.
00110 { 00111 return dqmFormat_; 00112 }
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_, find(), python::cmstools::loop(), VarParsing::obj, sistrip::root_, SiStripEnumsAndStrings::runType(), runType_, sistripTop_, sistrip::taskId_, top_, and view_.
Referenced by SiStripTFile().
00071 { 00072 00073 //check directory structure and find readout view 00074 dqmTop_ = GetDirectory(sistrip::dqmRoot_.c_str()); 00075 if (dqmTop_) sistripTop_ = dqmTop_->GetDirectory(sistrip::root_.c_str()); 00076 if (sistripTop_) top_ = sistripTop_->GetDirectory(sistrip::controlView_.c_str()); 00077 if (top_!=gDirectory) view_ = sistrip::CONTROL_VIEW; 00078 00079 //does file conform with DQM Format requirements? 00080 if (dqmTop_ && sistripTop_ && top_) { 00081 dqmFormat_ = true;} 00082 00083 // Search for commissioning run_type 00084 if (sistripTop_) { 00085 TList* keylist = sistripTop_->GetListOfKeys(); 00086 if (keylist) { 00087 TObject* obj = keylist->First(); //the object 00088 if (obj) { 00089 bool loop = true; 00090 while (loop) { 00091 if (obj == keylist->Last()) {loop = false;} 00092 if ( std::string(obj->GetName()).find(sistrip::taskId_) != std::string::npos ) { 00093 runType_ = SiStripEnumsAndStrings::runType( std::string(obj->GetTitle()).substr(2,std::string::npos) ); 00094 // cout << " name: " << std::string(obj->GetName()) 00095 // << " title: " << std::string(obj->GetTitle()) 00096 // << " runType: " << SiStripEnumsAndStrings::runType( runType_ ) 00097 // << std::endl; 00098 } 00099 obj = keylist->After(obj); 00100 } 00101 } 00102 } 00103 } 00104 00105 return top_; 00106 }
sistrip::RunType & SiStripTFile::runType | ( | ) |
Get Method.
Definition at line 146 of file SiStripTFile.cc.
References runType_.
00146 { 00147 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_, lat::endl(), sistrip::mlDqmClient_, sistrip::root_, SiStripEnumsAndStrings::runType(), runType_, sistrip::sep_, sistripTop_, ss, sistrip::taskId_, top_, and view_.
Referenced by addDevice().
00037 { 00038 00039 view_ = view; 00040 runType_ = run_type; 00041 00042 if (view == sistrip::CONTROL_VIEW) { 00043 std::stringstream ss(""); 00044 ss << sistrip::dqmRoot_ << sistrip::dir_ << sistrip::root_ << sistrip::dir_ << sistrip::controlView_; 00045 top_ = addPath( ss.str() ); 00046 dqmTop_ = GetDirectory(sistrip::dqmRoot_.c_str()); 00047 sistripTop_ = dqmTop_->GetDirectory(sistrip::root_.c_str()); 00048 dqmFormat_ = true; 00049 00050 //TNamed defining commissioning runType 00051 std::stringstream run_type_label; 00052 std::stringstream run_type_title; 00053 run_type_label << sistrip::taskId_ << sistrip::sep_ << SiStripEnumsAndStrings::runType(runType_); 00054 run_type_title << "s=" << SiStripEnumsAndStrings::runType(runType_); 00055 TNamed run_type_description(run_type_label.str().c_str(),run_type_title.str().c_str()); 00056 sistripTop_->WriteTObject(&run_type_description); 00057 } 00058 00059 else { 00060 edm::LogWarning(mlDqmClient_) 00061 << "[CommissioningFile::setDQMFormat]: Currently only implemented for Control View." 00062 << std::endl; 00063 return 0; 00064 } 00065 00066 return top_; 00067 }
TDirectory * SiStripTFile::sistripTop | ( | ) |
Returns the sistrip::root_ directory.
Definition at line 134 of file SiStripTFile.cc.
References dqmFormat_, lat::endl(), sistrip::mlDqmClient_, and sistripTop_.
00134 { 00135 if (!dqmFormat_) { 00136 edm::LogWarning(mlDqmClient_) 00137 << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format." 00138 << std::endl; 00139 return 0; 00140 } 00141 00142 return sistripTop_;}
TDirectory * SiStripTFile::top | ( | ) |
Returns the "top" directory (describing the readout view).
Definition at line 116 of file SiStripTFile.cc.
References top_.
00116 { 00117 return top_;}
sistrip::View & SiStripTFile::View | ( | ) |
Get Method.
Definition at line 151 of file SiStripTFile.cc.
References view_.
00151 { 00152 return 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().