Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
#include "DQM/TrackingMonitorClient/interface/TrackingUtility.h"
#include "DQMServices/Core/interface/DQMStore.h"

#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
//
// Get a list of MEs in a folder
//
int TrackingUtility::getMEList(std::string name, std::vector<std::string>& values) {
  values.clear();
  std::string prefix_str = name.substr(0, (name.find(':')));
  prefix_str += "/";
  std::string temp_str = name.substr(name.find(':') + 1);
  split(temp_str, values, ",");
  for (std::vector<std::string>::iterator it = values.begin(); it != values.end(); it++)
    (*it).insert(0, prefix_str);
  return values.size();
}
//
// Get a list of MEs in a folder and the path name
//
int TrackingUtility::getMEList(std::string name, std::string& dir_path, std::vector<std::string>& values) {
  values.clear();
  dir_path = name.substr(0, (name.find(':')));
  dir_path += "/";
  std::string temp_str = name.substr(name.find(':') + 1);
  split(temp_str, values, ",");
  return values.size();
}

// Check if the requested ME exists in a folder
bool TrackingUtility::checkME(std::string name, std::string me_name, std::string& full_path) {
  if (name.find(name) == std::string::npos)
    return false;
  std::string prefix_str = name.substr(0, (name.find(':')));
  prefix_str += "/";
  std::string temp_str = name.substr(name.find(':') + 1);
  std::vector<std::string> values;
  split(temp_str, values, ",");
  for (std::vector<std::string>::iterator it = values.begin(); it != values.end(); it++) {
    if ((*it).find(me_name) != std::string::npos) {
      full_path = prefix_str + (*it);
      return true;
    }
  }
  return false;
}
//
// -- Split a given string into a number of strings using given
//    delimiters and fill a vector with splitted strings
//
void TrackingUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
  // Skip delimiters at beginning.
  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);

  // Find first "non-delimiter".
  std::string::size_type pos = str.find_first_of(delimiters, lastPos);

  while (std::string::npos != pos || std::string::npos != lastPos) {
    // Found a token, add it to the std::vector.
    tokens.push_back(str.substr(lastPos, pos - lastPos));

    // Skip delimiters.  Note the "not_of"
    lastPos = str.find_first_not_of(delimiters, pos);

    // Find next "non-delimiter"
    pos = str.find_first_of(delimiters, lastPos);
  }
}
//
// -- Get Color code from Status
//
void TrackingUtility::getMEStatusColor(int status, int& rval, int& gval, int& bval) {
  if (status == dqm::qstatus::STATUS_OK) {
    rval = 0;
    gval = 255;
    bval = 0;
  } else if (status == dqm::qstatus::WARNING) {
    rval = 255;
    gval = 255;
    bval = 0;
  } else if (status == dqm::qstatus::ERROR) {
    rval = 255;
    gval = 0;
    bval = 0;
  } else if (status == dqm::qstatus::OTHER) {
    rval = 255;
    gval = 150;
    bval = 0;
  } else {
    rval = 0;
    gval = 0;
    bval = 255;
  }
}
//
// -- Get Color code from Status
//
void TrackingUtility::getMEStatusColor(int status, int& icol, std::string& tag) {
  if (status == dqm::qstatus::STATUS_OK) {
    tag = "Ok";
    icol = 3;
  } else if (status == dqm::qstatus::WARNING) {
    tag = "Warning";
    icol = 5;
  } else if (status == dqm::qstatus::ERROR) {
    tag = "Error";
    icol = 2;
  } else if (status == dqm::qstatus::OTHER) {
    tag = "Other";
    icol = 1;
  } else {
    tag = " ";
    icol = 1;
  }
}

//
// -- Get Status of Monitor Element
//
int TrackingUtility::getMEStatus(MonitorElement* me) {
  int status = 0;
  if (me->getQReports().empty()) {
    status = 0;
  } else if (me->hasError()) {
    status = dqm::qstatus::ERROR;
  } else if (me->hasWarning()) {
    status = dqm::qstatus::WARNING;
  } else if (me->hasOtherReport()) {
    status = dqm::qstatus::OTHER;
  } else {
    status = dqm::qstatus::STATUS_OK;
  }
  return status;
}
//
// --  Fill Module Names
//
void TrackingUtility::getModuleFolderList(DQMStore::IBooker& ibooker,
                                          DQMStore::IGetter& igetter,
                                          std::vector<std::string>& mfolders) {
  std::string currDir = ibooker.pwd();
  if (currDir.find("module_") != std::string::npos) {
    //    std::string mId = currDir.substr(currDir.find("module_")+7, 9);
    mfolders.push_back(currDir);
  } else {
    std::vector<std::string> subdirs = igetter.getSubdirs();
    for (std::vector<std::string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
      ibooker.cd(*it);
      getModuleFolderList(ibooker, igetter, mfolders);
      ibooker.goUp();
    }
  }
}
//
// -- Get Status of Monitor Element
//
int TrackingUtility::getMEStatus(MonitorElement* me, int& bad_channels) {
  int status = 0;
  if (me->getQReports().empty()) {
    status = 0;
    bad_channels = -1;
  } else {
    std::vector<QReport*> qreports = me->getQReports();
    bad_channels = qreports[0]->getBadChannels().size();
    if (me->hasError()) {
      status = dqm::qstatus::ERROR;
    } else if (me->hasWarning()) {
      status = dqm::qstatus::WARNING;
    } else if (me->hasOtherReport()) {
      status = dqm::qstatus::OTHER;
    } else {
      status = dqm::qstatus::STATUS_OK;
    }
  }
  return status;
}
//
// -- Get Status of Monitor Element
//
void TrackingUtility::getMEValue(MonitorElement* me, std::string& val) {
  val = "";
  if (me) {
    if (me->kind() == MonitorElement::Kind::REAL) {
      val = std::to_string(me->getFloatValue());
    } else if (me->kind() == MonitorElement::Kind::INT) {
      val = std::to_string(me->getIntValue());
    }
  }
}
//
// -- go to a given Directory
//
bool TrackingUtility::goToDir(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, std::string name) {
  std::string currDir = ibooker.pwd();
  std::string dirName = currDir.substr(currDir.find_last_of('/') + 1);
  if (dirName.find(name) == 0) {
    return true;
  }
  std::vector<std::string> subDirVec = igetter.getSubdirs();
  for (std::vector<std::string>::const_iterator ic = subDirVec.begin(); ic != subDirVec.end(); ic++) {
    const std::string& fname = (*ic);
    if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
        (fname.find("HLT") != std::string::npos))
      continue;
    igetter.cd(fname);
    if (!goToDir(ibooker, igetter, name))
      ibooker.goUp();
    else
      return true;
  }
  return false;
}
//
// -- Set Bad Channel Flag from hname
//
void TrackingUtility::setBadModuleFlag(std::string& hname, uint16_t& flg) {
  if (hname.find("FractionOfBadChannels") != std::string::npos)
    flg |= (1 << 0);
  else if (hname.find("NumberOfDigi") != std::string::npos)
    flg |= (1 << 1);
  else if (hname.find("NumberOfCluster") != std::string::npos)
    flg |= (1 << 2);
  else if (hname.find("ExcludedFedChannel") != std::string::npos)
    flg |= (1 << 3);
  else if (hname.find("DCSError") != std::string::npos)
    flg |= (1 << 4);
}
//
// -- Get the Status Message from Bad Module Flag
//
void TrackingUtility::getBadModuleStatus(uint16_t flag, std::string& message) {
  if (flag == 0)
    message += " No Error";
  else {
    //    message += " Error from :: ";
    if (((flag >> 0) & 0x1) > 0)
      message += " Fed BadChannel : ";
    if (((flag >> 1) & 0x1) > 0)
      message += " # of Digi : ";
    if (((flag >> 2) & 0x1) > 0)
      message += " # of Clusters :";
    if (((flag >> 3) & 0x1) > 0)
      message += " Excluded FED Channel ";
    if (((flag >> 4) & 0x1) > 0)
      message += " DCSError ";
  }
}
//
// -- Set Event Info Folder
//
void TrackingUtility::getTopFolderPath(DQMStore::IBooker& ibooker,
                                       DQMStore::IGetter& igetter,
                                       std::string top_dir,
                                       std::string& path) {
  path = "";
  ibooker.cd();
  if (igetter.dirExists(top_dir)) {
    ibooker.cd(top_dir);
    path = ibooker.pwd();
  } else {
    if (TrackingUtility::goToDir(ibooker, igetter, top_dir)) {
      std::string tdir = "TrackParameters";
      if (TrackingUtility::goToDir(ibooker, igetter, tdir)) {
        path = ibooker.pwd();
        path = path.substr(0, path.find(tdir) - 1);
      }
    }
  }
}