CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/DQM/CSCMonitorModule/interface/CSCDQM_Utility.h

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  CSCDQM_Utility.h
00005  *
00006  *    Description:  CSC Utilities class
00007  *
00008  *        Version:  1.0
00009  *        Created:  10/30/2008 04:40:38 PM
00010  *       Revision:  none
00011  *       Compiler:  gcc
00012  *
00013  *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
00014  *        Company:  CERN, CH
00015  *
00016  * =====================================================================================
00017  */
00018 
00019 #ifndef CSCDQM_Utility_H
00020 #define CSCDQM_Utility_H
00021 
00022 #include <string>
00023 #include <map>
00024 #include <set>
00025 #include <vector>
00026 #include <sstream>
00027 #include <stdint.h>
00028 #include <math.h>
00029 
00030 #ifndef CSC_RENDER_PLUGIN
00031 #include <xercesc/util/XMLString.hpp>
00032 #endif
00033 
00034 #include <TString.h>
00035 #include <TPRegexp.h>
00036 
00037 namespace cscdqm {
00038 
00044   template <class T>
00045   const std::string toString(T& t) {
00046     std::ostringstream st;
00047     st << t;
00048     std::string result = st.str();
00049     return result;
00050   }
00051 
00059   template <class T>
00060   bool stringToNumber(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
00061     std::istringstream iss(s);
00062     return !(iss >> f >> t).fail();
00063   }
00064 
00069   class Utility {
00070 
00071     public:
00072 
00073       static bool regexMatch(const std::string& expression, const std::string& message);
00074       static bool regexMatch(const TPRegexp& re_expression, const std::string& message);
00075       static void regexReplace(const std::string& expression, std::string& message, const std::string replace = "");
00076       static void regexReplace(const TPRegexp& re_expression, std::string& message, const std::string replace = "");
00077       static std::string regexReplaceStr(const std::string& expression, const std::string& message, const std::string replace = "");
00078       static std::string regexReplaceStr(const TPRegexp& re_expression, const std::string& message, const std::string replace = "");
00079 
00080       static int getCSCTypeBin(const std::string& cstr);
00081       static std::string getCSCTypeLabel(int endcap, int station, int ring);
00082       static int tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
00083       static void splitString(const std::string& str, const std::string& delim, std::vector<std::string>& results);
00084       static void trimString(std::string& str);
00085       static uint32_t fastHash(const char* data, int len);
00086       static uint32_t fastHash(const char* data) { return fastHash(data, strlen(data)); }
00087 
00088       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);
00089       static bool   checkError(const unsigned int N, const unsigned int n, const double threshold, const double sigfail);
00090       static double SignificanceLevelLow(const unsigned int N, const unsigned int n, const double eps);
00091       static double SignificanceLevelHigh(const unsigned int N, const unsigned int n);
00092 
00093   };
00094 
00095 
00096 #ifndef CSC_RENDER_PLUGIN
00097 
00098 #define XERCES_TRANSCODE(str) cscdqm::XercesStringTranscoder(str).unicodeForm()
00099 
00105   class XercesStringTranscoder {
00106 
00107     public :
00108 
00109       XercesStringTranscoder(const char* const toTranscode) {
00110         fUnicodeForm = XERCES_CPP_NAMESPACE::XMLString::transcode(toTranscode);
00111       }
00112 
00113       ~XercesStringTranscoder() {
00114         XERCES_CPP_NAMESPACE::XMLString::release(&fUnicodeForm);
00115       }
00116 
00117       const XMLCh* unicodeForm() const {
00118         return fUnicodeForm;
00119       }
00120 
00121     private :
00122 
00123       XMLCh* fUnicodeForm;
00124 
00125   };
00126 
00127 #endif  
00128 
00129 }
00130 
00131 #endif