OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
IndexMap.h
Go to the documentation of this file.
1//
2// Class IndexMap
3//
4// This class stores and prints the sequence of elements that the referenc particle passes.
5// Each time the reference particle enters or leaves an element an entry is added to the map.
6// With help of this map one can determine which element can be found at a given position.
7//
8// Copyright (c) 2016, Christof Metzger-Kraus, Helmholtz-Zentrum Berlin, Germany
9// 2017 - 2020 Christof Metzger-Kraus
10//
11// All rights reserved
12//
13// This file is part of OPAL.
14//
15// OPAL is free software: you can redistribute it and/or modify
16// it under the terms of the GNU General Public License as published by
17// the Free Software Foundation, either version 3 of the License, or
18// (at your option) any later version.
19//
20// You should have received a copy of the GNU General Public License
21// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
22//
23#ifndef OPAL_INDEXMAP_H
24#define OPAL_INDEXMAP_H
25
26#include <ostream>
27#include <map>
28
31
32#include <set>
33#include <utility>
34
35
37{
38public:
39 struct Range
40 {
41 typedef double first_type;
42 typedef double second_type;
45 };
46 typedef Range key_t;
47 typedef std::set<std::shared_ptr<Component> > value_t;
48
49 IndexMap();
50
51 void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val);
52
54
55 void tidyUp(double zstop);
56
57 void print(std::ostream&) const;
58 void saveSDDS(double startS) const;
59 size_t size() const;
60
61 size_t numElements() const;
62 key_t getRange(const IndexMap::value_t::value_type &element, double position) const;
63 value_t getTouchingElements(const key_t &range) const;
64
65 class OutOfBounds: public OpalException {
66 public:
67 OutOfBounds(const std::string &meth, const std::string &msg):
68 OpalException(meth, msg) { }
69
71 OpalException(rhs) { }
72
73 virtual ~OutOfBounds() { }
74
75 private:
77 };
78
79private:
80 class myCompare {
81 public:
82 bool operator()(const key_t x , const key_t y) const
83 {
84 if (x.begin < y.begin) return true;
85
86 if (x.begin == y.begin) {
87 if (x.end < y.end) return true;
88 }
89
90 return false;
91 }
92 };
93
94 typedef std::map<key_t, value_t, myCompare> map_t;
95 typedef std::multimap<value_t::value_type, key_t> invertedMap_t;
98
100
101 static bool almostEqual(double, double);
102 static const double oneMinusEpsilon_m;
103};
104
105inline
106size_t IndexMap::size() const {
107 return mapRange2Element_m.size();
108}
109
110inline
111std::ostream& operator<< (std::ostream &out, const IndexMap &im)
112{
113 im.print(out);
114 return out;
115}
116
117inline
119 im.print(out.getStream());
120 return out;
121}
122
123#endif
T * value_type(const SliceIterator< T > &)
std::ostream & operator<<(std::ostream &out, const IndexMap &im)
Definition: IndexMap.h:111
MMatrix< double > im(MMatrix< m_complex > mc)
Definition: MMatrix.cpp:387
std::map< key_t, value_t, myCompare > map_t
Definition: IndexMap.h:94
static const double oneMinusEpsilon_m
Definition: IndexMap.h:102
double totalPathLength_m
Definition: IndexMap.h:99
size_t size() const
Definition: IndexMap.h:106
void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val)
Definition: IndexMap.cpp:113
size_t numElements() const
void tidyUp(double zstop)
Definition: IndexMap.cpp:148
std::set< std::shared_ptr< Component > > value_t
Definition: IndexMap.h:47
value_t getTouchingElements(const key_t &range) const
Definition: IndexMap.cpp:396
invertedMap_t mapElement2Range_m
Definition: IndexMap.h:97
Range key_t
Definition: IndexMap.h:46
key_t getRange(const IndexMap::value_t::value_type &element, double position) const
Definition: IndexMap.cpp:375
map_t mapRange2Element_m
Definition: IndexMap.h:96
IndexMap()
Definition: IndexMap.cpp:44
std::multimap< value_t::value_type, key_t > invertedMap_t
Definition: IndexMap.h:95
static bool almostEqual(double, double)
Definition: IndexMap.cpp:410
void saveSDDS(double startS) const
Definition: IndexMap.cpp:177
void print(std::ostream &) const
Definition: IndexMap.cpp:50
value_t query(key_t::first_type s, key_t::second_type ds)
Definition: IndexMap.cpp:76
first_type begin
Definition: IndexMap.h:43
double first_type
Definition: IndexMap.h:41
second_type end
Definition: IndexMap.h:44
double second_type
Definition: IndexMap.h:42
virtual ~OutOfBounds()
Definition: IndexMap.h:73
OutOfBounds(const std::string &meth, const std::string &msg)
Definition: IndexMap.h:67
OutOfBounds(const OutOfBounds &rhs)
Definition: IndexMap.h:70
bool operator()(const key_t x, const key_t y) const
Definition: IndexMap.h:82
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Definition: Inform.h:42
std::ostream & getStream()
Definition: Inform.h:89