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

Member Typedef Documentation

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

Definition at line 37 of file SiStripTFile.h.

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

Definition at line 40 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 14 of file SiStripTFile.cc.

References readDQMFormat().

17  :
18  TFile(fname,option,ftitle,compress),
21  top_(gDirectory),
22  dqmTop_(0),
23  sistripTop_(0),
24  dqmFormat_(false)
25 {
26  readDQMFormat();
27 }
sistrip::View view_
Definition: SiStripTFile.h:92
TDirectory * sistripTop_
Definition: SiStripTFile.h:101
TDirectory * readDQMFormat()
Definition: SiStripTFile.cc:70
sistrip::RunType runType_
Definition: SiStripTFile.h:89
TDirectory * top_
Definition: SiStripTFile.h:95
TDirectory * dqmTop_
Definition: SiStripTFile.h:98
string fname
main script
SiStripTFile::~SiStripTFile ( )
virtual

Destructor

Definition at line 31 of file SiStripTFile.cc.

31 {;}

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

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

155  {
156 
157  if (view_ == sistrip::CONTROL_VIEW) {
159  SiStripFecKey control_path(key);
160  std::string directory_path = control_path.path();
161  cd(sistrip::dqmRoot_);
162  addPath(directory_path);
163  }
164 
165  else {
167  << "[CommissioningFile::addDevice]: Currently only implemented for Control View."
168  << std::endl;
169  }
170 
171 }
TDirectory * setDQMFormat(sistrip::RunType, sistrip::View)
Definition: SiStripTFile.cc:35
static const char mlDqmClient_[]
TDirectory * addPath(const std::string &)
sistrip::View view_
Definition: SiStripTFile.h:92
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_[]
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 175 of file SiStripTFile.cc.

References dir, sistrip::dir_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by addDevice(), and setDQMFormat().

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

References begin, end, newFWLiteAna::found, python.cmstools::loop(), getGTfromDQMFile::obj, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by findHistos().

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

Returns the dqm directory

Definition at line 120 of file SiStripTFile.cc.

References dqmFormat_, dqmTop_, and sistrip::mlDqmClient_.

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

References dirContent(), accesses::dirs, and mergeVDriftHistosByStation::histos.

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

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

Definition at line 109 of file SiStripTFile.cc.

References dqmFormat_.

109  {
110  return dqmFormat_;
111 }
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 70 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_, AlCaHLTBitMon_QueryRunRegistry::string, sistrip::taskId_, top_, and view_.

Referenced by SiStripTFile().

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

Get Method

Definition at line 145 of file SiStripTFile.cc.

References runType_.

145  {
146  return runType_;}
sistrip::RunType runType_
Definition: SiStripTFile.h:89
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 35 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().

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

Returns the sistrip::root_ directory

Definition at line 133 of file SiStripTFile.cc.

References dqmFormat_, sistrip::mlDqmClient_, and sistripTop_.

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

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

Definition at line 115 of file SiStripTFile.cc.

References top_.

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

Get Method

Definition at line 150 of file SiStripTFile.cc.

References view_.

150  {
151  return view_;}
sistrip::View view_
Definition: SiStripTFile.h:92

Member Data Documentation

bool SiStripTFile::dqmFormat_
private

True if dqmFormat() operation has been performed

Definition at line 104 of file SiStripTFile.h.

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

TDirectory* SiStripTFile::dqmTop_
private

dqm directory

Definition at line 98 of file SiStripTFile.h.

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

sistrip::RunType SiStripTFile::runType_
private

RunType

Definition at line 89 of file SiStripTFile.h.

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

TDirectory* SiStripTFile::sistripTop_
private

sistrip::root_ directory

Definition at line 101 of file SiStripTFile.h.

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

TDirectory* SiStripTFile::top_
private

Readout view directory

Definition at line 95 of file SiStripTFile.h.

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

sistrip::View SiStripTFile::view_
private

Logical view.

Definition at line 92 of file SiStripTFile.h.

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