File indexing completed on 2024-04-06 12:11:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <iostream>
0015 #include <functional>
0016 #include <algorithm>
0017
0018 #include "TEveManager.h"
0019 #include "TClass.h"
0020 #include "FWCore/Reflection/interface/BaseWithDict.h"
0021 #include "FWCore/Reflection/interface/MemberWithDict.h"
0022 #include "FWCore/Reflection/interface/FunctionWithDict.h"
0023
0024
0025 #include "Fireworks/Core/interface/FWConfiguration.h"
0026 #include "Fireworks/Core/interface/FWTableViewManager.h"
0027 #include "Fireworks/Core/interface/FWEventItem.h"
0028 #include "Fireworks/Core/interface/FWGUIManager.h"
0029 #include "Fireworks/Core/interface/FWColorManager.h"
0030
0031 #include "Fireworks/Core/interface/FWTypeToRepresentations.h"
0032 #include "Fireworks/Core/interface/fwLog.h"
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 FWTableViewManager::FWTableViewManager(FWGUIManager *iGUIMgr) : FWViewManagerBase() {
0046 FWGUIManager::ViewBuildFunctor f;
0047 f = std::bind(&FWTableViewManager::buildView, this, std::placeholders::_1, std::placeholders::_2);
0048 iGUIMgr->registerViewBuilder(FWViewType::idToName(FWViewType::kTable), f);
0049
0050
0051 table("reco::GenParticle")
0052 .column("pT", 1, "pt")
0053 .column("eta", 3)
0054 .column("phi", 3)
0055 .column("status", TableEntry::INT)
0056 .column("pdgId", TableEntry::INT);
0057
0058 table("reco::Muon")
0059 .column("q", TableEntry::INT, "charge")
0060 .column("pT", 1, "pt")
0061 .column("global", TableEntry::BOOL, "isGlobalMuon")
0062 .column("tracker", TableEntry::BOOL, "isTrackerMuon")
0063 .column("SA", TableEntry::BOOL, "isStandAloneMuon")
0064 .column("calo", TableEntry::BOOL, "isCaloMuon")
0065 .column("tr pt", 1, "track().pt()")
0066 .column("eta", 3)
0067 .column("phi", 3)
0068 .column("matches", TableEntry::INT, "numberOfMatches('SegmentArbitration')")
0069 .column("d0", 3, "track().d0()")
0070 .column("d0 / d0Err", 3, "track().d0() / track().d0Error()");
0071
0072 table("reco::GsfElectron")
0073 .column("q", TableEntry::INT, "charge")
0074 .column("pT", 1, "pt")
0075 .column("eta", 3)
0076 .column("phi", 3)
0077 .column("E/p", 3, "eSuperClusterOverP")
0078 .column("H/E", 3, "hadronicOverEm")
0079 .column("fbrem", 3, "(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()")
0080 .column("dei", 3, "deltaEtaSuperClusterTrackAtVtx()")
0081 .column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()");
0082
0083 table("reco::Photon").column("pT", 1, "pt").column("eta", 3).column("phi", 3).column("H/E", 3, "hadronicOverEm");
0084
0085 table("reco::CaloJet")
0086 .column("pT", 1, "pt")
0087 .column("eta", 3)
0088 .column("phi", 3)
0089 .column("ECAL", 1, "p4().E() * emEnergyFraction()")
0090 .column("HCAL", 1, "p4().E() * energyFractionHadronic()")
0091 .column("emf", 3, "emEnergyFraction()");
0092
0093 table("reco::Jet")
0094 .column("pT", 1, "pt")
0095 .column("eta", 3)
0096 .column("phi", 3)
0097 .column("electronEnergyFraction", 3, "electronEnergyFraction()")
0098 .column("muonEnergyFraction", 3, "muonEnergyFraction()")
0099 .column("photonEnergyFraction", 3, "photonEnergyFraction()");
0100
0101 table("reco::MET").column("et", 1).column("phi", 3).column("sumEt", 1).column("mEtSig", 3);
0102
0103 table("reco::Track")
0104 .column("q", TableEntry::INT, "charge")
0105 .column("pT", 1, "pt")
0106 .column("eta", 3)
0107 .column("phi", 3)
0108 .column("d0", 5)
0109 .column("d0Err", 5, "d0Error")
0110 .column("dz", 5)
0111 .column("dzErr", 5, "dzError")
0112 .column("vx", 5)
0113 .column("vy", 5)
0114 .column("vz", 5)
0115 .column("pixel hits", TableEntry::INT, "hitPattern().numberOfValidPixelHits()")
0116 .column("strip hits", TableEntry::INT, "hitPattern().numberOfValidStripHits()")
0117 .column("chi2", 3)
0118 .column("ndof", TableEntry::INT);
0119
0120 table("DTRecSegment4D")
0121 .column("wheel", 0, "chamberId.wheel")
0122 .column("station", 0, "chamberId.station")
0123 .column("sector", 0, "chamberId.sector")
0124 .column("t0phi", 2, "phiSegment.t0")
0125 .column("t0theta", 2, "zSegment.t0")
0126 .column("hasPhi", -2, "hasPhi")
0127 .column("hasZed", -2, "hasZed")
0128 .column("chi2", 2, "chi2")
0129 .column("dof", 0, "degreesOfFreedom");
0130
0131 table("DTRecHit1DPair")
0132 .column("wheel", 0, "wireId.wheel")
0133 .column("station", 0, "wireId.station")
0134 .column("sector", 0, "wireId.sector")
0135 .column("SL", 0, "wireId.superlayer")
0136 .column("layer", 0, "wireId.layer")
0137 .column("wire", 0, "wireId.wire")
0138 .column("digiTime", 2, "digiTime");
0139
0140 table("CSCSegment")
0141 .column("endcap", 0, "cscDetId.endcap")
0142 .column("station", 0, "cscDetId.station")
0143 .column("ring", 0, "cscDetId.ring")
0144 .column("chamber", 0, "cscDetId.chamber");
0145
0146 table("reco::Vertex")
0147 .column("x", 5)
0148 .column("xError", 5)
0149 .column("y", 5)
0150 .column("yError", 5)
0151 .column("z", 5)
0152 .column("zError", 5)
0153 .column("tracks", TableEntry::INT, "tracksSize")
0154 .column("chi2", 3)
0155 .column("ndof", 3);
0156
0157 table("CaloTower").column("emEt", 1).column("hadEt", 1).column("et", 1, "Et").column("eta", 3).column("phi", 3);
0158
0159 table("CaloRecHit")
0160 .column("id", TableEntry::INT, "detid.rawId")
0161 .column("energy", 3)
0162 .column("time", 3)
0163 .column("flags", TableEntry::INT, "flags");
0164
0165 table("reco::PFCandidate")
0166 .column("et", 1, "Et")
0167 .column("eta", 3)
0168 .column("phi", 3)
0169 .column("ecalEnergy", 3, "ecalEnergy()")
0170 .column("hcalEnergy", 3, "hcalEnergy()")
0171 .column("track pt", 3, "trackRef().pt()");
0172
0173 table("reco::Electron")
0174 .column("pT", 1, "pt")
0175 .column("eta", 3)
0176 .column("phi", 3)
0177 .column("E/p", 3, "eSuperClusterOverP")
0178 .column("H/E", 3, "hadronicOverEm")
0179 .column("fbrem", 3, "(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()")
0180 .column("dei", 3, "deltaEtaSuperClusterTrackAtVtx")
0181 .column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()")
0182 .column("charge", 0, "charge")
0183 .column("isPF", 0, "isPF()")
0184 .column("sieie", 3, "sigmaIetaIeta")
0185 .column("isNotConv", 1, "passConversionVeto");
0186
0187 table("pat::PackedCandidate")
0188 .column("pT", 1, "pt")
0189 .column("eta", 3)
0190 .column("phi", 3)
0191 .column("pdgId", 0)
0192 .column("charge", 0)
0193 .column("dxy", 3)
0194 .column("dzAssociatedPV", 3, "dzAssociatedPV()");
0195
0196 table("l1t::HGCalTriggerCell").column("pT", 1, "pt").column("eta", 3).column("phi", 3).column("detId", 0);
0197
0198 table("CaloParticle").column("eta", 3).column("phi", 3).column("energy", 3);
0199 }
0200
0201 FWTableViewManager::~FWTableViewManager() {}
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 FWTableViewManager::TableHandle FWTableViewManager::table(const char *name) {
0220 TableHandle handle(name, m_tableFormats);
0221 return handle;
0222 }
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232 FWTableViewManager::TableHandle &FWTableViewManager::TableHandle::column(const char *name,
0233 int precision,
0234 const char *expression) {
0235 TableEntry columnEntry;
0236 columnEntry.name = name;
0237 columnEntry.precision = precision;
0238 columnEntry.expression = expression;
0239
0240 m_specs[m_name].push_back(columnEntry);
0241 return *this;
0242 }
0243
0244
0245
0246
0247 FWTableViewManager::TableSpecs::iterator FWTableViewManager::tableFormatsImpl(const edm::TypeWithDict &key) {
0248 TableSpecs::iterator ret = m_tableFormats.find(key.name());
0249 if (ret != m_tableFormats.end())
0250 return ret;
0251
0252
0253 edm::TypeBases bases(key);
0254 for (auto const &base : bases) {
0255 ret = tableFormatsImpl(edm::BaseWithDict(base).typeOf());
0256 if (ret != m_tableFormats.end())
0257 return ret;
0258 }
0259
0260 return m_tableFormats.end();
0261 }
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276 FWTableViewManager::TableSpecs::iterator FWTableViewManager::tableFormats(const edm::TypeWithDict &key) {
0277 static const std::string isint("int");
0278 static const std::string isbool("bool");
0279 static const std::string isdouble("double");
0280 static const std::string isfloat("float");
0281
0282 std::string keyType = key.name();
0283
0284 TableSpecs::iterator ret = m_tableFormats.find(keyType);
0285
0286 if (ret != m_tableFormats.end())
0287 return ret;
0288
0289 ret = tableFormatsImpl(key);
0290
0291 if (ret != m_tableFormats.end())
0292 return ret;
0293
0294 TableHandle handle = table(keyType.c_str());
0295 edm::TypeFunctionMembers functionMembers(key);
0296 for (auto const &member : functionMembers) {
0297 edm::FunctionWithDict m(member);
0298 if (m.functionParameterSize())
0299 continue;
0300 if (!m.isPublic())
0301 continue;
0302 if (!m.isConst())
0303 continue;
0304 if (m.finalReturnType().name() == isint)
0305 handle.column(m.name().c_str(), TableEntry::INT);
0306 else if (m.finalReturnType().name() == isbool)
0307 handle.column(m.name().c_str(), TableEntry::BOOL);
0308 else if (m.finalReturnType().name() == isdouble)
0309 handle.column(m.name().c_str(), 5);
0310 else if (m.finalReturnType().name() == isfloat)
0311 handle.column(m.name().c_str(), 3);
0312 }
0313 edm::TypeDataMembers dataMembers(key);
0314 for (auto const &member : dataMembers) {
0315 edm::MemberWithDict m(member);
0316 if (!m.isPublic())
0317 continue;
0318 if (!m.isConst())
0319 continue;
0320 if (m.typeOf().name() == isint)
0321 handle.column(m.name().c_str(), TableEntry::INT);
0322 else if (m.typeOf().name() == isbool)
0323 handle.column(m.name().c_str(), TableEntry::BOOL);
0324 else if (m.typeOf().name() == isdouble)
0325 handle.column(m.name().c_str(), 5);
0326 else if (m.typeOf().name() == isfloat)
0327 handle.column(m.name().c_str(), 3);
0328 }
0329 return m_tableFormats.find(keyType);
0330 }
0331
0332
0333
0334
0335
0336
0337 FWTableViewManager::TableSpecs::iterator FWTableViewManager::tableFormats(const TClass &key) {
0338 return tableFormats(edm::TypeWithDict::byName(key.GetName()));
0339 }
0340
0341 class FWViewBase *FWTableViewManager::buildView(TEveWindowSlot *iParent, const std::string & ) {
0342 TEveManager::TRedrawDisabler disableRedraw(gEve);
0343 auto view = std::make_shared<FWTableView>(iParent, this);
0344 view->setBackgroundColor(colorManager().background());
0345 m_views.push_back(view);
0346 view->beingDestroyed_.connect(std::bind(&FWTableViewManager::beingDestroyed, this, std::placeholders::_1));
0347 return view.get();
0348 }
0349
0350 void FWTableViewManager::beingDestroyed(const FWViewBase *iView) {
0351 for (Views::iterator it = m_views.begin(), itEnd = m_views.end(); it != itEnd; ++it) {
0352 if (it->get() == iView) {
0353 m_views.erase(it);
0354 return;
0355 }
0356 }
0357 }
0358
0359 void FWTableViewManager::newItem(const FWEventItem *iItem) {
0360 m_items.push_back(iItem);
0361 iItem->goingToBeDestroyed_.connect(std::bind(&FWTableViewManager::destroyItem, this, std::placeholders::_1));
0362 notifyViews();
0363 }
0364
0365
0366 void FWTableViewManager::notifyViews(void) {
0367 for (size_t i = 0, e = m_views.size(); i != e; ++i) {
0368 FWTableView *view = m_views[i].get();
0369 view->updateItems();
0370 view->dataChanged();
0371 }
0372 }
0373
0374
0375
0376
0377
0378
0379 void FWTableViewManager::destroyItem(const FWEventItem *iItem) {
0380
0381
0382 for (size_t i = 0, e = m_items.size(); i != e; ++i) {
0383 if (m_items[i] != iItem)
0384 continue;
0385 m_items[i] = nullptr;
0386 }
0387
0388 notifyViews();
0389 }
0390
0391
0392
0393
0394
0395 void FWTableViewManager::removeAllItems(void) {
0396 m_items.clear();
0397 notifyViews();
0398 }
0399
0400 void FWTableViewManager::modelChangesComing() { gEve->DisableRedraw(); }
0401
0402 void FWTableViewManager::modelChangesDone() {
0403 gEve->EnableRedraw();
0404
0405
0406
0407 dataChanged();
0408 }
0409
0410
0411 void FWTableViewManager::colorsChanged() {
0412 for (size_t i = 0, e = m_views.size(); i != e; ++i)
0413 m_views[i].get()->resetColors(colorManager());
0414 }
0415
0416 void FWTableViewManager::dataChanged() {
0417 for (size_t i = 0, e = m_views.size(); i != e; ++i)
0418 m_views[i].get()->dataChanged();
0419 }
0420
0421 FWTypeToRepresentations FWTableViewManager::supportedTypesAndRepresentations() const {
0422 FWTypeToRepresentations returnValue;
0423 return returnValue;
0424 }
0425
0426 const std::string FWTableViewManager::kConfigTypeNames = "typeNames";
0427
0428 void FWTableViewManager::addTo(FWConfiguration &iTo) const {
0429
0430
0431
0432 if (!m_views.empty())
0433 return;
0434
0435
0436
0437 addToImpl(iTo);
0438 }
0439
0440 void FWTableViewManager::addToImpl(FWConfiguration &iTo) const {
0441 FWConfiguration typeNames(1);
0442 char prec[100];
0443
0444 for (TableSpecs::const_iterator iType = m_tableFormats.begin(), iType_end = m_tableFormats.end(); iType != iType_end;
0445 ++iType) {
0446 const std::string &typeName = iType->first;
0447 typeNames.addValue(typeName);
0448 FWConfiguration columns(1);
0449 const TableEntries &entries = iType->second;
0450 for (size_t ei = 0, ee = entries.size(); ei != ee; ++ei) {
0451 const TableEntry &entry = entries[ei];
0452 columns.addValue(entry.name);
0453 columns.addValue(entry.expression);
0454 columns.addValue((snprintf(prec, 100, "%d", entry.precision), prec));
0455 }
0456 iTo.addKeyValue(typeName, columns);
0457 }
0458 iTo.addKeyValue(kConfigTypeNames, typeNames);
0459 }
0460
0461 void FWTableViewManager::setFrom(const FWConfiguration &iFrom) {
0462 try {
0463 const FWConfiguration *typeNames = iFrom.valueForKey(kConfigTypeNames);
0464 if (typeNames == nullptr) {
0465 fwLog(fwlog::kWarning) << "no table column configuration stored, using defaults\n";
0466 return;
0467 }
0468
0469
0470
0471
0472
0473 for (FWConfiguration::StringValuesIt iType = typeNames->stringValues()->begin(),
0474 iTypeEnd = typeNames->stringValues()->end();
0475 iType != iTypeEnd;
0476 ++iType) {
0477
0478 const FWConfiguration *columns = iFrom.valueForKey(*iType);
0479 assert(columns != nullptr);
0480 TableHandle handle = table(iType->c_str());
0481 for (FWConfiguration::StringValuesIt it = columns->stringValues()->begin(),
0482 itEnd = columns->stringValues()->end();
0483 it != itEnd;
0484 ++it) {
0485 const std::string &name = *it++;
0486 const std::string &expr = *it++;
0487 int prec = atoi(it->c_str());
0488 handle.column(name.c_str(), prec, expr.c_str());
0489 }
0490 }
0491 } catch (...) {
0492
0493
0494
0495 }
0496 }