Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:58

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  CSCDQM_Utility.h
0005  *
0006  *    Description:  CSC Utilities class
0007  *
0008  *        Version:  1.0
0009  *        Created:  10/30/2008 04:40:38 PM
0010  *       Revision:  none
0011  *       Compiler:  gcc
0012  *
0013  *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
0014  *        Company:  CERN, CH
0015  *
0016  * =====================================================================================
0017  */
0018 
0019 #ifndef CSCDQM_Utility_H
0020 #define CSCDQM_Utility_H
0021 
0022 #include <string>
0023 #include <map>
0024 #include <set>
0025 #include <vector>
0026 #include <sstream>
0027 #include <cstdint>
0028 #include <cmath>
0029 
0030 #include <TString.h>
0031 #include <TPRegexp.h>
0032 
0033 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0034 
0035 namespace cscdqm {
0036 
0037   /**
0038   * @brief  Converting from whatever to string (failsafe!) 
0039   * @param  t whatever
0040   * @return result string
0041   */
0042   template <class T>
0043   const std::string toString(T& t) {
0044     std::ostringstream st;
0045     st << t;
0046     std::string result = st.str();
0047     return result;
0048   }
0049 
0050   /**
0051   * @brief  Converting from string to whatever number (failsafe!) 
0052   * @param  t result number
0053   * @param  s source string
0054   * @param  f base
0055   * @return true if success, else - false
0056   */
0057   template <class T>
0058   bool stringToNumber(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
0059     std::istringstream iss(s);
0060     return !(iss >> f >> t).fail();
0061   }
0062 
0063   /**
0064    * @class Utility
0065    * @brief General and CSCDQM Framework related utility routines
0066    */
0067   class Utility {
0068   public:
0069     static bool regexMatch(const std::string& expression, const std::string& message);
0070     static bool regexMatch(const TPRegexp& re_expression, const std::string& message);
0071     static void regexReplace(const std::string& expression, std::string& message, const std::string replace = "");
0072     static void regexReplace(const TPRegexp& re_expression, std::string& message, const std::string replace = "");
0073     static std::string regexReplaceStr(const std::string& expression,
0074                                        const std::string& message,
0075                                        const std::string replace = "");
0076     static std::string regexReplaceStr(const TPRegexp& re_expression,
0077                                        const std::string& message,
0078                                        const std::string replace = "");
0079 
0080     static int getCSCTypeBin(const std::string& cstr);
0081     static std::string getCSCTypeLabel(int endcap, int station, int ring);
0082     static int tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
0083     static void splitString(const std::string& str, const std::string& delim, std::vector<std::string>& results);
0084     static void trimString(std::string& str);
0085     static uint32_t fastHash(const char* data, int len);
0086     static uint32_t fastHash(const char* data) { return fastHash(data, strlen(data)); }
0087 
0088     static short checkOccupancy(const unsigned int N,
0089                                 const unsigned int n,
0090                                 const double low_threshold,
0091                                 const double high_threshold,
0092                                 const double low_sigfail,
0093                                 const double high_sigfail);
0094     static bool checkError(const unsigned int N, const unsigned int n, const double threshold, const double sigfail);
0095     static double SignificanceLevelLow(const unsigned int N, const unsigned int n, const double eps);
0096     static double SignificanceLevelHigh(const unsigned int N, const unsigned int n);
0097 
0098     static int getRUIfromDDUId(unsigned ddu_id);
0099   };
0100 }  // namespace cscdqm
0101 
0102 #endif