LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LArVoxelList.h
Go to the documentation of this file.
1 
57 
58 #ifndef LARVOXELLIST_H
59 #define LARVOXELLIST_H
60 
63 
64 #include <map>
65 
66 namespace sim {
67 
69  {
70  public:
74  typedef std::map<LArVoxelID, LArVoxelData> list_type;
75  typedef list_type::key_type key_type;
76  typedef list_type::mapped_type mapped_type;
77  typedef list_type::value_type value_type;
80  typedef list_type::reverse_iterator reverse_iterator;
81  typedef list_type::const_reverse_iterator const_reverse_iterator;
82  typedef list_type::size_type size_type;
83  typedef list_type::difference_type difference_type;
84  typedef list_type::key_compare key_compare;
85  typedef list_type::allocator_type allocator_type;
86 
87  // Standard constructor and destructor.
88  LArVoxelList();
89  virtual ~LArVoxelList();
90 
91  // Add the energy to the entry with the key; if the key doesn't
92  // exist, create it. Allow the addition both with and without a
93  // particle's track ID for LArVoxelData.
94  void Add( const key_type& key, const double& energy ) { m_voxelList[key].Add(energy); }
95  void Add( const key_type& key, const double& energy, const int& id ) { m_voxelList[key].Add(energy,id); }
96 
97  // The arithmetic methods "advertised" in the class description
98  // above.
99  void Add( const LArVoxelList& );
101  {
102  this->Add(other);
103  return *this;
104  }
106  {
107  return LArVoxelList(*this) += other;
108  }
109 
110  LArVoxelList& operator*=( const double& value );
111  const LArVoxelList operator* (const double& value) const
112  {
113  return LArVoxelList(*this) *= value;
114  }
115  // Just in case: define the result of "scalar * LArVoxelList" to be
116  // the same as "LArVoxelList * scalar".
117  friend const LArVoxelList operator*(const double& value, const LArVoxelList& list);
118 
119  // Apply a threshold cut to the voxels in the list, removing all
120  // those that fall below the cut.
121  void Cut( const double& );
122 
123  const key_type& ID( const size_type ) const;
124  double Energy( const size_type ) const;
125 
126  friend std::ostream& operator<< ( std::ostream& output, const LArVoxelList& );
127 
128  // Standard STL methods, to make this class look like an STL map.
129  // Again, if you don't know STL, you can just ignore these
130  // methods.
131  iterator begin() { return m_voxelList.begin(); }
132  const_iterator begin() const { return m_voxelList.begin(); }
133  iterator end() { return m_voxelList.end(); }
134  const_iterator end() const { return m_voxelList.end(); }
135  reverse_iterator rbegin() { return m_voxelList.rbegin(); }
136  const_reverse_iterator rbegin() const { return m_voxelList.rbegin(); }
137  reverse_iterator rend() { return m_voxelList.rend(); }
138  const_reverse_iterator rend() const { return m_voxelList.rend(); }
139 
140  size_type size() const { return m_voxelList.size(); }
141  bool empty() const { return m_voxelList.empty(); }
142  void swap( LArVoxelList& other ) { m_voxelList.swap( other.m_voxelList ); }
143  void clear() { m_voxelList.clear(); }
144 
145  iterator find(const key_type& key) { return m_voxelList.find(key); }
146  const_iterator find(const key_type& key) const { return m_voxelList.find(key); }
147  iterator upper_bound(const key_type& key) { return m_voxelList.upper_bound(key); }
148  const_iterator upper_bound(const key_type& key) const { return m_voxelList.upper_bound(key); }
149  iterator lower_bound(const key_type& key) { return m_voxelList.lower_bound(key); }
150  const_iterator lower_bound(const key_type& key) const { return m_voxelList.lower_bound(key); }
151 
152  mapped_type& operator[](const key_type& key) { return m_voxelList[key]; }
153  // My own little addition: operator[] in a const context.
154  const mapped_type& operator[]( const key_type& key ) const { return m_voxelList.at(key); }
155  mapped_type& at(const key_type& key) { return m_voxelList.at(key); }
156  const mapped_type& at(const key_type& key) const { return m_voxelList.at(key); }
157 
158  // In addition to operator[], include one insert() method for
159  // anyone who wants to include a LArVoxelID / LArVoxelData pair
160  // directly. Note that, as with operator[], there's no check
161  // against overwriting an existing item.
162  void insert( const key_type& key, const mapped_type& value ) { m_voxelList[key] = value; }
163 
164  size_type erase( const key_type& key ) { return m_voxelList.erase(key); }
165 
166  private:
167  list_type m_voxelList;
168 
169  };
170 
171 } // namespace sim
172 
173 #endif // LARVOXELLIST_H
174 
const LArVoxelList operator*(const double &value) const
Definition: LArVoxelList.h:111
const mapped_type & at(const key_type &key) const
Definition: LArVoxelList.h:156
list_type::mapped_type mapped_type
Definition: LArVoxelList.h:76
intermediate_table::iterator iterator
size_type size() const
Definition: LArVoxelList.h:140
void insert(const key_type &key, const mapped_type &value)
Definition: LArVoxelList.h:162
list_type::reverse_iterator reverse_iterator
Definition: LArVoxelList.h:80
reverse_iterator rbegin()
Definition: LArVoxelList.h:135
void swap(LArVoxelList &other)
Definition: LArVoxelList.h:142
list_type::key_compare key_compare
Definition: LArVoxelList.h:84
list_type m_voxelList
A sorted list of <LArVoxelID,double> pairs = (voxel ID, energy)
Definition: LArVoxelList.h:167
const mapped_type & operator[](const key_type &key) const
Definition: LArVoxelList.h:154
std::map< LArVoxelID, LArVoxelData > list_type
Definition: LArVoxelList.h:74
iterator begin()
Definition: LArVoxelList.h:131
LArVoxelList & operator+=(const LArVoxelList &other)
Definition: LArVoxelList.h:100
void Add(const key_type &key, const double &energy, const int &id)
Definition: LArVoxelList.h:95
list_type::const_iterator const_iterator
Definition: LArVoxelList.h:79
friend std::ostream & operator<<(std::ostream &output, const LArVoxelList &)
double Energy(const size_type) const
list_type::value_type value_type
Definition: LArVoxelList.h:77
intermediate_table::const_iterator const_iterator
Encapsulates the information we want store for a voxel.
list_type::const_reverse_iterator const_reverse_iterator
Definition: LArVoxelList.h:81
iterator find(const key_type &key)
Definition: LArVoxelList.h:145
double energy
Definition: plottest35.C:25
list_type::difference_type difference_type
Definition: LArVoxelList.h:83
reverse_iterator rend()
Definition: LArVoxelList.h:137
bool empty() const
Definition: LArVoxelList.h:141
void Cut(const double &)
Apply an energy cut to the voxels.
list_type::iterator iterator
Definition: LArVoxelList.h:78
Monte Carlo Simulation.
iterator upper_bound(const key_type &key)
Definition: LArVoxelList.h:147
const_iterator upper_bound(const key_type &key) const
Definition: LArVoxelList.h:148
const_iterator begin() const
Definition: LArVoxelList.h:132
list_type::size_type size_type
Definition: LArVoxelList.h:82
LArVoxelList & operator*=(const double &value)
const_iterator find(const key_type &key) const
Definition: LArVoxelList.h:146
std::string value(boost::any const &)
const_iterator end() const
Definition: LArVoxelList.h:134
list_type::key_type key_type
Definition: LArVoxelList.h:75
const_reverse_iterator rbegin() const
Definition: LArVoxelList.h:136
const_iterator lower_bound(const key_type &key) const
Definition: LArVoxelList.h:150
size_type erase(const key_type &key)
Definition: LArVoxelList.h:164
void Add(const key_type &key, const double &energy)
Definition: LArVoxelList.h:94
iterator lower_bound(const key_type &key)
Definition: LArVoxelList.h:149
mapped_type & at(const key_type &key)
Definition: LArVoxelList.h:155
const key_type & ID(const size_type) const
mapped_type & operator[](const key_type &key)
Definition: LArVoxelList.h:152
Unique identifier for a given LAr voxel.
const_reverse_iterator rend() const
Definition: LArVoxelList.h:138
list_type::allocator_type allocator_type
Definition: LArVoxelList.h:85
const LArVoxelList operator+(const LArVoxelList &other) const
Definition: LArVoxelList.h:105
virtual ~LArVoxelList()