|
22 | 22 | #include <string> |
23 | 23 | #include <type_traits> |
24 | 24 | #include <array> |
| 25 | +#include <sstream> |
| 26 | +#include <format> |
25 | 27 | #endif |
26 | 28 |
|
27 | 29 | namespace o2 |
@@ -135,6 +137,11 @@ class Vertex : public VertexBase |
135 | 137 | { |
136 | 138 | } |
137 | 139 |
|
| 140 | +#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE_DEVICE) |
| 141 | + void print() const; |
| 142 | + std::string asString() const; |
| 143 | +#endif |
| 144 | + |
138 | 145 | GPUd() ushort getNContributors() const { return mNContributors; } |
139 | 146 | GPUd() void setNContributors(ushort v) { mNContributors = v; } |
140 | 147 | GPUd() void addContributor() { mNContributors++; } |
@@ -162,6 +169,39 @@ class Vertex : public VertexBase |
162 | 169 |
|
163 | 170 | #if !defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_NO_FMT) |
164 | 171 | std::ostream& operator<<(std::ostream& os, const o2::dataformats::VertexBase& v); |
| 172 | + |
| 173 | +// small helper concept |
| 174 | +template <typename T> |
| 175 | +concept Streamable = requires(std::ostream& os, T a) { |
| 176 | + { os << a } -> std::same_as<std::ostream&>; |
| 177 | +}; |
| 178 | + |
| 179 | +template <typename Stamp> |
| 180 | +inline std::string Vertex<Stamp>::asString() const |
| 181 | +{ |
| 182 | + if constexpr (Streamable<Stamp>) { |
| 183 | + std::ostringstream oss; |
| 184 | + oss << mTimeStamp; |
| 185 | + return std::format("{} NContrib:{} Chi2:{:.2f} Flags:{:b} Stamp:{}", VertexBase::asString(), mNContributors, mChi2, mBits, oss.str()); |
| 186 | + } else if constexpr (requires { mTimeStamp.getTimeStamp(); }) { |
| 187 | + return std::format("{} NContrib:{} Chi2:{:.2f} Flags:{:b} Stamp:{}", VertexBase::asString(), mNContributors, mChi2, mBits, mTimeStamp.getTimeStamp()); |
| 188 | + } else { |
| 189 | + return std::format("{} NContrib:{} Chi2:{:.2f} Flags:{:b} Stamp:X", VertexBase::asString(), mNContributors, mChi2, mBits); |
| 190 | + } |
| 191 | +} |
| 192 | + |
| 193 | +template <typename Stamp> |
| 194 | +inline std::ostream& operator<<(std::ostream& os, const o2::dataformats::Vertex<Stamp>& v) |
| 195 | +{ |
| 196 | + os << v.asString(); |
| 197 | + return os; |
| 198 | +} |
| 199 | + |
| 200 | +template <typename Stamp> |
| 201 | +inline void Vertex<Stamp>::print() const |
| 202 | +{ |
| 203 | + std::cout << *this << '\n'; |
| 204 | +} |
165 | 205 | #endif |
166 | 206 |
|
167 | 207 | } // namespace dataformats |
|
0 commit comments