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.39 2010/09/16 20:30:51 amraktad Exp $
12 //
13 
14 // system include files
15 #include <sstream>
16 #include <boost/bind.hpp>
17 #include "TClass.h"
18 
19 // user include files
28 
29 //
30 // constants, enums and typedefs
31 //
32 
33 //
34 // static data member definitions
35 //
36 
37 //
38 // constructors and destructor
39 //
41  m_changeManager(iManager),
42  m_context(0),
43  m_event(0),
44  m_accessorFactory(new FWItemAccessorFactory())
45 {
46 }
47 
48 // FWEventItemsManager::FWEventItemsManager(const FWEventItemsManager& rhs)
49 // {
50 // // do actual copying here;
51 // }
52 
60 {
61  for (size_t i = 0, e = m_items.size(); i != e; ++i)
62  delete m_items[i];
63 
64  m_items.clear();
65 }
66 
67 //
68 // assignment operators
69 //
70 // const FWEventItemsManager& FWEventItemsManager::operator=(const FWEventItemsManager& rhs)
71 // {
72 // //An exception safe implementation is
73 // FWEventItemsManager temp(rhs);
74 // swap(rhs);
75 //
76 // return *this;
77 // }
78 
79 //
80 // member functions
81 //
82 const FWEventItem*
84 {
86 
89  fwLog(fwlog::kWarning) << Form("FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n", FWColorManager::getDefaultStartColorIndex());
91  temp.setDisplayProperties(prop);
92  }
93 
94  m_items.push_back(new FWEventItem(m_context,m_items.size(),m_accessorFactory->accessorFor(temp.type()),
95  temp) );
96  newItem_(m_items.back());
97  m_items.back()->goingToBeDestroyed_.connect(boost::bind(&FWEventItemsManager::removeItem,this,_1));
98  if(m_event) {
100  m_items.back()->setEvent(m_event);
101  }
102  return m_items.back();
103 }
104 
108 void
110 {
112  m_event = iEvent;
113  for(size_t i = 0, e = m_items.size(); i != e; ++i)
114  {
115  FWEventItem *item = m_items[i];
116  if(item)
117  item->setEvent(iEvent);
118  }
119 }
120 
126 void
128 {
129  for (size_t i = 0, e = m_items.size(); i != e; ++i)
130  {
131  FWEventItem *item = m_items[i];
132  if (item) {
133  item->destroy();
134  }
135  m_items[i]=0;
136  }
138 
139  m_items.clear();
140 }
141 
142 static const std::string kType("type");
143 static const std::string kModuleLabel("moduleLabel");
144 static const std::string kProductInstanceLabel("productInstanceLabel");
145 static const std::string kProcessName("processName");
146 static const std::string kFilterExpression("filterExpression");
147 static const std::string kColor("color");
148 static const std::string kIsVisible("isVisible");
149 static const std::string kTrue("t");
150 static const std::string kFalse("f");
151 static const std::string kLayer("layer");
152 static const std::string kPurpose("purpose");
153 static const std::string kTransparency("transparency");
154 
155 void
157 {
159  assert(0!=cm);
160  for(std::vector<FWEventItem*>::const_iterator it = m_items.begin();
161  it != m_items.end();
162  ++it)
163  {
164  if(!*it) continue;
166  ROOT::Reflex::Type dataType( ROOT::Reflex::Type::ByTypeInfo(*((*it)->type()->GetTypeInfo())));
167  assert(dataType != ROOT::Reflex::Type() );
168 
169  conf.addKeyValue(kType,FWConfiguration(dataType.Name(ROOT::Reflex::SCOPED)));
170  conf.addKeyValue(kModuleLabel,FWConfiguration((*it)->moduleLabel()));
171  conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
172  conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
173  conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
174  {
175  std::ostringstream os;
176  os << (*it)->defaultDisplayProperties().color();
177  conf.addKeyValue(kColor, FWConfiguration(os.str()));
178  }
179  conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
180  {
181  std::ostringstream os;
182  os << (*it)->layer();
183  conf.addKeyValue(kLayer,FWConfiguration(os.str()));
184  }
185  conf.addKeyValue(kPurpose,(*it)->purpose());
186  {
187  std::ostringstream os;
188  os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
189  conf.addKeyValue(kTransparency, FWConfiguration(os.str()));
190  }
191  iTo.addKeyValue((*it)->name(), conf, true);
192  }
193 }
194 
197 void
199 {
200 
202  assert(0!=cm);
203 
204  clearItems();
205  const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
206  assert(0!=keyValues);
207  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin();
208  it != keyValues->end();
209  ++it)
210  {
211  const std::string& name = it->first;
212  const FWConfiguration& conf = it->second;
213  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
214  assert(0!=keyValues);
215  const std::string& type = (*keyValues)[0].second.value();
216  const std::string& moduleLabel = (*keyValues)[1].second.value();
217  const std::string& productInstanceLabel = (*keyValues)[2].second.value();
218  const std::string& processName = (*keyValues)[3].second.value();
219  const std::string& filterExpression = (*keyValues)[4].second.value();
220  const std::string& sColor = (*keyValues)[5].second.value();
221  const bool isVisible = (*keyValues)[6].second.value() == kTrue;
222 
223  unsigned int colorIndex;
224  if(conf.version() < 5)
225  {
226  std::istringstream is(sColor);
227  Color_t color;
228  is >> color;
229  colorIndex = cm->oldColorToIndex(color, conf.version());
230  }
231  else
232  {
233  // In version 4 we assume:
234  // fireworks colors start at ROOT index 1000
235  // geometry colors start at ROOT index 1100
236  // We save them as such -- no conversions needed.
237  std::istringstream is(sColor);
238  is >> colorIndex;
239  }
240 
241  int transparency = 0;
242 
243  // Read transparency from file. We don't care about checking errors
244  // because strtol returns 0 in that case.
245  if (conf.version() > 3)
246  transparency = strtol((*keyValues)[9].second.value().c_str(), 0, 10);
247 
248  FWDisplayProperties dp(colorIndex, isVisible, transparency);
249 
250  unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), 0, 10);
251 
252  //For older configs assume name is the same as purpose
253  std::string purpose(name);
254  if (conf.version() > 1)
255  purpose = (*keyValues)[8].second.value();
256 
257  FWPhysicsObjectDesc desc(name,
258  TClass::GetClass(type.c_str()),
259  purpose,
260  dp,
261  moduleLabel,
262  productInstanceLabel,
263  processName,
264  filterExpression,
265  layer);
266  add(desc);
267  }
268 }
269 
280 void
282 {
283  assert(iItem->id() < m_items.size());
284  m_items[iItem->id()] = 0;
285 }
286 
287 void
289 {
290  m_context = iContext;
291 }
292 
293 //
294 // const member functions
295 //
298 {
299  return m_items.begin();
300 }
303 {
304  return m_items.end();
305 }
306 
309 const FWEventItem*
310 FWEventItemsManager::find(const std::string& iName) const
311 {
312  for (size_t i = 0, e = m_items.size(); i != e; ++i)
313  {
314  const FWEventItem *item = m_items[i];
315  if (item && item->name() == iName)
316  return item;
317  }
318  return 0;
319 }
320 
321 //
322 // static member functions
323 //
FWModelChangeManager * m_changeManager
type
Definition: HCALResponse.h:22
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
int i
Definition: DBlmapReader.cc:9
const FWEventItem * add(const FWPhysicsObjectDesc &iItem)
const KeyValues * keyValues() const
void destroy() const
Definition: FWEventItem.cc:615
void removeItem(const FWEventItem *)
const FWDisplayProperties & displayProperties() const
static const std::string kModuleLabel("moduleLabel")
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:131
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
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
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
const std::string * moduleLabel() const
Definition: HLTadd.h:40