File indexing completed on 2024-04-06 12:11:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <sstream>
0015 #include <functional>
0016 #include "TClass.h"
0017
0018
0019 #include "Fireworks/Core/interface/FWEventItemsManager.h"
0020 #include "Fireworks/Core/interface/FWEventItem.h"
0021 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0022 #include "Fireworks/Core/interface/FWColorManager.h"
0023 #include "Fireworks/Core/interface/FWConfiguration.h"
0024 #include "Fireworks/Core/interface/FWDisplayProperties.h"
0025 #include "Fireworks/Core/interface/FWItemAccessorFactory.h"
0026 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0027 #include "Fireworks/Core/interface/fwLog.h"
0028 #include <cassert>
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 FWEventItemsManager::FWEventItemsManager(FWModelChangeManager* iManager)
0042 : m_changeManager(iManager), m_context(nullptr), m_event(nullptr), m_accessorFactory(new FWItemAccessorFactory()) {}
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 FWEventItemsManager::~FWEventItemsManager() {
0056 for (size_t i = 0, e = m_items.size(); i != e; ++i)
0057 delete m_items[i];
0058
0059 m_items.clear();
0060 }
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 FWEventItem* FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem, const FWConfiguration* pbc, bool doSetEvent) {
0078 FWPhysicsObjectDesc temp(iItem);
0079
0080 if (!m_context->colorManager()->colorHasIndex(temp.displayProperties().color())) {
0081 FWDisplayProperties prop(temp.displayProperties());
0082 fwLog(fwlog::kWarning) << Form(
0083 "FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n",
0084 FWColorManager::getDefaultStartColorIndex());
0085 prop.setColor(FWColorManager::getDefaultStartColorIndex());
0086 temp.setDisplayProperties(prop);
0087 }
0088
0089 m_items.push_back(new FWEventItem(m_context, m_items.size(), m_accessorFactory->accessorFor(temp.type()), temp, pbc));
0090 newItem_(m_items.back());
0091 m_items.back()->goingToBeDestroyed_.connect(std::bind(&FWEventItemsManager::removeItem, this, std::placeholders::_1));
0092 if (doSetEvent && m_event) {
0093 FWChangeSentry sentry(*m_changeManager);
0094 m_items.back()->setEvent(m_event);
0095 }
0096 return m_items.back();
0097 }
0098
0099
0100
0101
0102 void FWEventItemsManager::newEvent(const edm::EventBase* iEvent) {
0103 FWChangeSentry sentry(*m_changeManager);
0104 m_event = iEvent;
0105 for (size_t i = 0, e = m_items.size(); i != e; ++i) {
0106 FWEventItem* item = m_items[i];
0107 if (item)
0108 item->setEvent(iEvent);
0109 }
0110 }
0111
0112
0113
0114
0115
0116
0117 void FWEventItemsManager::clearItems(void) {
0118 for (size_t i = 0, e = m_items.size(); i != e; ++i) {
0119 FWEventItem* item = m_items[i];
0120 if (item) {
0121 item->destroy();
0122 }
0123 m_items[i] = nullptr;
0124 }
0125 goingToClearItems_();
0126
0127 m_items.clear();
0128 }
0129
0130 static const std::string kType("type");
0131 static const std::string kModuleLabel("moduleLabel");
0132 static const std::string kProductInstanceLabel("productInstanceLabel");
0133 static const std::string kProcessName("processName");
0134 static const std::string kFilterExpression("filterExpression");
0135 static const std::string kColor("color");
0136 static const std::string kIsVisible("isVisible");
0137 static const std::string kTrue("t");
0138 static const std::string kFalse("f");
0139 static const std::string kLayer("layer");
0140 static const std::string kPurpose("purpose");
0141 static const std::string kTransparency("transparency");
0142
0143 void FWEventItemsManager::addTo(FWConfiguration& iTo) const {
0144 FWColorManager* cm = m_context->colorManager();
0145 assert(nullptr != cm);
0146 for (std::vector<FWEventItem*>::const_iterator it = m_items.begin(); it != m_items.end(); ++it) {
0147 if (!*it)
0148 continue;
0149 FWConfiguration conf(6);
0150 edm::TypeWithDict dataType((*((*it)->type()->GetTypeInfo())));
0151 assert(dataType != edm::TypeWithDict());
0152
0153 conf.addKeyValue(kType, FWConfiguration(dataType.name()));
0154 conf.addKeyValue(kModuleLabel, FWConfiguration((*it)->moduleLabel()));
0155 conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
0156 conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
0157 conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
0158 {
0159 std::ostringstream os;
0160 os << (*it)->defaultDisplayProperties().color();
0161 conf.addKeyValue(kColor, FWConfiguration(os.str()));
0162 }
0163 conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
0164 {
0165 std::ostringstream os;
0166 os << (*it)->layer();
0167 conf.addKeyValue(kLayer, FWConfiguration(os.str()));
0168 }
0169 conf.addKeyValue(kPurpose, (*it)->purpose());
0170 {
0171 std::ostringstream os;
0172 os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
0173 conf.addKeyValue(kTransparency, FWConfiguration(os.str()));
0174 }
0175
0176 FWConfiguration pbTmp;
0177 (*it)->getConfig()->addTo(pbTmp);
0178 conf.addKeyValue("PBConfig", pbTmp, true);
0179
0180 iTo.addKeyValue((*it)->name(), conf, true);
0181 }
0182 }
0183
0184
0185
0186 void FWEventItemsManager::setFrom(const FWConfiguration& iFrom) {
0187 FWColorManager* cm = m_context->colorManager();
0188 assert(nullptr != cm);
0189
0190 clearItems();
0191 const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
0192
0193 if (keyValues == nullptr)
0194 return;
0195
0196 std::vector<FWEventItem*> newItems;
0197 newItems.reserve(keyValues->size());
0198
0199 for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin(); it != keyValues->end(); ++it) {
0200 const std::string& name = it->first;
0201 const FWConfiguration& conf = it->second;
0202 const FWConfiguration::KeyValues* keyValues = conf.keyValues();
0203 assert(nullptr != keyValues);
0204 const std::string& type = (*keyValues)[0].second.value();
0205 const std::string& moduleLabel = (*keyValues)[1].second.value();
0206 const std::string& productInstanceLabel = (*keyValues)[2].second.value();
0207 const std::string& processName = (*keyValues)[3].second.value();
0208 const std::string& filterExpression = (*keyValues)[4].second.value();
0209 const std::string& sColor = (*keyValues)[5].second.value();
0210 const bool isVisible = (*keyValues)[6].second.value() == kTrue;
0211
0212 unsigned int colorIndex;
0213 if (conf.version() < 5) {
0214 std::istringstream is(sColor);
0215 Color_t color;
0216 is >> color;
0217 colorIndex = cm->oldColorToIndex(color, conf.version());
0218 } else {
0219
0220
0221
0222
0223 std::istringstream is(sColor);
0224 is >> colorIndex;
0225 }
0226
0227 int transparency = 0;
0228
0229
0230
0231 if (conf.version() > 3)
0232 transparency = strtol((*keyValues)[9].second.value().c_str(), nullptr, 10);
0233
0234 FWDisplayProperties dp(colorIndex, isVisible, transparency);
0235
0236 unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), nullptr, 10);
0237
0238
0239 std::string purpose(name);
0240 if (conf.version() > 1)
0241 purpose = (*keyValues)[8].second.value();
0242
0243 FWConfiguration* proxyConfig =
0244 (FWConfiguration*)conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : nullptr;
0245
0246
0247 if (conf.version() < 6) {
0248 assert(proxyConfig == nullptr);
0249 if (purpose == "VerticesWithTracks") {
0250 purpose = "Vertices";
0251 proxyConfig = new FWConfiguration();
0252 FWConfiguration vTmp;
0253 vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
0254 proxyConfig->addKeyValue("Var", vTmp, true);
0255 }
0256 }
0257
0258 FWPhysicsObjectDesc desc(name,
0259 TClass::GetClass(type.c_str()),
0260 purpose,
0261 dp,
0262 moduleLabel,
0263 productInstanceLabel,
0264 processName,
0265 filterExpression,
0266 layer);
0267
0268 newItems.push_back(add(desc, proxyConfig, false));
0269 }
0270
0271 if (m_event) {
0272 FWChangeSentry sentry(*m_changeManager);
0273 for (auto ip : newItems)
0274 ip->setEvent(m_event);
0275 }
0276 }
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288 void FWEventItemsManager::removeItem(const FWEventItem* iItem) {
0289 assert(iItem->id() < m_items.size());
0290 removingItem_(iItem);
0291 m_items[iItem->id()] = nullptr;
0292 }
0293
0294 void FWEventItemsManager::setContext(fireworks::Context* iContext) { m_context = iContext; }
0295
0296
0297
0298
0299 FWEventItemsManager::const_iterator FWEventItemsManager::begin() const { return m_items.begin(); }
0300 FWEventItemsManager::const_iterator FWEventItemsManager::end() const { return m_items.end(); }
0301
0302
0303
0304 const FWEventItem* FWEventItemsManager::find(const std::string& iName) const {
0305 for (size_t i = 0, e = m_items.size(); i != e; ++i) {
0306 const FWEventItem* item = m_items[i];
0307 if (item && item->name() == iName)
0308 return item;
0309 }
0310 return nullptr;
0311 }
0312
0313
0314
0315