CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondCore/EcalPlugins/plugins/EcalPyUtils.cc

Go to the documentation of this file.
00001 /*
00002  * Make some convenient Ecal function available in python
00003  * 
00004  * \author Stefano Argiro
00005  * \version $Id: EcalPyUtils.cc,v 1.7 2012/07/18 10:40:33 davidlt Exp $
00006  */
00007 
00008 
00009 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00010 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00011 #include "CondTools/Ecal/interface/EcalFloatCondObjectContainerXMLTranslator.h"
00012 #include <boost/python.hpp>
00013 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
00014 
00015 using namespace boost::python;
00016 
00017 
00018 
00019 namespace ecalpyutils{
00020   
00021   std::vector<int> hashedIndexToEtaPhi(int hashedindex){
00022     int ieta= EBDetId::unhashIndex(hashedindex).ieta();
00023     int iphi= EBDetId::unhashIndex(hashedindex).iphi();
00024     std::vector<int> ret;
00025     ret.push_back(ieta);
00026     ret.push_back(iphi);
00027     return ret;
00028   }
00029   
00030   std::vector<int> hashedIndexToXY(int hashedindex){
00031     int ix= EEDetId::unhashIndex(hashedindex).ix();
00032     int iy= EEDetId::unhashIndex(hashedindex).iy();
00033     int zside =  EEDetId::unhashIndex(hashedindex).zside();
00034     std::vector<int> ret;
00035     ret.push_back(ix);
00036     ret.push_back(iy);
00037     ret.push_back(zside);
00038     return ret;
00039   }
00040 
00041   
00042   int hashedIndex(int ieta, int iphi){
00043     EBDetId d(ieta,iphi);
00044     return d.hashedIndex();
00045   }
00046 
00047   int hashedIndexEE(int ix, int iy, int iz){
00048 
00049     if (EEDetId::validDetId(ix,iy,iz)) {
00050       EEDetId d(ix,iy,iz);
00051       return d.hashedIndex();
00052     }
00053     return 0;
00054   }
00055 
00056   int ism(int ieta, int iphi){
00057     EBDetId d(ieta,iphi);
00058     return d.ism();
00059   }
00060 
00061   std::string arraystoXML(const std::vector<float>& eb, const std::vector<float>& ee){
00062     EcalCondHeader h;
00063     return EcalFloatCondObjectContainerXMLTranslator::dumpXML(h,eb,ee);
00064   }
00065 }
00066 
00067 BOOST_PYTHON_MODULE(pluginEcalPyUtils) {
00068 
00069 //   looks like these are already defined somewhere
00070 
00071 //   python access to stl integer vectors 
00072 //   class_< std::vector<int> >("vectorInt") 
00073 //     .def(vector_indexing_suite<std::vector<int> >()) 
00074 //   ; 
00075 
00076 //   class_< std::vector<float> >("vectorFloat") 
00077 //     .def(vector_indexing_suite<std::vector<float> >()) 
00078 //   ; 
00079 
00080   def("hashedIndexToEtaPhi",&ecalpyutils::hashedIndexToEtaPhi);
00081   def("hashedIndexToXY",&ecalpyutils::hashedIndexToXY);
00082   def("hashedIndex",&ecalpyutils::hashedIndex);
00083   def("hashedIndexEE",&ecalpyutils::hashedIndexEE);
00084   def("ism",&ecalpyutils::ism);
00085   def("barrelfromXML",&EcalFloatCondObjectContainerXMLTranslator::barrelfromXML);
00086   def("endcapfromXML",&EcalFloatCondObjectContainerXMLTranslator::endcapfromXML);
00087   def("arraystoXML",&ecalpyutils::arraystoXML);
00088 }
00089