CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingUtility.cc
Go to the documentation of this file.
3 
5 //
6 // Get a list of MEs in a folder
7 //
8 int TrackingUtility::getMEList(std::string name, std::vector<std::string>& values) {
9  values.clear();
10  std::string prefix_str = name.substr(0,(name.find(":")));
11  prefix_str += "/";
12  std::string temp_str = name.substr(name.find(":")+1);
13  split(temp_str, values, ",");
14  for (std::vector<std::string>::iterator it = values.begin();
15  it != values.end(); it++) (*it).insert(0,prefix_str);
16  return values.size();
17 }
18 //
19 // Get a list of MEs in a folder and the path name
20 //
21 int TrackingUtility::getMEList(std::string name, std::string& dir_path, std::vector<std::string>& values) {
22  values.clear();
23  dir_path = name.substr(0,(name.find(":")));
24  dir_path += "/";
25  std::string temp_str = name.substr(name.find(":")+1);
26  split(temp_str, values, ",");
27  return values.size();
28 }
29 
30 // Check if the requested ME exists in a folder
32  if (name.find(name) == std::string::npos) return false;
33  std::string prefix_str = name.substr(0,(name.find(":")));
34  prefix_str += "/";
35  std::string temp_str = name.substr(name.find(":")+1);
36  std::vector<std::string> values;
37  split(temp_str, values, ",");
38  for (std::vector<std::string>::iterator it = values.begin();
39  it != values.end(); it++) {
40  if ((*it).find(me_name) != std::string::npos) {
41  full_path = prefix_str + (*it);
42  return true;
43  }
44  }
45  return false;
46 }
47 //
48 // -- Split a given string into a number of strings using given
49 // delimiters and fill a vector with splitted strings
50 //
51 void TrackingUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
52  // Skip delimiters at beginning.
53  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
54 
55  // Find first "non-delimiter".
56  std::string::size_type pos = str.find_first_of(delimiters, lastPos);
57 
58  while (std::string::npos != pos || std::string::npos != lastPos) {
59  // Found a token, add it to the std::vector.
60  tokens.push_back(str.substr(lastPos, pos - lastPos));
61 
62  // Skip delimiters. Note the "not_of"
63  lastPos = str.find_first_not_of(delimiters, pos);
64 
65  // Find next "non-delimiter"
66  pos = str.find_first_of(delimiters, lastPos);
67  }
68 }
69 //
70 // -- Get Color code from Status
71 //
72 void TrackingUtility::getMEStatusColor(int status, int& rval, int&gval, int& bval) {
73  if (status == dqm::qstatus::STATUS_OK) {
74  rval = 0; gval = 255; bval = 0;
75  } else if (status == dqm::qstatus::WARNING) {
76  rval = 255; gval = 255; bval = 0;
77  } else if (status == dqm::qstatus::ERROR) {
78  rval = 255; gval = 0; bval = 0;
79  } else if (status == dqm::qstatus::OTHER) {
80  rval = 255; gval = 150; bval = 0;
81  } else {
82  rval = 0; gval = 0; bval = 255;
83  }
84 }
85 //
86 // -- Get Color code from Status
87 //
89  if (status == dqm::qstatus::STATUS_OK) {
90  tag = "Ok";
91  icol = 3;
92  } else if (status == dqm::qstatus::WARNING) {
93  tag = "Warning";
94  icol = 5;
95  } else if (status == dqm::qstatus::ERROR) {
96  tag = "Error";
97  icol = 2;
98  } else if (status == dqm::qstatus::OTHER) {
99  tag = "Other";
100  icol = 1;
101  } else {
102  tag = " ";
103  icol = 1;
104  }
105 }
106 
107 //
108 // -- Get Status of Monitor Element
109 //
111  int status = 0;
112  if (me->getQReports().size() == 0) {
113  status = 0;
114  } else if (me->hasError()) {
115  status = dqm::qstatus::ERROR;
116  } else if (me->hasWarning()) {
117  status = dqm::qstatus::WARNING;
118  } else if (me->hasOtherReport()) {
119  status = dqm::qstatus::OTHER;
120  } else {
121  status = dqm::qstatus::STATUS_OK;
122  }
123  return status;
124 }
125 //
126 // -- Fill Module Names
127 //
128 void TrackingUtility::getModuleFolderList(DQMStore::IBooker & ibooker, DQMStore::IGetter & igetter, std::vector<std::string>& mfolders){
129  std::string currDir = ibooker.pwd();
130  if (currDir.find("module_") != std::string::npos) {
131  // std::string mId = currDir.substr(currDir.find("module_")+7, 9);
132  mfolders.push_back(currDir);
133  } else {
134  std::vector<std::string> subdirs = igetter.getSubdirs();
135  for (std::vector<std::string>::const_iterator it = subdirs.begin();
136  it != subdirs.end(); it++) {
137  ibooker.cd(*it);
138  getModuleFolderList(ibooker,igetter, mfolders);
139  ibooker.goUp();
140  }
141  }
142 }
143 //
144 // -- Get Status of Monitor Element
145 //
146 int TrackingUtility::getMEStatus(MonitorElement* me, int& bad_channels) {
147  int status = 0;
148  if (me->getQReports().size() == 0) {
149  status = 0;
150  bad_channels = -1;
151  } else {
152  std::vector<QReport *> qreports = me->getQReports();
153  bad_channels =qreports[0]->getBadChannels().size();
154  if (me->hasError()) {
155  status = dqm::qstatus::ERROR;
156  } else if (me->hasWarning()) {
157  status = dqm::qstatus::WARNING;
158  } else if (me->hasOtherReport()) {
159  status = dqm::qstatus::OTHER;
160  } else {
161  status = dqm::qstatus::STATUS_OK;
162  }
163  }
164  return status;
165 }
166 //
167 // -- Get Status of Monitor Element
168 //
170  val = "";
171  if ( me && ( me->kind()==MonitorElement::DQM_KIND_REAL || me->kind()==MonitorElement::DQM_KIND_INT ) ) {
172  val = me->valueString();
173  val = val.substr(val.find("=")+1);
174  }
175 }
176 //
177 // -- go to a given Directory
178 //
180  std::string currDir = ibooker.pwd();
181  std::string dirName = currDir.substr(currDir.find_last_of("/")+1);
182  if (dirName.find(name) == 0) {
183  return true;
184  }
185  std::vector<std::string> subDirVec = igetter.getSubdirs();
186  for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
187  ic != subDirVec.end(); ic++) {
188  std::string fname = (*ic);
189  if (
190  (fname.find("Reference") != std::string::npos) ||
191  (fname.find("AlCaReco") != std::string::npos) ||
192  (fname.find("HLT") != std::string::npos)
193  ) continue;
194  igetter.cd(fname);
195  if (!goToDir(ibooker,igetter, name)) ibooker.goUp();
196  else return true;
197  }
198  return false;
199 }
200 //
201 // -- Set Bad Channel Flag from hname
202 //
203 void TrackingUtility::setBadModuleFlag(std::string & hname, uint16_t& flg){
204 
205  if (hname.find("FractionOfBadChannels") != std::string::npos) flg |= (1<<0);
206  else if (hname.find("NumberOfDigi") != std::string::npos) flg |= (1<<1);
207  else if (hname.find("NumberOfCluster") != std::string::npos) flg |= (1<<2);
208  else if (hname.find("ExcludedFedChannel") != std::string::npos) flg |= (1<<3);
209  else if (hname.find("DCSError") != std::string::npos) flg |= (1<<4);
210 }
211 //
212 // -- Get the Status Message from Bad Module Flag
213 //
215  if (flag == 0) message += " No Error";
216  else {
217  // message += " Error from :: ";
218  if (((flag >> 0) & 0x1) > 0) message += " Fed BadChannel : ";
219  if (((flag >> 1) & 0x1) > 0) message += " # of Digi : ";
220  if (((flag >> 2) & 0x1) > 0) message += " # of Clusters :";
221  if (((flag >> 3) & 0x1) > 0) message += " Excluded FED Channel ";
222  if (((flag >> 4) & 0x1) > 0) message += " DCSError ";
223  }
224 }
225 //
226 // -- Set Event Info Folder
227 //
229  path = "";
230  ibooker.cd();
231  if (igetter.dirExists(top_dir)) {
232  ibooker.cd(top_dir);
233  path = ibooker.pwd();
234  } else {
235  if (TrackingUtility::goToDir(ibooker,igetter, top_dir)) {
236  std::string tdir = "TrackParameters";
237  if (TrackingUtility::goToDir(ibooker,igetter, tdir)) {
238  path = ibooker.pwd();
239  path = path.substr(0, path.find(tdir)-1);
240  }
241  }
242  }
243 }
static void getModuleFolderList(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, std::vector< std::string > &m_ids)
void cd(void)
Definition: DQMStore.cc:322
static const int OTHER
void cd(void)
Definition: DQMStore.cc:266
const std::string & pwd(void)
Definition: DQMStore.cc:282
bool hasError(void) const
true if at least of one of the quality tests returned an error
static const int WARNING
static int getMEList(std::string name, std::vector< std::string > &values)
uint16_t size_type
static bool checkME(std::string element, std::string name, std::string &full_path)
static int getMEStatus(MonitorElement *me)
static void split(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
static void getBadModuleStatus(uint16_t flag, std::string &message)
bool hasWarning(void) const
true if at least of one of the quality tests returned a warning
static bool goToDir(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, std::string name)
Kind kind(void) const
Get the type of the monitor element.
std::string valueString(void) const
bool dirExists(const std::string &path)
Definition: DQMStore.cc:318
unsigned long long int rval
Definition: vlib.h:22
static void getMEStatusColor(int status, int &rval, int &gval, int &bval)
void goUp(void)
Definition: DQMStore.cc:278
std::vector< QReport * > getQReports(void) const
get map of QReports
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
bool hasOtherReport(void) const
true if at least of one of the tests returned some other (non-ok) status
static void getMEValue(MonitorElement *me, std::string &val)
std::vector< std::string > getSubdirs(void)
Definition: DQMStore.cc:306
string fname
main script
static const int STATUS_OK
tuple status
Definition: ntuplemaker.py:245
static void getTopFolderPath(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, std::string top_dir, std::string &path)
static const int ERROR