CMS 3D CMS Logo

FWEventItemsManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWEventItemsManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Fri Jan 4 10:38:18 EST 2008
11 //
12 
13 // system include files
14 #include <sstream>
15 #include <functional>
16 #include "TClass.h"
17 
18 // user include files
28 #include <cassert>
29 
30 //
31 // constants, enums and typedefs
32 //
33 
34 //
35 // static data member definitions
36 //
37 
38 //
39 // constructors and destructor
40 //
42  : m_changeManager(iManager), m_context(nullptr), m_event(nullptr), m_accessorFactory(new FWItemAccessorFactory()) {}
43 
44 // FWEventItemsManager::FWEventItemsManager(const FWEventItemsManager& rhs)
45 // {
46 // // do actual copying here;
47 // }
48 
56  for (size_t i = 0, e = m_items.size(); i != e; ++i)
57  delete m_items[i];
58 
59  m_items.clear();
60 }
61 
62 //
63 // assignment operators
64 //
65 // const FWEventItemsManager& FWEventItemsManager::operator=(const FWEventItemsManager& rhs)
66 // {
67 // //An exception safe implementation is
68 // FWEventItemsManager temp(rhs);
69 // swap(rhs);
70 //
71 // return *this;
72 // }
73 
74 //
75 // member functions
76 //
77 FWEventItem* FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem, const FWConfiguration* pbc, bool doSetEvent) {
79 
80  if (!m_context->colorManager()->colorHasIndex(temp.displayProperties().color())) {
81  FWDisplayProperties prop(temp.displayProperties());
82  fwLog(fwlog::kWarning) << Form(
83  "FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n",
86  temp.setDisplayProperties(prop);
87  }
88 
89  m_items.push_back(new FWEventItem(m_context, m_items.size(), m_accessorFactory->accessorFor(temp.type()), temp, pbc));
90  newItem_(m_items.back());
91  m_items.back()->goingToBeDestroyed_.connect(std::bind(&FWEventItemsManager::removeItem, this, std::placeholders::_1));
92  if (doSetEvent && m_event) {
94  m_items.back()->setEvent(m_event);
95  }
96  return m_items.back();
97 }
98 
104  m_event = iEvent;
105  for (size_t i = 0, e = m_items.size(); i != e; ++i) {
107  if (item)
108  item->setEvent(iEvent);
109  }
110 }
111 
118  for (size_t i = 0, e = m_items.size(); i != e; ++i) {
120  if (item) {
121  item->destroy();
122  }
123  m_items[i] = nullptr;
124  }
126 
127  m_items.clear();
128 }
129 
130 static const std::string kType("type");
131 static const std::string kModuleLabel("moduleLabel");
132 static const std::string kProductInstanceLabel("productInstanceLabel");
133 static const std::string kProcessName("processName");
134 static const std::string kFilterExpression("filterExpression");
135 static const std::string kColor("color");
136 static const std::string kIsVisible("isVisible");
137 static const std::string kTrue("t");
138 static const std::string kFalse("f");
139 static const std::string kLayer("layer");
140 static const std::string kPurpose("purpose");
141 static const std::string kTransparency("transparency");
142 
145  assert(nullptr != cm);
146  for (std::vector<FWEventItem*>::const_iterator it = m_items.begin(); it != m_items.end(); ++it) {
147  if (!*it)
148  continue;
149  FWConfiguration conf(6);
150  edm::TypeWithDict dataType((*((*it)->type()->GetTypeInfo())));
152 
153  conf.addKeyValue(kType, FWConfiguration(dataType.name()));
154  conf.addKeyValue(kModuleLabel, FWConfiguration((*it)->moduleLabel()));
155  conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
156  conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
157  conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
158  {
159  std::ostringstream os;
160  os << (*it)->defaultDisplayProperties().color();
161  conf.addKeyValue(kColor, FWConfiguration(os.str()));
162  }
163  conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
164  {
165  std::ostringstream os;
166  os << (*it)->layer();
167  conf.addKeyValue(kLayer, FWConfiguration(os.str()));
168  }
169  conf.addKeyValue(kPurpose, (*it)->purpose());
170  {
171  std::ostringstream os;
172  os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
174  }
175 
176  FWConfiguration pbTmp;
177  (*it)->getConfig()->addTo(pbTmp);
178  conf.addKeyValue("PBConfig", pbTmp, true);
179 
180  iTo.addKeyValue((*it)->name(), conf, true);
181  }
182 }
183 
188  assert(nullptr != cm);
189 
190  clearItems();
191  const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
192 
193  if (keyValues == nullptr)
194  return;
195 
196  std::vector<FWEventItem*> newItems;
197  newItems.reserve(keyValues->size());
198 
199  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin(); it != keyValues->end(); ++it) {
200  const std::string& name = it->first;
201  const FWConfiguration& conf = it->second;
202  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
203  assert(nullptr != keyValues);
204  const std::string& type = (*keyValues)[0].second.value();
205  const std::string& moduleLabel = (*keyValues)[1].second.value();
206  const std::string& productInstanceLabel = (*keyValues)[2].second.value();
207  const std::string& processName = (*keyValues)[3].second.value();
208  const std::string& filterExpression = (*keyValues)[4].second.value();
209  const std::string& sColor = (*keyValues)[5].second.value();
210  const bool isVisible = (*keyValues)[6].second.value() == kTrue;
211 
212  unsigned int colorIndex;
213  if (conf.version() < 5) {
214  std::istringstream is(sColor);
215  Color_t color;
216  is >> color;
217  colorIndex = cm->oldColorToIndex(color, conf.version());
218  } else {
219  // In version 4 we assume:
220  // fireworks colors start at ROOT index 1000
221  // geometry colors start at ROOT index 1100
222  // We save them as such -- no conversions needed.
223  std::istringstream is(sColor);
224  is >> colorIndex;
225  }
226 
227  int transparency = 0;
228 
229  // Read transparency from file. We don't care about checking errors
230  // because strtol returns 0 in that case.
231  if (conf.version() > 3)
232  transparency = strtol((*keyValues)[9].second.value().c_str(), nullptr, 10);
233 
234  FWDisplayProperties dp(colorIndex, isVisible, transparency);
235 
236  unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), nullptr, 10);
237 
238  //For older configs assume name is the same as purpose
240  if (conf.version() > 1)
241  purpose = (*keyValues)[8].second.value();
242 
243  FWConfiguration* proxyConfig =
244  (FWConfiguration*)conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : nullptr;
245 
246  // beckward compatibilty for obsolete proxy builders
247  if (conf.version() < 6) {
248  assert(proxyConfig == nullptr);
249  if (purpose == "VerticesWithTracks") {
250  purpose = "Vertices";
251  proxyConfig = new FWConfiguration();
252  FWConfiguration vTmp;
253  vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
254  proxyConfig->addKeyValue("Var", vTmp, true);
255  }
256  }
257 
259  TClass::GetClass(type.c_str()),
260  purpose,
261  dp,
262  moduleLabel,
263  productInstanceLabel,
264  processName,
265  filterExpression,
266  layer);
267 
268  newItems.push_back(add(desc, proxyConfig, false));
269  }
270 
271  if (m_event) {
273  for (auto ip : newItems)
274  ip->setEvent(m_event);
275  }
276 }
277 
289  assert(iItem->id() < m_items.size());
290  removingItem_(iItem);
291  m_items[iItem->id()] = nullptr;
292 }
293 
295 
296 //
297 // const member functions
298 //
301 
305  for (size_t i = 0, e = m_items.size(); i != e; ++i) {
306  const FWEventItem* item = m_items[i];
307  if (item && item->name() == iName)
308  return item;
309  }
310  return nullptr;
311 }
312 
313 //
314 // static member functions
315 //
FWModelChangeManager * m_changeManager
void removeItem(const FWEventItem *)
static const std::string kModuleLabel("moduleLabel")
sigc::signal< void(FWEventItem *)> newItem_
unsigned int id() const
Definition: FWEventItem.cc:433
static const std::string kTrue("t")
void setFrom(const FWConfiguration &) override
static Color_t getDefaultStartColorIndex()
bool colorHasIndex(Color_t) const
static const std::string kType("type")
void setContext(fireworks::Context *)
assert(be >=bs)
const FWEventItem * find(const std::string &iName) const
static const std::string kColor("color")
static const std::string kProductInstanceLabel("productInstanceLabel")
U second(std::pair< T, U > const &p)
static const std::string kFilterExpression("filterExpression")
static const std::string kProcessName("processName")
int iEvent
Definition: GenABIO.cc:224
static const std::string kFalse("f")
FWEventItem * add(const FWPhysicsObjectDesc &iItem, const FWConfiguration *pbConf=nullptr, bool doSetEvent=true)
static const std::string kLayer("layer")
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const edm::EventBase * m_event
std::shared_ptr< FWItemAccessorFactory > m_accessorFactory
#define fwLog(_level_)
Definition: fwLog.h:45
static const std::string kTransparency("transparency")
const FWConfiguration * valueForKey(const std::string &iKey) const
sigc::signal< void(const FWEventItem *)> removingItem_
void newEvent(const edm::EventBase *iEvent)
void addTo(FWConfiguration &) const override
static const std::string kIsVisible("isVisible")
static const std::string kPurpose("purpose")
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
fireworks::Context * m_context
std::vector< FWEventItem * > m_items
const_iterator end() const
const KeyValues * keyValues() const
std::vector< FWEventItem * >::const_iterator const_iterator
Color_t oldColorToIndex(Color_t, int version) const
sigc::signal< void()> goingToClearItems_
FWColorManager * colorManager() const
Definition: Context.h:58
FWEventItemsManager(FWModelChangeManager *)
unsigned int version() const