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