CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: FWEventItemsManager.cc,v 1.49 2013/01/25 19:44:03 wmtan Exp $
12 //
13 
14 // system include files
15 #include <sstream>
16 #include <boost/bind.hpp>
17 #include "TClass.h"
18 
19 // user include files
29 #include <cassert>
30 
31 //
32 // constants, enums and typedefs
33 //
34 
35 //
36 // static data member definitions
37 //
38 
39 //
40 // constructors and destructor
41 //
43  m_changeManager(iManager),
44  m_context(0),
45  m_event(0),
46  m_accessorFactory(new FWItemAccessorFactory())
47 {
48 }
49 
50 // FWEventItemsManager::FWEventItemsManager(const FWEventItemsManager& rhs)
51 // {
52 // // do actual copying here;
53 // }
54 
62 {
63  for (size_t i = 0, e = m_items.size(); i != e; ++i)
64  delete m_items[i];
65 
66  m_items.clear();
67 }
68 
69 //
70 // assignment operators
71 //
72 // const FWEventItemsManager& FWEventItemsManager::operator=(const FWEventItemsManager& rhs)
73 // {
74 // //An exception safe implementation is
75 // FWEventItemsManager temp(rhs);
76 // swap(rhs);
77 //
78 // return *this;
79 // }
80 
81 //
82 // member functions
83 //
84 const FWEventItem*
86 {
88 
91  fwLog(fwlog::kWarning) << Form("FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n", FWColorManager::getDefaultStartColorIndex());
93  temp.setDisplayProperties(prop);
94  }
95 
96  m_items.push_back(new FWEventItem(m_context,m_items.size(),m_accessorFactory->accessorFor(temp.type()),
97  temp, pbc));
98  newItem_(m_items.back());
99  m_items.back()->goingToBeDestroyed_.connect(boost::bind(&FWEventItemsManager::removeItem,this,_1));
100  if(m_event) {
102  m_items.back()->setEvent(m_event);
103  }
104  return m_items.back();
105 }
106 
110 void
112 {
114  m_event = iEvent;
115  for(size_t i = 0, e = m_items.size(); i != e; ++i)
116  {
117  FWEventItem *item = m_items[i];
118  if(item)
119  item->setEvent(iEvent);
120  }
121 }
122 
128 void
130 {
131  for (size_t i = 0, e = m_items.size(); i != e; ++i)
132  {
133  FWEventItem *item = m_items[i];
134  if (item) {
135  item->destroy();
136  }
137  m_items[i]=0;
138  }
140 
141  m_items.clear();
142 }
143 
144 static const std::string kType("type");
145 static const std::string kModuleLabel("moduleLabel");
146 static const std::string kProductInstanceLabel("productInstanceLabel");
147 static const std::string kProcessName("processName");
148 static const std::string kFilterExpression("filterExpression");
149 static const std::string kColor("color");
150 static const std::string kIsVisible("isVisible");
151 static const std::string kTrue("t");
152 static const std::string kFalse("f");
153 static const std::string kLayer("layer");
154 static const std::string kPurpose("purpose");
155 static const std::string kTransparency("transparency");
156 
157 void
159 {
161  assert(0!=cm);
162  for(std::vector<FWEventItem*>::const_iterator it = m_items.begin();
163  it != m_items.end();
164  ++it)
165  {
166  if(!*it) continue;
168  edm::TypeWithDict dataType((*((*it)->type()->GetTypeInfo())));
169  assert(dataType != edm::TypeWithDict() );
170 
172  conf.addKeyValue(kModuleLabel,FWConfiguration((*it)->moduleLabel()));
173  conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
174  conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
175  conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
176  {
177  std::ostringstream os;
178  os << (*it)->defaultDisplayProperties().color();
179  conf.addKeyValue(kColor, FWConfiguration(os.str()));
180  }
181  conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
182  {
183  std::ostringstream os;
184  os << (*it)->layer();
185  conf.addKeyValue(kLayer,FWConfiguration(os.str()));
186  }
187  conf.addKeyValue(kPurpose,(*it)->purpose());
188  {
189  std::ostringstream os;
190  os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
191  conf.addKeyValue(kTransparency, FWConfiguration(os.str()));
192  }
193 
194  FWConfiguration pbTmp;
195  (*it)->getConfig()->addTo(pbTmp);
196  conf.addKeyValue("PBConfig",pbTmp, true);
197 
198  iTo.addKeyValue((*it)->name(), conf, true);
199  }
200 }
201 
204 void
206 {
207 
209  assert(0!=cm);
210 
211  clearItems();
212  const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
213 
214  if (keyValues == 0) return;
215 
216  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin();
217  it != keyValues->end();
218  ++it)
219  {
220  const std::string& name = it->first;
221  const FWConfiguration& conf = it->second;
222  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
223  assert(0!=keyValues);
224  const std::string& type = (*keyValues)[0].second.value();
225  const std::string& moduleLabel = (*keyValues)[1].second.value();
226  const std::string& productInstanceLabel = (*keyValues)[2].second.value();
227  const std::string& processName = (*keyValues)[3].second.value();
228  const std::string& filterExpression = (*keyValues)[4].second.value();
229  const std::string& sColor = (*keyValues)[5].second.value();
230  const bool isVisible = (*keyValues)[6].second.value() == kTrue;
231 
232  unsigned int colorIndex;
233  if(conf.version() < 5)
234  {
235  std::istringstream is(sColor);
236  Color_t color;
237  is >> color;
238  colorIndex = cm->oldColorToIndex(color, conf.version());
239  }
240  else
241  {
242  // In version 4 we assume:
243  // fireworks colors start at ROOT index 1000
244  // geometry colors start at ROOT index 1100
245  // We save them as such -- no conversions needed.
246  std::istringstream is(sColor);
247  is >> colorIndex;
248  }
249 
250  int transparency = 0;
251 
252  // Read transparency from file. We don't care about checking errors
253  // because strtol returns 0 in that case.
254  if (conf.version() > 3)
255  transparency = strtol((*keyValues)[9].second.value().c_str(), 0, 10);
256 
257  FWDisplayProperties dp(colorIndex, isVisible, transparency);
258 
259  unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), 0, 10);
260 
261  //For older configs assume name is the same as purpose
262  std::string purpose(name);
263  if (conf.version() > 1)
264  purpose = (*keyValues)[8].second.value();
265 
266  FWConfiguration* proxyConfig = (FWConfiguration*) conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : 0;
267 
268  // beckward compatibilty for obsolete proxy builders
269  if (conf.version() < 6)
270  {
271  assert(proxyConfig == 0);
272  if (purpose == "VerticesWithTracks")
273  {
274  purpose = "Vertices";
275  proxyConfig = new FWConfiguration();
276  FWConfiguration vTmp; vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
277  proxyConfig->addKeyValue("Var", vTmp,true);
278  }
279  }
280 
281  FWPhysicsObjectDesc desc(name,
282  TClass::GetClass(type.c_str()),
283  purpose,
284  dp,
285  moduleLabel,
286  productInstanceLabel,
287  processName,
288  filterExpression,
289  layer);
290 
291  add(desc, proxyConfig );
292  }
293 }
294 
305 void
307 {
308  assert(iItem->id() < m_items.size());
309  m_items[iItem->id()] = 0;
310 }
311 
312 void
314 {
315  m_context = iContext;
316 }
317 
318 //
319 // const member functions
320 //
323 {
324  return m_items.begin();
325 }
328 {
329  return m_items.end();
330 }
331 
334 const FWEventItem*
336 {
337  for (size_t i = 0, e = m_items.size(); i != e; ++i)
338  {
339  const FWEventItem *item = m_items[i];
340  if (item && item->name() == iName)
341  return item;
342  }
343  return 0;
344 }
345 
346 //
347 // static member functions
348 //
FWModelChangeManager * m_changeManager
type
Definition: HCALResponse.h:21
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
int i
Definition: DBlmapReader.cc:9
const KeyValues * keyValues() const
void destroy() const
Definition: FWEventItem.cc:609
void removeItem(const FWEventItem *)
const FWDisplayProperties & displayProperties() const
static const std::string kModuleLabel("moduleLabel")
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:121
const std::string & name() const
Definition: FWEventItem.cc:501
boost::shared_ptr< FWItemAccessorFactory > m_accessorFactory
void setFrom(const FWConfiguration &)
FWColorManager * colorManager() const
Definition: Context.h:66
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
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:243
static const std::string kFalse("f")
void setDisplayProperties(const FWDisplayProperties &)
sigc::signal< void, FWEventItem * > newItem_
unsigned int id() const
Definition: FWEventItem.cc:495
const FWEventItem * find(const std::string &iName) const
static const std::string kLayer("layer")
tuple conf
Definition: dbtoconf.py:185
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const edm::EventBase * m_event
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:51
auto dp
Definition: deltaR.h:24
static const std::string kTransparency("transparency")
void newEvent(const edm::EventBase *iEvent)
const FWEventItem * add(const FWPhysicsObjectDesc &iItem, const FWConfiguration *pbConf=0)
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