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*
84 FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem, bool showFilteredInTable, const FWConfiguration* pbc)
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, showFilteredInTable, 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 kShowFilteredEntriesInTable("showFilteredEntriesInTable");
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())));
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  conf.addKeyValue(kShowFilteredEntriesInTable, FWConfiguration((*it)->showFilteredEntries() ? kTrue : kFalse));
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 {
209 
211  assert(0!=cm);
212 
213  clearItems();
214  const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
215 
216  if (keyValues == 0) return;
217 
218  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin();
219  it != keyValues->end();
220  ++it)
221  {
222  const std::string& name = it->first;
223  const FWConfiguration& conf = it->second;
224  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
225  assert(0!=keyValues);
226  const std::string& type = (*keyValues)[0].second.value();
227  const std::string& moduleLabel = (*keyValues)[1].second.value();
228  const std::string& productInstanceLabel = (*keyValues)[2].second.value();
229  const std::string& processName = (*keyValues)[3].second.value();
230  const std::string& filterExpression = (*keyValues)[4].second.value();
231  const std::string& sColor = (*keyValues)[5].second.value();
232  const bool isVisible = (*keyValues)[6].second.value() == kTrue;
233 
234  unsigned int colorIndex;
235  if(conf.version() < 5)
236  {
237  std::istringstream is(sColor);
238  Color_t color;
239  is >> color;
240  colorIndex = cm->oldColorToIndex(color, conf.version());
241  }
242  else
243  {
244  // In version 4 we assume:
245  // fireworks colors start at ROOT index 1000
246  // geometry colors start at ROOT index 1100
247  // We save them as such -- no conversions needed.
248  std::istringstream is(sColor);
249  is >> colorIndex;
250  }
251 
252  int transparency = 0;
253 
254  // Read transparency from file. We don't care about checking errors
255  // because strtol returns 0 in that case.
256  if (conf.version() > 3)
257  transparency = strtol((*keyValues)[9].second.value().c_str(), 0, 10);
258 
259  FWDisplayProperties dp(colorIndex, isVisible, true, transparency);
260 
261  unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), 0, 10);
262 
263  //For older configs assume name is the same as purpose
264  std::string purpose(name);
265  if (conf.version() > 1)
266  purpose = (*keyValues)[8].second.value();
267 
268  FWConfiguration* proxyConfig = (FWConfiguration*) conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : 0;
269 
270  // beckward compatibilty for obsolete proxy builders
271  if (conf.version() < 6)
272  {
273  assert(proxyConfig == 0);
274  if (purpose == "VerticesWithTracks")
275  {
276  purpose = "Vertices";
277  proxyConfig = new FWConfiguration();
278  FWConfiguration vTmp; vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
279  proxyConfig->addKeyValue("Var", vTmp,true);
280  }
281  }
282 
283  bool showFilteredInTable = true;
284  if (conf.version() > 6) {
285  showFilteredInTable = (*keyValues)[10].second.value() == kTrue;
286  }
287 
288  FWPhysicsObjectDesc desc(name,
289  TClass::GetClass(type.c_str()),
290  purpose,
291  dp,
292  moduleLabel,
293  productInstanceLabel,
294  processName,
295  filterExpression,
296  layer);
297 
298  add(desc, showFilteredInTable, proxyConfig );
299  }
300 }
301 
312 void
314 {
315  assert(iItem->id() < m_items.size());
316  m_items[iItem->id()] = 0;
317 }
318 
319 void
321 {
322  m_context = iContext;
323 }
324 
325 //
326 // const member functions
327 //
330 {
331  return m_items.begin();
332 }
335 {
336  return m_items.end();
337 }
338 
341 const FWEventItem*
343 {
344  for (size_t i = 0, e = m_items.size(); i != e; ++i)
345  {
346  const FWEventItem *item = m_items[i];
347  if (item && item->name() == iName)
348  return item;
349  }
350  return 0;
351 }
352 
353 //
354 // static member functions
355 //
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:622
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:513
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:507
const FWEventItem * find(const std::string &iName) const
static const std::string kLayer("layer")
static const std::string kShowFilteredEntriesInTable("showFilteredEntriesInTable")
tuple conf
Definition: dbtoconf.py:185
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const edm::EventBase * m_event
const std::string & value(unsigned int iIndex=0) const
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
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
const FWEventItem * add(const FWPhysicsObjectDesc &iItem, bool showFilteredInTable=true, const FWConfiguration *pbConf=0)
void addTo(FWConfiguration &) const
std::vector< FWEventItem * >::const_iterator const_iterator
sigc::signal< void > goingToClearItems_
FWEventItemsManager(FWModelChangeManager *)
const_iterator end() const