CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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,
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::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 ()
 
virtual ~SiStripTFile ()
 

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 22 of file SiStripTFile.h.

Member Typedef Documentation

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.

Constructor & Destructor Documentation

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().

18  :
19  TFile(fname,option,ftitle,compress),
22  top_(gDirectory),
23  dqmTop_(0),
24  sistripTop_(0),
25  dqmFormat_(false)
26 {
27  readDQMFormat();
28 }
sistrip::View view_
Definition: SiStripTFile.h:93
TDirectory * sistripTop_
Definition: SiStripTFile.h:102
TDirectory * readDQMFormat()
Definition: SiStripTFile.cc:71
sistrip::RunType runType_
Definition: SiStripTFile.h:90
TDirectory * top_
Definition: SiStripTFile.h:96
TDirectory * dqmTop_
Definition: SiStripTFile.h:99
string fname
main script
SiStripTFile::~SiStripTFile ( )
virtual

Destructor

Definition at line 32 of file SiStripTFile.cc.

32 {;}

Member Function Documentation

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_.

156  {
157 
158  if (view_ == sistrip::CONTROL_VIEW) {
160  SiStripFecKey control_path(key);
161  std::string directory_path = control_path.path();
162  cd(sistrip::dqmRoot_);
163  addPath(directory_path);
164  }
165 
166  else {
168  << "[CommissioningFile::addDevice]: Currently only implemented for Control View."
169  << std::endl;
170  }
171 
172 }
TDirectory * setDQMFormat(sistrip::RunType, sistrip::View)
Definition: SiStripTFile.cc:36
static const char mlDqmClient_[]
TDirectory * addPath(const std::string &)
sistrip::View view_
Definition: SiStripTFile.h:93
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:46
static const char dqmRoot_[]
list key
Definition: combine.py:13
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().

176  {
177 
178 // std::string path = dir;
179 // std::string root = sistrip::dqmRoot_+"/"+sistrip::root_+"/";
180 // if ( path.find( root ) == std::string::npos ) {
181 // cerr << "Did not find \"" << root << "\" root in path: " << dir;
182 // path = root + dir;
183 // }
184 
185  std::vector<std::string> directories; directories.reserve(10);
186 
187  //fill std::vector
188  std::string::const_iterator it, previous_dir, latest_dir;
189  if (*(path.begin()) == std::string(sistrip::dir_)) {
190  it = previous_dir = latest_dir = path.begin();}
191  else {it = previous_dir = latest_dir = path.begin()-1;}
192 
193  while (it != path.end()) {
194  it++;
195  if (*it == std::string(sistrip::dir_)) {
196  previous_dir = latest_dir;
197  latest_dir = it;
198  directories.push_back(std::string(previous_dir+1, latest_dir));
199  }
200  }
201 
202  if (latest_dir != (path.end()-1)) {
203  directories.push_back(std::string(latest_dir+1, path.end()));}
204 
205  //update file
206  TDirectory* child = gDirectory;
207  for (std::vector<std::string>::const_iterator dir = directories.begin(); dir != directories.end(); dir++) {
208  if (!dynamic_cast<TDirectory*>(child->Get(dir->c_str()))) {
209  child = child->mkdir(dir->c_str());
210  child->cd();}
211  else {child->Cd(dir->c_str()); child = gDirectory;}
212  }
213  return child;
214 }
static const char dir_[]
list path
Definition: scaleCards.py:51
dbl *** dir
Definition: mlp_gen.cc:35
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 getGTfromDQMFile::obj.

Referenced by findHistos().

237  {
238 
239  TList* keylist = dir->GetListOfKeys();
240  if (keylist) {
241 
242  TObject* obj = keylist->First(); // the object (dir or histo)
243 
244  if ( obj ) {
245  bool loop = true;
246  while (loop) {
247  if (obj == keylist->Last()) {loop = false;}
248 
249  if (dynamic_cast<TDirectory*>(dir->Get(obj->GetName()))) {
250  TDirectory* child = dynamic_cast<TDirectory*>(dir->Get(obj->GetName()));
251 
252  //update record of directories
253  dirs->push_back(child);
254  }
255 
256  TH1* his = dynamic_cast<TH1*>( dir->Get(obj->GetName()) );
257  if ( his ) {
258  bool found = false;
259  std::vector<TH1*>::iterator ihis = (*histos)[std::string(dir->GetPath())].begin();
260  for ( ; ihis != (*histos)[std::string(dir->GetPath())].end(); ihis++ ) {
261  if ( (*ihis)->GetName() == his->GetName() ) { found = true; }
262  }
263  if ( !found ) { (*histos)[std::string(dir->GetPath())].push_back(his); }
264  }
265  obj = keylist->After(obj);
266  }
267  }
268  }
269 
270 }
#define end
Definition: vmac.h:38
#define begin
Definition: vmac.h:31
dbl *** dir
Definition: mlp_gen.cc:35
TDirectory * SiStripTFile::dqmTop ( )

Returns the dqm directory

Definition at line 121 of file SiStripTFile.cc.

References dqmFormat_, dqmTop_, and sistrip::mlDqmClient_.

121  {
122  if (!dqmFormat_) {
124  << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format."
125  << std::endl;
126  return 0;
127  }
128 
129  return dqmTop_;}
static const char mlDqmClient_[]
TDirectory * dqmTop_
Definition: SiStripTFile.h:99
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.

218  {
219 
220  std::vector< TDirectory* > dirs;
221  dirs.reserve(20000);
222  dirs.push_back(dir);
223 
224  //loop through all directories and record tprofiles (matching label taskId_) contained within them.
225 
226  while ( !dirs.empty() ) {
227  dirContent(dirs[0], &dirs, histos);
228  dirs.erase(dirs.begin());
229  }
230 }
void dirContent(TDirectory *, std::vector< TDirectory * > *, std::map< std::string, std::vector< TH1 * > > *)
dbl *** dir
Definition: mlp_gen.cc:35
bool SiStripTFile::queryDQMFormat ( )

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

Definition at line 110 of file SiStripTFile.cc.

References dqmFormat_.

110  {
111  return dqmFormat_;
112 }
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(), getGTfromDQMFile::obj, sistrip::root_, SiStripEnumsAndStrings::runType(), runType_, sistripTop_, sistrip::taskId_, top_, and view_.

Referenced by SiStripTFile().

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

Get Method

Definition at line 146 of file SiStripTFile.cc.

References runType_.

146  {
147  return runType_;}
sistrip::RunType runType_
Definition: SiStripTFile.h:90
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_, SiStripEnumsAndStrings::runType(), runType_, sistrip::sep_, sistripTop_, sistrip::taskId_, top_, and view_.

Referenced by addDevice().

37  {
38 
39  view_ = view;
40  runType_ = run_type;
41 
42  if (view == sistrip::CONTROL_VIEW) {
43  std::stringstream ss("");
45  top_ = addPath( ss.str() );
46  dqmTop_ = GetDirectory(sistrip::dqmRoot_);
47  sistripTop_ = dqmTop_->GetDirectory(sistrip::root_);
48  dqmFormat_ = true;
49 
50  //TNamed defining commissioning runType
51  std::stringstream run_type_label;
52  std::stringstream run_type_title;
54  run_type_title << "s=" << SiStripEnumsAndStrings::runType(runType_);
55  TNamed run_type_description(run_type_label.str().c_str(),run_type_title.str().c_str());
56  sistripTop_->WriteTObject(&run_type_description);
57  }
58 
59  else {
61  << "[CommissioningFile::setDQMFormat]: Currently only implemented for Control View."
62  << std::endl;
63  return 0;
64  }
65 
66  return top_;
67 }
static const char dir_[]
static const char mlDqmClient_[]
TDirectory * addPath(const std::string &)
sistrip::View view_
Definition: SiStripTFile.h:93
TDirectory * sistripTop_
Definition: SiStripTFile.h:102
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:90
TDirectory * top_
Definition: SiStripTFile.h:96
TDirectory * dqmTop_
Definition: SiStripTFile.h:99
static const char root_[]
TDirectory * SiStripTFile::sistripTop ( )

Returns the sistrip::root_ directory

Definition at line 134 of file SiStripTFile.cc.

References dqmFormat_, sistrip::mlDqmClient_, and sistripTop_.

134  {
135  if (!dqmFormat_) {
137  << "[SiStripTFile::dqm]: Error requested dqm directory when not in dqm format."
138  << std::endl;
139  return 0;
140  }
141 
142  return sistripTop_;}
static const char mlDqmClient_[]
TDirectory * sistripTop_
Definition: SiStripTFile.h:102
TDirectory * SiStripTFile::top ( )

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

Definition at line 116 of file SiStripTFile.cc.

References top_.

116  {
117  return top_;}
TDirectory * top_
Definition: SiStripTFile.h:96
sistrip::View & SiStripTFile::View ( )

Get Method

Definition at line 151 of file SiStripTFile.cc.

References view_.

151  {
152  return view_;}
sistrip::View view_
Definition: SiStripTFile.h:93

Member Data Documentation

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().