00001
00002
00003 #include "CondFormats/EcalObjects/interface/EcalCondObjectContainer.h"
00004 #include "TH2F.h"
00005 #include "TCanvas.h"
00006 #include "TStyle.h"
00007 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00008 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00009 #include "CondTools/Ecal/interface/EcalFloatCondObjectContainerXMLTranslator.h"
00010 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00011 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00012
00013 #include <string>
00014
00015 #include <fstream>
00016 #include <sstream>
00017 #include <algorithm>
00018 #include <numeric>
00019 #include <iterator>
00020 #include <boost/ref.hpp>
00021 #include <boost/bind.hpp>
00022 #include <boost/function.hpp>
00023 #include <boost/iterator/transform_iterator.hpp>
00024 #include <algorithm>
00025
00026 namespace {
00027 struct Printer {
00028 Printer() : i(0){}
00029 void reset() { i=0;}
00030 void doB(float const & item) {
00031 ss << i <<":"<< item << "\n";
00032 i++;
00033 }
00034 void doE(float const & item) {
00035 ss << i <<":"<< item << "\n";
00036 i++;
00037 }
00038 int i;
00039 std::stringstream ss;
00040 };
00041 }
00042
00043
00044 namespace cond {
00045
00046
00047 namespace ecalcond {
00048
00049 typedef EcalFloatCondObjectContainer Container;
00050 typedef Container::value_type value_type;
00051
00052 enum How { singleChannel, bySuperModule, barrel, endcap, all};
00053
00054
00055 void extractBarrel(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
00056 result.resize(cont.barrelItems().size());
00057 std::copy(cont.barrelItems().begin(),cont.barrelItems().end(),result.begin());
00058 }
00059
00060 void extractEndcap(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
00061 result.resize(cont.endcapItems().size());
00062 std::copy(cont.endcapItems().begin(),cont.endcapItems().end(),result.begin());
00063 }
00064
00065 void extractAll(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
00066
00067
00068 result.resize(cont.barrelItems().size()+ cont.endcapItems().size());
00069
00070 std::copy(cont.barrelItems().begin(),cont.barrelItems().end(),result.begin());
00071 std::copy(cont.endcapItems().begin(),cont.endcapItems().end(),result.end());
00072 }
00073
00074 void extractSuperModules(Container const & cont, std::vector<int> const & which, std::vector<float> & result) {
00075
00076 }
00077
00078 void extractSingleChannel(Container const & cont, std::vector<int> const & which, std::vector<float> & result) {
00079 result.reserve(which.size());
00080 for (unsigned int i=0; i<which.size();i++) {
00081 result.push_back(cont[which[i]]);
00082 }
00083 }
00084
00085 typedef boost::function<void(Container const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
00086
00087 }
00088
00089 template<>
00090 struct ExtractWhat<ecalcond::Container> {
00091
00092 ecalcond::How m_how;
00093 std::vector<int> m_which;
00094
00095 ecalcond::How const & how() const { return m_how;}
00096 std::vector<int> const & which() const { return m_which;}
00097
00098 void set_how(ecalcond::How i) {m_how=i;}
00099 void set_which(std::vector<int> & i) { m_which.swap(i);}
00100 };
00101
00102
00103
00104
00105 template<>
00106 class ValueExtractor<ecalcond::Container>: public BaseValueExtractor<ecalcond::Container> {
00107 public:
00108
00109 static ecalcond::CondExtractor & extractor(ecalcond::How how) {
00110 static ecalcond::CondExtractor fun[5] = {
00111 ecalcond::CondExtractor(ecalcond::extractSingleChannel),
00112 ecalcond::CondExtractor(ecalcond::extractSuperModules),
00113 ecalcond::CondExtractor(ecalcond::extractBarrel),
00114 ecalcond::CondExtractor(ecalcond::extractEndcap),
00115 ecalcond::CondExtractor(ecalcond::extractAll)
00116 };
00117 return fun[how];
00118 }
00119
00120
00121 typedef ecalcond::Container Class;
00122 typedef ExtractWhat<Class> What;
00123 static What what() { return What();}
00124
00125 ValueExtractor(){}
00126 ValueExtractor(What const & what)
00127 : m_what(what)
00128 {
00129
00130
00131 }
00132
00133 void compute(Class const & it){
00134 std::vector<float> res;
00135 extractor(m_what.how())(it,m_what.which(),res);
00136 swap(res);
00137 }
00138
00139 private:
00140 What m_what;
00141
00142 };
00143
00144
00145 template<>
00146 std::string
00147 PayLoadInspector<EcalFloatCondObjectContainer>::dump() const {
00148
00149 std::stringstream ss;
00150 EcalCondHeader header;
00151 ss<<EcalFloatCondObjectContainerXMLTranslator::dumpXML(header,object());
00152 return ss.str();
00153
00154
00155
00156
00157
00158
00159
00160
00161 }
00162
00163 template<>
00164 std::string PayLoadInspector<EcalFloatCondObjectContainer>::summary() const {
00165 std::stringstream ss;
00166 ss << "sizes="
00167 << object().barrelItems().size() <<","
00168 << object().endcapItems().size() <<";";
00169 ss << std::endl;
00170 return ss.str();
00171 }
00172
00173
00174
00175 template<>
00176 std::string PayLoadInspector<EcalFloatCondObjectContainer>::plot(std::string const & filename,
00177 std::string const &,
00178 std::vector<int> const&,
00179 std::vector<float> const& ) const {
00180
00181 gStyle->SetPalette(1);
00182 TCanvas canvas("CC map","CC map",840,280);
00183
00184
00185 TPad pad1("p1","p1", 0.0, 0.0, 0.2, 1.0);
00186 TPad pad2("p2","p2", 0.2, 0.0, 0.8, 1.0);
00187 TPad pad3("p3","p3", 0.8, 0.0, 1.0, 1.0);
00188 pad1.Draw();
00189 pad2.Draw();
00190 pad3.Draw();
00191
00192 TH2F barrelmap("EB","EB",360,1,360, 171, -85,86);
00193 TH2F endcmap_p("EE+","EE+",100,1,101,100,1,101);
00194 TH2F endcmap_m("EE-","EE-",100,1,101,100,1,101);
00195
00196 const int kSides = 2;
00197 const int kBarlRings = EBDetId::MAX_IETA;
00198 const int kBarlWedges = EBDetId::MAX_IPHI;
00199 const int kEndcWedgesX = EEDetId::IX_MAX;
00200 const int kEndcWedgesY = EEDetId::IY_MAX;
00201
00203 for (int sign=0; sign<kSides; sign++) {
00204
00205 int thesign = sign==1 ? 1:-1;
00206
00207 for (int ieta=0; ieta<kBarlRings; ieta++) {
00208 for (int iphi=0; iphi<kBarlWedges; iphi++) {
00209 EBDetId id((ieta+1)*thesign, iphi+1);
00210 barrelmap.Fill(iphi+1,ieta*thesign + thesign, object()[id.rawId()]);
00211 }
00212 }
00213
00214 for (int ix=0; ix<kEndcWedgesX; ix++) {
00215 for (int iy=0; iy<kEndcWedgesY; iy++) {
00216 if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00217 EEDetId id(ix+1,iy+1,thesign);
00218
00219 if (thesign==1) {
00220 endcmap_p.Fill(ix+1,iy+1,object()[id.rawId()]);
00221 }
00222 else{
00223 endcmap_m.Fill(ix+1,iy+1,object()[id.rawId()]);
00224
00225 }
00226 }
00227 }
00228
00229
00230
00231 }
00232
00233
00234
00235 pad1.cd();
00236 endcmap_m.SetStats(0);
00237 endcmap_m.Draw("colz");
00238
00239 pad2.cd();
00240 barrelmap.SetStats(0);
00241 barrelmap.Draw("colz");
00242
00243 pad3.cd();
00244 endcmap_p.SetStats(0);
00245 endcmap_p.Draw("colz");
00246
00247 canvas.SaveAs(filename.c_str());
00248 return filename;
00249 }
00250
00251
00252 }
00253
00254 namespace condPython {
00255 template<>
00256 void defineWhat<cond::ecalcond::Container>() {
00257 using namespace boost::python;
00258 enum_<cond::ecalcond::How>("How")
00259 .value("singleChannel",cond::ecalcond::singleChannel)
00260 .value("bySuperModule",cond::ecalcond::bySuperModule)
00261 .value("barrel",cond::ecalcond::barrel)
00262 .value("endcap",cond::ecalcond::endcap)
00263 .value("all",cond::ecalcond::all)
00264 ;
00265
00266 typedef cond::ExtractWhat<cond::ecalcond::Container> What;
00267 class_<What>("What",init<>())
00268 .def("set_how",&What::set_how)
00269 .def("set_which",&What::set_which)
00270 .def("how",&What::how, return_value_policy<copy_const_reference>())
00271 .def("which",&What::which, return_value_policy<copy_const_reference>())
00272 ;
00273 }
00274 }
00275
00276
00277
00278
00279 PYTHON_WRAPPER(EcalFloatCondObjectContainer,EcalFloatCondObjectContainer);