General and CSCDQM Framework related utility routines. More...
#include <CSCDQM_Utility.h>
Static Public Member Functions | |
static bool | checkError (const unsigned int N, const unsigned int n, const double threshold, const double sigfail) |
Check the hypothesis that error events (n) value above threshold comparing with the expected 0 and statistics is enough. | |
static short | checkOccupancy (const unsigned int N, const unsigned int n, const double low_threshold, const double high_threshold, const double low_sigfail, const double high_sigfail) |
Check the hypothesis that observed events (n) value is too low or too high comparing with the expected N. | |
static uint32_t | fastHash (const char *data, int len) |
Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html) | |
static uint32_t | fastHash (const char *data) |
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 bool | regexMatch (const TPRegexp &re_expression, const std::string &message) |
Match RegExp expression against string message and return result. | |
static bool | regexMatch (const std::string &expression, const std::string &message) |
Match RegExp expression string against string message and return result. | |
static void | regexReplace (const TPRegexp &re_expression, std::string &message, const std::string replace="") |
Replace string part that matches RegExp expression with some string. | |
static void | regexReplace (const std::string &expression, std::string &message, const std::string replace="") |
Replace string part that matches RegExp expression with some string. | |
static std::string | regexReplaceStr (const std::string &expression, const std::string &message, const std::string replace="") |
Replace string part that matches RegExp expression with some string. | |
static std::string | regexReplaceStr (const TPRegexp &re_expression, const std::string &message, const std::string replace="") |
Replace string part that matches RegExp expression with some string. | |
static double | SignificanceLevelHigh (const unsigned int N, const unsigned int n) |
Calculate error significance alpha for the given number of events based on reference number of errors for "hot" elements: actual number of events have to be larger then the reference. | |
static double | SignificanceLevelLow (const unsigned int N, const unsigned int n, const double eps) |
Calculate error significance alpha for the given number of errors based on reference number of errors for "cold" elements: actual number of events have to be less then the reference. | |
static void | splitString (const 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. |
General and CSCDQM Framework related utility routines.
Definition at line 69 of file CSCDQM_Utility.h.
bool cscdqm::Utility::checkError | ( | const unsigned int | N, |
const unsigned int | n, | ||
const double | threshold, | ||
const double | sigfail | ||
) | [static] |
Check the hypothesis that error events (n) value above threshold comparing with the expected 0 and statistics is enough.
N | Number of total events |
n | Actual (observed) number of events errors |
threshold | Rate of tolerance (<1) |
sigfail | Significance threshold for low value |
Definition at line 301 of file CSCDQM_Utility.cc.
References n, and SignificanceLevelLow().
Referenced by cscdqm::Summary::ReadErrorChambers().
short cscdqm::Utility::checkOccupancy | ( | const unsigned int | N, |
const unsigned int | n, | ||
const double | low_threshold, | ||
const double | high_threshold, | ||
const double | low_sigfail, | ||
const double | high_sigfail | ||
) | [static] |
Check the hypothesis that observed events (n) value is too low or too high comparing with the expected N.
N | Expected number of events |
n | Actual (observed) number of events |
low_threshold | Rate of lower boundary of tolerance (< 1) |
high_threshold | Rate of higher boundary of tolerance (> 1) |
low_sigfail | Significance threshold for low value |
high_sigfail | Significance threshold for high value |
Definition at line 278 of file CSCDQM_Utility.cc.
References n, SignificanceLevelHigh(), and SignificanceLevelLow().
Referenced by cscdqm::Summary::ReadReportingChambersRef().
{ if (N > 0) { double eps_meas = (1.0 * n) / (1.0 * N); if (eps_meas < low_threshold) { double S = Utility::SignificanceLevelLow(N, n, low_threshold); if (S > low_sigfail) return -1; } else if (eps_meas > high_threshold) { double S = Utility::SignificanceLevelHigh(N, n); if (S > high_sigfail) return 1; } } return 0; }
uint32_t cscdqm::Utility::fastHash | ( | const char * | data, |
int | len | ||
) | [static] |
Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html)
data | Source Data |
length | of data |
Definition at line 221 of file CSCDQM_Utility.cc.
References data, get16bits, cond::hash, NULL, and tmp.
{ uint32_t hash = len, tmp; int rem; if (len <= 0 || data == NULL) return 0; rem = len & 3; len >>= 2; /* Main loop */ for (;len > 0; len--) { hash += get16bits (data); tmp = (get16bits (data+2) << 11) ^ hash; hash = (hash << 16) ^ tmp; data += 2*sizeof (uint16_t); hash += hash >> 11; } /* Handle end cases */ switch (rem) { case 3: hash += get16bits (data); hash ^= hash << 16; hash ^= data[sizeof (uint16_t)] << 18; hash += hash >> 11; break; case 2: hash += get16bits (data); hash ^= hash << 11; hash += hash >> 17; break; case 1: hash += *data; hash ^= hash << 10; hash += hash >> 1; } /* Force "avalanching" of final 127 bits */ hash ^= hash << 3; hash += hash >> 5; hash ^= hash << 4; hash += hash >> 17; hash ^= hash << 25; hash += hash >> 6; return hash; }
static uint32_t cscdqm::Utility::fastHash | ( | const char * | data | ) | [inline, static] |
int cscdqm::Utility::getCSCTypeBin | ( | const std::string & | cstr | ) | [static] |
Get CSC y-axis position from chamber string.
cstr | Chamber string |
Definition at line 33 of file CSCDQM_Utility.cc.
Referenced by cscdqm::EventProcessor::getCSCFromMap().
{ if (cstr.compare("ME-4/2") == 0) return 0; if (cstr.compare("ME-4/1") == 0) return 1; if (cstr.compare("ME-3/2") == 0) return 2; if (cstr.compare("ME-3/1") == 0) return 3; if (cstr.compare("ME-2/2") == 0) return 4; if (cstr.compare("ME-2/1") == 0) return 5; if (cstr.compare("ME-1/3") == 0) return 6; if (cstr.compare("ME-1/2") == 0) return 7; if (cstr.compare("ME-1/1") == 0) return 8; if (cstr.compare("ME+1/1") == 0) return 9; if (cstr.compare("ME+1/2") == 0) return 10; if (cstr.compare("ME+1/3") == 0) return 11; if (cstr.compare("ME+2/1") == 0) return 12; if (cstr.compare("ME+2/2") == 0) return 13; if (cstr.compare("ME+3/1") == 0) return 14; if (cstr.compare("ME+3/2") == 0) return 15; if (cstr.compare("ME+4/1") == 0) return 16; if (cstr.compare("ME+4/2") == 0) return 17; return 0; }
std::string cscdqm::Utility::getCSCTypeLabel | ( | int | endcap, |
int | station, | ||
int | ring | ||
) | [static] |
Get CSC label from CSC parameters.
endcap | Endcap number |
station | Station number |
ring | Ring number |
Definition at line 62 of file CSCDQM_Utility.cc.
References diffTwoXMLs::label, relativeConstraints::ring, and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by cscdqm::EventProcessor::getCSCFromMap().
{ std::string label = "Unknown"; std::ostringstream st; if ((endcap > 0) && (station > 0) && (ring > 0)) { if (endcap == 1) { st << "ME+" << station << "/" << ring; label = st.str(); } else if (endcap==2) { st << "ME-" << station << "/" << ring; label = st.str(); } else { label = "Unknown"; } } return label; }
bool cscdqm::Utility::regexMatch | ( | const TPRegexp & | re_expression, |
const std::string & | message | ||
) | [static] |
Match RegExp expression against string message and return result.
re_expression | RegExp expression to match |
message | value to check |
Definition at line 139 of file CSCDQM_Utility.cc.
{ TPRegexp *re = const_cast<TPRegexp*>(&re_expression); return re->MatchB(message); }
bool cscdqm::Utility::regexMatch | ( | const std::string & | expression, |
const std::string & | message | ||
) | [static] |
Match RegExp expression string against string message and return result.
expression | RegExp expression in string to match |
message | value to check |
Definition at line 150 of file CSCDQM_Utility.cc.
Referenced by CSCMonitorModule::bookMonitorObject(), CSCOfflineClient::bookMonitorObject(), cscdqm::Configuration::needBookMO(), and cscdqm::HistoDef::processName().
{ return regexMatch(TPRegexp(expression), message); }
void cscdqm::Utility::regexReplace | ( | const TPRegexp & | re_expression, |
std::string & | message, | ||
const std::string | replace = "" |
||
) | [static] |
Replace string part that matches RegExp expression with some string.
re_expression | RegExp expression to match |
message | value to check |
replace | string to replace matched part |
Definition at line 172 of file CSCDQM_Utility.cc.
References alignCSCRings::s.
void cscdqm::Utility::regexReplace | ( | const std::string & | expression, |
std::string & | message, | ||
const std::string | replace = "" |
||
) | [static] |
Replace string part that matches RegExp expression with some string.
expression | RegExp expression in string to match |
message | value to check |
replace | string to replace matched part |
Definition at line 161 of file CSCDQM_Utility.cc.
{ Utility::regexReplace(TPRegexp(expression), message, replace); }
std::string cscdqm::Utility::regexReplaceStr | ( | const std::string & | expression, |
const std::string & | message, | ||
const std::string | replace = "" |
||
) | [static] |
Replace string part that matches RegExp expression with some string.
expression | RegExp expression in string to match |
message | value to check |
replace | string to replace matched part |
Definition at line 187 of file CSCDQM_Utility.cc.
{ return regexReplaceStr(TPRegexp(expression), message, replace); }
std::string cscdqm::Utility::regexReplaceStr | ( | const TPRegexp & | re_expression, |
const std::string & | message, | ||
const std::string | replace = "" |
||
) | [static] |
Replace string part that matches RegExp expression with some string.
re_expression | RegExp expression to match |
message | value to check |
replace | string to replace matched part |
Definition at line 199 of file CSCDQM_Utility.cc.
References alignCSCRings::s.
double cscdqm::Utility::SignificanceLevelHigh | ( | const unsigned int | N, |
const unsigned int | n | ||
) | [static] |
Calculate error significance alpha for the given number of events based on reference number of errors for "hot" elements: actual number of events have to be larger then the reference.
N | number of reference events |
n | number of actual events |
no - n observed, ne - n expected
Definition at line 353 of file CSCDQM_Utility.cc.
References funct::log(), N, n, Vispa::Plugins::EdmBrowser::EdmDataAccessor::ne(), and mathSSE::sqrt().
Referenced by checkOccupancy().
double cscdqm::Utility::SignificanceLevelLow | ( | const unsigned int | N, |
const unsigned int | n, | ||
const double | eps | ||
) | [static] |
Calculate error significance alpha for the given number of errors based on reference number of errors for "cold" elements: actual number of events have to be less then the reference.
N | Number of events |
n | Number of errors |
eps | Rate of tolerance |
std::cout << "N = " << N << ", n = " << n << ", eps = " << eps << "\n";
Definition at line 322 of file CSCDQM_Utility.cc.
References a, b, funct::log(), n, alignCSCRings::r, and mathSSE::sqrt().
Referenced by checkError(), and checkOccupancy().
{ double l_eps = eps; if (l_eps <= 0.0) l_eps = 0.000001; if (l_eps >= 1.0) l_eps = 0.999999; double eps_meas = (1.0 * n) / (1.0 * N); double a = 1.0, b = 1.0; if (n > 0) { for (unsigned int r = 0; r < n; r++) a = a * (eps_meas / l_eps); } if (n < N) { for (unsigned int r = 0; r < (N - n); r++) b = b * (1 - eps_meas) / (1 - l_eps); } return sqrt(2.0 * log(a * b)); }
void cscdqm::Utility::splitString | ( | const 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 105 of file CSCDQM_Utility.cc.
References pos.
{ std::string::size_type lastPos = str.find_first_not_of(delim, 0); std::string::size_type pos = str.find_first_of(delim, lastPos); while (std::string::npos != pos || std::string::npos != lastPos) { results.push_back(str.substr(lastPos, pos - lastPos)); lastPos = str.find_first_not_of(delim, pos); pos = str.find_first_of(delim, lastPos); } }
int cscdqm::Utility::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 87 of file CSCDQM_Utility.cc.
References pos.
{ std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); std::string::size_type pos = str.find_first_of(delimiters, lastPos); while (std::string::npos != pos || std::string::npos != lastPos) { tokens.push_back(str.substr(lastPos, pos - lastPos)); lastPos = str.find_first_not_of(delimiters, pos); pos = str.find_first_of(delimiters, lastPos); } return tokens.size(); }
void cscdqm::Utility::trimString | ( | std::string & | str | ) | [static] |
Trim string.
str | string to trim |
Definition at line 119 of file CSCDQM_Utility.cc.
References pos.
{ std::string::size_type pos = str.find_last_not_of(' '); if(pos != std::string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(' '); if(pos != std::string::npos) { str.erase(0, pos); } } else { str.erase(str.begin(), str.end()); } }