test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalPyWrapperFunctions.h
Go to the documentation of this file.
1 #ifndef CondCore_EcalPlugins_plugins_EcalPyWrapperFunctions_H
2 #define CondCore_EcalPlugins_plugins_EcalPyWrapperFunctions_H
3 
4 #include <sstream>
5 
6 //inherit this class, override getValues() function
7 //virtual class EcalPyWrapperStrategy {
8 //
9 //};
10 //class EcalMeanStrategy: EcalPyWrapperStrategy{
11 //
12 //};
13 //class EcalMeanStrategy: EcalPyWrapperStrategy{
14 //
15 //};
16 
17 template <class T>
19 public:
20  static const unsigned int MEAN = 0;
21  static const unsigned int STATUS = 1;
22 
23  EcalPyWrapperHelper(unsigned int totalValues, unsigned int status = 0, std::string names = "-Means: "):total_values(totalValues), status(status), names(names){}
24  //~EcalPyWrapperHelper();
25  std::string printBarrelsEndcaps( const std::vector<T> & barrelItems, const std::vector<T> & endcapItems) {
26  std::stringstream ss;
27 
28  //print barrels:
29  type_vValues barrelsVec = getValues(barrelItems);
30  unsigned int barrelsTotal = barrelItems.size();
31  ss << std::endl << "---Barrels. Total: " << barrelsTotal << std::endl;
32  switch (status){
33  case (MEAN) : ss << names << std::endl; break;
34  case (STATUS): ss << "-With errors: " << std::endl; break;// << ecalcond::bad(barrelItems) << std::endl; break;
35  default : break;
36  }
37  ss << printValues(barrelsVec, barrelsTotal);
38 
39  //print endcaps:
40  type_vValues endcapVec = getValues(endcapItems);
41  unsigned int endcapTotal = endcapItems.size();
42  ss << std::endl << "---Endcaps. Total: " << endcapTotal << std::endl;
43  switch (status){
44  case (MEAN) : ss << names << std::endl; break;
45  case (STATUS): ss << "-With errors: " << std::endl; break;// << ecalcond::bad(endcapItems) << std::endl; break;
46  default : break;
47  }
48  ss << printValues(endcapVec, endcapTotal);
49 
50  return ss.str();
51  }
52 protected:
53  unsigned int total_values;
54  unsigned int status;
56  typedef std::vector<std::pair< std::string, float> > type_vValues;
57 
58  //this needs to be overriden in inherited class:
59  virtual type_vValues getValues( const std::vector<T> & vItems) = 0;
60  /*EXAMPLE:
61  class EcalPedestalsHelper: public EcalPyWrapperHelper<EcalPedestal>{
62  public:
63  type_vValues getValues( const std::vector<EcalPedestal> & vItems)
64  {
65  unsigned int totalValues = 6;
66  type_vValues vValues(totalValues);
67 
68  vValues[0].first = "mean_x12";
69  vValues[1].first = "rms_x12";
70  vValues[2].first = "mean_x6";
71  vValues[3].first = "rms_x6";
72  vValues[4].first = "mean_x1";
73  vValues[5].first = "rms_x1";
74 
75  vValues[0].second = .0;
76  vValues[1].second = .0;
77  vValues[2].second = .0;
78  vValues[3].second = .0;
79  vValues[4].second = .0;
80  vValues[5].second = .0;
81 
82  //get info:
83  for(std::vector<EcalPedestal>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
84  vValues[0].second += iItems->mean(1);
85  vValues[1].second += iItems->rms(1);
86  vValues[2].second += iItems->mean(2);
87  vValues[3].second += iItems->rms(2);
88  vValues[4].second += iItems->mean(3);
89  vValues[5].second += iItems->rms(3);
90  }
91  return vValues;
92  }
93  */
94 private:
95  std::string printValues(const type_vValues & vValues, const unsigned int & total) {
96  std::stringstream ss;
97 
98  for (type_vValues::const_iterator iVal = vValues.begin(); iVal != vValues.end(); ++iVal){
99  switch (status){
100  case (MEAN) : ss << iVal->first << ": " << ((iVal->second)/total) << std::endl; break;
101  case (STATUS): if (iVal->second != 0) {ss << iVal->first << ": " << ((iVal->second)) << std::endl; break;} else {break; }
102  default : break;
103  }
104 
105  }
106  return ss.str();
107  }
108 
109 };
110 #endif
static const unsigned int STATUS
std::vector< std::pair< std::string, float > > type_vValues
std::string printValues(const type_vValues &vValues, const unsigned int &total)
virtual type_vValues getValues(const std::vector< T > &vItems)=0
static const unsigned int MEAN
EcalPyWrapperHelper(unsigned int totalValues, unsigned int status=0, std::string names="-Means: ")
std::string printBarrelsEndcaps(const std::vector< T > &barrelItems, const std::vector< T > &endcapItems)