CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions
jsoncollector::Utils Class Reference

#include <Utils.h>

Static Public Member Functions

static void bumpIndex (std::vector< int > &theVector, unsigned int index)
 
static void getHostAndPID (std::string &sHPid)
 
static void intArrayToString (std::vector< int > &theVector, std::string &theString)
 
static bool matchExactly (std::string s1, std::string s2)
 
static void stringToIntArray (std::vector< int > &theVector, const std::string &theString)
 
static std::vector< std::string > vectorDoubleToString (const std::vector< double > &doubleVector)
 
static std::vector< double > vectorStringToDouble (const std::vector< std::string > &stringVector)
 

Detailed Description

Definition at line 16 of file Utils.h.

Member Function Documentation

void Utils::bumpIndex ( std::vector< int > &  theVector,
unsigned int  index 
)
static

Bumps up the value at an index of the array, growing it as necessary The input vector has to be initialized!

Definition at line 85 of file Utils.cc.

References i, and getHLTprescales::index.

Referenced by jsoncollector::ObjectMerger::csvToJson().

85  {
86  // if starting with empty vector
87  if (theVector.size() == 0) {
88  theVector.push_back(0);
89  }
90  // bump index without growing
91  if (theVector.size() > index) {
92  theVector[index]++;
93  } else {
94  // create and grow another vector to the required index
95  vector<int> biggerVector(theVector);
96  for (unsigned int i = theVector.size() - 1; i < index; i++) {
97  biggerVector.push_back(0);
98  }
99  // bump the last element of the grown vector
100  biggerVector[biggerVector.size() - 1]++;
101  theVector = biggerVector;
102  }
103 }
int i
Definition: DBlmapReader.cc:9
void Utils::getHostAndPID ( std::string &  sHPid)
static

Returns a string of the type host_pid

Definition at line 43 of file Utils.cc.

References sysUtil::pid.

Referenced by jsoncollector::FastMonitor::outputFullHistoDataPoint().

43  {
44  stringstream hpid;
45  int pid = (int) getpid();
46  char hostname[128];
47  gethostname(hostname, sizeof hostname);
48  hpid << hostname << "_" << pid;
49  sHPid = hpid.str();
50 }
tuple pid
Definition: sysUtil.py:22
void Utils::intArrayToString ( std::vector< int > &  theVector,
std::string &  theString 
)
static

Converts an int array to string

Definition at line 72 of file Utils.cc.

References i.

Referenced by jsoncollector::ObjectMerger::csvToJson(), and jsoncollector::Operations::histo().

72  {
73  stringstream ss;
74  ss << "[";
75  for (unsigned int i = 0; i < theArray.size() - 1; i++) {
76  ss << theArray[i];
77  ss << ",";
78  }
79  if (theArray.size() > 0)
80  ss << theArray[theArray.size() - 1] << "]";
81 
82  theString = ss.str();
83 }
int i
Definition: DBlmapReader.cc:9
bool Utils::matchExactly ( std::string  s1,
std::string  s2 
)
static

Returns true if the strings match exactly

Definition at line 37 of file Utils.cc.

Referenced by jsoncollector::ObjectMerger::merge(), and jsoncollector::Operations::same().

37  {
38  if (s1.find(s2) == 0 && s2.find(s1) == 0)
39  return true;
40  return false;
41 }
tuple s2
Definition: indexGen.py:106
void Utils::stringToIntArray ( std::vector< int > &  theVector,
const std::string &  theString 
)
static

Parses a string into a vector of integers

Definition at line 52 of file Utils.cc.

References i, and mod().

Referenced by jsoncollector::Operations::histo().

52  {
53  // remove [] and whitespace
54  string mod = theString;
55  mod = mod.substr(1, mod.size() - 1);
56 
57  string mod2;
58  mod2.resize(mod.size());
59  std::remove_copy(mod.begin(), mod.end(), mod2.begin(), ' ');
60 
61  // parse
62  std::stringstream ss(mod2);
63  int i;
64  while (ss >> i) {
65  theArray.push_back(i);
66  char peek = ss.peek();
67  if (peek == ',')
68  ss.ignore();
69  }
70 }
int i
Definition: DBlmapReader.cc:9
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
vector< string > Utils::vectorDoubleToString ( const std::vector< double > &  doubleVector)
static

Convenience method to convert a vector of doubles into a vector of strings

Definition at line 19 of file Utils.cc.

References i.

19  {
20  vector<string> strVector;
21  stringstream ss;
22  for (unsigned int i = 0; i < doubleVector.size(); i++) {
23  ss << doubleVector.at(i);
24  strVector.push_back(ss.str());
25  ss.str("");
26  }
27  return strVector;
28 }
int i
Definition: DBlmapReader.cc:9
vector< double > Utils::vectorStringToDouble ( const std::vector< std::string > &  stringVector)
static

Convenience method to convert a vector of strings into a vector of doubles

Definition at line 30 of file Utils.cc.

References i.

Referenced by jsoncollector::ObjectMerger::applyOperation().

30  {
31  vector<double> dblVector;
32  for (unsigned int i = 0; i < stringVector.size(); i++)
33  dblVector.push_back(atof(stringVector.at(i).c_str()));
34  return dblVector;
35 }
int i
Definition: DBlmapReader.cc:9