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 <functional>
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), m_context(nullptr), m_event(nullptr), m_accessorFactory(new FWItemAccessorFactory()) {}
43 
44 // FWEventItemsManager::FWEventItemsManager(const FWEventItemsManager& rhs)
45 // {
46 // // do actual copying here;
47 // }
48 
56  for (size_t i = 0, e = m_items.size(); i != e; ++i)
57  delete m_items[i];
58 
59  m_items.clear();
60 }
61 
62 //
63 // assignment operators
64 //
65 // const FWEventItemsManager& FWEventItemsManager::operator=(const FWEventItemsManager& rhs)
66 // {
67 // //An exception safe implementation is
68 // FWEventItemsManager temp(rhs);
69 // swap(rhs);
70 //
71 // return *this;
72 // }
73 
74 //
75 // member functions
76 //
77 FWEventItem* FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem, const FWConfiguration* pbc, bool doSetEvent) {
79 
80  if (!m_context->colorManager()->colorHasIndex(temp.displayProperties().color())) {
81  FWDisplayProperties prop(temp.displayProperties());
82  fwLog(fwlog::kWarning) << Form(
83  "FWEventItemsManager::add(const FWPhysicsObjectDesc& iItem), color index not valid. Set Color idex to %d\n",
86  temp.setDisplayProperties(prop);
87  }
88 
89  m_items.push_back(new FWEventItem(m_context, m_items.size(), m_accessorFactory->accessorFor(temp.type()), temp, pbc));
90  newItem_(m_items.back());
91  m_items.back()->goingToBeDestroyed_.connect(std::bind(&FWEventItemsManager::removeItem, this, std::placeholders::_1));
92  if (doSetEvent && m_event) {
94  m_items.back()->setEvent(m_event);
95  }
96  return m_items.back();
97 }
98 
104  m_event = iEvent;
105  for (size_t i = 0, e = m_items.size(); i != e; ++i) {
107  if (item)
108  item->setEvent(iEvent);
109  }
110 }
111 
118  for (size_t i = 0, e = m_items.size(); i != e; ++i) {
120  if (item) {
121  item->destroy();
122  }
123  m_items[i] = nullptr;
124  }
126 
127  m_items.clear();
128 }
129 
130 static const std::string kType("type");
131 static const std::string kModuleLabel("moduleLabel");
132 static const std::string kProductInstanceLabel("productInstanceLabel");
133 static const std::string kProcessName("processName");
134 static const std::string kFilterExpression("filterExpression");
135 static const std::string kColor("color");
136 static const std::string kIsVisible("isVisible");
137 static const std::string kTrue("t");
138 static const std::string kFalse("f");
139 static const std::string kLayer("layer");
140 static const std::string kPurpose("purpose");
141 static const std::string kTransparency("transparency");
142 
145  assert(nullptr != cm);
146  for (std::vector<FWEventItem*>::const_iterator it = m_items.begin(); it != m_items.end(); ++it) {
147  if (!*it)
148  continue;
149  FWConfiguration conf(6);
150  edm::TypeWithDict dataType((*((*it)->type()->GetTypeInfo())));
152 
153  conf.addKeyValue(kType, FWConfiguration(dataType.name()));
154  conf.addKeyValue(kModuleLabel, FWConfiguration((*it)->moduleLabel()));
155  conf.addKeyValue(kProductInstanceLabel, FWConfiguration((*it)->productInstanceLabel()));
156  conf.addKeyValue(kProcessName, FWConfiguration((*it)->processName()));
157  conf.addKeyValue(kFilterExpression, FWConfiguration((*it)->filterExpression()));
158  {
159  std::ostringstream os;
160  os << (*it)->defaultDisplayProperties().color();
161  conf.addKeyValue(kColor, FWConfiguration(os.str()));
162  }
163  conf.addKeyValue(kIsVisible, FWConfiguration((*it)->defaultDisplayProperties().isVisible() ? kTrue : kFalse));
164  {
165  std::ostringstream os;
166  os << (*it)->layer();
167  conf.addKeyValue(kLayer, FWConfiguration(os.str()));
168  }
169  conf.addKeyValue(kPurpose, (*it)->purpose());
170  {
171  std::ostringstream os;
172  os << static_cast<int>((*it)->defaultDisplayProperties().transparency());
173  conf.addKeyValue(kTransparency, FWConfiguration(os.str()));
174  }
175 
176  FWConfiguration pbTmp;
177  (*it)->getConfig()->addTo(pbTmp);
178  conf.addKeyValue("PBConfig", pbTmp, true);
179 
180  iTo.addKeyValue((*it)->name(), conf, true);
181  }
182 }
183 
188  assert(nullptr != cm);
189 
190  clearItems();
191  const FWConfiguration::KeyValues* keyValues = iFrom.keyValues();
192 
193  if (keyValues == nullptr)
194  return;
195 
196  std::vector<FWEventItem*> newItems;
197  newItems.reserve(keyValues->size());
198 
199  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin(); it != keyValues->end(); ++it) {
200  const std::string& name = it->first;
201  const FWConfiguration& conf = it->second;
202  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
203  assert(nullptr != keyValues);
204  const std::string& type = (*keyValues)[0].second.value();
205  const std::string& moduleLabel = (*keyValues)[1].second.value();
206  const std::string& productInstanceLabel = (*keyValues)[2].second.value();
207  const std::string& processName = (*keyValues)[3].second.value();
208  const std::string& filterExpression = (*keyValues)[4].second.value();
209  const std::string& sColor = (*keyValues)[5].second.value();
210  const bool isVisible = (*keyValues)[6].second.value() == kTrue;
211 
212  unsigned int colorIndex;
213  if (conf.version() < 5) {
214  std::istringstream is(sColor);
215  Color_t color;
216  is >> color;
217  colorIndex = cm->oldColorToIndex(color, conf.version());
218  } else {
219  // In version 4 we assume:
220  // fireworks colors start at ROOT index 1000
221  // geometry colors start at ROOT index 1100
222  // We save them as such -- no conversions needed.
223  std::istringstream is(sColor);
224  is >> colorIndex;
225  }
226 
227  int transparency = 0;
228 
229  // Read transparency from file. We don't care about checking errors
230  // because strtol returns 0 in that case.
231  if (conf.version() > 3)
232  transparency = strtol((*keyValues)[9].second.value().c_str(), nullptr, 10);
233 
234  FWDisplayProperties dp(colorIndex, isVisible, transparency);
235 
236  unsigned int layer = strtol((*keyValues)[7].second.value().c_str(), nullptr, 10);
237 
238  //For older configs assume name is the same as purpose
240  if (conf.version() > 1)
241  purpose = (*keyValues)[8].second.value();
242 
243  FWConfiguration* proxyConfig =
244  (FWConfiguration*)conf.valueForKey("PBConfig") ? new FWConfiguration(*conf.valueForKey("PBConfig")) : nullptr;
245 
246  // beckward compatibilty for obsolete proxy builders
247  if (conf.version() < 6) {
248  assert(proxyConfig == nullptr);
249  if (purpose == "VerticesWithTracks") {
250  purpose = "Vertices";
251  proxyConfig = new FWConfiguration();
252  FWConfiguration vTmp;
253  vTmp.addKeyValue("Draw Tracks", FWConfiguration("1"));
254  proxyConfig->addKeyValue("Var", vTmp, true);
255  }
256  }
257 
259  TClass::GetClass(type.c_str()),
260  purpose,
261  dp,
262  moduleLabel,
263  productInstanceLabel,
264  processName,
265  filterExpression,
266  layer);
267 
268  newItems.push_back(add(desc, proxyConfig, false));
269  }
270 
271  if (m_event) {
273  for (auto ip : newItems)
274  ip->setEvent(m_event);
275  }
276 }
277 
289  assert(iItem->id() < m_items.size());
290  removingItem_(iItem);
291  m_items[iItem->id()] = nullptr;
292 }
293 
295 
296 //
297 // const member functions
298 //
301 
305  for (size_t i = 0, e = m_items.size(); i != e; ++i) {
306  const FWEventItem* item = m_items[i];
307  if (item && item->name() == iName)
308  return item;
309  }
310  return nullptr;
311 }
312 
313 //
314 // static member functions
315 //
hgcalPlots.purpose
purpose
Definition: hgcalPlots.py:2049
FWModelChangeManager.h
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:428
kType
static const std::string kType("type")
fireworks::Context
Definition: Context.h:41
FWEventItemsManager::add
FWEventItem * add(const FWPhysicsObjectDesc &iItem, const FWConfiguration *pbConf=nullptr, bool doSetEvent=true)
Definition: FWEventItemsManager.cc:77
FWEventItemsManager::newEvent
void newEvent(const edm::EventBase *iEvent)
Definition: FWEventItemsManager.cc:102
fireworks::Context::colorManager
FWColorManager * colorManager() const
Definition: Context.h:58
FWEventItemsManager::clearItems
void clearItems()
Definition: FWEventItemsManager.cc:117
FWEventItemsManager::addTo
void addTo(FWConfiguration &) const override
Definition: FWEventItemsManager.cc:143
FWEventItemsManager::m_context
fireworks::Context * m_context
Definition: FWEventItemsManager.h:86
kTransparency
static const std::string kTransparency("transparency")
FWEventItemsManager::m_items
std::vector< FWEventItem * > m_items
Definition: FWEventItemsManager.h:84
cms::cuda::assert
assert(be >=bs)
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
FWItemAccessorFactory.h
FWEventItem::id
unsigned int id() const
Definition: FWEventItem.cc:433
FWModelChangeManager
Definition: FWModelChangeManager.h:33
FWEventItemsManager::goingToClearItems_
sigc::signal< void > goingToClearItems_
Definition: FWEventItemsManager.h:75
FWItemAccessorFactory
Definition: FWItemAccessorFactory.h:31
FWEventItemsManager::FWEventItemsManager
FWEventItemsManager(FWModelChangeManager *)
Definition: FWEventItemsManager.cc:41
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
DTskim_cfg.dataType
dataType
Definition: DTskim_cfg.py:56
FWConfiguration::KeyValues
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
Definition: FWConfiguration.h:40
kFalse
static const std::string kFalse("f")
kProductInstanceLabel
static const std::string kProductInstanceLabel("productInstanceLabel")
FWEventItemsManager::m_accessorFactory
std::shared_ptr< FWItemAccessorFactory > m_accessorFactory
Definition: FWEventItemsManager.h:89
FWColorManager.h
Calorimetry_cff.dp
dp
Definition: Calorimetry_cff.py:157
kIsVisible
static const std::string kIsVisible("isVisible")
FWChangeSentry
Definition: FWModelChangeManager.h:68
kPurpose
static const std::string kPurpose("purpose")
FWConfiguration::valueForKey
const FWConfiguration * valueForKey(const std::string &iKey) const
Definition: FWConfiguration.cc:122
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWEventItemsManager::setFrom
void setFrom(const FWConfiguration &) override
Definition: FWEventItemsManager.cc:186
edm::TypeWithDict
Definition: TypeWithDict.h:38
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
FWPhysicsObjectDesc
Definition: FWPhysicsObjectDesc.h:30
FWEventItemsManager::end
const_iterator end() const
Definition: FWEventItemsManager.cc:300
FWProxyBuilderConfiguration.h
FWEventItemsManager::removeItem
void removeItem(const FWEventItem *)
Definition: FWEventItemsManager.cc:288
iEvent
int iEvent
Definition: GenABIO.cc:224
FWEventItemsManager::find
const FWEventItem * find(const std::string &iName) const
Definition: FWEventItemsManager.cc:304
FWDisplayProperties.h
FWEventItemsManager::const_iterator
std::vector< FWEventItem * >::const_iterator const_iterator
Definition: FWEventItemsManager.h:50
fwlog::kWarning
Definition: fwLog.h:35
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
fwLog.h
FWColorManager::getDefaultStartColorIndex
static Color_t getDefaultStartColorIndex()
Definition: FWColorManager.cc:38
FWConfiguration::version
unsigned int version() const
Definition: FWConfiguration.h:49
FWColorManager
Definition: FWColorManager.h:45
FWColorManager::oldColorToIndex
Color_t oldColorToIndex(Color_t, int version) const
Definition: FWColorManager.cc:275
FWEventItem.h
FWEventItemsManager::m_changeManager
FWModelChangeManager * m_changeManager
Definition: FWEventItemsManager.h:85
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
FWDisplayProperties
Definition: FWDisplayProperties.h:28
FWConfiguration::addKeyValue
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
Definition: FWConfiguration.cc:58
kModuleLabel
static const std::string kModuleLabel("moduleLabel")
FWEventItemsManager::begin
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
Definition: FWEventItemsManager.cc:299
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
FWEventItem
Definition: FWEventItem.h:56
FWEventItemsManager::setContext
void setContext(fireworks::Context *)
Definition: FWEventItemsManager.cc:294
kTrue
static const std::string kTrue("t")
kProcessName
static const std::string kProcessName("processName")
FWConfiguration::keyValues
const KeyValues * keyValues() const
Definition: FWConfiguration.h:51
edm::EventBase
Definition: EventBase.h:46
FWColorManager::colorHasIndex
bool colorHasIndex(Color_t) const
Definition: FWColorManager.cc:267
FWEventItemsManager::newItem_
sigc::signal< void, FWEventItem * > newItem_
Definition: FWEventItemsManager.h:73
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWEventItemsManager.h
FWConfiguration
Definition: FWConfiguration.h:31
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
kColor
static const std::string kColor("color")
FWEventItemsManager::m_event
const edm::EventBase * m_event
Definition: FWEventItemsManager.h:88
FWEventItemsManager::~FWEventItemsManager
~FWEventItemsManager() override
Definition: FWEventItemsManager.cc:55
kLayer
static const std::string kLayer("layer")
FWConfiguration.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
kFilterExpression
static const std::string kFilterExpression("filterExpression")
FWEventItemsManager::removingItem_
sigc::signal< void, const FWEventItem * > removingItem_
Definition: FWEventItemsManager.h:74