What is the reason behind the static TClonesArray in the JetEvent.h example

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22.00 built for linuxx8664gcc on Jul 31 2020, 11:07:00
Platform: Linux zion 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Compiler: gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0

I was taking a look at the tutorials/tree/JetEvent.h example because I need to implement something similar for our experiment.

I noticed that in the JetEvent class, the TClonesArray-s are defined two times, as non-static members and static members. In the constructor, the static members are allocated and then their pointers are copied into the non-static members. In the destructor, the static members are deallocated, end of the story.

Now, this does not make any sense to me but maybe there is a reason I cannot see. By having static members I must be careful to only define one object (singleton) of the JetEvent class and I preclude myself from ever using this class in a multithreading environment. Seems like shooting yourself in the foot to me.

Could you please clarify?
Thank you

Hi @LastStarDust ,
@pcanal or @Axel can correct me if I’m wrong, but I think that’s just a quirk of that particular tutorial (which is something like 20 years old).

The only thing you have to take care of is that you don’t allocate/deallocate TClonesArrays for each event, but keep the same ones around for the full event loop. The docs have a few more examples and elaborate a bit more.


1 Like

Thank you for the clarification.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.