CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCDQM_Utility.h
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: CSCDQM_Utility.h
5  *
6  * Description: CSC Utilities class
7  *
8  * Version: 1.0
9  * Created: 10/30/2008 04:40:38 PM
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
14  * Company: CERN, CH
15  *
16  * =====================================================================================
17  */
18 
19 #ifndef CSCDQM_Utility_H
20 #define CSCDQM_Utility_H
21 
22 #include <string>
23 #include <map>
24 #include <set>
25 #include <vector>
26 #include <sstream>
27 #include <stdint.h>
28 #include <math.h>
29 
30 #ifndef CSC_RENDER_PLUGIN
31 #include <xercesc/util/XMLString.hpp>
32 #endif
33 
34 #include <TString.h>
35 #include <TPRegexp.h>
36 
38 
39 namespace cscdqm {
40 
46  template <class T>
47  const std::string toString(T& t) {
48  std::ostringstream st;
49  st << t;
50  std::string result = st.str();
51  return result;
52  }
53 
61  template <class T>
62  bool stringToNumber(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
63  std::istringstream iss(s);
64  return !(iss >> f >> t).fail();
65  }
66 
71  class Utility {
72 
73  public:
74 
75  static bool regexMatch(const std::string& expression, const std::string& message);
76  static bool regexMatch(const TPRegexp& re_expression, const std::string& message);
77  static void regexReplace(const std::string& expression, std::string& message, const std::string replace = "");
78  static void regexReplace(const TPRegexp& re_expression, std::string& message, const std::string replace = "");
79  static std::string regexReplaceStr(const std::string& expression, const std::string& message, const std::string replace = "");
80  static std::string regexReplaceStr(const TPRegexp& re_expression, const std::string& message, const std::string replace = "");
81 
82  static int getCSCTypeBin(const std::string& cstr);
83  static std::string getCSCTypeLabel(int endcap, int station, int ring);
84  static int tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
85  static void splitString(const std::string& str, const std::string& delim, std::vector<std::string>& results);
86  static void trimString(std::string& str);
87  static uint32_t fastHash(const char* data, int len);
88  static uint32_t fastHash(const char* data) { return fastHash(data, strlen(data)); }
89 
90  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);
91  static bool checkError(const unsigned int N, const unsigned int n, const double threshold, const double sigfail);
92  static double SignificanceLevelLow(const unsigned int N, const unsigned int n, const double eps);
93  static double SignificanceLevelHigh(const unsigned int N, const unsigned int n);
94 
95  static int getRUIfromDDUId(unsigned ddu_id);
96 
97  };
98 
99 
100 #ifndef CSC_RENDER_PLUGIN
101 
102 #define XERCES_TRANSCODE(str) cscdqm::XercesStringTranscoder(str).unicodeForm()
103 
110 
111  public :
112 
113  XercesStringTranscoder(const char* const toTranscode) {
115  }
116 
119  }
120 
121  const XMLCh* unicodeForm() const {
122  return fUnicodeForm;
123  }
124 
125  private :
126 
127  XMLCh* fUnicodeForm;
128 
129  };
130 
131 #endif
132 
133 }
134 
135 #endif
static void splitString(const std::string &str, const std::string &delim, std::vector< std::string > &results)
Split string according to delimiter.
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 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 int getRUIfromDDUId(unsigned ddu_id)
Get RUI Number from DDU source ID for post LS1 configuration.
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...
static bool regexMatch(const std::string &expression, const std::string &message)
Match RegExp expression string against string message and return result.
General and CSCDQM Framework related utility routines.
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 st...
static uint32_t fastHash(const char *data, int len)
Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html)
tuple result
Definition: mps_fire.py:84
static void trimString(std::string &str)
Trim string.
This is a simple class that lets us do easy (though not terribly efficient) trancoding of char* data ...
const std::string toString(T &t)
Converting from whatever to string (failsafe!)
XMLCh * transcode(const T &fInput)
tuple results
Definition: mps_update.py:44
static std::string getCSCTypeLabel(int endcap, int station, int ring)
Get CSC label from CSC parameters.
double f[11][100]
static uint32_t fastHash(const char *data)
static int getCSCTypeBin(const std::string &cstr)
Get CSC y-axis position from chamber string.
#define N
Definition: blowfish.cc:9
const XMLCh * unicodeForm() const
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 expecte...
XercesStringTranscoder(const char *const toTranscode)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static void regexReplace(const std::string &expression, std::string &message, const std::string replace="")
Replace string part that matches RegExp expression with some string.
long double T
static int tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
Break string into tokens.
bool stringToNumber(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &))
Converting from string to whatever number (failsafe!)