test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions
cscdqm::Utility Class Reference

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. More...
 
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. More...
 
static uint32_t fastHash (const char *data, int len)
 Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html) More...
 
static uint32_t fastHash (const char *data)
 
static int getCSCTypeBin (const std::string &cstr)
 Get CSC y-axis position from chamber string. More...
 
static std::string getCSCTypeLabel (int endcap, int station, int ring)
 Get CSC label from CSC parameters. More...
 
static int getRUIfromDDUId (unsigned ddu_id)
 Get RUI Number from DDU source ID for post LS1 configuration. More...
 
static bool regexMatch (const std::string &expression, const std::string &message)
 Match RegExp expression string against string message and return result. More...
 
static bool regexMatch (const TPRegexp &re_expression, const std::string &message)
 Match RegExp expression against string message and return result. More...
 
static void regexReplace (const std::string &expression, std::string &message, const std::string replace="")
 Replace string part that matches RegExp expression with some string. More...
 
static void regexReplace (const TPRegexp &re_expression, std::string &message, const std::string replace="")
 Replace string part that matches RegExp expression with some string. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static void splitString (const std::string &str, const std::string &delim, std::vector< std::string > &results)
 Split string according to delimiter. More...
 
static int tokenize (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
 Break string into tokens. More...
 
static void trimString (std::string &str)
 Trim string. More...
 

Detailed Description

General and CSCDQM Framework related utility routines.

Definition at line 71 of file CSCDQM_Utility.h.

Member Function Documentation

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.

Parameters
NNumber of total events
nActual (observed) number of events errors
thresholdRate of tolerance (<1)
sigfailSignificance threshold for low value
Returns
check result: true - error is significant, false - otherwise

Definition at line 301 of file CSCDQM_Utility.cc.

References gen::n, and SignificanceLevelLow().

Referenced by cscdqm::Summary::ReadErrorChambers().

301  {
302  if (N > 0) {
303  const double eps_meas = (1.0 * n) / (1.0 * N);
304  if (eps_meas > threshold) {
305  if (Utility::SignificanceLevelLow(N, n, threshold) > sigfail) {
306  return true;
307  }
308  }
309  }
310  return false;
311  }
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...
#define N
Definition: blowfish.cc:9
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.

Parameters
NExpected number of events
nActual (observed) number of events
low_thresholdRate of lower boundary of tolerance (< 1)
high_thresholdRate of higher boundary of tolerance (> 1)
low_sigfailSignificance threshold for low value
high_sigfailSignificance threshold for high value
Returns
check outcome: 1 - observed number of events too high wrt expected (HOT), -1 - observed number of events too low wrt expected (COLD), 0 - observed number of events is fine wrt expected

Definition at line 278 of file CSCDQM_Utility.cc.

References gen::n, S(), SignificanceLevelHigh(), and SignificanceLevelLow().

Referenced by cscdqm::Summary::ReadReportingChambersRef().

278  {
279  if (N > 0) {
280  double eps_meas = (1.0 * n) / (1.0 * N);
281  if (eps_meas < low_threshold) {
282  double S = Utility::SignificanceLevelLow(N, n, low_threshold);
283  if (S > low_sigfail) return -1;
284  } else
285  if (eps_meas > high_threshold) {
286  double S = Utility::SignificanceLevelHigh(N, n);
287  if (S > high_sigfail) return 1;
288  }
289  }
290  return 0;
291  }
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...
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...
#define N
Definition: blowfish.cc:9
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
uint32_t cscdqm::Utility::fastHash ( const char *  data,
int  len 
)
static

Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html)

Parameters
dataSource Data
lengthof data
Returns
hash result

Definition at line 221 of file CSCDQM_Utility.cc.

References AlCaHLTBitMon_QueryRunRegistry::data, get16bits, cond::hash, NULL, and tmp.

221  {
222  uint32_t hash = len, tmp;
223  int rem;
224 
225  if (len <= 0 || data == NULL) return 0;
226  rem = len & 3;
227  len >>= 2;
228 
229  /* Main loop */
230  for (;len > 0; len--) {
231  hash += get16bits (data);
232  tmp = (get16bits (data+2) << 11) ^ hash;
233  hash = (hash << 16) ^ tmp;
234  data += 2*sizeof (uint16_t);
235  hash += hash >> 11;
236  }
237 
238  /* Handle end cases */
239  switch (rem) {
240  case 3: hash += get16bits (data);
241  hash ^= hash << 16;
242  hash ^= data[sizeof (uint16_t)] << 18;
243  hash += hash >> 11;
244  break;
245  case 2: hash += get16bits (data);
246  hash ^= hash << 11;
247  hash += hash >> 17;
248  break;
249  case 1: hash += *data;
250  hash ^= hash << 10;
251  hash += hash >> 1;
252  }
253 
254  /* Force "avalanching" of final 127 bits */
255  hash ^= hash << 3;
256  hash += hash >> 5;
257  hash ^= hash << 4;
258  hash += hash >> 17;
259  hash ^= hash << 25;
260  hash += hash >> 6;
261 
262  return hash;
263  }
#define NULL
Definition: scimark2.h:8
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define get16bits(d)
static uint32_t cscdqm::Utility::fastHash ( const char *  data)
inlinestatic

Definition at line 88 of file CSCDQM_Utility.h.

References fastHash().

Referenced by fastHash().

88 { return fastHash(data, strlen(data)); }
static uint32_t fastHash(const char *data, int len)
Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html)
int cscdqm::Utility::getCSCTypeBin ( const std::string &  cstr)
static

Get CSC y-axis position from chamber string.

Parameters
cstrChamber string
Returns
chamber y-axis position

Definition at line 33 of file CSCDQM_Utility.cc.

Referenced by cscdqm::EventProcessor::getCSCFromMap().

33  {
34  if (cstr.compare("ME-4/2") == 0) return 0;
35  if (cstr.compare("ME-4/1") == 0) return 1;
36  if (cstr.compare("ME-3/2") == 0) return 2;
37  if (cstr.compare("ME-3/1") == 0) return 3;
38  if (cstr.compare("ME-2/2") == 0) return 4;
39  if (cstr.compare("ME-2/1") == 0) return 5;
40  if (cstr.compare("ME-1/3") == 0) return 6;
41  if (cstr.compare("ME-1/2") == 0) return 7;
42  if (cstr.compare("ME-1/1") == 0) return 8;
43  if (cstr.compare("ME+1/1") == 0) return 9;
44  if (cstr.compare("ME+1/2") == 0) return 10;
45  if (cstr.compare("ME+1/3") == 0) return 11;
46  if (cstr.compare("ME+2/1") == 0) return 12;
47  if (cstr.compare("ME+2/2") == 0) return 13;
48  if (cstr.compare("ME+3/1") == 0) return 14;
49  if (cstr.compare("ME+3/2") == 0) return 15;
50  if (cstr.compare("ME+4/1") == 0) return 16;
51  if (cstr.compare("ME+4/2") == 0) return 17;
52  return 0;
53  }
std::string cscdqm::Utility::getCSCTypeLabel ( int  endcap,
int  station,
int  ring 
)
static

Get CSC label from CSC parameters.

Parameters
endcapEndcap number
stationStation number
ringRing number
Returns
chamber label

Definition at line 62 of file CSCDQM_Utility.cc.

References diffTwoXMLs::label, relativeConstraints::ring, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by cscdqm::EventProcessor::getCSCFromMap().

62  {
63  std::string label = "Unknown";
64  std::ostringstream st;
65  if ((endcap > 0) && (station > 0) && (ring > 0)) {
66  if (endcap == 1) {
67  st << "ME+" << station << "/" << ring;
68  label = st.str();
69  } else if (endcap==2) {
70  st << "ME-" << station << "/" << ring;
71  label = st.str();
72  } else {
73  label = "Unknown";
74  }
75  }
76  return label;
77  }
int cscdqm::Utility::getRUIfromDDUId ( unsigned  ddu_id)
static

Get RUI Number from DDU source ID for post LS1 configuration.

Parameters
ddu_idDDI Source ID

Definition at line 364 of file CSCDQM_Utility.cc.

References i, FEDNumbering::MAXCSCDDUFEDID, and FEDNumbering::MINCSCDDUFEDID.

Referenced by cscdqm::EventProcessor::processDDU(), and cscdqm::EventProcessor::processExaminer().

364  {
365  int rui = -1;
366  const unsigned postLS1_map [] = { 841, 842, 843, 844, 845, 846, 847, 848, 849,
367  831, 832, 833, 834, 835, 836, 837, 838, 839,
368  861, 862, 863, 864, 865, 866, 867, 868, 869,
369  851, 852, 853, 854, 855, 856, 857, 858, 859 };
370  if ( (ddu_id >= FEDNumbering::MINCSCDDUFEDID) && (ddu_id <= FEDNumbering::MAXCSCDDUFEDID) )
371  {
372  for ( int i = 0; i < 36; i++)
373  {
374  if (ddu_id == postLS1_map[i]) { rui = i+1; return rui;}
375  }
376  } else {
377  rui = ddu_id & 0xFF;
378  }
379  return rui;
380  }
int i
Definition: DBlmapReader.cc:9
bool cscdqm::Utility::regexMatch ( const std::string &  expression,
const std::string &  message 
)
static

Match RegExp expression string against string message and return result.

Parameters
expressionRegExp expression in string to match
messagevalue to check
Returns
true if message matches RegExp expression

Definition at line 150 of file CSCDQM_Utility.cc.

Referenced by CSCOfflineClient::bookMonitorObject(), CSCMonitorModule::bookMonitorObject(), cscdqm::Collection::load(), cscdqm::Configuration::needBookMO(), and cscdqm::HistoDef::processName().

150  {
151  return regexMatch(TPRegexp(expression), message);
152  }
static bool regexMatch(const std::string &expression, const std::string &message)
Match RegExp expression string against string message and return result.
bool cscdqm::Utility::regexMatch ( const TPRegexp &  re_expression,
const std::string &  message 
)
static

Match RegExp expression against string message and return result.

Parameters
re_expressionRegExp expression to match
messagevalue to check
Returns
true if message matches RegExp expression

Definition at line 139 of file CSCDQM_Utility.cc.

139  {
140  TPRegexp *re = const_cast<TPRegexp*>(&re_expression);
141  return re->MatchB(message);
142  }
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.

Parameters
expressionRegExp expression in string to match
messagevalue to check
replacestring to replace matched part

Definition at line 161 of file CSCDQM_Utility.cc.

161  {
162  Utility::regexReplace(TPRegexp(expression), message, replace);
163  }
static void regexReplace(const std::string &expression, std::string &message, const std::string replace="")
Replace string part that matches RegExp expression with some string.
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.

Parameters
re_expressionRegExp expression to match
messagevalue to check
replacestring to replace matched part

Definition at line 172 of file CSCDQM_Utility.cc.

References alignCSCRings::s.

172  {
173  TString s(message);
174  TPRegexp *re = const_cast<TPRegexp*>(&re_expression);
175  re->Substitute(s, replace);
176  message = s;
177  }
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.

Parameters
expressionRegExp expression in string to match
messagevalue to check
replacestring to replace matched part
Returns
modified string

Definition at line 187 of file CSCDQM_Utility.cc.

187  {
188  return regexReplaceStr(TPRegexp(expression), message, replace);
189  }
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.
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.

Parameters
re_expressionRegExp expression to match
messagevalue to check
replacestring to replace matched part
Returns
modified string

Definition at line 199 of file CSCDQM_Utility.cc.

References alignCSCRings::s.

199  {
200  TString s(message);
201  TPRegexp *re = const_cast<TPRegexp*>(&re_expression);
202  re->Substitute(s, replace);
203  return s.Data();
204  }
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.

Parameters
Nnumber of reference events
nnumber of actual events
Returns
error significance

no - n observed, ne - n expected

Definition at line 353 of file CSCDQM_Utility.cc.

References dqm-mbProfile::log, N, gen::n, Vispa.Plugins.EdmBrowser.EdmDataAccessor::ne(), and mathSSE::sqrt().

Referenced by checkOccupancy().

353  {
354  if (N > n) return 0.0;
356  double no = 1.0 * n, ne = 1.0 * N;
357  return sqrt(2.0 * (no * (log(no / ne) - 1) + ne));
358  }
T sqrt(T t)
Definition: SSEVec.h:18
#define N
Definition: blowfish.cc:9
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.

Parameters
NNumber of events
nNumber of errors
epsRate of tolerance
Returns
Significance level

std::cout << "N = " << N << ", n = " << n << ", eps = " << eps << "\n";

Definition at line 322 of file CSCDQM_Utility.cc.

References a, b, dqm-mbProfile::log, gen::n, alignCSCRings::r, and mathSSE::sqrt().

Referenced by checkError(), and checkOccupancy().

322  {
323 
326  double l_eps = eps;
327  if (l_eps <= 0.0) l_eps = 0.000001;
328  if (l_eps >= 1.0) l_eps = 0.999999;
329 
330  double eps_meas = (1.0 * n) / (1.0 * N);
331  double a = 1.0, b = 1.0;
332 
333  if (n > 0) {
334  for (unsigned int r = 0; r < n; r++) a = a * (eps_meas / l_eps);
335  }
336 
337  if (n < N) {
338  for (unsigned int r = 0; r < (N - n); r++) b = b * (1 - eps_meas) / (1 - l_eps);
339  }
340 
341  return sqrt(2.0 * log(a * b));
342 
343  }
T sqrt(T t)
Definition: SSEVec.h:18
#define N
Definition: blowfish.cc:9
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void cscdqm::Utility::splitString ( const std::string &  str,
const std::string &  delim,
std::vector< std::string > &  results 
)
static

Split string according to delimiter.

Parameters
strString to split
delimDelimiter
resultsVector to write results to
Returns

Definition at line 105 of file CSCDQM_Utility.cc.

Referenced by cscdqm::Detector::AddressFromString().

105  {
106  std::string::size_type lastPos = str.find_first_not_of(delim, 0);
107  std::string::size_type pos = str.find_first_of(delim, lastPos);
108  while (std::string::npos != pos || std::string::npos != lastPos) {
109  results.push_back(str.substr(lastPos, pos - lastPos));
110  lastPos = str.find_first_not_of(delim, pos);
111  pos = str.find_first_of(delim, lastPos);
112  }
113  }
uint16_t size_type
tuple results
Definition: mps_update.py:44
int cscdqm::Utility::tokenize ( const std::string &  str,
std::vector< std::string > &  tokens,
const std::string &  delimiters = " " 
)
static

Break string into tokens.

Parameters
strsource string to break
tokenspointer to result vector
delimitersdelimiter string, default " "
Returns

Definition at line 87 of file CSCDQM_Utility.cc.

Referenced by cscdqm::Collection::book().

87  {
88  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
89  std::string::size_type pos = str.find_first_of(delimiters, lastPos);
90  while (std::string::npos != pos || std::string::npos != lastPos) {
91  tokens.push_back(str.substr(lastPos, pos - lastPos));
92  lastPos = str.find_first_not_of(delimiters, pos);
93  pos = str.find_first_of(delimiters, lastPos);
94  }
95  return tokens.size();
96  }
uint16_t size_type
void cscdqm::Utility::trimString ( std::string &  str)
static

Trim string.

Parameters
strstring to trim

Definition at line 119 of file CSCDQM_Utility.cc.

Referenced by cscdqm::Detector::AddressFromString().

119  {
120  std::string::size_type pos = str.find_last_not_of(' ');
121  if(pos != std::string::npos) {
122  str.erase(pos + 1);
123  pos = str.find_first_not_of(' ');
124  if(pos != std::string::npos) {
125  str.erase(0, pos);
126  }
127  } else {
128  str.erase(str.begin(), str.end());
129  }
130  }
uint16_t size_type