CMS 3D CMS Logo

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

: Adds functionality to TFile to ease building and navigation of TFiles containing DQM histograms. More...

#include <SiStripTFile.h>

Inheritance diagram for SiStripTFile:

Public Types

typedef std::vector< TH1 * > Histos
 
typedef std::map< std::string, HistosHistosMap
 

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::RunTyperunType ()
 
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::ViewView ()
 
 ~SiStripTFile () override
 

Private Attributes

bool dqmFormat_
 
TDirectory * dqmTop_
 
sistrip::RunType runType_
 
TDirectory * sistripTop_
 
TDirectory * top_
 
sistrip::View view_
 

Detailed Description

: Adds functionality to TFile to ease building and navigation of TFiles containing DQM histograms.

Author
: M.Wingham

Definition at line 21 of file SiStripTFile.h.

Member Typedef Documentation

◆ Histos

typedef std::vector<TH1*> SiStripTFile::Histos

Definition at line 32 of file SiStripTFile.h.

◆ HistosMap

typedef std::map<std::string, Histos> SiStripTFile::HistosMap

Definition at line 35 of file SiStripTFile.h.

Constructor & Destructor Documentation

◆ SiStripTFile()

SiStripTFile::SiStripTFile ( const char *  fname,
Option_t *  option = "UPDATE",
const char *  ftitle = "",
Int_t  compress = 1 
)

Constructor

Definition at line 14 of file SiStripTFile.cc.

References readDQMFormat().

15  : TFile(fname, option, ftitle, compress),
18  top_(gDirectory),
19  dqmTop_(nullptr),
20  sistripTop_(nullptr),
21  dqmFormat_(false) {
22  readDQMFormat();
23 }
sistrip::View view_
Definition: SiStripTFile.h:86
TDirectory * sistripTop_
Definition: SiStripTFile.h:95
TDirectory * readDQMFormat()
Definition: SiStripTFile.cc:63
sistrip::RunType runType_
Definition: SiStripTFile.h:83
TDirectory * top_
Definition: SiStripTFile.h:89
TDirectory * dqmTop_
Definition: SiStripTFile.h:92
string fname
main script

◆ ~SiStripTFile()

SiStripTFile::~SiStripTFile ( )
override

Destructor

Definition at line 27 of file SiStripTFile.cc.

27 { ; }

Member Function Documentation

◆ addDevice()

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 147 of file SiStripTFile.cc.

References addPath(), hippyaddtobaddatafiles::cd(), sistrip::CONTROL_VIEW, dqmFormat_, sistrip::dqmRoot_, crabWrapper::key, sistrip::mlDqmClient_, SiStripKey::path(), setDQMFormat(), AlCaHLTBitMon_QueryRunRegistry::string, sistrip::UNKNOWN_RUN_TYPE, and view_.

147  {
148  if (view_ == sistrip::CONTROL_VIEW) {
149  if (!dqmFormat_)
151  SiStripFecKey control_path(key);
152  const std::string& directory_path = control_path.path();
154  addPath(directory_path);
155  }
156 
157  else {
158  edm::LogWarning(mlDqmClient_) << "[CommissioningFile::addDevice]: Currently only implemented for Control View."
159  << std::endl;
160  }
161 }
TDirectory * setDQMFormat(sistrip::RunType, sistrip::View)
Definition: SiStripTFile.cc:31
static const char mlDqmClient_[]
TDirectory * addPath(const std::string &)
sistrip::View view_
Definition: SiStripTFile.h:86
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
static const char dqmRoot_[]
Log< level::Warning, false > LogWarning

◆ addPath()

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 165 of file SiStripTFile.cc.

References submitPVValidationJobs::child, DeadROC_duringRun::dir, sistrip::dir_, castor_dqm_sourceclient_file_cfg::path, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by addDevice(), and setDQMFormat().

165  {
166  // std::string path = dir;
167  // std::string root = sistrip::dqmRoot_+"/"+sistrip::root_+"/";
168  // if ( path.find( root ) == std::string::npos ) {
169  // cerr << "Did not find \"" << root << "\" root in path: " << dir;
170  // path = root + dir;
171  // }
172 
173  std::vector<std::string> directories;
174  directories.reserve(10);
175 
176  //fill std::vector
177  std::string::const_iterator it, previous_dir, latest_dir;
178  if (*(path.begin()) == std::string(sistrip::dir_)) {
179  it = previous_dir = latest_dir = path.begin();
180  } else {
181  it = previous_dir = latest_dir = path.begin() - 1;
182  }
183 
184  while (it != path.end()) {
185  it++;
186  if (*it == std::string(sistrip::dir_)) {
187  previous_dir = latest_dir;
188  latest_dir = it;
189  directories.push_back(std::string(previous_dir + 1, latest_dir));
190  }
191  }
192 
193  if (latest_dir != (path.end() - 1)) {
194  directories.push_back(std::string(latest_dir + 1, path.end()));
195  }
196 
197  //update file
198  TDirectory* child = gDirectory;
199  for (std::vector<std::string>::const_iterator dir = directories.begin(); dir != directories.end(); dir++) {
200  if (!dynamic_cast<TDirectory*>(child->Get(dir->c_str()))) {
201  child = child->mkdir(dir->c_str());
202  child->cd();
203  } else {
204  child->Cd(dir->c_str());
205  child = gDirectory;
206  }
207  }
208  return child;
209 }
static const char dir_[]

◆ dirContent()

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 228 of file SiStripTFile.cc.

References DeadROC_duringRun::dir, heppy_check::dirs, mps_fire::end, newFWLiteAna::found, heppy_loop::loop, getGTfromDQMFile::obj, push_back(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by findHistos().

230  {
231  TList* keylist = dir->GetListOfKeys();
232  if (keylist) {
233  TObject* obj = keylist->First(); // the object (dir or histo)
234 
235  if (obj) {
236  bool loop = true;
237  while (loop) {
238  if (obj == keylist->Last()) {
239  loop = false;
240  }
241 
242  if (dynamic_cast<TDirectory*>(dir->Get(obj->GetName()))) {
243  TDirectory* child = dynamic_cast<TDirectory*>(dir->Get(obj->GetName()));
244 
245  //update record of directories
246  dirs->push_back(child);
247  }
248 
249  TH1* his = dynamic_cast<TH1*>(dir->Get(obj->GetName()));
250  if (his) {
251  bool found = false;
252  std::vector<TH1*>::iterator ihis = (*histos)[std::string(dir->GetPath())].begin();
253  for (; ihis != (*histos)[std::string(dir->GetPath())].end(); ihis++) {
254  if ((*ihis)->GetName() == his->GetName()) {
255  found = true;
256  }
257  }
258  if (!found) {
259  (*histos)[std::string(dir->GetPath())].push_back(his);
260  }
261  }
262  obj = keylist->After(obj);
263  }
264  }
265  }
266 }
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})

◆ dqmTop()

TDirectory * SiStripTFile::dqmTop ( )

Returns the dqm directory

Definition at line 115 of file SiStripTFile.cc.

References dqmFormat_, dqmTop_, and sistrip::mlDqmClient_.

115  {
116  if (!dqmFormat_) {
117  edm::LogWarning(mlDqmClient_) << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format."
118  << std::endl;
119  return nullptr;
120  }
121 
122  return dqmTop_;
123 }
static const char mlDqmClient_[]
TDirectory * dqmTop_
Definition: SiStripTFile.h:92
Log< level::Warning, false > LogWarning

◆ findHistos()

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 213 of file SiStripTFile.cc.

References DeadROC_duringRun::dir, dirContent(), heppy_check::dirs, and combine::histos.

213  {
214  std::vector<TDirectory*> dirs;
215  dirs.reserve(20000);
216  dirs.push_back(dir);
217 
218  //loop through all directories and record tprofiles (matching label taskId_) contained within them.
219 
220  while (!dirs.empty()) {
221  dirContent(dirs[0], &dirs, histos);
222  dirs.erase(dirs.begin());
223  }
224 }
void dirContent(TDirectory *, std::vector< TDirectory *> *, std::map< std::string, std::vector< TH1 *> > *)
histos
Definition: combine.py:4

◆ queryDQMFormat()

bool SiStripTFile::queryDQMFormat ( )

Checks to see if the file complies with DQM format requirements.

Definition at line 107 of file SiStripTFile.cc.

References dqmFormat_.

107 { return dqmFormat_; }

◆ readDQMFormat()

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 63 of file SiStripTFile.cc.

References sistrip::CONTROL_VIEW, sistrip::controlView_, dqmFormat_, sistrip::dqmRoot_, dqmTop_, spr::find(), heppy_loop::loop, getGTfromDQMFile::obj, sistrip::root_, SiStripEnumsAndStrings::runType(), runType_, sistripTop_, AlCaHLTBitMon_QueryRunRegistry::string, sistrip::taskId_, top_, and view_.

Referenced by SiStripTFile().

63  {
64  //check directory structure and find readout view
65  dqmTop_ = GetDirectory(sistrip::dqmRoot_);
66  if (dqmTop_)
67  sistripTop_ = dqmTop_->GetDirectory(sistrip::root_);
68  if (sistripTop_)
69  top_ = sistripTop_->GetDirectory(sistrip::controlView_);
70  if (top_ != gDirectory)
72 
73  //does file conform with DQM Format requirements?
74  if (dqmTop_ && sistripTop_ && top_) {
75  dqmFormat_ = true;
76  }
77 
78  // Search for commissioning run_type
79  if (sistripTop_) {
80  TList* keylist = sistripTop_->GetListOfKeys();
81  if (keylist) {
82  TObject* obj = keylist->First(); //the object
83  if (obj) {
84  bool loop = true;
85  while (loop) {
86  if (obj == keylist->Last()) {
87  loop = false;
88  }
89  if (std::string(obj->GetName()).find(sistrip::taskId_) != std::string::npos) {
90  runType_ = SiStripEnumsAndStrings::runType(std::string(obj->GetTitle()).substr(2, std::string::npos));
91  // cout << " name: " << std::string(obj->GetName())
92  // << " title: " << std::string(obj->GetTitle())
93  // << " runType: " << SiStripEnumsAndStrings::runType( runType_ )
94  // << std::endl;
95  }
96  obj = keylist->After(obj);
97  }
98  }
99  }
100  }
101 
102  return top_;
103 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
sistrip::View view_
Definition: SiStripTFile.h:86
TDirectory * sistripTop_
Definition: SiStripTFile.h:95
static std::string runType(const sistrip::RunType &)
static const char controlView_[]
static const char taskId_[]
static const char dqmRoot_[]
sistrip::RunType runType_
Definition: SiStripTFile.h:83
TDirectory * top_
Definition: SiStripTFile.h:89
TDirectory * dqmTop_
Definition: SiStripTFile.h:92
static const char root_[]

◆ runType()

sistrip::RunType & SiStripTFile::runType ( )

Get Method

Definition at line 139 of file SiStripTFile.cc.

References runType_.

139 { return runType_; }
sistrip::RunType runType_
Definition: SiStripTFile.h:83

◆ setDQMFormat()

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 31 of file SiStripTFile.cc.

References addPath(), sistrip::CONTROL_VIEW, sistrip::controlView_, sistrip::dir_, dqmFormat_, sistrip::dqmRoot_, dqmTop_, sistrip::mlDqmClient_, sistrip::root_, SiStripEnumsAndStrings::runType(), runType_, sistrip::sep_, sistripTop_, contentValuesCheck::ss, sistrip::taskId_, top_, and view_.

Referenced by addDevice().

31  {
32  view_ = view;
33  runType_ = run_type;
34 
35  if (view == sistrip::CONTROL_VIEW) {
36  std::stringstream ss("");
38  top_ = addPath(ss.str());
39  dqmTop_ = GetDirectory(sistrip::dqmRoot_);
40  sistripTop_ = dqmTop_->GetDirectory(sistrip::root_);
41  dqmFormat_ = true;
42 
43  //TNamed defining commissioning runType
44  std::stringstream run_type_label;
45  std::stringstream run_type_title;
47  run_type_title << "s=" << SiStripEnumsAndStrings::runType(runType_);
48  TNamed run_type_description(run_type_label.str().c_str(), run_type_title.str().c_str());
49  sistripTop_->WriteTObject(&run_type_description);
50  }
51 
52  else {
53  edm::LogWarning(mlDqmClient_) << "[CommissioningFile::setDQMFormat]: Currently only implemented for Control View."
54  << std::endl;
55  return nullptr;
56  }
57 
58  return top_;
59 }
static const char dir_[]
static const char mlDqmClient_[]
TDirectory * addPath(const std::string &)
sistrip::View view_
Definition: SiStripTFile.h:86
TDirectory * sistripTop_
Definition: SiStripTFile.h:95
static std::string runType(const sistrip::RunType &)
static const char sep_[]
static const char controlView_[]
static const char taskId_[]
static const char dqmRoot_[]
sistrip::RunType runType_
Definition: SiStripTFile.h:83
TDirectory * top_
Definition: SiStripTFile.h:89
TDirectory * dqmTop_
Definition: SiStripTFile.h:92
static const char root_[]
Log< level::Warning, false > LogWarning

◆ sistripTop()

TDirectory * SiStripTFile::sistripTop ( )

Returns the sistrip::root_ directory

Definition at line 127 of file SiStripTFile.cc.

References dqmFormat_, sistrip::mlDqmClient_, and sistripTop_.

127  {
128  if (!dqmFormat_) {
129  edm::LogWarning(mlDqmClient_) << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format."
130  << std::endl;
131  return nullptr;
132  }
133 
134  return sistripTop_;
135 }
static const char mlDqmClient_[]
TDirectory * sistripTop_
Definition: SiStripTFile.h:95
Log< level::Warning, false > LogWarning

◆ top()

TDirectory * SiStripTFile::top ( )

Returns the "top" directory (describing the readout view)

Definition at line 111 of file SiStripTFile.cc.

References top_.

111 { return top_; }
TDirectory * top_
Definition: SiStripTFile.h:89

◆ View()

sistrip::View & SiStripTFile::View ( )

Get Method

Definition at line 143 of file SiStripTFile.cc.

References view_.

143 { return view_; }
sistrip::View view_
Definition: SiStripTFile.h:86

Member Data Documentation

◆ dqmFormat_

bool SiStripTFile::dqmFormat_
private

True if dqmFormat() operation has been performed

Definition at line 98 of file SiStripTFile.h.

Referenced by addDevice(), dqmTop(), queryDQMFormat(), readDQMFormat(), setDQMFormat(), and sistripTop().

◆ dqmTop_

TDirectory* SiStripTFile::dqmTop_
private

dqm directory

Definition at line 92 of file SiStripTFile.h.

Referenced by dqmTop(), readDQMFormat(), and setDQMFormat().

◆ runType_

sistrip::RunType SiStripTFile::runType_
private

RunType

Definition at line 83 of file SiStripTFile.h.

Referenced by readDQMFormat(), runType(), and setDQMFormat().

◆ sistripTop_

TDirectory* SiStripTFile::sistripTop_
private

sistrip::root_ directory

Definition at line 95 of file SiStripTFile.h.

Referenced by readDQMFormat(), setDQMFormat(), and sistripTop().

◆ top_

TDirectory* SiStripTFile::top_
private

Readout view directory

Definition at line 89 of file SiStripTFile.h.

Referenced by readDQMFormat(), setDQMFormat(), and top().

◆ view_

sistrip::View SiStripTFile::view_
private

Logical view.

Definition at line 86 of file SiStripTFile.h.

Referenced by addDevice(), readDQMFormat(), setDQMFormat(), and View().