CMS 3D CMS Logo

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)
 
static uint32_t fastHash (const char *data, int len)
 Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html) More...
 
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 67 of file CSCDQM_Utility.h.

Member Function Documentation

◆ checkError()

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 331 of file CSCDQM_Utility.cc.

331  {
332  if (N > 0) {
333  const double eps_meas = (1.0 * n) / (1.0 * N);
334  if (eps_meas > threshold) {
335  if (Utility::SignificanceLevelLow(N, n, threshold) > sigfail) {
336  return true;
337  }
338  }
339  }
340  return false;
341  }

References N, dqmiodumpmetadata::n, SignificanceLevelLow(), and remoteMonitoring_LED_IterMethod_cfg::threshold.

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

◆ checkOccupancy()

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 302 of file CSCDQM_Utility.cc.

307  {
308  if (N > 0) {
309  double eps_meas = (1.0 * n) / (1.0 * N);
310  if (eps_meas < low_threshold) {
311  double S = Utility::SignificanceLevelLow(N, n, low_threshold);
312  if (S > low_sigfail)
313  return -1;
314  } else if (eps_meas > high_threshold) {
315  double S = Utility::SignificanceLevelHigh(N, n);
316  if (S > high_sigfail)
317  return 1;
318  }
319  }
320  return 0;
321  }

References N, dqmiodumpmetadata::n, SignificanceLevelHigh(), and SignificanceLevelLow().

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

◆ fastHash() [1/2]

static uint32_t cscdqm::Utility::fastHash ( const char *  data)
inlinestatic

Definition at line 86 of file CSCDQM_Utility.h.

86 { return fastHash(data, strlen(data)); }

References data, and fastHash().

Referenced by fastHash().

◆ fastHash() [2/2]

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 242 of file CSCDQM_Utility.cc.

242  {
243  uint32_t hash = len, tmp;
244  int rem;
245 
246  if (len <= 0 || data == nullptr)
247  return 0;
248  rem = len & 3;
249  len >>= 2;
250 
251  /* Main loop */
252  for (; len > 0; len--) {
253  hash += get16bits(data);
254  tmp = (get16bits(data + 2) << 11) ^ hash;
255  hash = (hash << 16) ^ tmp;
256  data += 2 * sizeof(uint16_t);
257  hash += hash >> 11;
258  }
259 
260  /* Handle end cases */
261  switch (rem) {
262  case 3:
263  hash += get16bits(data);
264  hash ^= hash << 16;
265  hash ^= data[sizeof(uint16_t)] << 18;
266  hash += hash >> 11;
267  break;
268  case 2:
269  hash += get16bits(data);
270  hash ^= hash << 11;
271  hash += hash >> 17;
272  break;
273  case 1:
274  hash += *data;
275  hash ^= hash << 10;
276  hash += hash >> 1;
277  }
278 
279  /* Force "avalanching" of final 127 bits */
280  hash ^= hash << 3;
281  hash += hash >> 5;
282  hash ^= hash << 4;
283  hash += hash >> 17;
284  hash ^= hash << 25;
285  hash += hash >> 6;
286 
287  return hash;
288  }

References data, get16bits, cond::hash, and createJobs::tmp.

◆ getCSCTypeBin()

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.

33  {
34  if (cstr == "ME-4/2")
35  return 0;
36  if (cstr == "ME-4/1")
37  return 1;
38  if (cstr == "ME-3/2")
39  return 2;
40  if (cstr == "ME-3/1")
41  return 3;
42  if (cstr == "ME-2/2")
43  return 4;
44  if (cstr == "ME-2/1")
45  return 5;
46  if (cstr == "ME-1/3")
47  return 6;
48  if (cstr == "ME-1/2")
49  return 7;
50  if (cstr == "ME-1/1")
51  return 8;
52  if (cstr == "ME+1/1")
53  return 9;
54  if (cstr == "ME+1/2")
55  return 10;
56  if (cstr == "ME+1/3")
57  return 11;
58  if (cstr == "ME+2/1")
59  return 12;
60  if (cstr == "ME+2/2")
61  return 13;
62  if (cstr == "ME+3/1")
63  return 14;
64  if (cstr == "ME+3/2")
65  return 15;
66  if (cstr == "ME+4/1")
67  return 16;
68  if (cstr == "ME+4/2")
69  return 17;
70  return 0;
71  }

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

◆ getCSCTypeLabel()

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 80 of file CSCDQM_Utility.cc.

80  {
81  std::string label = "Unknown";
82  std::ostringstream st;
83  if ((endcap > 0) && (station > 0) && (ring > 0)) {
84  if (endcap == 1) {
85  st << "ME+" << station << "/" << ring;
86  label = st.str();
87  } else if (endcap == 2) {
88  st << "ME-" << station << "/" << ring;
89  label = st.str();
90  } else {
91  label = "Unknown";
92  }
93  }
94  return label;
95  }

References makeMuonMisalignmentScenario::endcap, label, relativeConstraints::ring, relativeConstraints::station, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ getRUIfromDDUId()

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 397 of file CSCDQM_Utility.cc.

397  {
398  int rui = -1;
399  const unsigned postLS1_map[] = {841, 842, 843, 844, 845, 846, 847, 848, 849, 831, 832, 833,
400  834, 835, 836, 837, 838, 839, 861, 862, 863, 864, 865, 866,
401  867, 868, 869, 851, 852, 853, 854, 855, 856, 857, 858, 859};
402  if ((ddu_id >= FEDNumbering::MINCSCDDUFEDID) && (ddu_id <= FEDNumbering::MAXCSCDDUFEDID)) {
403  for (int i = 0; i < 36; i++) {
404  if (ddu_id == postLS1_map[i]) {
405  rui = i + 1;
406  return rui;
407  }
408  }
409  } else {
410  rui = ddu_id & 0xFF;
411  }
412  return rui;
413  }

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

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

◆ regexMatch() [1/2]

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 166 of file CSCDQM_Utility.cc.

166  {
167  return regexMatch(TPRegexp(expression), message);
168  }

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

◆ regexMatch() [2/2]

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 155 of file CSCDQM_Utility.cc.

155  {
156  TPRegexp* re = const_cast<TPRegexp*>(&re_expression);
157  return re->MatchB(message);
158  }

◆ regexReplace() [1/2]

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 177 of file CSCDQM_Utility.cc.

177  {
178  Utility::regexReplace(TPRegexp(expression), message, replace);
179  }

References python.rootplot.root2matplotlib::replace().

◆ regexReplace() [2/2]

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 188 of file CSCDQM_Utility.cc.

188  {
189  TString s(message);
190  TPRegexp* re = const_cast<TPRegexp*>(&re_expression);
191  re->Substitute(s, replace);
192  message = static_cast<const char*>(s);
193  }

References python.rootplot.root2matplotlib::replace(), and alignCSCRings::s.

◆ regexReplaceStr() [1/2]

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 203 of file CSCDQM_Utility.cc.

205  {
206  return regexReplaceStr(TPRegexp(expression), message, replace);
207  }

References python.rootplot.root2matplotlib::replace().

◆ regexReplaceStr() [2/2]

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 217 of file CSCDQM_Utility.cc.

219  {
220  TString s(message);
221  TPRegexp* re = const_cast<TPRegexp*>(&re_expression);
222  re->Substitute(s, replace);
223  return s.Data();
224  }

References python.rootplot.root2matplotlib::replace(), and alignCSCRings::s.

◆ SignificanceLevelHigh()

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 385 of file CSCDQM_Utility.cc.

385  {
386  if (N > n)
387  return 0.0;
389  double no = 1.0 * n, ne = 1.0 * N;
390  return sqrt(2.0 * (no * (log(no / ne) - 1) + ne));
391  }

References dqm-mbProfile::log, N, dqmiodumpmetadata::n, and mathSSE::sqrt().

Referenced by checkOccupancy().

◆ SignificanceLevelLow()

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 352 of file CSCDQM_Utility.cc.

352  {
355  double l_eps = eps;
356  if (l_eps <= 0.0)
357  l_eps = 0.000001;
358  if (l_eps >= 1.0)
359  l_eps = 0.999999;
360 
361  double eps_meas = (1.0 * n) / (1.0 * N);
362  double a = 1.0, b = 1.0;
363 
364  if (n > 0) {
365  for (unsigned int r = 0; r < n; r++)
366  a = a * (eps_meas / l_eps);
367  }
368 
369  if (n < N) {
370  for (unsigned int r = 0; r < (N - n); r++)
371  b = b * (1 - eps_meas) / (1 - l_eps);
372  }
373 
374  return sqrt(2.0 * log(a * b));
375  }

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

Referenced by checkError(), and checkOccupancy().

◆ splitString()

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 122 of file CSCDQM_Utility.cc.

122  {
123  std::string::size_type lastPos = str.find_first_not_of(delim, 0);
124  std::string::size_type pos = str.find_first_of(delim, lastPos);
125  while (std::string::npos != pos || std::string::npos != lastPos) {
126  results.push_back(str.substr(lastPos, pos - lastPos));
127  lastPos = str.find_first_not_of(delim, pos);
128  pos = str.find_first_of(delim, lastPos);
129  }
130  }

References bookConverter::results, and str.

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

◆ tokenize()

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 104 of file CSCDQM_Utility.cc.

104  {
105  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
106  std::string::size_type pos = str.find_first_of(delimiters, lastPos);
107  while (std::string::npos != pos || std::string::npos != lastPos) {
108  tokens.push_back(str.substr(lastPos, pos - lastPos));
109  lastPos = str.find_first_not_of(delimiters, pos);
110  pos = str.find_first_of(delimiters, lastPos);
111  }
112  return tokens.size();
113  }

References str.

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

◆ trimString()

void cscdqm::Utility::trimString ( std::string &  str)
static

Trim string.

Parameters
strstring to trim

Definition at line 136 of file CSCDQM_Utility.cc.

136  {
137  std::string::size_type pos = str.find_last_not_of(' ');
138  if (pos != std::string::npos) {
139  str.erase(pos + 1);
140  pos = str.find_first_not_of(' ');
141  if (pos != std::string::npos) {
142  str.erase(0, pos);
143  }
144  } else {
145  str.erase(str.begin(), str.end());
146  }
147  }

References str.

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

mps_fire.i
i
Definition: mps_fire.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
cscdqm::Utility::SignificanceLevelHigh
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...
Definition: CSCDQM_Utility.cc:385
cond::hash
Definition: Time.h:19
relativeConstraints.station
station
Definition: relativeConstraints.py:67
pos
Definition: PixelAliasList.h:18
cscdqm::Utility::SignificanceLevelLow
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...
Definition: CSCDQM_Utility.cc:352
bookConverter.results
results
Definition: bookConverter.py:144
cscdqm::Utility::regexMatch
static bool regexMatch(const std::string &expression, const std::string &message)
Match RegExp expression string against string message and return result.
Definition: CSCDQM_Utility.cc:166
cscdqm::Utility::fastHash
static uint32_t fastHash(const char *data, int len)
Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html)
Definition: CSCDQM_Utility.cc:242
cscdqm::Utility::regexReplaceStr
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.
Definition: CSCDQM_Utility.cc:203
makeMuonMisalignmentScenario.endcap
endcap
Definition: makeMuonMisalignmentScenario.py:320
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
FEDNumbering::MAXCSCDDUFEDID
Definition: FEDNumbering.h:90
alignCSCRings.s
s
Definition: alignCSCRings.py:92
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
str
#define str(s)
Definition: TestProcessor.cc:48
N
#define N
Definition: blowfish.cc:9
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
a
double a
Definition: hdecay.h:119
get16bits
#define get16bits(d)
Definition: CSCDQM_Utility.cc:233
alignCSCRings.r
r
Definition: alignCSCRings.py:93
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
FEDNumbering::MINCSCDDUFEDID
Definition: FEDNumbering.h:89
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
cscdqm::Utility::regexReplace
static void regexReplace(const std::string &expression, std::string &message, const std::string replace="")
Replace string part that matches RegExp expression with some string.
Definition: CSCDQM_Utility.cc:177
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
S
Definition: CSCDBL1TPParametersExtended.h:16
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
label
const char * label
Definition: PFTauDecayModeTools.cc:11
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444