FairShip
Loading...
Searching...
No Matches
test_data_class_io.cxx
Go to the documentation of this file.
1
9
10#include <iostream>
11#include <memory>
12#include <type_traits>
13#include <vector>
14
15// Include all data class headers
16#include "CaloScoringPlaneHit.h"
18#include "DetectorHit.h"
19#include "MTCDetHit.h"
20#include "MTCDetPoint.h"
21#include "RecoTrack.h"
22#include "RecoVertex.h"
23#include "ShipMCTrack.h"
24#include "SiliconTargetHit.h"
25#include "SiliconTargetPoint.h"
26#include "TTPoint.h"
27#include "TargetPoint.h"
28#include "TimeDetHit.h"
29#include "TimeDetPoint.h"
30#include "UpstreamTaggerHit.h"
31#include "UpstreamTaggerPoint.h"
33#include "strawtubesHit.h"
34#include "strawtubesPoint.h"
35#include "vetoHit.h"
36#include "vetoHitOnTrack.h"
37#include "vetoPoint.h"
38
39// Test helper: verify a type is copyable (required for std::vector)
40template <typename T>
41constexpr bool test_copyable() {
42 return std::is_copy_constructible<T>::value &&
43 std::is_copy_assignable<T>::value;
44}
45
46// Test helper: verify const-correctness of getters
47template <typename T>
48void test_const_access(const T& obj) {
49 // This will only compile if getters are properly const-qualified
50}
51
52// Specializations for const-access tests
54 [[maybe_unused]] auto digi = obj.GetDigi();
55 [[maybe_unused]] auto detID = obj.GetDetectorID();
56}
57
59 [[maybe_unused]] auto pdg = obj.GetPdgCode();
60 [[maybe_unused]] auto px = obj.GetPx();
61 [[maybe_unused]] auto py = obj.GetPy();
62 [[maybe_unused]] auto pz = obj.GetPz();
63}
64
66 [[maybe_unused]] auto dist = obj.GetDist();
67 [[maybe_unused]] auto hitID = obj.GetHitID();
68}
69
71 [[maybe_unused]] auto px = obj.px();
72 [[maybe_unused]] auto charge = obj.charge();
73 [[maybe_unused]] const auto& cov = obj.GetCovarianceElements();
74 TVector3 position;
75 [[maybe_unused]] auto ok = obj.ExtrapolateToZ(0., position);
76}
77
79 [[maybe_unused]] auto z = obj.z();
80 [[maybe_unused]] const auto& ids = obj.trackIds();
81 [[maybe_unused]] auto doca = obj.doca();
82}
83
84void test_const_access(const vetoHit& obj) {
85 [[maybe_unused]] auto adc = obj.GetADC();
86 [[maybe_unused]] auto tdc = obj.GetTDC();
87 [[maybe_unused]] auto eloss = obj.GetEloss();
88 [[maybe_unused]] auto valid = obj.isValid();
89}
90
91void test_const_access(const vetoPoint& obj) {
92 [[maybe_unused]] auto pdg = obj.PdgCode();
93}
94
96 [[maybe_unused]] auto tdc = obj.GetTDC();
97 [[maybe_unused]] auto station = obj.GetStationNumber();
98 [[maybe_unused]] auto view = obj.GetViewNumber();
99 [[maybe_unused]] auto layer = obj.GetLayerNumber();
100 [[maybe_unused]] auto straw = obj.GetStrawNumber();
101 [[maybe_unused]] auto valid = obj.isValid();
102}
103
105 [[maybe_unused]] auto pdg = obj.PdgCode();
106 [[maybe_unused]] auto dist = obj.dist2Wire();
107}
108
110 [[maybe_unused]] auto pos = obj.GetXYZ();
111 [[maybe_unused]] auto mom = obj.GetMom();
112 [[maybe_unused]] auto time = obj.GetTime();
113 [[maybe_unused]] auto pid = obj.GetPid();
114 [[maybe_unused]] auto muon = obj.IsMuon();
115 [[maybe_unused]] auto identified = obj.IsIdentified();
116}
117
119 [[maybe_unused]] auto pdg = obj.PdgCode();
120}
121
122void test_const_access(const MTCDetHit& obj) {
123 [[maybe_unused]] auto signal = obj.GetSignal();
124 [[maybe_unused]] auto time = obj.GetTime();
125 [[maybe_unused]] auto channelID = obj.GetChannelID();
126 [[maybe_unused]] auto layer = obj.GetLayer();
127 [[maybe_unused]] auto sipm = obj.GetSiPM();
128 [[maybe_unused]] auto energy = obj.GetEnergy();
129}
130
132 [[maybe_unused]] auto pdg = obj.PdgCode();
133 [[maybe_unused]] auto layer = obj.GetLayer();
134 [[maybe_unused]] auto layerType = obj.GetLayerType();
135}
136
138 [[maybe_unused]] auto signal = obj.GetSignal();
139 [[maybe_unused]] auto x = obj.GetX();
140 [[maybe_unused]] auto y = obj.GetY();
141 [[maybe_unused]] auto z = obj.GetZ();
142 [[maybe_unused]] auto layer = obj.GetLayer();
143 [[maybe_unused]] auto plane = obj.GetPlane();
144}
145
147 [[maybe_unused]] auto pdg = obj.PdgCode();
148 [[maybe_unused]] auto layer = obj.GetLayer();
149}
150
152 [[maybe_unused]] auto valid = obj.isValid();
153}
154
156 [[maybe_unused]] auto pdg = obj.PdgCode();
157}
158
160 [[maybe_unused]] auto x = obj.GetX();
161 [[maybe_unused]] auto y = obj.GetY();
162 [[maybe_unused]] auto z = obj.GetZ();
163 [[maybe_unused]] auto time = obj.GetTime();
164 [[maybe_unused]] auto adc = obj.GetADC();
165 [[maybe_unused]] auto tileID = obj.GetTileID();
166 [[maybe_unused]] auto triggered = obj.IsTriggered();
167}
168
170 [[maybe_unused]] auto pdg = obj.PdgCode();
171}
172
174 [[maybe_unused]] auto pdg = obj.PdgCode();
175}
176
177void test_const_access(const TTPoint& obj) {
178 [[maybe_unused]] auto pdg = obj.PdgCode();
179}
180
182 [[maybe_unused]] auto pdg = obj.PdgCode();
183}
184
185// Test vector operations
186template <typename T>
187bool test_vector_operations(const char* class_name) {
188 std::cout << "Testing " << class_name << "... ";
189
190 // Test 1: Can we create a vector?
191 if (!test_copyable<T>()) {
192 std::cout << "FAIL: Not copyable (private copy constructor?)" << std::endl;
193 return false;
194 }
195
196 try {
197 // Test 2: Create default objects
198 std::vector<T> vec;
199 vec.reserve(10);
200
201 // Test 3: Emplace back (uses default constructor)
202 vec.emplace_back();
203
204 // Test 4: Push back (uses copy constructor)
205 T obj;
206 vec.push_back(obj);
207
208 // Test 5: Access elements with const reference
209 const T& const_ref = vec[0];
210 test_const_access(const_ref);
211
212 // Test 6: Vector resize (uses copy constructor)
213 vec.resize(5);
214
215 std::cout << "PASS" << std::endl;
216 return true;
217 } catch (const std::exception& e) {
218 std::cout << "FAIL: " << e.what() << std::endl;
219 return false;
220 }
221}
222
223int main(int argc, char** argv) {
224 std::cout << "\n=== Testing Data Classes for std::vector compatibility ===\n"
225 << std::endl;
226
227 int passed = 0;
228 int total = 0;
229
230 // Test base classes
231 std::cout << "\n--- Base Classes ---" << std::endl;
232 total++;
233 if (test_vector_operations<SHiP::DetectorHit>("SHiP::DetectorHit")) passed++;
234 total++;
235 if (test_vector_operations<ShipMCTrack>("ShipMCTrack")) passed++;
236 total++;
237 if (test_vector_operations<vetoHitOnTrack>("vetoHitOnTrack")) passed++;
238 total++;
239 if (test_vector_operations<SHiP::RecoTrack>("SHiP::RecoTrack")) passed++;
240 total++;
241 if (test_vector_operations<SHiP::RecoVertex>("SHiP::RecoVertex")) passed++;
242
243 // Test Hit classes
244 std::cout << "\n--- Hit Classes ---" << std::endl;
245 total++;
246 if (test_vector_operations<vetoHit>("vetoHit")) passed++;
247 total++;
248 if (test_vector_operations<strawtubesHit>("strawtubesHit")) passed++;
249 total++;
250 if (test_vector_operations<MTCDetHit>("MTCDetHit")) passed++;
251 total++;
252 if (test_vector_operations<SiliconTargetHit>("SiliconTargetHit")) passed++;
253 total++;
254 if (test_vector_operations<TimeDetHit>("TimeDetHit")) passed++;
255 total++;
256 if (test_vector_operations<UpstreamTaggerHit>("UpstreamTaggerHit")) passed++;
257 total++;
258 if (test_vector_operations<CaloScoringPlaneHit>("CaloScoringPlaneHit"))
259 passed++;
260
261 // Test Point classes
262 std::cout << "\n--- Point Classes ---" << std::endl;
263 total++;
264 if (test_vector_operations<vetoPoint>("vetoPoint")) passed++;
265 total++;
266 if (test_vector_operations<strawtubesPoint>("strawtubesPoint")) passed++;
267 total++;
268 if (test_vector_operations<CaloScoringPlanePoint>("CaloScoringPlanePoint"))
269 passed++;
270 total++;
271 if (test_vector_operations<MTCDetPoint>("MTCDetPoint")) passed++;
272 total++;
273 if (test_vector_operations<SiliconTargetPoint>("SiliconTargetPoint"))
274 passed++;
275 total++;
276 if (test_vector_operations<TimeDetPoint>("TimeDetPoint")) passed++;
277 total++;
278 if (test_vector_operations<UpstreamTaggerPoint>("UpstreamTaggerPoint"))
279 passed++;
280 total++;
282 "UpstreamTaggerScoringPoint"))
283 passed++;
284 total++;
285 if (test_vector_operations<TTPoint>("TTPoint")) passed++;
286 total++;
287 if (test_vector_operations<TargetPoint>("TargetPoint")) passed++;
288
289 std::cout << "\n=== Summary ===" << std::endl;
290 std::cout << "Passed: " << passed << " / " << total << std::endl;
291 std::cout << "Failed: " << (total - passed) << " / " << total << std::endl;
292
293 if (passed == total) {
294 std::cout << "\n✓ All tests PASSED!" << std::endl;
295 std::cout
296 << "All data classes are compatible with std::vector and RNtuple I/O\n"
297 << std::endl;
298 return 0;
299 } else {
300 std::cout << "\n✗ Some tests FAILED!" << std::endl;
301 std::cout << "Fix the failing classes before using with RNtuple\n"
302 << std::endl;
303 return 1;
304 }
305}
Digitised scoring-plane hit with a particle-identification outcome.
Hit class for UpstreamTagger scoring plane.
Track crossing of one of the vacuum scoring planes around the UBT.
void test_const_access(const T &obj)
constexpr bool test_copyable()
bool test_vector_operations(const char *class_name)