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