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