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 assert(0!=keyValues);
00207 for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin();
00208 it != keyValues->end();
00209 ++it)
00210 {
00211 const std::string& name = it->first;
00212 const FWConfiguration& conf = it->second;
00213 const FWConfiguration::KeyValues* keyValues = conf.keyValues();
00214 assert(0!=keyValues);
00215 const std::string& type = (*keyValues)[0].second.value();
00216 const std::string& moduleLabel = (*keyValues)[1].second.value();
00217 const std::string& productInstanceLabel = (*keyValues)[2].second.value();
00218 const std::string& processName = (*keyValues)[3].second.value();
00219 const std::string& filterExpression = (*keyValues)[4].second.value();
00220 const std::string& sColor = (*keyValues)[5].second.value();
00221 const bool isVisible = (*keyValues)[6].second.value() == kTrue;
00222
00223 unsigned int colorIndex;
00224 if(conf.version() < 5)
00225 {
00226 std::istringstream is(sColor);
00227 Color_t color;
00228 is >> color;
00229 colorIndex = cm->oldColorToIndex(color, conf.version());
00230 }
00231 else
00232 {
00233
00234
00235
00236
00237 std::istringstream is(sColor);
00238 is >> colorIndex;
00239 }
00240
00241 int transparency = 0;
00242
00243
00244
00245 if (conf.version() > 3)
00246 transparency = strtol((*keyValues)[9].second.value().c_str(), 0, 10);
00247
00248 FWDisplayProperties dp(colorIndex, isVisible, transparency);
00249
00250 unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), 0, 10);
00251
00252
00253 std::string purpose(name);
00254 if (conf.version() > 1)
00255 purpose = (*keyValues)[8].second.value();
00256
00257 FWPhysicsObjectDesc desc(name,
00258 TClass::GetClass(type.c_str()),
00259 purpose,
00260 dp,
00261 moduleLabel,
00262 productInstanceLabel,
00263 processName,
00264 filterExpression,
00265 layer);
00266 add(desc);
00267 }
00268 }
00269
00280 void
00281 FWEventItemsManager::removeItem(const FWEventItem* iItem)
00282 {
00283 assert(iItem->id() < m_items.size());
00284 m_items[iItem->id()] = 0;
00285 }
00286
00287 void
00288 FWEventItemsManager::setContext(fireworks::Context* iContext)
00289 {
00290 m_context = iContext;
00291 }
00292
00293
00294
00295
00296 FWEventItemsManager::const_iterator
00297 FWEventItemsManager::begin() const
00298 {
00299 return m_items.begin();
00300 }
00301 FWEventItemsManager::const_iterator
00302 FWEventItemsManager::end() const
00303 {
00304 return m_items.end();
00305 }
00306
00309 const FWEventItem*
00310 FWEventItemsManager::find(const std::string& iName) const
00311 {
00312 for (size_t i = 0, e = m_items.size(); i != e; ++i)
00313 {
00314 const FWEventItem *item = m_items[i];
00315 if (item && item->name() == iName)
00316 return item;
00317 }
00318 return 0;
00319 }
00320
00321
00322
00323