00001 #include "CondFormats/EcalObjects/interface/EcalDCSTowerStatus.h"
00002 #include "CondTools/Ecal/interface/EcalDCSTowerStatusXMLTranslator.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 "TColor.h"
00009 #include "TLine.h"
00010 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00011 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00012
00013 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00014 #include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
00015
00016 #include <string>
00017 #include <sstream>
00018 #include <algorithm>
00019 #include <numeric>
00020 #include <iterator>
00021 #include <boost/ref.hpp>
00022 #include <boost/bind.hpp>
00023 #include <boost/function.hpp>
00024 #include <boost/iterator/transform_iterator.hpp>
00025
00026 #include <fstream>
00027
00028 #include "CondCore/EcalPlugins/plugins/EcalPyWrapperFunctions.h"
00029
00030 namespace cond {
00031
00032 namespace ecalcond {
00033
00034 typedef EcalDCSTowerStatus::Items Items;
00035 typedef EcalDCSTowerStatus::value_type value_type;
00036
00037 enum How { singleChannel, bySuperModule, all};
00038
00039 int bad(Items const & cont) {
00040 return std::count_if(cont.begin(),cont.end(),
00041 boost::bind(std::greater<int>(),
00042 boost::bind(&value_type::getStatusCode,_1),0)
00043 );
00044 }
00045
00046 void extractBarrel(EcalDCSTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00047 result.resize(1);
00048 result[0] = bad(cont.barrelItems());
00049 }
00050
00051 void extractEndcap(EcalDCSTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00052 result.resize(1);
00053 result[0] = bad(cont.endcapItems());
00054 }
00055 void extractAll(EcalDCSTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
00056 result.resize(1);
00057 result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
00058 }
00059
00060 void extractSuperModules(EcalDCSTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00061
00062 }
00063
00064 void extractSingleChannel(EcalDCSTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
00065 result.reserve(which.size());
00066 for (unsigned int i=0; i<which.size();i++) {
00067 result.push_back(cont[which[i]].getStatusCode());
00068 }
00069 }
00070
00071 typedef boost::function<void(EcalDCSTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
00072 }
00073
00074 template<>
00075 struct ExtractWhat<EcalDCSTowerStatus> {
00076
00077 ecalcond::How m_how;
00078 std::vector<int> m_which;
00079
00080 ecalcond::How const & how() const { return m_how;}
00081 std::vector<int> const & which() const { return m_which;}
00082
00083 void set_how(ecalcond::How i) {m_how=i;}
00084 void set_which(std::vector<int> & i) { m_which.swap(i);}
00085 };
00086
00087
00088 template<>
00089 class ValueExtractor<EcalDCSTowerStatus>: public BaseValueExtractor<EcalDCSTowerStatus> {
00090 public:
00091
00092 static ecalcond::CondExtractor & extractor(ecalcond::How how) {
00093 static ecalcond::CondExtractor fun[3] = {
00094 ecalcond::CondExtractor(ecalcond::extractSingleChannel),
00095 ecalcond::CondExtractor(ecalcond::extractSuperModules),
00096 ecalcond::CondExtractor(ecalcond::extractAll)
00097 };
00098 return fun[how];
00099 }
00100
00101 typedef EcalDCSTowerStatus Class;
00102 typedef ExtractWhat<Class> What;
00103 static What what() { return What();}
00104
00105 ValueExtractor(){}
00106 ValueExtractor(What const & what)
00107 : m_what(what)
00108 {
00109
00110 }
00111
00112 void compute(Class const & it){
00113 std::vector<float> res;
00114 extractor(m_what.how())(it,m_what.which(),res);
00115 swap(res);
00116 }
00117
00118 private:
00119 What m_what;
00120 };
00121
00122
00123 template<>
00124 std::string PayLoadInspector<EcalDCSTowerStatus>::dump() const {
00125 std::stringstream ss;
00126 EcalCondHeader h;
00127 ss << EcalDCSTowerStatusXMLTranslator::dumpXML(h,object());
00128 return ss.str();
00129 }
00130
00131 class EcalDCSTowerStatusHelper: public EcalPyWrapperHelper<EcalChannelStatusCode>{
00132 public:
00133
00134 EcalDCSTowerStatusHelper():EcalPyWrapperHelper<EcalObject>(6, STATUS, "-Errors total: "){}
00135 protected:
00136
00137
00138 typedef EcalChannelStatusCode EcalObject;
00139
00140 type_vValues getValues( const std::vector<EcalObject> & vItems)
00141 {
00142
00143
00144
00145 type_vValues vValues(total_values);
00146
00147
00148 vValues[0].first = "LVSTATUS(0)";
00149 vValues[1].first = "LVNOMINALSTATUS(1)";
00150 vValues[2].first = "HVSTATUS(2)";
00151 vValues[3].first = "HVNOMINALSTATUS(3)";
00152 vValues[4].first = "HVEEDSTATUS(4)";
00153 vValues[5].first = "HVEEDNOMINALSTATUS(5)";
00154
00155
00156 vValues[0].second = .0;
00157 vValues[1].second = .0;
00158 vValues[2].second = .0;
00159 vValues[3].second = .0;
00160 vValues[4].second = .0;
00161 vValues[5].second = .0;
00162
00163
00164 unsigned int shift = 0, mask = 1;
00165 unsigned int statusCode;
00166 for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
00167
00168 statusCode = iItems->getStatusCode();
00169 for (shift = 0; shift < total_values; ++shift){
00170 mask = 1 << (shift);
00171
00172 if (statusCode & mask){
00173 vValues[shift].second += 1;
00174 }
00175 }
00176 }
00177 return vValues;
00178 }
00179 };
00180
00181 template<>
00182 std::string PayLoadInspector<EcalDCSTowerStatus>::summary() const {
00183 std::stringstream ss;
00184 EcalDCSTowerStatusHelper helper;
00185 ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
00186 return ss.str();
00187 }
00188
00189
00190
00191 template<>
00192 std::string PayLoadInspector<EcalDCSTowerStatus>::plot(std::string const & filename,
00193 std::string const &,
00194 std::vector<int> const&,
00195 std::vector<float> const& ) const {
00196
00197
00198
00199
00200
00201 gStyle->SetPalette(1);
00202
00203 const Int_t NRGBs = 5;
00204 const Int_t NCont = 255;
00205
00206 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
00207 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
00208 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
00209 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
00210 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
00211 gStyle->SetNumberContours(NCont);
00212
00213 TCanvas canvas("CC map","CC map",800,800);
00214 TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
00215 padb->Draw();
00216 TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
00217 padem->Draw();
00218 TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
00219 padep->Draw();
00220
00221
00222 TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 34, -17, 17);
00223 TH2F* endc_p = new TH2F("EE+","EE+ Tower Status",22, 0, 22, 22, 0, 22);
00224 TH2F* endc_m = new TH2F("EE-","EE- Tower Status",22, 0, 22, 22, 0, 22);
00225 for(uint cellid = 0;
00226 cellid < EcalTrigTowerDetId::kEBTotalTowers;
00227 ++cellid) {
00228 EcalTrigTowerDetId rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
00229 if (object().find(rawid) == object().end()) continue;
00230 int ieta = rawid.ieta();
00231 if(ieta > 0) ieta--;
00232 int iphi = rawid.iphi() - 1;
00233 barrel->Fill(iphi, ieta, object()[rawid].getStatusCode());
00234 }
00235 for(uint cellid = 0;
00236 cellid < EcalTrigTowerDetId::kEETotalTowers;
00237 ++cellid) {
00238 if(EcalScDetId::validHashIndex(cellid)) {
00239 EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
00240 int ix = rawid.ix();
00241 int iy = rawid.iy();
00242 int side = rawid.zside();
00243 if(side == -1)
00244 endc_m->Fill(ix, iy, object()[rawid].getStatusCode());
00245 else
00246 endc_p->Fill(ix, iy, object()[rawid].getStatusCode());
00247 }
00248 }
00249 TLine* l = new TLine(0., 0., 0., 0.);
00250 l->SetLineWidth(1);
00251 padb->cd();
00252 barrel->SetStats(0);
00253 barrel->SetMaximum(14);
00254 barrel->SetMinimum(0);
00255 barrel->Draw("colz");
00256
00257 for(int i = 0; i <17; i++) {
00258 Double_t x = 4.+ (i * 4);
00259 l = new TLine(x, -17., x, 17.);
00260 l->Draw();
00261 }
00262 l = new TLine(0., 0., 72., 0.);
00263 l->Draw();
00264
00265 int ixSectorsEE[136] = {
00266 8,14,14,17,17,18,18,19,19,20,20,21,21,20,20,19,19,18,18,17,
00267 17,14,14, 8, 8, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4,
00268 4, 5, 5, 8, 8, 8, 9, 9,10,10,12,12,13,13,12,12,10,10, 9, 9,
00269 10,10, 0,11,11, 0,10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 0,12,13,
00270 13,14,14,15,15,16,16,17,17, 0, 9, 8, 8, 3, 3, 1, 0,13,14,14,
00271 19,19,21, 0, 9, 8, 8, 7, 7, 5, 5, 3, 3, 2, 0,13,14,14,15,15,
00272 17,17,19,19,20, 0,14,14,13,13,12,12,0};
00273 int iySectorsEE[136] = {
00274 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 8, 8,14,14,17,17,18,18,19,19,
00275 20,20,21,21,20,20,19,19,18,18,17,17,14,14, 8, 8, 5, 5, 4, 4,
00276 3, 3, 2, 2, 1, 4, 4, 7, 7, 9, 9,10,10,12,12,13,13,12,12,10,
00277 10, 9, 0,13,21, 0,13,13,14,14,15,15,16,16,18,18,19, 0,13,13,
00278 14,14,15,15,16,16,18,18,19, 0,11,11,12,12,13,13, 0,11,11,12,
00279 12,13,13, 0,10,10, 9, 9, 8, 8, 7, 7, 6, 6, 0,10,10, 9, 9, 8,
00280 8, 7, 7, 6, 6, 0, 2, 4, 4, 7, 7, 9, 0} ;
00281 padem->cd();
00282 endc_m->SetStats(0);
00283 endc_m->SetMaximum(14);
00284 endc_m->SetMinimum(0);
00285 endc_m->Draw("colz");
00286 for ( int i = 0; i < 136; i=i+1) {
00287 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00288 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00289 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00290 ixSectorsEE[i+1], iySectorsEE[i+1]);
00291 }
00292 }
00293
00294 padep->cd();
00295 endc_p->SetStats(0);
00296 endc_p->SetMaximum(14);
00297 endc_p->SetMinimum(0);
00298 endc_p->Draw("colz");
00299 for ( int i = 0; i < 136; i=i+1) {
00300 if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
00301 (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
00302 l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
00303 ixSectorsEE[i+1], iySectorsEE[i+1]);
00304 }
00305 }
00306
00307 canvas.SaveAs(filename.c_str());
00308 return filename;
00309 }
00310 }
00311
00312
00313 namespace condPython {
00314 template<>
00315 void defineWhat<EcalDCSTowerStatus>() {
00316 using namespace boost::python;
00317 enum_<cond::ecalcond::How>("How")
00318 .value("singleChannel",cond::ecalcond::singleChannel)
00319 .value("bySuperModule",cond::ecalcond::bySuperModule)
00320 .value("all",cond::ecalcond::all)
00321 ;
00322
00323 typedef cond::ExtractWhat<EcalDCSTowerStatus> What;
00324 class_<What>("What",init<>())
00325 .def("set_how",&What::set_how)
00326 .def("set_which",&What::set_which)
00327 .def("how",&What::how, return_value_policy<copy_const_reference>())
00328 .def("which",&What::which, return_value_policy<copy_const_reference>())
00329 ;
00330 }
00331 }
00332
00333 PYTHON_WRAPPER(EcalDCSTowerStatus,EcalDCSTowerStatus);