00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CSCUtility_H
00019 #define CSCUtility_H
00020
00021 #include <string>
00022 #include <vector>
00023 #include <sstream>
00024 #include <bitset>
00025 #include <map>
00026 #include <iostream>
00027 #include <fstream>
00028 #include <iomanip>
00029 #include "stdint.h"
00030
00035 typedef std::map<std::string, std::string> Histo;
00036 typedef Histo::iterator HistoIter;
00037 typedef std::map<std::string, Histo> HistoDef;
00038 typedef HistoDef::iterator HistoDefIter;
00039 typedef std::map<std::string, HistoDef> HistoDefMap;
00040 typedef HistoDefMap::iterator HistoDefMapIter;
00041
00042 typedef std::bitset<36> BitsetDDU;
00043 typedef std::bitset<32> Bitset32;
00044
00052 template <class T>
00053 bool stringToNumber(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
00054 std::istringstream iss(s);
00055 return !(iss >> f >> t).fail();
00056 }
00057
00058 #undef get16bits
00059 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
00060 #define get16bits(d) (*((const uint16_t *) (d)))
00061 #endif
00062
00063 #if !defined (get16bits)
00064 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) + (uint32_t)(((const uint8_t *)(d))[0]) )
00065 #endif
00066
00071 class CSCUtility {
00072
00073 public:
00074
00075 static std::string getDDUTag(const unsigned int& dduNumber, std::string& buffer);
00076 static bool findHistoValue(Histo& h, const std::string name, std::string& value);
00077 static bool findHistoValue(Histo& h, const std::string name, int& value);
00078 static bool findHistoValue(Histo& h, const std::string name, double& value);
00079 static std::string getHistoValue(Histo& h, const std::string name, std::string& value, const std::string def_value = "");
00080 static int getHistoValue(Histo& h, const std::string name, int& value, const int def_value = 0);
00081 static double getHistoValue(Histo& h, const std::string name, double& value, const int def_value = 0);
00082 static int ParseAxisLabels(const std::string& s, std::map<int, std::string>& labels);
00083 static int getCSCTypeBin(const std::string& cstr);
00084 static std::string getCSCTypeLabel(int endcap, int station, int ring );
00085 static int tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
00086 static void splitString(std::string str, const std::string delim, std::vector<std::string>& results);
00087 static void trimString(std::string& str);
00088 static uint32_t fastHash(const char * data, int len);
00089
00090 };
00091
00092 #endif