GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TUnpackedEvent.h
Go to the documentation of this file.
1#ifndef TUNPACKEDEVENT_H
2#define TUNPACKEDEVENT_H
3
4#ifndef __CINT__
5#include <type_traits>
6#include <memory>
7#endif
8#if __GNUC__ > 5
9#include <sstream>
10#endif
11
12#include "TClass.h"
13
14#include "TDetector.h"
15
16class TFragment;
17
19public:
22
23 TUnpackedEvent(const TUnpackedEvent&) = default;
24 TUnpackedEvent(TUnpackedEvent&&) noexcept = default;
25 TUnpackedEvent& operator=(const TUnpackedEvent&) = default;
26 TUnpackedEvent& operator=(TUnpackedEvent&&) noexcept = default;
27
28#ifndef __CINT__
29 template <typename T>
30 std::shared_ptr<T> GetDetector(bool make_if_not_found = false);
31 std::shared_ptr<TDetector> GetDetector(TClass* cls, bool make_if_not_found = false);
32
33 std::vector<std::shared_ptr<TDetector>>& GetDetectors() { return fDetectors; }
34 void AddDetector(const std::shared_ptr<TDetector>& det) { fDetectors.push_back(det); }
35 void AddRawData(const std::shared_ptr<const TFragment>& frag);
36 void SetRawData(const std::vector<std::shared_ptr<const TFragment>>& fragments) { fFragments = fragments; }
37#endif
38 void ClearRawData();
39
40 void Build();
41
42 size_t Size() { return fDetectors.size(); }
43
44#if __GNUC__ > 5
45 std::ostringstream Print();
46#endif
47
48private:
49 void BuildHits();
50
51#ifndef __CINT__
52 std::vector<std::shared_ptr<const TFragment>> fFragments;
53 std::vector<std::shared_ptr<TDetector>> fDetectors;
54#endif
55};
56
57#ifndef __CINT__
58template <typename T>
59std::shared_ptr<T> TUnpackedEvent::GetDetector(bool make_if_not_found)
60{
61 static_assert(std::is_base_of<TDetector, T>::value, "T must be a subclass of TDetector");
62 for(const auto& det : fDetectors) {
63 std::shared_ptr<T> output = std::dynamic_pointer_cast<T>(det);
64 if(output) {
65 return output;
66 }
67 }
68
69 if(make_if_not_found) {
70 std::shared_ptr<T> output = std::make_shared<T>();
71 fDetectors.push_back(output);
72 return output;
73 }
74 return nullptr;
75}
76#endif
77
78#endif /* _TUNPACKEDEVENT_H_ */
void SetRawData(const std::vector< std::shared_ptr< const TFragment > > &fragments)
TUnpackedEvent(TUnpackedEvent &&) noexcept=default
std::vector< std::shared_ptr< TDetector > > fDetectors
void AddDetector(const std::shared_ptr< TDetector > &det)
std::shared_ptr< T > GetDetector(bool make_if_not_found=false)
TUnpackedEvent(const TUnpackedEvent &)=default
void AddRawData(const std::shared_ptr< const TFragment > &frag)
std::vector< std::shared_ptr< TDetector > > & GetDetectors()
std::vector< std::shared_ptr< const TFragment > > fFragments