Two processes using the same TChain with same files

If I want to run two (or more) processes at the same time to access the same TChain (with the same files), but with each process getting a different range of entries, will this cause problems? Will there be some sort of memory or other conflict?

I had this problem, for me the solution was to place a mutex at the point where I read the TChain, and then copy the data from the TChain variables to a threadlocal storage. Afterwards it is safe to release the mutex. But be warned, non of the root objects is really threadsafe. I had to write wrapper classes to deal with it.

To have really different processes will be very tricky, I’d rather go for threads…

EDIT: if you want to see how I did this, check this forum post: viewtopic.php?f=3&t=16805&p=71884#p71884

Hi,

If you are using separate processes, there will be not problem at all; it is actually the way Proof will work.

If you are using threads within the same process then there will be issues, especially if you are using the same TChain object (as oppose to the same chain description in two different objects).

Cheers,
Philippe.

Shouldn’t this depend on how the filesystem treats competing disk accesses? If this the different entry ranges of the TChain are within the same file?

[quote]Shouldn’t this depend on how the filesystem treats competing disk accesses? If this the different entry ranges of the TChain are within the same file?[/quote]Humm … if the file system is working correctly and if we are talking about reading from the same file twice, using two separate process will always work. What will depend on the file system implementation/layout is the ultimate performance. The file system may or may not have to actually read the same bytes out of the physical disk depending on many factor … but the end result will always be ‘correct’.

Cheers,
Philippe.

I will be using separate processes so it sounds like things will work. Thanks!

In case someone stumbles across this in the future, I was also interested in doing this, but with TThread. I ended up having to create a derived class of TChain that made use of the producer-consumer scheme. One thread handles the production (getting the data from the chain and storing it in a circular buffer) and any number of threads can consume the data (analyze it). The performance gain with increasing number of consumers depends on the task being performed, the producer will at some point be the limiting factor.