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