CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PedestalPyWrapper.cc
Go to the documentation of this file.
4 
5 #include <string>
6 #include <sstream>
7 #include <algorithm>
8 #include <iterator>
9 #include <boost/ref.hpp>
10 #include <boost/bind.hpp>
11 #include <boost/function.hpp>
12 
13 namespace {
14  struct Printer {
15  void doit(Pedestals::Item const & item) {
16  ss << item.m_mean << "," << item.m_variance <<"; ";
17  }
18  std::stringstream ss;
19  };
20 }
21 
22 
23 
24 namespace cond {
25 
26  template<>
28 
29  struct DescrQuantity {
30  std::vector<std::string> me;
31  DescrQuantity() : me(2) {
32  me[0]="mean";
33  me[1]="variance";
34  }
35  };
36 
37  // example using multiple choice (not static to make the python binding easier
38  /*static*/ std::vector<std::string> const & descr_quantity() {
39  static DescrQuantity d;
40  return d.me;
41  }
42 
43  std::vector<int> m_which;
44  std::vector<int> const & which() const { return m_which;}
45  void set_which(std::vector<int> & i) { m_which.swap(i);}
46 
47  std::vector<int> m_quantity;
48  std::vector<int> const & quantity() const { return m_quantity;}
49  void set_quantity(std::vector<int> & i) { m_quantity.swap(i);}
50  };
51 
52  template<>
53  class ValueExtractor<Pedestals>: public BaseValueExtractor<Pedestals> {
54  public:
55 
56  typedef Pedestals Class;
58  static What what() { return What();}
59 
60  typedef boost::function<float(Pedestals::Item const &)> Value;
61  static std::vector<Value> const & allValues() {
62  static std::vector<Value> v(2);
63  // shall be done only ones in the usual constructor (later)...
64  v[0]=boost::bind(&Pedestals::Item::m_mean,_1);
65  v[1]=boost::bind(&Pedestals::Item::m_variance,_1);
66  return v;
67  }
68 
71  : m_which(what.which()), m_what(what.quantity().size())
72  {
73  // here one can make stuff really complicated...
74  std::vector<Value> const & v = allValues();
75  for (size_t i=0; i< m_what.size(); i++) m_what[i] = v[what.quantity()[i]];
76  }
77  void compute(Class const & it) override{
78  for (size_t i=0; i<m_which.size(); ++i) {
79  if (m_which[i]< int(it.m_pedestals.size()))
80  for (size_t j=0; j< m_what.size(); ++j) add(m_what[j](it.m_pedestals[m_which[i]]));
81  }
82  }
83  private:
84  std::vector<int> m_which;
85  std::vector<Value> m_what;
86  };
87 
88 
89  template<>
92  Printer p;
93  std::for_each(object().m_pedestals.begin(),
94  object().m_pedestals.end(),boost::bind(&Printer::doit,boost::ref(p),_1));
95  p.ss << std::endl;
96  return p.ss.str();
97  }
98 
99  /* use default....
100  template<>
101  std::string PayLoadInspector<Pedestals>::summary() const {
102  std::stringstream ss;
103  ss << "size="<<object().m_pedestals.size() <<";";
104  ss << std::endl;
105  return ss.str();
106  }
107  */
108 }
109 
110 namespace condPython {
111  template<>
113  using namespace boost::python;
114  typedef cond::ExtractWhat<Pedestals> What;
115  class_<What>("What",init<>())
116  .def("set_which",&What::set_which)
117  .def("which",&What::which, return_value_policy<copy_const_reference>())
118  .def("set_quantity",&What::set_quantity)
119  .def("quantity",&What::quantity, return_value_policy<copy_const_reference>())
120  .def("descr_quantity",&What::descr_quantity, return_value_policy<copy_const_reference>())
121  ;
122 
123  }
124 }
125 
126 PYTHON_WRAPPER(Pedestals,Pedestal);
void set_which(std::vector< int > &i)
std::vector< std::string > const & descr_quantity()
int i
Definition: DBlmapReader.cc:9
ExtractWhat< Class > What
void set_quantity(std::vector< int > &i)
#define PYTHON_WRAPPER(_class, _name)
std::vector< Item > m_pedestals
Definition: Pedestals.h:19
static std::vector< Value > const & allValues()
int j
Definition: DBlmapReader.cc:9
std::vector< int > const & quantity() const
std::vector< int > const & which() const
list object
Definition: dbtoconf.py:77
void defineWhat< Pedestals >()
boost::function< float(Pedestals::Item const &)> Value
float m_variance
Definition: Pedestals.h:12
std::string dump() const
void compute(Class const &it) override
tuple size
Write out results.