CMS 3D CMS Logo

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 
00028 #include <xercesc/util/XMLString.hpp>
00029 #include <boost/shared_ptr.hpp>
00030 #include <TString.h>
00031 #include <TPRegexp.h>
00032 
00033 namespace cscdqm {
00034 
00040   template <class T>
00041   const std::string toString(T& t) {
00042     std::ostringstream st;
00043     st << t;
00044     std::string result = st.str();
00045     return result;
00046   }
00047 
00055   template <class T>
00056   bool stringToNumber(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
00057     std::istringstream iss(s);
00058     return !(iss >> f >> t).fail();
00059   }
00060 
00065   class Utility {
00066 
00067     public:
00068 
00069       static const bool regexMatch(const TPRegexp& re_expression, const std::string& message);
00070       static const bool regexMatch(const std::string& expression, const std::string& message);
00071 
00072       static const int getCSCTypeBin(const std::string& cstr);
00073       static const std::string getCSCTypeLabel(int endcap, int station, int ring);
00074       static const int tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
00075       static void splitString(std::string str, const std::string delim, std::vector<std::string>& results);
00076       static void trimString(std::string& str);
00077       static uint32_t fastHash(const char * data, int len);
00078       static uint32_t fastHash(const char * data) { return fastHash(data, strlen(data)); }
00079 
00080   };
00081 
00082 
00083 #define XERCES_TRANSCODE(str) cscdqm::XercesStringTranscoder(str).unicodeForm()
00084 
00090   class XercesStringTranscoder {
00091 
00092     public :
00093 
00094       XercesStringTranscoder(const char* const toTranscode) {
00095         fUnicodeForm = XERCES_CPP_NAMESPACE::XMLString::transcode(toTranscode);
00096       }
00097 
00098       ~XercesStringTranscoder() {
00099         XERCES_CPP_NAMESPACE::XMLString::release(&fUnicodeForm);
00100       }
00101 
00102       const XMLCh* unicodeForm() const {
00103         return fUnicodeForm;
00104       }
00105 
00106     private :
00107 
00108       XMLCh* fUnicodeForm;
00109 
00110   };
00111 
00112 }
00113 
00114 #endif

Generated on Tue Jun 9 17:32:32 2009 for CMSSW by  doxygen 1.5.4