ATLAS Offline Software
LArVectorProxy.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /**
6  * @file LArElecCalib/LArVectorProxy.icc
7  * @author scott snyder <snyder@bnl.gov>
8  * @date Apr, 2011
9  * @brief Proxy for accessing a range of float values like a vector.
10  */
11 
12 
13 #include <stdexcept>
14 
15 
16 /**
17  * @brief Default constructor.
18  * Creates the proxy in an invalid state.
19  */
20 inline
21 LArVectorProxy::LArVectorProxy()
22  : std::span<const float>() {}
23 
24 
25 /**
26  * @brief Construct a proxy referencing an existing vector.
27  * @param vec The existing vector to reference.
28  */
29 inline
30 LArVectorProxy::LArVectorProxy (const std::vector<value_type>& vec)
31  : std::span<const float>(vec.cbegin(),vec.cend())
32 {
33 }
34 
35 
36 /**
37  * @brief Construct a proxy referencing a range of vectors in memory.
38  * @param beg Pointer to the start of the range.
39  * @param end Pointer to the (exclusive) end of the range.
40  */
41 inline
42 LArVectorProxy::LArVectorProxy (const value_type* beg, const value_type* end)
43  : std::span<const float>(beg,end)
44 {
45 }
46 
47 
48 /**
49  * @brief Test to see if the proxy has been initialized.
50  */
51 inline
52 bool LArVectorProxy::valid() const
53 {
54  return data() != nullptr;
55 }
56 
57 
58 /**
59  * @brief Vector indexing with bounds check.
60  */
61 inline
62 LArVectorProxy::value_type LArVectorProxy::at (size_t i) const
63 {
64  if (i >= size())
65  throw std::out_of_range ("LArVectorProxy::at");
66  return operator[](i);
67 }
68 
69 
70 /**
71  * @brief Convert back to a vector.
72  */
73 inline
74 std::vector<LArVectorProxy::value_type> LArVectorProxy::asVector() const
75 {
76  return std::vector<value_type> (begin(), end());
77 }