#include <DQM/CSCMonitorModule/interface/CSCUtility.h>
Static Public Member Functions | |
static uint32_t | fastHash (const char *data, int len) |
Calculate super fast hash (from https://www.azillionmonkeys.com/qed/hash.html). | |
static bool | findHistoValue (Histo &h, const std::string name, double &value) |
Find double histogram value in map. | |
static bool | findHistoValue (Histo &h, const std::string name, int &value) |
Find int histogram value in map. | |
static bool | findHistoValue (Histo &h, const std::string name, std::string &value) |
Find string histogram value in map. | |
static int | getCSCTypeBin (const std::string &cstr) |
Get CSC y-axis position from chamber string. | |
static std::string | getCSCTypeLabel (int endcap, int station, int ring) |
Get CSC label from CSC parameters. | |
static std::string | getDDUTag (const unsigned int &dduNumber, std::string &buffer) |
Format and return DDU Tag (to be folder name). | |
static double | getHistoValue (Histo &h, const std::string name, double &value, const int def_value=0) |
get Histogram double value out of the map and | |
static int | getHistoValue (Histo &h, const std::string name, int &value, const int def_value=0) |
get Histogram int value out of the map and | |
static std::string | getHistoValue (Histo &h, const std::string name, std::string &value, const std::string def_value="") |
get Histogram string value out of the map and | |
static int | ParseAxisLabels (const std::string &s, std::map< int, std::string > &labels) |
Parse Axis label string and return values in vector. | |
static void | splitString (std::string str, const std::string delim, std::vector< std::string > &results) |
Split string according to delimiter. | |
static int | tokenize (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ") |
Break string into tokens. | |
static void | trimString (std::string &str) |
Trim string. |
Definition at line 71 of file CSCUtility.h.
uint32_t CSCUtility::fastHash | ( | const char * | data, | |
int | len | |||
) | [static] |
Calculate super fast hash (from https://www.azillionmonkeys.com/qed/hash.html).
data | Source Data | |
length | of data |
Definition at line 277 of file CSCUtility.cc.
References get16bits, NULL, and tmp.
00277 { 00278 uint32_t hash = len, tmp; 00279 int rem; 00280 00281 if (len <= 0 || data == NULL) return 0; 00282 rem = len & 3; 00283 len >>= 2; 00284 00285 /* Main loop */ 00286 for (;len > 0; len--) { 00287 hash += get16bits (data); 00288 tmp = (get16bits (data+2) << 11) ^ hash; 00289 hash = (hash << 16) ^ tmp; 00290 data += 2*sizeof (uint16_t); 00291 hash += hash >> 11; 00292 } 00293 00294 /* Handle end cases */ 00295 switch (rem) { 00296 case 3: hash += get16bits (data); 00297 hash ^= hash << 16; 00298 hash ^= data[sizeof (uint16_t)] << 18; 00299 hash += hash >> 11; 00300 break; 00301 case 2: hash += get16bits (data); 00302 hash ^= hash << 11; 00303 hash += hash >> 17; 00304 break; 00305 case 1: hash += *data; 00306 hash ^= hash << 10; 00307 hash += hash >> 1; 00308 } 00309 00310 /* Force "avalanching" of final 127 bits */ 00311 hash ^= hash << 3; 00312 hash += hash >> 5; 00313 hash ^= hash << 4; 00314 hash += hash >> 17; 00315 hash ^= hash << 25; 00316 hash += hash >> 6; 00317 00318 return hash; 00319 }
Find double histogram value in map.
Definition at line 79 of file CSCUtility.cc.
References i.
00079 { 00080 HistoIter i = h.find(name); 00081 if(i == h.end()) { 00082 return false; 00083 } else { 00084 if(EOF == std::sscanf(i->second.c_str(), "%lf", &value)) { 00085 return false; 00086 } 00087 } 00088 return true; 00089 }
Find int histogram value in map.
Definition at line 60 of file CSCUtility.cc.
References i.
00060 { 00061 HistoIter i = h.find(name); 00062 if(i == h.end()) { 00063 return false; 00064 } else { 00065 if(EOF == std::sscanf(i->second.c_str(), "%d", &value)) { 00066 return false; 00067 } 00068 } 00069 return true; 00070 }
Find string histogram value in map.
Definition at line 43 of file CSCUtility.cc.
References i.
Referenced by getHistoValue().
00043 { 00044 HistoIter i = h.find(name); 00045 if(i == h.end()) { 00046 return false; 00047 } else { 00048 value = i->second; 00049 } 00050 return true; 00051 }
int CSCUtility::getCSCTypeBin | ( | const std::string & | cstr | ) | [static] |
Get CSC y-axis position from chamber string.
cstr | Chamber string |
Definition at line 168 of file CSCUtility.cc.
Referenced by CSCMonitorModule::getCSCFromMap().
00168 { 00169 if (cstr.compare("ME-4/2") == 0) return 0; 00170 if (cstr.compare("ME-4/1") == 0) return 1; 00171 if (cstr.compare("ME-3/2") == 0) return 2; 00172 if (cstr.compare("ME-3/1") == 0) return 3; 00173 if (cstr.compare("ME-2/2") == 0) return 4; 00174 if (cstr.compare("ME-2/1") == 0) return 5; 00175 if (cstr.compare("ME-1/3") == 0) return 6; 00176 if (cstr.compare("ME-1/2") == 0) return 7; 00177 if (cstr.compare("ME-1/1") == 0) return 8; 00178 if (cstr.compare("ME+1/1") == 0) return 9; 00179 if (cstr.compare("ME+1/2") == 0) return 10; 00180 if (cstr.compare("ME+1/3") == 0) return 11; 00181 if (cstr.compare("ME+2/1") == 0) return 12; 00182 if (cstr.compare("ME+2/2") == 0) return 13; 00183 if (cstr.compare("ME+3/1") == 0) return 14; 00184 if (cstr.compare("ME+3/2") == 0) return 15; 00185 if (cstr.compare("ME+4/1") == 0) return 16; 00186 if (cstr.compare("ME+4/2") == 0) return 17; 00187 return 0; 00188 }
Get CSC label from CSC parameters.
endcap | Endcap number | |
station | Station number | |
ring | Ring number |
Definition at line 197 of file CSCUtility.cc.
Referenced by CSCMonitorModule::getCSCFromMap().
00197 { 00198 std::string label = "Unknown"; 00199 std::ostringstream st; 00200 if ((endcap > 0) && (station > 0) && (ring > 0)) { 00201 if (endcap == 1) { 00202 st << "ME+" << station << "/" << ring; 00203 label = st.str(); 00204 } else if (endcap==2) { 00205 st << "ME-" << station << "/" << ring; 00206 label = st.str(); 00207 } else { 00208 label = "Unknown"; 00209 } 00210 } 00211 return label; 00212 }
std::string CSCUtility::getDDUTag | ( | const unsigned int & | dduNumber, | |
std::string & | buffer | |||
) | [static] |
Format and return DDU Tag (to be folder name).
ddNumber | DDU number (1 - 36) | |
buffer | Buffer to be filled with data |
Definition at line 28 of file CSCUtility.cc.
Referenced by CSCMonitorModule::MEDDU().
00028 { 00029 std::stringstream oss; 00030 oss << std::setfill('0'); 00031 oss << "DDU_" << std::setw(2) << dduNumber; 00032 buffer = oss.str(); 00033 return buffer; 00034 }
double CSCUtility::getHistoValue | ( | Histo & | h, | |
const std::string | name, | |||
double & | value, | |||
const int | def_value = 0 | |||
) | [static] |
get Histogram double value out of the map and
h | Histogram map | |
name | parameter name | |
value | handler for parameter value | |
default | value if parameter not found |
Definition at line 129 of file CSCUtility.cc.
References findHistoValue().
00129 { 00130 if(!findHistoValue(h, name, value)) { 00131 value = def_value; 00132 } 00133 return value; 00134 }
int CSCUtility::getHistoValue | ( | Histo & | h, | |
const std::string | name, | |||
int & | value, | |||
const int | def_value = 0 | |||
) | [static] |
get Histogram int value out of the map and
h | Histogram map | |
name | parameter name | |
value | handler for parameter value | |
default | value if parameter not found |
Definition at line 114 of file CSCUtility.cc.
References findHistoValue().
00114 { 00115 if(!findHistoValue(h, name, value)) { 00116 value = def_value; 00117 } 00118 return value; 00119 }
std::string CSCUtility::getHistoValue | ( | Histo & | h, | |
const std::string | name, | |||
std::string & | value, | |||
const std::string | def_value = "" | |||
) | [static] |
get Histogram string value out of the map and
h | Histogram map | |
name | parameter name | |
value | handler for parameter value | |
default | value if parameter not found |
Definition at line 99 of file CSCUtility.cc.
References findHistoValue().
00099 { 00100 if(!findHistoValue(h, name, value)) { 00101 value = def_value; 00102 } 00103 return value; 00104 }
int CSCUtility::ParseAxisLabels | ( | const std::string & | s, | |
std::map< int, std::string > & | labels | |||
) | [static] |
Parse Axis label string and return values in vector.
s | source string to parse | |
labels | pointer to result vector |
Definition at line 142 of file CSCUtility.cc.
References label, NULL, and tmp.
00142 { 00143 std::string tmp = s; 00144 std::string::size_type pos = tmp.find("|"); 00145 char* stopstring = NULL; 00146 00147 while (pos != std::string::npos) { 00148 std::string label_pair = tmp.substr(0, pos); 00149 tmp.replace(0,pos+1,""); 00150 if (label_pair.find("=") != std::string::npos) { 00151 int nbin = strtol(label_pair.substr(0,label_pair.find("=")).c_str(), &stopstring, 10); 00152 std::string label = label_pair.substr(label_pair.find("=")+1, label_pair.length()); 00153 while (label.find("\'") != std::string::npos) { 00154 label.erase(label.find("\'"),1); 00155 } 00156 labels[nbin] = label; 00157 } 00158 pos = tmp.find("|"); 00159 } 00160 return labels.size(); 00161 }
void CSCUtility::splitString | ( | std::string | str, | |
const std::string | delim, | |||
std::vector< std::string > & | results | |||
) | [static] |
Split string according to delimiter.
str | String to split | |
delim | Delimiter | |
results | Vector to write results to |
Definition at line 240 of file CSCUtility.cc.
00240 { 00241 unsigned int cutAt; 00242 while ((cutAt = str.find_first_of(delim)) != str.npos) { 00243 if(cutAt > 0) { 00244 results.push_back(str.substr(0, cutAt)); 00245 } 00246 str = str.substr(cutAt + 1); 00247 } 00248 if(str.length() > 0) { 00249 results.push_back(str); 00250 } 00251 }
int CSCUtility::tokenize | ( | const std::string & | str, | |
std::vector< std::string > & | tokens, | |||
const std::string & | delimiters = " " | |||
) | [static] |
Break string into tokens.
str | source string to break | |
tokens | pointer to result vector | |
delimiters | delimiter string, default " " |
Definition at line 222 of file CSCUtility.cc.
00222 { 00223 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); 00224 std::string::size_type pos = str.find_first_of(delimiters, lastPos); 00225 while (std::string::npos != pos || std::string::npos != lastPos) { 00226 tokens.push_back(str.substr(lastPos, pos - lastPos)); 00227 lastPos = str.find_first_not_of(delimiters, pos); 00228 pos = str.find_first_of(delimiters, lastPos); 00229 } 00230 return tokens.size(); 00231 }
void CSCUtility::trimString | ( | std::string & | str | ) | [static] |
Trim string.
str | string to trim |
Definition at line 259 of file CSCUtility.cc.
00259 { 00260 std::string::size_type pos = str.find_last_not_of(' '); 00261 if(pos != std::string::npos) { 00262 str.erase(pos + 1); 00263 pos = str.find_first_not_of(' '); 00264 if(pos != std::string::npos) 00265 str.erase(0, pos); 00266 } else 00267 str.erase(str.begin(), str.end()); 00268 }