CMS 3D CMS Logo

SiStripTFile.cc
Go to the documentation of this file.
1 
6 #include "TDirectory.h"
7 #include "TH1.h"
8 #include <sstream>
9 
10 using namespace sistrip;
11 
12 //-----------------------------------------------------------------------------
13 
14 SiStripTFile::SiStripTFile(const char* fname, Option_t* option, const char* ftitle, Int_t compress)
15  : TFile(fname, option, ftitle, compress),
16  runType_(sistrip::UNKNOWN_RUN_TYPE),
17  view_(sistrip::UNKNOWN_VIEW),
18  top_(gDirectory),
19  dqmTop_(nullptr),
20  sistripTop_(nullptr),
21  dqmFormat_(false) {
22  readDQMFormat();
23 }
24 
25 //-----------------------------------------------------------------------------
26 
28 
29 //-----------------------------------------------------------------------------
30 
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 }
60 
61 //-----------------------------------------------------------------------------
62 
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 }
104 
105 //-----------------------------------------------------------------------------
106 
108 
109 //-----------------------------------------------------------------------------
110 
111 TDirectory* SiStripTFile::top() { return top_; }
112 
113 //-----------------------------------------------------------------------------
114 
115 TDirectory* SiStripTFile::dqmTop() {
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 }
124 
125 //-----------------------------------------------------------------------------
126 
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 }
136 
137 //-----------------------------------------------------------------------------
138 
140 
141 //-----------------------------------------------------------------------------
142 
144 
145 //-----------------------------------------------------------------------------
146 
147 void SiStripTFile::addDevice(unsigned int key) {
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 }
162 
163 //-----------------------------------------------------------------------------
164 
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 }
210 
211 //-----------------------------------------------------------------------------
212 
213 void SiStripTFile::findHistos(TDirectory* dir, std::map<std::string, std::vector<TH1*> >* histos) {
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 }
225 
226 //-----------------------------------------------------------------------------
227 
228 void SiStripTFile::dirContent(TDirectory* dir,
229  std::vector<TDirectory*>* dirs,
230  std::map<std::string, std::vector<TH1*> >* histos) {
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 }
SiStripEnumsAndStrings::runType
static std::string runType(const sistrip::RunType &)
Definition: SiStripEnumsAndStrings.cc:39
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
SiStripTFile::addPath
TDirectory * addPath(const std::string &)
Definition: SiStripTFile.cc:165
sistrip::View
View
Definition: ConstantsForView.h:26
SiStripTFile::View
sistrip::View & View()
Definition: SiStripTFile.cc:143
SiStripTFile::runType_
sistrip::RunType runType_
Definition: SiStripTFile.h:83
heppy_check.dirs
dirs
Definition: heppy_check.py:26
sistrip::dir_
static const char dir_[]
Definition: ConstantsForDqm.h:17
SiStripTFile::sistripTop
TDirectory * sistripTop()
Definition: SiStripTFile.cc:127
SiStripTFile::runType
sistrip::RunType & runType()
Definition: SiStripTFile.cc:139
sistrip::RunType
RunType
Definition: ConstantsForRunType.h:70
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:87
sistrip::mlDqmClient_
static const char mlDqmClient_[]
Definition: ConstantsForLogger.h:19
end
#define end
Definition: vmac.h:39
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
sistrip::sep_
static const char sep_[]
Definition: ConstantsForDqm.h:18
SiStripTFile::addDevice
void addDevice(unsigned int key)
Definition: SiStripTFile.cc:147
SiStripFecKey
Utility class that identifies a position within the strip tracker control structure,...
Definition: SiStripFecKey.h:45
SiStripFecKey.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
sistrip::taskId_
static const char taskId_[]
Definition: ConstantsForDqm.h:31
SiStripTFile::sistripTop_
TDirectory * sistripTop_
Definition: SiStripTFile.h:95
SiStripTFile::setDQMFormat
TDirectory * setDQMFormat(sistrip::RunType, sistrip::View)
Definition: SiStripTFile.cc:31
SiStripKey::path
const std::string & path() const
Definition: SiStripKey.h:121
heppy_loop.loop
loop
Definition: heppy_loop.py:28
sistrip::controlView_
static const char controlView_[]
Definition: ConstantsForView.h:21
sistrip::UNKNOWN_RUN_TYPE
Definition: ConstantsForRunType.h:94
sistrip::root_
static const char root_[]
Definition: ConstantsForDqm.h:30
SiStripTFile::readDQMFormat
TDirectory * readDQMFormat()
Definition: SiStripTFile.cc:63
sistrip::UNKNOWN_VIEW
Definition: ConstantsForView.h:27
sistrip::dqmRoot_
static const char dqmRoot_[]
Definition: ConstantsForDqm.h:28
combine.histos
histos
Definition: combine.py:4
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
SiStripTFile::top_
TDirectory * top_
Definition: SiStripTFile.h:89
SiStripEnumsAndStrings.h
SiStripTFile::view_
sistrip::View view_
Definition: SiStripTFile.h:86
SiStripTFile.h
sistrip::CONTROL_VIEW
Definition: ConstantsForView.h:30
SiStripTFile::dqmFormat_
bool dqmFormat_
Definition: SiStripTFile.h:98
hippyaddtobaddatafiles.cd
def cd(newdir)
Definition: hippyaddtobaddatafiles.py:40
SiStripTFile::findHistos
void findHistos(TDirectory *, std::map< std::string, std::vector< TH1 * > > *)
Definition: SiStripTFile.cc:213
class-composition.child
child
Definition: class-composition.py:91
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
genParticles_cff.map
map
Definition: genParticles_cff.py:11
SiStripTFile::dqmTop
TDirectory * dqmTop()
Definition: SiStripTFile.cc:115
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
SiStripTFile::dirContent
void dirContent(TDirectory *, std::vector< TDirectory * > *, std::map< std::string, std::vector< TH1 * > > *)
Definition: SiStripTFile.cc:228
child
Definition: simpleInheritance.h:11
SiStripTFile::dqmTop_
TDirectory * dqmTop_
Definition: SiStripTFile.h:92
crabWrapper.key
key
Definition: crabWrapper.py:19
SiStripTFile::top
TDirectory * top()
Definition: SiStripTFile.cc:111
SiStripTFile::~SiStripTFile
~SiStripTFile() override
Definition: SiStripTFile.cc:27
begin
#define begin
Definition: vmac.h:32
SiStripTFile::SiStripTFile
SiStripTFile(const char *fname, Option_t *option="UPDATE", const char *ftitle="", Int_t compress=1)
Definition: SiStripTFile.cc:14
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
SiStripTFile::queryDQMFormat
bool queryDQMFormat()
Definition: SiStripTFile.cc:107