CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CondCore/SiStripPlugins/plugins/SiStripSummaryPyWrapper.cc

Go to the documentation of this file.
00001 
00002 #include "CondFormats/SiStripObjects/interface/SiStripSummary.h"
00003 
00004 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00005 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00006 
00007 #include <string>
00008 #include <fstream>
00009 
00010   
00011 namespace cond {
00012 
00013   template<>
00014   struct ExtractWhat<SiStripSummary> {
00015 
00016     std::string m_quantity;
00017     sistripsummary::TrackerRegion m_trackerregion;
00018 
00019     std::string const & quantity() const { return m_quantity;}
00020     sistripsummary::TrackerRegion const & trackerregion() const { return m_trackerregion;}
00021  
00022     void set_quantity( std::string i) { m_quantity=i;}
00023     void set_trackerregion(sistripsummary::TrackerRegion i) {m_trackerregion=i;}
00024   };
00025 
00026 
00027   
00028 
00029   template<>
00030   class ValueExtractor<SiStripSummary>: public  BaseValueExtractor<SiStripSummary> {
00031       public:
00032 
00033       typedef SiStripSummary Class;
00034       typedef ExtractWhat<Class> What;
00035       static What what() { return What();}
00036 
00037       ValueExtractor(){};
00038       ValueExtractor(What const & what)
00039       : m_what(what)
00040       {
00041           // here one can make stuff really complicated...
00042       }
00043       void compute(Class const & it){
00044           std::vector<std::string> vlistItems;
00045           std::vector<float> res;
00046           uint32_t detid=m_what.trackerregion();
00047           std::string::size_type oldloc=0; 
00048           std::string ListItems   =   m_what.quantity();
00049           std::string::size_type loc = ListItems.find( ",", oldloc );
00050           size_t count=1;
00051           while( loc != std::string::npos ) {
00052               vlistItems.push_back(ListItems.substr(oldloc,loc-oldloc));
00053               oldloc=loc+1;
00054               loc=ListItems.find( ",", oldloc );
00055               count++; 
00056           } 
00057           //there is a single item
00058           vlistItems.push_back(ListItems.substr(oldloc,loc-oldloc));
00059           std::vector<float> vres=it.getSummaryObj(detid,vlistItems);
00060           res.insert(res.end(),vres.begin(),vres.end());
00061           //res.push_back(detid);
00062           swap(res);
00063       }
00064   private:
00065     What  m_what;
00066   };
00067 
00068 
00069   template<>
00070   std::string
00071   PayLoadInspector<SiStripSummary>::dump() const {
00072     std::stringstream ss;
00073     std::vector<std::string>  listWhat= object().getUserDBContent();
00074     for(size_t i=0;i<listWhat.size();++i)
00075       ss << listWhat[i] << "###";
00076     return ss.str();
00077     
00078   }
00079   
00080   template<>
00081   std::string PayLoadInspector<SiStripSummary>::summary() const {
00082     std::stringstream ss;
00083     ss << "Nr.Det " << object().getRegistryVectorEnd()-object().getRegistryVectorBegin()
00084        << "\nNr.Quantities " << object().getUserDBContent().size()
00085        << "\nNr.values " << object().getDataVectorEnd()-object().getDataVectorBegin()
00086        << "\nRunNr= " << object().getRunNr()
00087        << "\ntimeValue= " << object().getTimeValue();
00088     //ss << "names of DBquantities ";
00089     //std::vector<std::string>  listWhat= object().getUserDBContent();
00090     //for(size_t i=0;i<listWhat.size();++i)
00091     // ss << listWhat[i] << "\n";
00092     return ss.str(); 
00093   }
00094   
00095 
00096   template<>
00097   std::string PayLoadInspector<SiStripSummary>::plot(std::string const & filename,
00098                                                    std::string const &, 
00099                                                    std::vector<int> const&, 
00100                                                    std::vector<float> const& ) const {
00101     std::string fname = filename + ".png";
00102    std::ofstream f(fname.c_str());
00103     return fname;
00104   }
00105 
00106 
00107 }
00108 
00109 
00110 namespace condPython {
00111   template<>
00112   void defineWhat<SiStripSummary>() {
00113     using namespace boost::python;
00114     enum_<sistripsummary::TrackerRegion>("TrackerRegion")
00115       .value("Tracker",sistripsummary::TRACKER)
00116       .value("TIB",sistripsummary::TIB)
00117       .value("TID",sistripsummary::TID)
00118       .value("TOB",sistripsummary::TOB)
00119       .value("TEC",sistripsummary::TEC)
00120       .value("TIB_L1",sistripsummary::TIB_1)
00121       .value("TIB_L2",sistripsummary::TIB_2)
00122       .value("TIB_L3",sistripsummary::TIB_3)
00123       .value("TIB_L4",sistripsummary::TIB_4)
00124       .value("TOB_L1",sistripsummary::TOB_1)
00125       .value("TOB_L2",sistripsummary::TOB_2)
00126       .value("TOB_L3",sistripsummary::TOB_3)
00127       .value("TOB_L4",sistripsummary::TOB_4)
00128       .value("TOB_L5",sistripsummary::TOB_5)
00129       .value("TOB_L6",sistripsummary::TOB_6)
00130       .value("TIDM_D1",sistripsummary::TIDM_1)
00131       .value("TIDM_D2",sistripsummary::TIDM_2)
00132       .value("TIDM_D3",sistripsummary::TIDM_3)
00133       .value("TIDP_D1",sistripsummary::TIDP_1)
00134       .value("TIDP_D2",sistripsummary::TIDP_2)
00135       .value("TIDP_D3",sistripsummary::TIDP_3)
00136       .value("TECP_D1",sistripsummary::TECP_1)
00137       .value("TECP_D2",sistripsummary::TECP_2)
00138       .value("TECP_D3",sistripsummary::TECP_3)
00139       .value("TECP_D4",sistripsummary::TECP_4)
00140       .value("TECP_D5",sistripsummary::TECP_5)
00141       .value("TECP_D6",sistripsummary::TECP_6)
00142       .value("TECP_D7",sistripsummary::TECP_7)
00143       .value("TECP_D8",sistripsummary::TECP_8)
00144       .value("TECP_D9",sistripsummary::TECP_9)
00145       .value("TECM_D1",sistripsummary::TECM_1)
00146       .value("TECM_D2",sistripsummary::TECM_2)
00147       .value("TECM_D3",sistripsummary::TECM_3)
00148       .value("TECM_D4",sistripsummary::TECM_4)
00149       .value("TECM_D5",sistripsummary::TECM_5)
00150       .value("TECM_D6",sistripsummary::TECM_6)
00151       .value("TECM_D7",sistripsummary::TECM_7)
00152       .value("TECM_D8",sistripsummary::TECM_8)
00153       .value("TECM_D9",sistripsummary::TECM_9)
00154       ;
00155 
00156     typedef cond::ExtractWhat<SiStripSummary> What;
00157     class_<What>("What",init<>())
00158       .def("set_quantity",&What::set_quantity)
00159       .def("set_how",&What::set_trackerregion)
00160       .def("quantity",&What::quantity, return_value_policy<copy_const_reference>())
00161       .def("how",&What::trackerregion, return_value_policy<copy_const_reference>())
00162       ;
00163   }
00164 }
00165 
00166 
00167 
00168 
00169 PYTHON_WRAPPER(SiStripSummary,SiStripSummary);