CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripTFile.cc
Go to the documentation of this file.
1 // Last commit: $Id: SiStripTFile.cc,v 1.3 2008/02/21 14:19:05 bainbrid Exp $
2 
7 #include "TDirectory.h"
8 #include "TH1.h"
9 #include <sstream>
10 
11 using namespace sistrip;
12 
13 //-----------------------------------------------------------------------------
14 
16  Option_t* option,
17  const char* ftitle,
18  Int_t compress ) :
19  TFile(fname,option,ftitle,compress),
20  runType_(sistrip::UNKNOWN_RUN_TYPE),
21  view_(sistrip::UNKNOWN_VIEW),
22  top_(gDirectory),
23  dqmTop_(0),
24  sistripTop_(0),
25  dqmFormat_(false)
26 {
27  readDQMFormat();
28 }
29 
30 //-----------------------------------------------------------------------------
31 
33 
34 //-----------------------------------------------------------------------------
35 
37  sistrip::View view) {
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 }
68 
69 //-----------------------------------------------------------------------------
70 
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 }
107 
108 //-----------------------------------------------------------------------------
109 
111  return dqmFormat_;
112 }
113 
114 //-----------------------------------------------------------------------------
115 
116 TDirectory* SiStripTFile::top() {
117  return top_;}
118 
119 //-----------------------------------------------------------------------------
120 
121 TDirectory* SiStripTFile::dqmTop() {
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_;}
130 
131 
132 //-----------------------------------------------------------------------------
133 
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_;}
143 
144 //-----------------------------------------------------------------------------
145 
147  return runType_;}
148 
149 //-----------------------------------------------------------------------------
150 
152  return view_;}
153 
154 //-----------------------------------------------------------------------------
155 
156 void SiStripTFile::addDevice(unsigned int key) {
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 }
173 
174 //-----------------------------------------------------------------------------
175 
176 TDirectory* SiStripTFile::addPath( const std::string& path ) {
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 }
215 
216 //-----------------------------------------------------------------------------
217 
218 void SiStripTFile::findHistos( TDirectory* dir, std::map< std::string, std::vector<TH1*> >* histos ) {
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 }
231 
232 //-----------------------------------------------------------------------------
233 
234 
235 void SiStripTFile::dirContent(TDirectory* dir,
236  std::vector<TDirectory*>* dirs,
237  std::map< std::string, std::vector<TH1*> >* histos ) {
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 }
271 
static const char dir_[]
void dirContent(TDirectory *, std::vector< TDirectory * > *, std::map< std::string, std::vector< TH1 * > > *)
TDirectory * setDQMFormat(sistrip::RunType, sistrip::View)
Definition: SiStripTFile.cc:36
virtual ~SiStripTFile()
Definition: SiStripTFile.cc:32
static const char mlDqmClient_[]
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
TDirectory * addPath(const std::string &)
dictionary map
Definition: Association.py:160
int path() const
Definition: HLTadd.h:3
sistrip::View view_
Definition: SiStripTFile.h:93
TDirectory * sistripTop_
Definition: SiStripTFile.h:102
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:46
static std::string runType(const sistrip::RunType &)
static const char sep_[]
TDirectory * dqmTop()
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
TDirectory * readDQMFormat()
Definition: SiStripTFile.cc:71
static const char controlView_[]
static const char taskId_[]
bool queryDQMFormat()
static const char dqmRoot_[]
const std::string & path() const
Definition: SiStripKey.h:127
#define end
Definition: vmac.h:38
sistrip::RunType runType_
Definition: SiStripTFile.h:90
TDirectory * top_
Definition: SiStripTFile.h:96
sistrip::RunType & runType()
void findHistos(TDirectory *, std::map< std::string, std::vector< TH1 * > > *)
dictionary histos
Definition: combine.py:3
sistrip::View & View()
TDirectory * sistripTop()
TDirectory * dqmTop_
Definition: SiStripTFile.h:99
string fname
main script
TDirectory * top()
#define begin
Definition: vmac.h:31
list key
Definition: combine.py:13
SiStripTFile(const char *fname, Option_t *option="UPDATE", const char *ftitle="", Int_t compress=1)
Definition: SiStripTFile.cc:15
static const char root_[]
dbl *** dir
Definition: mlp_gen.cc:35
void addDevice(unsigned int key)