Unstable results when enabling MT and filling a THnD histogram using Take

Hi @Javier_Galan,

we found the source of the problem.

The lines:

    std::vector<std::vector<double> > data;
    auto parValues1 = df.Take<double>("final_posX");
    data.push_back(*parValues1);
    auto parValues2 = df.Take<double>("final_posY");
    data.push_back(*parValues2);
    auto parValues3 = df.Take<double>("final_energy");
    data.push_back(*parValues3);

should be reordered to:

    auto parValues1 = df.Take<double>("final_posX");
    auto parValues2 = df.Take<double>("final_posY");
    auto parValues3 = df.Take<double>("final_energy");
    
    std::vector<std::vector<double> > data;
    data.push_back(*parValues1);
    data.push_back(*parValues2);
    data.push_back(*parValues3);

This way you only perform a single event loop (you first book all three actions and then get the values - start the event loop) and everything will work fine in multithreaded mode as well (also you get an improvement performance-wise). In your case, you initiated 3 multi-threaded event loops (you booked the action, got values, booked another action, got values, booked the third action, got values) which then processes entries in different order.

We will work on making better warnings so that such issues are avoided.

Have a nice end of week,
cheers,
Marta

1 Like