00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <sstream>
00016 #include <boost/bind.hpp>
00017 #include "TClass.h"
00018
00019
00020 #include "Fireworks/Core/interface/FWEventItemsManager.h"
00021 #include "Fireworks/Core/interface/FWEventItem.h"
00022 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00023 #include "Fireworks/Core/interface/FWColorManager.h"
00024 #include "Fireworks/Core/interface/FWConfiguration.h"
00025 #include "Fireworks/Core/interface/FWDisplayProperties.h"
00026 #include "Fireworks/Core/interface/FWItemAccessorFactory.h"
00027 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
00028 #include "Fireworks/Core/interface/fwLog.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 FWEventItemsManager::FWEventItemsManager(FWModelChangeManager* iManager) :
00042 m_changeManager(iManager),
00043 m_context(0),
00044 m_event(0),
00045 m_accessorFactory(new FWItemAccessorFactory())
00046 {
00047 }
00048
00049
00050
00051
00052
00053
00060 FWEventItemsManager::~FWEventItemsManager()
00061 {
00062 for (size_t i = 0, e = m_items.size(); i != e; ++i)
00063 delete m_items[i];
00064
00065 m_items.clear();
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 const FWEventItem*
00084 FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem, const FWConfiguration* pbc)
00085 {
00086 FWPhysicsObjectDesc temp(iItem);
00087
00088 if(! m_context->colorManager()->colorHasIndex(temp.displayProperties().color())) {
00089 FWDisplayProperties prop(temp.displayProperties());
00090 fwLog(fwlog::kWarning) << Form("FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n", FWColorManager::getDefaultStartColorIndex());
00091 prop.setColor(FWColorManager::getDefaultStartColorIndex());
00092 temp.setDisplayProperties(prop);
00093 }
00094
00095 m_items.push_back(new FWEventItem(m_context,m_items.size(),m_accessorFactory->accessorFor(temp.type()),
00096 temp, pbc));
00097 newItem_(m_items.back());
00098 m_items.back()->goingToBeDestroyed_.connect(boost::bind(&FWEventItemsManager::removeItem,this,_1));
00099 if(m_event) {
00100 FWChangeSentry sentry(*m_changeManager);
00101 m_items.back()->setEvent(m_event);
00102 }
00103 return m_items.back();
00104 }
00105
00109 void
00110 FWEventItemsManager::newEvent(const edm::EventBase* iEvent)
00111 {
00112 FWChangeSentry sentry(*m_changeManager);
00113 m_event = iEvent;
00114 for(size_t i = 0, e = m_items.size(); i != e; ++i)
00115 {
00116 FWEventItem *item = m_items[i];
00117 if(item)
00118 item->setEvent(iEvent);
00119 }
00120 }
00121
00127 void
00128 FWEventItemsManager::clearItems(void)
00129 {
00130 for (size_t i = 0, e = m_items.size(); i != e; ++i)
00131 {
00132 FWEventItem *item = m_items[i];
00133 if (item) {
00134 item->destroy();
00135 }
00136 m_items[i]=0;
00137 }
00138 goingToClearItems_();
00139
00140 m_items.clear();
00141 }
00142
00143 static const std::string kType("type");
00144 static const std::string kModuleLabel("moduleLabel");
00145 static const std::string kProductInstanceLabel("productInstanceLabel");
00146 static const std::string kProcessName("processName");
00147 static const std::string kFilterExpression("filterExpression");
00148 static const std::string kColor("color");
00149 static const std::string kIsVisible("isVisible");
00150 static const std::string kTrue("t");
00151 static const std::string kFalse("f");
00152 static const std::string kLayer("layer");
00153 static const std::string kPurpose("purpose");
00154 static const std::string kTransparency("transparency");
00155
00156 void
00157 FWEventItemsManager::addTo(FWConfiguration& iTo) const
00158 {
00159 FWColorManager* cm = m_context->colorManager();
00160 assert(0!=cm);
00161 for(std::vector<FWEventItem*>::const_iterator it = m_items.begin();
00162 it != m_items.end();
00163 ++it)
00164 {
00165 if(!*it) continue;
00166 FWConfiguration conf(6);
00167 ROOT::Reflex::Type dataType( ROOT::Reflex::Type::ByTypeInfo(*((*it)->type()->GetTypeInfo())));
00168 assert(dataType != ROOT::Reflex::Type() );
00169
00170 conf.addKeyValue(kType,FWConfiguration(dataType.Name(ROOT::Reflex::SCOPED)));
00171 conf.addKeyValue(kModuleLabel,FWConfiguration((*it)->moduleLabel()));
00172 conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
00173 conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
00174 conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
00175 {
00176 std::ostringstream os;
00177 os << (*it)->defaultDisplayProperties().color();
00178 conf.addKeyValue(kColor, FWConfiguration(os.str()));
00179 }
00180 conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
00181 {
00182 std::ostringstream os;
00183 os << (*it)->layer();
00184 conf.addKeyValue(kLayer,FWConfiguration(os.str()));
00185 }
00186 conf.addKeyValue(kPurpose,(*it)->purpose());
00187 {
00188 std::ostringstream os;
00189 os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
00190 conf.addKeyValue(kTransparency, FWConfiguration(os.str()));
00191 }
00192
00193 FWConfiguration pbTmp;
00194 (*it)->getConfig()->addTo(pbTmp);
00195 conf.addKeyValue("PBConfig",pbTmp, true);
00196
00197 iTo.addKeyValue((*it)->name(), conf, true);
00198 }
00199 }
00200
00203 void
00204 FWEventItemsManager::setFrom(const FWConfiguration& iFrom)
00205 {
00206
00207 FWColorManager* cm = m_context->colorManager();
00208 assert(0!=cm);
00209
00210 clearItems();
00211 const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
00212
00213 if (keyValues == 0) return;
00214
00215 for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin();
00216 it != keyValues->end();
00217 ++it)
00218 {
00219 const std::string& name = it->first;
00220 const FWConfiguration& conf = it->second;
00221 const FWConfiguration::KeyValues* keyValues = conf.keyValues();
00222 assert(0!=keyValues);
00223 const std::string& type = (*keyValues)[0].second.value();
00224 const std::string& moduleLabel = (*keyValues)[1].second.value();
00225 const std::string& productInstanceLabel = (*keyValues)[2].second.value();
00226 const std::string& processName = (*keyValues)[3].second.value();
00227 const std::string& filterExpression = (*keyValues)[4].second.value();
00228 const std::string& sColor = (*keyValues)[5].second.value();
00229 const bool isVisible = (*keyValues)[6].second.value() == kTrue;
00230
00231 unsigned int colorIndex;
00232 if(conf.version() < 5)
00233 {
00234 std::istringstream is(sColor);
00235 Color_t color;
00236 is >> color;
00237 colorIndex = cm->oldColorToIndex(color, conf.version());
00238 }
00239 else
00240 {
00241
00242
00243
00244
00245 std::istringstream is(sColor);
00246 is >> colorIndex;
00247 }
00248
00249 int transparency = 0;
00250
00251
00252
00253 if (conf.version() > 3)
00254 transparency = strtol((*keyValues)[9].second.value().c_str(), 0, 10);
00255
00256 FWDisplayProperties dp(colorIndex, isVisible, transparency);
00257
00258 unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), 0, 10);
00259
00260
00261 std::string purpose(name);
00262 if (conf.version() > 1)
00263 purpose = (*keyValues)[8].second.value();
00264
00265 FWConfiguration* proxyConfig = (FWConfiguration*) conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : 0;
00266
00267
00268 if (conf.version() < 6)
00269 {
00270 assert(proxyConfig == 0);
00271 if (purpose == "VerticesWithTracks")
00272 {
00273 purpose = "Vertices";
00274 proxyConfig = new FWConfiguration();
00275 FWConfiguration vTmp; vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
00276 proxyConfig->addKeyValue("Var", vTmp,true);
00277 }
00278 }
00279
00280 FWPhysicsObjectDesc desc(name,
00281 TClass::GetClass(type.c_str()),
00282 purpose,
00283 dp,
00284 moduleLabel,
00285 productInstanceLabel,
00286 processName,
00287 filterExpression,
00288 layer);
00289
00290 add(desc, proxyConfig );
00291 }
00292 }
00293
00304 void
00305 FWEventItemsManager::removeItem(const FWEventItem* iItem)
00306 {
00307 assert(iItem->id() < m_items.size());
00308 m_items[iItem->id()] = 0;
00309 }
00310
00311 void
00312 FWEventItemsManager::setContext(fireworks::Context* iContext)
00313 {
00314 m_context = iContext;
00315 }
00316
00317
00318
00319
00320 FWEventItemsManager::const_iterator
00321 FWEventItemsManager::begin() const
00322 {
00323 return m_items.begin();
00324 }
00325 FWEventItemsManager::const_iterator
00326 FWEventItemsManager::end() const
00327 {
00328 return m_items.end();
00329 }
00330
00333 const FWEventItem*
00334 FWEventItemsManager::find(const std::string& iName) const
00335 {
00336 for (size_t i = 0, e = m_items.size(); i != e; ++i)
00337 {
00338 const FWEventItem *item = m_items[i];
00339 if (item && item->name() == iName)
00340 return item;
00341 }
00342 return 0;
00343 }
00344
00345
00346
00347