00001 #include "CondFormats/EcalObjects/interface/EcalDAQTowerStatus.h"
00002 #include "CondTools/Ecal/interface/EcalDAQTowerStatusXMLTranslator.h"
00003 #include "CondTools/Ecal/interface/EcalCondHeader.h"
00004 #include "TROOT.h"
00005 #include "TH2F.h"
00006 #include "TCanvas.h"
00007 #include "TStyle.h"
00008 #include "TLine.h"
00009 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00010 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00011
00012 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00013 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00014
00015 #include <string>
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
00025 #include <fstream>
00026
00027 namespace cond {
00028
00029 namespace ecalcond {
00030
00031 typedef EcalDAQTowerStatus::Items Items;
00032 typedef EcalDAQTowerStatus::value_type value_type;
00033
00034 enum How { singleChannel, bySuperModule, all};
00035
00036 int bad(Items const & cont) {
00037 return std::count_if(cont.begin(),cont.end(),
00038 boost::bind(std::greater<int>(),
00039 boost::bind(&value_type::getStatusCode,_1),0)
00040 );
00041 }
00042
00043 void extractBarrel(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00044 result.resize(1);
00045 result[0] = bad(cont.barrelItems());
00046 }
00047
00048 void extractEndcap(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00049 result.resize(1);
00050 result[0] = bad(cont.endcapItems());
00051 }
00052 void extractAll(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00053 result.resize(1);
00054 result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
00055 }
00056
00057 void extractSuperModules(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00058
00059 }
00060
00061 void extractSingleChannel(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00062 result.reserve(which.size());
00063 for (unsigned int i=0; i<which.size();i++) {
00064 result.push_back(cont[which[i]].getStatusCode());
00065 }
00066 }
00067
00068 typedef boost::function<void(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
00069 }
00070
00071 template<>
00072 struct ExtractWhat<EcalDAQTowerStatus> {
00073
00074 ecalcond::How m_how;
00075 std::vector<int> m_which;
00076
00077 ecalcond::How const & how() const { return m_how;}
00078 std::vector<int> const & which() const { return m_which;}
00079
00080 void set_how(ecalcond::How i) {m_how=i;}
00081 void set_which(std::vector<int> & i) { m_which.swap(i);}
00082 };
00083
00084
00085 template<>
00086 class ValueExtractor<EcalDAQTowerStatus>: public BaseValueExtractor<EcalDAQTowerStatus> {
00087 public:
00088
00089 static ecalcond::CondExtractor & extractor(ecalcond::How how) {
00090 static ecalcond::CondExtractor fun[3] = {
00091 ecalcond::CondExtractor(ecalcond::extractSingleChannel),
00092 ecalcond::CondExtractor(ecalcond::extractSuperModules),
00093 ecalcond::CondExtractor(ecalcond::extractAll)
00094 };
00095 return fun[how];
00096 }
00097
00098 typedef EcalDAQTowerStatus Class;
00099 typedef ExtractWhat<Class> What;
00100 static What what() { return What();}
00101
00102 ValueExtractor(){}
00103 ValueExtractor(What const & what)
00104 : m_what(what)
00105 {
00106
00107 }
00108
00109 void compute(Class const & it){
00110 std::vector<float> res;
00111 extractor(m_what.how())(it,m_what.which(),res);
00112 swap(res);
00113 }
00114
00115 private:
00116 What m_what;
00117 };
00118
00119
00120 template<>
00121 std::string PayLoadInspector<EcalDAQTowerStatus>::dump() const {
00122 std::stringstream ss;
00123 EcalCondHeader h;
00124 ss << EcalDAQTowerStatusXMLTranslator::dumpXML(h,object());
00125 return ss.str();
00126 }
00127
00128 template<>
00129 std::string PayLoadInspector<EcalDAQTowerStatus>::summary() const {
00130 std::cout << "***************************************"<< std::endl;
00131 std::stringstream ss;
00132 ss << "sizes="
00133 << object().barrelItems().size() <<","
00134 << object().endcapItems().size() <<";";
00135 ss << std::endl;
00136 return ss.str();
00137 }
00138
00139
00140
00141 template<>
00142 std::string PayLoadInspector<EcalDAQTowerStatus>::plot(std::string const & filename,
00143 std::string const &,
00144 std::vector<int> const&,
00145 std::vector<float> const& ) const {
00146
00147
00148
00149 TCanvas canvas("CC map","CC map",800,800);
00150 TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
00151 padb->Draw();
00152 TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
00153 padem->Draw();
00154 TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
00155 padep->Draw();
00156
00157 TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 34, -17, 17);
00158 TH2F* endc_p = new TH2F("EE+","EE+ Tower Status",22, 0, 22, 22, 0, 22);
00159 TH2F* endc_m = new TH2F("EE-","EE- Tower Status",22, 0, 22, 22, 0, 22);
00160 for(uint cellid = 0;
00161 cellid < EcalTrigTowerDetId::kEBTotalTowers;
00162 ++cellid) {
00163 EcalTrigTowerDetId rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
00164 if (object().find(rawid) == object().end()) continue;
00165 int ieta = rawid.ieta();
00166 if(ieta > 0) ieta--;
00167 int iphi = rawid.iphi() - 1;
00168 barrel->Fill(iphi, ieta, object()[rawid].getStatusCode());
00169 }
00170 for(uint cellid = 0;
00171 cellid < EcalTrigTowerDetId::kEETotalTowers;
00172 ++cellid) {
00173 if(EcalScDetId::validHashIndex(cellid)) {
00174 EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
00175 int ix = rawid.ix();
00176 int iy = rawid.iy();
00177 int side = rawid.zside();
00178 if(side == -1)
00179 endc_m->Fill(ix, iy, object()[rawid].getStatusCode());
00180 else
00181 endc_p->Fill(ix, iy, object()[rawid].getStatusCode());
00182 }
00183 }
00184 TLine* l = new TLine(0., 0., 0., 0.);
00185 l->SetLineWidth(1);
00186 padb->cd();
00187 barrel->SetStats(0);
00188
00189
00190
00191 barrel->Draw("col");
00192 for(int i = 0; i <17; i++) {
00193 Double_t x = 4.+ (i * 4);
00194 l = new TLine(x, -17., x, 17.);
00195 l->Draw();
00196 }
00197 l = new TLine(0., 0., 72., 0.);
00198 l->Draw();
00199
00200 int ixSectorsEE[136] = {
00201 8,14,14,17,17,18,18,19,19,20,20,21,21,20,20,19,19,18,18,17,
00202 17,14,14, 8, 8, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4,
00203 4, 5, 5, 8, 8, 8, 9, 9,10,10,12,12,13,13,12,12,10,10, 9, 9,
00204 10,10, 0,11,11, 0,10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 0,12,13,
00205 13,14,14,15,15,16,16,17,17, 0, 9, 8, 8, 3, 3, 1, 0,13,14,14,
00206 19,19,21, 0, 9, 8, 8, 7, 7, 5, 5, 3, 3, 2, 0,13,14,14,15,15,
00207 17,17,19,19,20, 0,14,14,13,13,12,12,0};
00208 int iySectorsEE[136] = {
00209 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 8, 8,14,14,17,17,18,18,19,19,
00210 20,20,21,21,20,20,19,19,18,18,17,17,14,14, 8, 8, 5, 5, 4, 4,
00211 3, 3, 2, 2, 1, 4, 4, 7, 7, 9, 9,10,10,12,12,13,13,12,12,10,
00212 10, 9, 0,13,21, 0,13,13,14,14,15,15,16,16,18,18,19, 0,13,13,
00213 14,14,15,15,16,16,18,18,19, 0,11,11,12,12,13,13, 0,11,11,12,
00214 12,13,13, 0,10,10, 9, 9, 8, 8, 7, 7, 6, 6, 0,10,10, 9, 9, 8,
00215 8, 7, 7, 6, 6, 0, 2, 4, 4, 7, 7, 9, 0} ;
00216 padem->cd();
00217 endc_m->SetStats(0);
00218 endc_m->Draw("col");
00219 for ( int i = 0; i < 136; i=i+1) {
00220 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00221 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00222 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00223 ixSectorsEE[i+1], iySectorsEE[i+1]);
00224 }
00225 }
00226
00227 padep->cd();
00228 endc_p->SetStats(0);
00229 endc_p->Draw("col");
00230 for ( int i = 0; i < 136; i=i+1) {
00231 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00232 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00233 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00234 ixSectorsEE[i+1], iySectorsEE[i+1]);
00235 }
00236 }
00237
00238 canvas.SaveAs(filename.c_str());
00239 return filename;
00240 }
00241 }
00242
00243
00244 namespace condPython {
00245 template<>
00246 void defineWhat<EcalDAQTowerStatus>() {
00247 using namespace boost::python;
00248 enum_<cond::ecalcond::How>("How")
00249 .value("singleChannel",cond::ecalcond::singleChannel)
00250 .value("bySuperModule",cond::ecalcond::bySuperModule)
00251 .value("all",cond::ecalcond::all)
00252 ;
00253
00254 typedef cond::ExtractWhat<EcalDAQTowerStatus> What;
00255 class_<What>("What",init<>())
00256 .def("set_how",&What::set_how)
00257 .def("set_which",&What::set_which)
00258 .def("how",&What::how, return_value_policy<copy_const_reference>())
00259 .def("which",&What::which, return_value_policy<copy_const_reference>())
00260 ;
00261 }
00262 }
00263
00264 PYTHON_WRAPPER(EcalDAQTowerStatus,EcalDAQTowerStatus);