FairShip
Loading...
Searching...
No Matches
test_data_class_io.cxx File Reference
#include <iostream>
#include <memory>
#include <type_traits>
#include <vector>
#include "CaloScoringPlaneHit.h"
#include "CaloScoringPlanePoint.h"
#include "DetectorHit.h"
#include "MTCDetHit.h"
#include "MTCDetPoint.h"
#include "RecoTrack.h"
#include "RecoVertex.h"
#include "ShipMCTrack.h"
#include "SiliconTargetHit.h"
#include "SiliconTargetPoint.h"
#include "TTPoint.h"
#include "TargetPoint.h"
#include "TimeDetHit.h"
#include "TimeDetPoint.h"
#include "UpstreamTaggerHit.h"
#include "UpstreamTaggerPoint.h"
#include "UpstreamTaggerScoringPoint.h"
#include "strawtubesHit.h"
#include "strawtubesPoint.h"
#include "vetoHit.h"
#include "vetoHitOnTrack.h"
#include "vetoPoint.h"
Include dependency graph for test_data_class_io.cxx:

Go to the source code of this file.

Functions

template<typename T>
constexpr bool test_copyable ()
template<typename T>
void test_const_access (const T &obj)
void test_const_access (const SHiP::DetectorHit &obj)
void test_const_access (const ShipMCTrack &obj)
void test_const_access (const vetoHitOnTrack &obj)
void test_const_access (const SHiP::RecoTrack &obj)
void test_const_access (const SHiP::RecoVertex &obj)
void test_const_access (const vetoHit &obj)
void test_const_access (const vetoPoint &obj)
void test_const_access (const strawtubesHit &obj)
void test_const_access (const strawtubesPoint &obj)
void test_const_access (const CaloScoringPlaneHit &obj)
void test_const_access (const CaloScoringPlanePoint &obj)
void test_const_access (const MTCDetHit &obj)
void test_const_access (const MTCDetPoint &obj)
void test_const_access (const SiliconTargetHit &obj)
void test_const_access (const SiliconTargetPoint &obj)
void test_const_access (const TimeDetHit &obj)
void test_const_access (const TimeDetPoint &obj)
void test_const_access (const UpstreamTaggerHit &obj)
void test_const_access (const UpstreamTaggerPoint &obj)
void test_const_access (const UpstreamTaggerScoringPoint &obj)
void test_const_access (const TTPoint &obj)
void test_const_access (const TargetPoint &obj)
template<typename T>
bool test_vector_operations (const char *class_name)
int main (int argc, char **argv)

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 223 of file test_data_class_io.cxx.

223 {
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}
bool test_vector_operations(const char *class_name)

◆ test_const_access() [1/23]

void test_const_access ( const CaloScoringPlaneHit & obj)

Definition at line 109 of file test_data_class_io.cxx.

109 {
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}

◆ test_const_access() [2/23]

void test_const_access ( const CaloScoringPlanePoint & obj)

Definition at line 118 of file test_data_class_io.cxx.

118 {
119 [[maybe_unused]] auto pdg = obj.PdgCode();
120}

◆ test_const_access() [3/23]

void test_const_access ( const MTCDetHit & obj)

Definition at line 122 of file test_data_class_io.cxx.

122 {
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}

◆ test_const_access() [4/23]

void test_const_access ( const MTCDetPoint & obj)

Definition at line 131 of file test_data_class_io.cxx.

131 {
132 [[maybe_unused]] auto pdg = obj.PdgCode();
133 [[maybe_unused]] auto layer = obj.GetLayer();
134 [[maybe_unused]] auto layerType = obj.GetLayerType();
135}

◆ test_const_access() [5/23]

void test_const_access ( const SHiP::DetectorHit & obj)

Definition at line 53 of file test_data_class_io.cxx.

53 {
54 [[maybe_unused]] auto digi = obj.GetDigi();
55 [[maybe_unused]] auto detID = obj.GetDetectorID();
56}

◆ test_const_access() [6/23]

void test_const_access ( const SHiP::RecoTrack & obj)

Definition at line 70 of file test_data_class_io.cxx.

70 {
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}

◆ test_const_access() [7/23]

void test_const_access ( const SHiP::RecoVertex & obj)

Definition at line 78 of file test_data_class_io.cxx.

78 {
79 [[maybe_unused]] auto z = obj.z();
80 [[maybe_unused]] const auto& ids = obj.trackIds();
81 [[maybe_unused]] auto doca = obj.doca();
82}

◆ test_const_access() [8/23]

void test_const_access ( const ShipMCTrack & obj)

Definition at line 58 of file test_data_class_io.cxx.

58 {
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}

◆ test_const_access() [9/23]

void test_const_access ( const SiliconTargetHit & obj)

Definition at line 137 of file test_data_class_io.cxx.

137 {
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}

◆ test_const_access() [10/23]

void test_const_access ( const SiliconTargetPoint & obj)

Definition at line 146 of file test_data_class_io.cxx.

146 {
147 [[maybe_unused]] auto pdg = obj.PdgCode();
148 [[maybe_unused]] auto layer = obj.GetLayer();
149}

◆ test_const_access() [11/23]

void test_const_access ( const strawtubesHit & obj)

Definition at line 95 of file test_data_class_io.cxx.

95 {
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}

◆ test_const_access() [12/23]

void test_const_access ( const strawtubesPoint & obj)

Definition at line 104 of file test_data_class_io.cxx.

104 {
105 [[maybe_unused]] auto pdg = obj.PdgCode();
106 [[maybe_unused]] auto dist = obj.dist2Wire();
107}

◆ test_const_access() [13/23]

template<typename T>
void test_const_access ( const T & obj)

Definition at line 48 of file test_data_class_io.cxx.

48 {
49 // This will only compile if getters are properly const-qualified
50}

◆ test_const_access() [14/23]

void test_const_access ( const TargetPoint & obj)

Definition at line 181 of file test_data_class_io.cxx.

181 {
182 [[maybe_unused]] auto pdg = obj.PdgCode();
183}

◆ test_const_access() [15/23]

void test_const_access ( const TimeDetHit & obj)

Definition at line 151 of file test_data_class_io.cxx.

151 {
152 [[maybe_unused]] auto valid = obj.isValid();
153}

◆ test_const_access() [16/23]

void test_const_access ( const TimeDetPoint & obj)

Definition at line 155 of file test_data_class_io.cxx.

155 {
156 [[maybe_unused]] auto pdg = obj.PdgCode();
157}

◆ test_const_access() [17/23]

void test_const_access ( const TTPoint & obj)

Definition at line 177 of file test_data_class_io.cxx.

177 {
178 [[maybe_unused]] auto pdg = obj.PdgCode();
179}

◆ test_const_access() [18/23]

void test_const_access ( const UpstreamTaggerHit & obj)

Definition at line 159 of file test_data_class_io.cxx.

159 {
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}

◆ test_const_access() [19/23]

void test_const_access ( const UpstreamTaggerPoint & obj)

Definition at line 169 of file test_data_class_io.cxx.

169 {
170 [[maybe_unused]] auto pdg = obj.PdgCode();
171}

◆ test_const_access() [20/23]

void test_const_access ( const UpstreamTaggerScoringPoint & obj)

Definition at line 173 of file test_data_class_io.cxx.

173 {
174 [[maybe_unused]] auto pdg = obj.PdgCode();
175}

◆ test_const_access() [21/23]

void test_const_access ( const vetoHit & obj)

Definition at line 84 of file test_data_class_io.cxx.

84 {
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}

◆ test_const_access() [22/23]

void test_const_access ( const vetoHitOnTrack & obj)

Definition at line 65 of file test_data_class_io.cxx.

65 {
66 [[maybe_unused]] auto dist = obj.GetDist();
67 [[maybe_unused]] auto hitID = obj.GetHitID();
68}

◆ test_const_access() [23/23]

void test_const_access ( const vetoPoint & obj)

Definition at line 91 of file test_data_class_io.cxx.

91 {
92 [[maybe_unused]] auto pdg = obj.PdgCode();
93}

◆ test_copyable()

template<typename T>
bool test_copyable ( )
constexpr

Test script to verify data classes can be used with std::vector and RNtuple This test verifies:

  • Copy constructors are public
  • Move constructors are accessible
  • Getters are const-correct
  • Classes work with std::vector

Definition at line 41 of file test_data_class_io.cxx.

41 {
42 return std::is_copy_constructible<T>::value &&
43 std::is_copy_assignable<T>::value;
44}

◆ test_vector_operations()

template<typename T>
bool test_vector_operations ( const char * class_name)

Definition at line 187 of file test_data_class_io.cxx.

187 {
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}
void test_const_access(const T &obj)
constexpr bool test_copyable()