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 <boost/bind.hpp>
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),
43  m_context(0),
44  m_event(0),
45  m_accessorFactory(new FWItemAccessorFactory())
46 {
47 }
48 
49 // FWEventItemsManager::FWEventItemsManager(const FWEventItemsManager& rhs)
50 // {
51 // // do actual copying here;
52 // }
53 
61 {
62  for (size_t i = 0, e = m_items.size(); i != e; ++i)
63  delete m_items[i];
64 
65  m_items.clear();
66 }
67 
68 //
69 // assignment operators
70 //
71 // const FWEventItemsManager& FWEventItemsManager::operator=(const FWEventItemsManager& rhs)
72 // {
73 // //An exception safe implementation is
74 // FWEventItemsManager temp(rhs);
75 // swap(rhs);
76 //
77 // return *this;
78 // }
79 
80 //
81 // member functions
82 //
85  const FWConfiguration* pbc,
86  bool doSetEvent)
87 {
89 
92  fwLog(fwlog::kWarning) << Form("FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n", FWColorManager::getDefaultStartColorIndex());
94  temp.setDisplayProperties(prop);
95  }
96 
97  m_items.push_back(new FWEventItem(m_context,m_items.size(),m_accessorFactory->accessorFor(temp.type()),
98  temp, pbc));
99  newItem_(m_items.back());
100  m_items.back()->goingToBeDestroyed_.connect(boost::bind(&FWEventItemsManager::removeItem,this,_1));
101  if (doSetEvent && m_event)
102  {
104  m_items.back()->setEvent(m_event);
105  }
106  return m_items.back();
107 }
108 
112 void
114 {
116  m_event = iEvent;
117  for(size_t i = 0, e = m_items.size(); i != e; ++i)
118  {
119  FWEventItem *item = m_items[i];
120  if(item)
121  item->setEvent(iEvent);
122  }
123 }
124 
130 void
132 {
133  for (size_t i = 0, e = m_items.size(); i != e; ++i)
134  {
135  FWEventItem *item = m_items[i];
136  if (item) {
137  item->destroy();
138  }
139  m_items[i]=0;
140  }
142 
143  m_items.clear();
144 }
145 
146 static const std::string kType("type");
147 static const std::string kModuleLabel("moduleLabel");
148 static const std::string kProductInstanceLabel("productInstanceLabel");
149 static const std::string kProcessName("processName");
150 static const std::string kFilterExpression("filterExpression");
151 static const std::string kColor("color");
152 static const std::string kIsVisible("isVisible");
153 static const std::string kTrue("t");
154 static const std::string kFalse("f");
155 static const std::string kLayer("layer");
156 static const std::string kPurpose("purpose");
157 static const std::string kTransparency("transparency");
158 
159 void
161 {
163  assert(0!=cm);
164  for(std::vector<FWEventItem*>::const_iterator it = m_items.begin();
165  it != m_items.end();
166  ++it)
167  {
168  if(!*it) continue;
169  FWConfiguration conf(6);
170  edm::TypeWithDict dataType((*((*it)->type()->GetTypeInfo())));
171  assert(dataType != edm::TypeWithDict() );
172 
174  conf.addKeyValue(kModuleLabel,FWConfiguration((*it)->moduleLabel()));
175  conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
176  conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
177  conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
178  {
179  std::ostringstream os;
180  os << (*it)->defaultDisplayProperties().color();
181  conf.addKeyValue(kColor, FWConfiguration(os.str()));
182  }
183  conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
184  {
185  std::ostringstream os;
186  os << (*it)->layer();
187  conf.addKeyValue(kLayer,FWConfiguration(os.str()));
188  }
189  conf.addKeyValue(kPurpose,(*it)->purpose());
190  {
191  std::ostringstream os;
192  os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
193  conf.addKeyValue(kTransparency, FWConfiguration(os.str()));
194  }
195 
196  FWConfiguration pbTmp;
197  (*it)->getConfig()->addTo(pbTmp);
198  conf.addKeyValue("PBConfig",pbTmp, true);
199 
200  iTo.addKeyValue((*it)->name(), conf, true);
201  }
202 }
203 
206 void
208 {
210  assert(0!=cm);
211 
212  clearItems();
213  const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
214 
215  if (keyValues == 0) return;
216 
217  std::vector<FWEventItem*> newItems;
218  newItems.reserve(keyValues->size());
219 
220  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin();
221  it != keyValues->end();
222  ++it)
223  {
224  const std::string& name = it->first;
225  const FWConfiguration& conf = it->second;
226  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
227  assert(0!=keyValues);
228  const std::string& type = (*keyValues)[0].second.value();
229  const std::string& moduleLabel = (*keyValues)[1].second.value();
230  const std::string& productInstanceLabel = (*keyValues)[2].second.value();
231  const std::string& processName = (*keyValues)[3].second.value();
232  const std::string& filterExpression = (*keyValues)[4].second.value();
233  const std::string& sColor = (*keyValues)[5].second.value();
234  const bool isVisible = (*keyValues)[6].second.value() == kTrue;
235 
236  unsigned int colorIndex;
237  if(conf.version() < 5)
238  {
239  std::istringstream is(sColor);
240  Color_t color;
241  is >> color;
242  colorIndex = cm->oldColorToIndex(color, conf.version());
243  }
244  else
245  {
246  // In version 4 we assume:
247  // fireworks colors start at ROOT index 1000
248  // geometry colors start at ROOT index 1100
249  // We save them as such -- no conversions needed.
250  std::istringstream is(sColor);
251  is >> colorIndex;
252  }
253 
254  int transparency = 0;
255 
256  // Read transparency from file. We don't care about checking errors
257  // because strtol returns 0 in that case.
258  if (conf.version() > 3)
259  transparency = strtol((*keyValues)[9].second.value().c_str(), 0, 10);
260 
261  FWDisplayProperties dp(colorIndex, isVisible, transparency);
262 
263  unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), 0, 10);
264 
265  //For older configs assume name is the same as purpose
266  std::string purpose(name);
267  if (conf.version() > 1)
268  purpose = (*keyValues)[8].second.value();
269 
270  FWConfiguration* proxyConfig = (FWConfiguration*) conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : 0;
271 
272  // beckward compatibilty for obsolete proxy builders
273  if (conf.version() < 6)
274  {
275  assert(proxyConfig == 0);
276  if (purpose == "VerticesWithTracks")
277  {
278  purpose = "Vertices";
279  proxyConfig = new FWConfiguration();
280  FWConfiguration vTmp; vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
281  proxyConfig->addKeyValue("Var", vTmp,true);
282  }
283  }
284 
285  FWPhysicsObjectDesc desc(name,
286  TClass::GetClass(type.c_str()),
287  purpose,
288  dp,
289  moduleLabel,
290  productInstanceLabel,
291  processName,
292  filterExpression,
293  layer);
294 
295  newItems.push_back( add(desc, proxyConfig, false) );
296  }
297 
298  if (m_event)
299  {
301  for (auto ip : newItems)
302  ip->setEvent(m_event);
303  }
304 }
305 
316 void
318 {
319  assert(iItem->id() < m_items.size());
320  removingItem_(iItem);
321  m_items[iItem->id()] = 0;
322 }
323 
324 void
326 {
327  m_context = iContext;
328 }
329 
330 //
331 // const member functions
332 //
335 {
336  return m_items.begin();
337 }
340 {
341  return m_items.end();
342 }
343 
346 const FWEventItem*
348 {
349  for (size_t i = 0, e = m_items.size(); i != e; ++i)
350  {
351  const FWEventItem *item = m_items[i];
352  if (item && item->name() == iName)
353  return item;
354  }
355  return 0;
356 }
357 
358 //
359 // static member functions
360 //
FWModelChangeManager * m_changeManager
type
Definition: HCALResponse.h:21
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
const KeyValues * keyValues() const
void destroy() const
Definition: FWEventItem.cc:610
void removeItem(const FWEventItem *)
const FWDisplayProperties & displayProperties() const
static const std::string kModuleLabel("moduleLabel")
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:122
const std::string & name() const
Definition: FWEventItem.cc:502
void setFrom(const FWConfiguration &)
FWColorManager * colorManager() const
Definition: Context.h:65
static const std::string kTrue("t")
static Color_t getDefaultStartColorIndex()
unsigned int version() const
Color_t oldColorToIndex(Color_t, int version) const
static const std::string kType("type")
void setContext(fireworks::Context *)
const TClass * type() const
sigc::signal< void, const FWEventItem * > removingItem_
FWEventItem * add(const FWPhysicsObjectDesc &iItem, const FWConfiguration *pbConf=0, bool doSetEvent=true)
bool colorHasIndex(Color_t) const
static const std::string kColor("color")
Color_t color() const
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:230
static const std::string kFalse("f")
void setDisplayProperties(const FWDisplayProperties &)
sigc::signal< void, FWEventItem * > newItem_
unsigned int id() const
Definition: FWEventItem.cc:496
const FWEventItem * find(const std::string &iName) const
static const std::string kLayer("layer")
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const edm::EventBase * m_event
std::shared_ptr< FWItemAccessorFactory > m_accessorFactory
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
#define fwLog(_level_)
Definition: fwLog.h:50
auto dp
Definition: deltaR.h:22
static const std::string kTransparency("transparency")
void newEvent(const edm::EventBase *iEvent)
static const std::string kIsVisible("isVisible")
static const std::string kPurpose("purpose")
fireworks::Context * m_context
const FWConfiguration * valueForKey(const std::string &iKey) const
std::vector< FWEventItem * > m_items
void addTo(FWConfiguration &) const
std::vector< FWEventItem * >::const_iterator const_iterator
sigc::signal< void > goingToClearItems_
FWEventItemsManager(FWModelChangeManager *)
const_iterator end() const