Utility

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/*
 * =====================================================================================
 *
 *       Filename:  CSCDQM_Utility.h
 *
 *    Description:  CSC Utilities class
 *
 *        Version:  1.0
 *        Created:  10/30/2008 04:40:38 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
 *        Company:  CERN, CH
 *
 * =====================================================================================
 */

#ifndef CSCDQM_Utility_H
#define CSCDQM_Utility_H

#include <string>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <cstdint>
#include <cmath>

#include <TString.h>
#include <TPRegexp.h>

#include "DataFormats/FEDRawData/interface/FEDNumbering.h"

namespace cscdqm {

  /**
  * @brief  Converting from whatever to string (failsafe!) 
  * @param  t whatever
  * @return result string
  */
  template <class T>
  const std::string toString(T& t) {
    std::ostringstream st;
    st << t;
    std::string result = st.str();
    return result;
  }

  /**
  * @brief  Converting from string to whatever number (failsafe!) 
  * @param  t result number
  * @param  s source string
  * @param  f base
  * @return true if success, else - false
  */
  template <class T>
  bool stringToNumber(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
    std::istringstream iss(s);
    return !(iss >> f >> t).fail();
  }

  /**
   * @class Utility
   * @brief General and CSCDQM Framework related utility routines
   */
  class Utility {
  public:
    static bool regexMatch(const std::string& expression, const std::string& message);
    static bool regexMatch(const TPRegexp& re_expression, const std::string& message);
    static void regexReplace(const std::string& expression, std::string& message, const std::string replace = "");
    static void regexReplace(const TPRegexp& re_expression, std::string& message, const std::string replace = "");
    static std::string regexReplaceStr(const std::string& expression,
                                       const std::string& message,
                                       const std::string replace = "");
    static std::string regexReplaceStr(const TPRegexp& re_expression,
                                       const std::string& message,
                                       const std::string replace = "");

    static int getCSCTypeBin(const std::string& cstr);
    static std::string getCSCTypeLabel(int endcap, int station, int ring);
    static int tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
    static void splitString(const std::string& str, const std::string& delim, std::vector<std::string>& results);
    static void trimString(std::string& str);
    static uint32_t fastHash(const char* data, int len);
    static uint32_t fastHash(const char* data) { return fastHash(data, strlen(data)); }

    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);
    static bool checkError(const unsigned int N, const unsigned int n, const double threshold, const double sigfail);
    static double SignificanceLevelLow(const unsigned int N, const unsigned int n, const double eps);
    static double SignificanceLevelHigh(const unsigned int N, const unsigned int n);

    static int getRUIfromDDUId(unsigned ddu_id);
  };
}  // namespace cscdqm

#endif