test
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 //
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 //
83 const FWEventItem*
85 {
87 
90  fwLog(fwlog::kWarning) << Form("FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n", FWColorManager::getDefaultStartColorIndex());
92  temp.setDisplayProperties(prop);
93  }
94 
95  m_items.push_back(new FWEventItem(m_context,m_items.size(),m_accessorFactory->accessorFor(temp.type()),
96  temp, pbc));
97  newItem_(m_items.back());
98  m_items.back()->goingToBeDestroyed_.connect(boost::bind(&FWEventItemsManager::removeItem,this,_1));
99  if(m_event) {
101  m_items.back()->setEvent(m_event);
102  }
103  return m_items.back();
104 }
105 
109 void
111 {
113  m_event = iEvent;
114  for(size_t i = 0, e = m_items.size(); i != e; ++i)
115  {
116  FWEventItem *item = m_items[i];
117  if(item)
118  item->setEvent(iEvent);
119  }
120 }
121 
127 void
129 {
130  for (size_t i = 0, e = m_items.size(); i != e; ++i)
131  {
132  FWEventItem *item = m_items[i];
133  if (item) {
134  item->destroy();
135  }
136  m_items[i]=0;
137  }
139 
140  m_items.clear();
141 }
142 
143 static const std::string kType("type");
144 static const std::string kModuleLabel("moduleLabel");
145 static const std::string kProductInstanceLabel("productInstanceLabel");
146 static const std::string kProcessName("processName");
147 static const std::string kFilterExpression("filterExpression");
148 static const std::string kColor("color");
149 static const std::string kIsVisible("isVisible");
150 static const std::string kTrue("t");
151 static const std::string kFalse("f");
152 static const std::string kLayer("layer");
153 static const std::string kPurpose("purpose");
154 static const std::string kTransparency("transparency");
155 
156 void
158 {
160  assert(0!=cm);
161  for(std::vector<FWEventItem*>::const_iterator it = m_items.begin();
162  it != m_items.end();
163  ++it)
164  {
165  if(!*it) continue;
166  FWConfiguration conf(6);
167  edm::TypeWithDict dataType((*((*it)->type()->GetTypeInfo())));
169 
171  conf.addKeyValue(kModuleLabel,FWConfiguration((*it)->moduleLabel()));
172  conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
173  conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
174  conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
175  {
176  std::ostringstream os;
177  os << (*it)->defaultDisplayProperties().color();
178  conf.addKeyValue(kColor, FWConfiguration(os.str()));
179  }
180  conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
181  {
182  std::ostringstream os;
183  os << (*it)->layer();
184  conf.addKeyValue(kLayer,FWConfiguration(os.str()));
185  }
186  conf.addKeyValue(kPurpose,(*it)->purpose());
187  {
188  std::ostringstream os;
189  os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
190  conf.addKeyValue(kTransparency, FWConfiguration(os.str()));
191  }
192 
193  FWConfiguration pbTmp;
194  (*it)->getConfig()->addTo(pbTmp);
195  conf.addKeyValue("PBConfig",pbTmp, true);
196 
197  iTo.addKeyValue((*it)->name(), conf, true);
198  }
199 }
200 
203 void
205 {
206 
208  assert(0!=cm);
209 
210  clearItems();
211  const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
212 
213  if (keyValues == 0) return;
214 
215  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin();
216  it != keyValues->end();
217  ++it)
218  {
219  const std::string& name = it->first;
220  const FWConfiguration& conf = it->second;
221  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
222  assert(0!=keyValues);
223  const std::string& type = (*keyValues)[0].second.value();
224  const std::string& moduleLabel = (*keyValues)[1].second.value();
225  const std::string& productInstanceLabel = (*keyValues)[2].second.value();
226  const std::string& processName = (*keyValues)[3].second.value();
227  const std::string& filterExpression = (*keyValues)[4].second.value();
228  const std::string& sColor = (*keyValues)[5].second.value();
229  const bool isVisible = (*keyValues)[6].second.value() == kTrue;
230 
231  unsigned int colorIndex;
232  if(conf.version() < 5)
233  {
234  std::istringstream is(sColor);
235  Color_t color;
236  is >> color;
237  colorIndex = cm->oldColorToIndex(color, conf.version());
238  }
239  else
240  {
241  // In version 4 we assume:
242  // fireworks colors start at ROOT index 1000
243  // geometry colors start at ROOT index 1100
244  // We save them as such -- no conversions needed.
245  std::istringstream is(sColor);
246  is >> colorIndex;
247  }
248 
249  int transparency = 0;
250 
251  // Read transparency from file. We don't care about checking errors
252  // because strtol returns 0 in that case.
253  if (conf.version() > 3)
254  transparency = strtol((*keyValues)[9].second.value().c_str(), 0, 10);
255 
256  FWDisplayProperties dp(colorIndex, isVisible, transparency);
257 
258  unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), 0, 10);
259 
260  //For older configs assume name is the same as purpose
261  std::string purpose(name);
262  if (conf.version() > 1)
263  purpose = (*keyValues)[8].second.value();
264 
265  FWConfiguration* proxyConfig = (FWConfiguration*) conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : 0;
266 
267  // beckward compatibilty for obsolete proxy builders
268  if (conf.version() < 6)
269  {
270  assert(proxyConfig == 0);
271  if (purpose == "VerticesWithTracks")
272  {
273  purpose = "Vertices";
274  proxyConfig = new FWConfiguration();
275  FWConfiguration vTmp; vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
276  proxyConfig->addKeyValue("Var", vTmp,true);
277  }
278  }
279 
280  FWPhysicsObjectDesc desc(name,
281  TClass::GetClass(type.c_str()),
282  purpose,
283  dp,
284  moduleLabel,
285  productInstanceLabel,
286  processName,
287  filterExpression,
288  layer);
289 
290  add(desc, proxyConfig );
291  }
292 }
293 
304 void
306 {
307  assert(iItem->id() < m_items.size());
308  m_items[iItem->id()] = 0;
309 }
310 
311 void
313 {
314  m_context = iContext;
315 }
316 
317 //
318 // const member functions
319 //
322 {
323  return m_items.begin();
324 }
327 {
328  return m_items.end();
329 }
330 
333 const FWEventItem*
335 {
336  for (size_t i = 0, e = m_items.size(); i != e; ++i)
337  {
338  const FWEventItem *item = m_items[i];
339  if (item && item->name() == iName)
340  return item;
341  }
342  return 0;
343 }
344 
345 //
346 // static member functions
347 //
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: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
boost::shared_ptr< FWItemAccessorFactory > m_accessorFactory
void setFrom(const FWConfiguration &)
FWColorManager * colorManager() const
Definition: Context.h:65
assert(m_qm.get())
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: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
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)
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