EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHHepMCGenEventMap.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHHepMCGenEventMap.cc
1 #include "PHHepMCGenEventMap.h"
2 
3 #include "PHHepMCGenEvent.h"
4 
5 #include <TSystem.h>
6 
7 #include <cassert>
8 #include <cstdlib> // for exit
9 #include <iterator> // for reverse_iterator
10 #include <utility> // for pair, make_pair
11 
13 {
14  for( const auto& pair:eventmap.get_map() )
15  { _map.insert(std::make_pair(pair.first, static_cast<PHHepMCGenEvent*>(pair.second->CloneMe()))); }
16 }
17 
19 {
20  Reset();
21  for( const auto& pair:eventmap.get_map() )
22  { _map.insert(std::make_pair(pair.first, static_cast<PHHepMCGenEvent*>(pair.second->CloneMe()))); }
23  return *this;
24 }
25 
27 {
28  Reset();
29 }
30 
32 {
33  // delete all events
34  for( const auto& pair:_map )
35  {
36  delete pair.second;
37  }
38 
39  // clear map
40  _map.clear();
41 }
42 
43 void PHHepMCGenEventMap::identify(std::ostream& os) const
44 {
45  os << "PHHepMCGenEventMap: size = " << _map.size() << std::endl;
46 
47  for (const auto& evt : _map)
48  {
49  std::cout << "Event[" << evt.first << "] : ";
50  assert(evt.second);
51  evt.second->identify();
52  }
53 
54  return;
55 }
56 
58 {
59  ConstIter iter = _map.find(id);
60  if (iter == _map.end()) return nullptr;
61  return iter->second;
62 }
63 
65 {
66  Iter iter = _map.find(id);
67  if (iter == _map.end()) return nullptr;
68  return iter->second;
69 }
70 
72 {
73  const int index = _map.empty() ? 1 : (_map.rbegin()->first+1);
74  auto newEvent = event ? static_cast<PHHepMCGenEvent*>(event->CloneMe()): new PHHepMCGenEvent();
75  newEvent->set_embedding_id(index);
76  _map.insert(std::make_pair(index,newEvent));
77  return newEvent;
78 }
79 
81 {
82  const int index = _map.empty() ? -1 : (_map.begin()->first-1);
83  auto newEvent = event ? static_cast<PHHepMCGenEvent*>(event->CloneMe()): new PHHepMCGenEvent();
84  newEvent->set_embedding_id(index);
85  _map.insert(std::make_pair(index,newEvent));
86  return newEvent;
87 }
88 
90 {
91  auto newEvent = event ? static_cast<PHHepMCGenEvent*>(event->CloneMe()): new PHHepMCGenEvent();
92  newEvent->set_embedding_id(index);
93  auto ret = _map.insert(std::make_pair(index, newEvent ));
94  if (ret.second == false)
95  {
96  std::cout
97  << "PHHepMCGenEventMap::insert_event - Fatal Error -"
98  << "embedding ID " << index << " is already used in the PHHepMCGenEventMap. Print map:";
99  identify();
100  gSystem->Exit(10);
101  }
102  return newEvent;
103 }