@@ -50,8 +50,11 @@ struct internal_Branch<TTree> {
5050};
5151} // namespace
5252
53+ template <typename ... Args>
54+ class GPUROOTDump ;
55+
5356template <class T , typename ... Args>
54- class GPUROOTDump : public GPUROOTDump <Args...>
57+ class GPUROOTDump <T, Args...> : public GPUROOTDump<Args...>
5558{
5659 public:
5760 template <typename ... Names>
@@ -65,59 +68,53 @@ class GPUROOTDump : public GPUROOTDump<Args...>
6568 {
6669 return GPUROOTDump<T, Args...>(name1, names...);
6770 }
68- void Fill (const T& o, Args... args)
71+
72+ void Fill (const T& o, const Args&... args)
73+ {
74+ stdspinlock spinlock (GPUROOTDumpBase::mMutex );
75+ FillInternal (o, args...);
76+ }
77+
78+ protected:
79+ void FillInternal (const T& o, const Args&... args)
6980 {
7081 mObj = o;
7182 GPUROOTDump<Args...>::Fill (args...);
7283 }
7384
74- protected:
7585 using GPUROOTDump<Args...>::mTree ;
7686 template <typename ... Names>
7787 GPUROOTDump (const char * name1, Names... names) : GPUROOTDump<Args...>(names...)
7888 {
89+ stdspinlock spinlock (GPUROOTDumpBase::mMutex );
7990 mTree ->Branch (name1, &mObj );
8091 }
8192
8293 private:
8394 T mObj ;
8495};
8596
86- template <class T >
87- class GPUROOTDump <T > : public GPUROOTDumpBase
97+ template <>
98+ class GPUROOTDump <> : public GPUROOTDumpBase
8899{
89100 public:
90- static GPUROOTDump<T>& get (const char * name) // return always the same instance, identified by template
91- {
92- static GPUROOTDump<T> instance (name);
93- return instance;
94- }
95- static GPUROOTDump<T> getNew (const char * name) // return new individual instance
96- {
97- return GPUROOTDump<T>(name);
98- }
99-
100101 void write () override { mTree ->Write (); }
101102
102- void Fill (const T& o)
103+ protected:
104+ void Fill ()
103105 {
104- mObj = o;
105106 mTree ->Fill ();
106107 }
107108
108- protected:
109109 GPUROOTDump (const char * name1, const char * nameTree = nullptr )
110110 {
111111 if (nameTree == nullptr ) {
112112 nameTree = name1;
113113 }
114+ stdspinlock spinlock (GPUROOTDumpBase::mMutex );
114115 mTree = new TTree (nameTree, nameTree);
115- mTree ->Branch (name1, &mObj );
116116 }
117117 TTree* mTree = nullptr ;
118-
119- private:
120- T mObj ;
121118};
122119
123120template <>
@@ -137,14 +134,16 @@ class GPUROOTDump<TNtuple> : public GPUROOTDumpBase
137134 void write () override { mNTuple ->Write (); }
138135
139136 template <typename ... Args>
140- void Fill (Args... args)
137+ void Fill (const Args& ... args)
141138 {
139+ stdspinlock spinlock (GPUROOTDumpBase::mMutex );
142140 mNTuple ->Fill (args...);
143141 }
144142
145143 private:
146144 GPUROOTDump (const char * name, const char * options)
147145 {
146+ stdspinlock spinlock (GPUROOTDumpBase::mMutex );
148147 mNTuple = new TNtuple (name, name, options);
149148 }
150149 TNtuple* mNTuple ;
@@ -155,18 +154,18 @@ class GPUROOTDump
155154{
156155 public:
157156 template <typename ... Names>
158- GPUd () void Fill (Args... args) const
157+ GPUd () static void Fill (Args... args)
159158 {
160159 }
161160 template <typename ... Names>
162161 GPUd () static GPUROOTDump<Args...>& get (Args... args)
163162 {
164- return *( GPUROOTDump<Args...>*)( size_t )( 1024 ); // Will never be used, return just some reference, which must not be nullptr by specification
163+ return GPUROOTDump<Args...>();
165164 }
166165 template <typename ... Names>
167166 GPUd () static GPUROOTDump<Args...>& getNew (Args... args)
168167 {
169- return *( GPUROOTDump<Args...>*)( size_t )( 1024 ); // Will never be used, return just some reference, which must not be nullptr by specification
168+ return GPUROOTDump<Args...>();
170169 }
171170};
172171#endif
0 commit comments