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 | Static Public Attributes
jsoncollector::Operations Class Reference

#include <Operations.h>

Static Public Member Functions

static double avg (std::vector< double >)
 
static std::string cat (const std::vector< std::string > &)
 
static std::string histo (const std::vector< std::string > &)
 
static std::string same (const std::vector< std::string > &)
 
static double sum (std::vector< double >)
 

Static Public Attributes

static const std::string AVG = "avg"
 
static const std::string CAT = "cat"
 
static const std::string HISTO = "histo"
 
static const std::string SAME = "same"
 
static const std::string SUM = "sum"
 

Detailed Description

Definition at line 16 of file Operations.h.

Member Function Documentation

double Operations::avg ( std::vector< double >  elems)
static

Definition at line 30 of file Operations.cc.

References sum().

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

30  {
31  return sum(elems) / elems.size();
32 }
static double sum(std::vector< double >)
Definition: Operations.cc:23
string Operations::cat ( const std::vector< std::string > &  )
static

Definition at line 80 of file Operations.cc.

References i.

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

80  {
81  stringstream ss;
82  for (unsigned int i = 0; i < elems.size(); i++) {
83  ss << elems.at(i);
84  if (i != elems.size() - 1) {
85  ss << ", ";
86  }
87  }
88  return ss.str();
89 }
int i
Definition: DBlmapReader.cc:9
string Operations::histo ( const std::vector< std::string > &  )
static

Definition at line 42 of file Operations.cc.

References i, jsoncollector::Utils::intArrayToString(), j, reco_skim_cfg_mod::maxSize, findQualityFiles::size, and jsoncollector::Utils::stringToIntArray().

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

42  {
43  vector<vector<int> > inputHistos;
44 
45  for (unsigned int i = 0; i < elems.size(); i++) {
46  vector<int> currentHisto;
47  string currentHistoAsString = elems.at(i);
48  Utils::stringToIntArray(currentHisto, currentHistoAsString);
49  inputHistos.push_back(currentHisto);
50  }
51 
52  if (inputHistos.size() > 0) {
53  // initialize resulting histo to largest size
54  unsigned int maxSize = 0;
55  for (unsigned int i = 0; i < inputHistos.size(); i++) {
56  if (inputHistos[i].size() > maxSize)
57  maxSize = inputHistos[i].size();
58  }
59 
60  // initialize the resulting histo to the size
61  vector<int> resultingHisto(maxSize);
62  for (unsigned int i = 0; i < resultingHisto.size(); i++)
63  resultingHisto[i] = 0;
64 
65  for (unsigned int i = 0; i < inputHistos.size(); i++) {
66  vector<int> currentHisto = inputHistos[i];
67  for (unsigned int j = 0; j < currentHisto.size(); j++) {
68  resultingHisto[j] += currentHisto[j];
69  }
70  }
71 
72  string resHistoAsString;
73  Utils::intArrayToString(resultingHisto, resHistoAsString);
74  return resHistoAsString;
75 
76  } else
77  return "Cannot load input histos";
78 }
int i
Definition: DBlmapReader.cc:9
static void stringToIntArray(std::vector< int > &theVector, const std::string &theString)
Definition: Utils.cc:52
tuple maxSize
&#39;/store/data/Commissioning08/BeamHalo/RECO/StuffAlmostToP5_v1/000/061/642/10A0FE34-A67D-DD11-AD05-000...
int j
Definition: DBlmapReader.cc:9
static void intArrayToString(std::vector< int > &theVector, std::string &theString)
Definition: Utils.cc:72
tuple size
Write out results.
string Operations::same ( const std::vector< std::string > &  )
static

Definition at line 34 of file Operations.cc.

References i, and jsoncollector::Utils::matchExactly().

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

34  {
35  for (unsigned int i = 0; i < elems.size() - 1; i++)
36  if (!Utils::matchExactly(elems.at(i), elems.at(i + 1)) || elems.at(i).length()
37  == 0)
38  return "N/A";
39  return elems.at(0);
40 }
int i
Definition: DBlmapReader.cc:9
static bool matchExactly(std::string s1, std::string s2)
Definition: Utils.cc:37
double Operations::sum ( std::vector< double >  elems)
static

Definition at line 23 of file Operations.cc.

References i.

Referenced by jsoncollector::ObjectMerger::applyOperation(), and avg().

23  {
24  double added = elems.at(0);
25  for (unsigned int i = 1; i < elems.size(); i++)
26  added += elems.at(i);
27  return added;
28 }
int i
Definition: DBlmapReader.cc:9

Member Data Documentation

const string Operations::AVG = "avg"
static

Definition at line 32 of file Operations.h.

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

const string Operations::CAT = "cat"
static

Definition at line 35 of file Operations.h.

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

const string Operations::HISTO = "histo"
static
const string Operations::SAME = "same"
static

Definition at line 33 of file Operations.h.

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

const string Operations::SUM = "sum"
static

Definition at line 31 of file Operations.h.

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