<commit_before>/// \file
/// \ingroup tutorial_multicore
/// Parallel fill of a histogram.
/// This tutorial shows how a histogram can be filled in parallel
/// with a multithreaded approach. The difference with the multiprocess case,
/// see mp201, is that here we cannot count on the copy-on-write mechanism, but
/// we rather need to protect the histogram resource with a TThreadedObject
/// class. The result of the filling is monitored with the *SnapshotMerge*
/// method. This method is not thread safe: in presence of ROOT histograms, the
/// system will not crash but the result is not uniquely defined.
///
/// \macro_image
/// \macro_code
///
/// \author <NAME>
/// \date January 2016

const UInt_t poolSize = 4U;

Int_t mt201_parallelHistoFill()
{
   TH1::AddDirectory(false);

   // The concrete histogram instances are concretely created in each thread
   // lazily, i.e. only if a method is invoked.
   auto ts_h = ROOT::MakeThreaded<TH1F>("myHist", "Filled in parallel", 128, -8, 8);

   // The function used to fill the histograms in each thread.
   auto fillRandomHisto = [&](int seed = 0) {
      TRandom3 rndm(seed);
      // IMPORTANT!
      // It is important to realise that a copy on the stack of the object we
      // would like to perform operations on is the most efficient way of
      // accessing it, in particular in presence of a tight loop like the one
      // below where any overhead put on top of the Fill function call would
      // have an impact.
      auto histogram = ts_h.Get();
      for (auto i : ROOT::TSeqI(1000000)) {
         histogram->Fill(rndm.Gaus(0, 1));
      }
   };

   // The seeds for the random number generators.
   auto seeds = ROOT::TSeqI(1, poolSize+1);

   std::vector<std::thread> pool;

   // A monitoring thread. This is here only to illustrate the functionality of
   // the SnapshotMerge method.
   // It allows "to spy" the multithreaded calculation without the need
   // of interrupting it.
   auto monitor = [&]() {
      for (auto i : ROOT::TSeqI(5)) {
         std::this_thread::sleep_for(std::chrono::duration<double, std::nano>(500));
         auto h = ts_h.SnapshotMerge();<commit_msg>Improve documentation<commit_after>/// \file
/// \ingroup tutorial_multicore
/// Parallel fill of a histogram.
/// This tutorial shows how a histogram can be filled in parallel
/// with a multithreaded approach. The difference with the multiprocess case,
/// see mp201, is that here we cannot count on the copy-on-write mechanism, but
/// we rather need to protect the histogram resource with a TThreadedObject
/// class. The result of the filling is monitored with the *SnapshotMerge*
/// method. This method is not thread safe: in presence of ROOT histograms, the
/// system will not crash but the result is not uniquely defined.
///
/// \macro_image
/// \macro_code
///
/// \author <NAME>
/// \date January 2016

const UInt_t poolSize = 4U;

Int_t mt201_parallelHistoFill()
{
   TH1::AddDirectory(false);

   // The concrete histogram instances are created in each thread
   // lazily, i.e. only if a method is invoked.
   auto ts_h = ROOT::MakeThreaded<TH1F>("myHist", "Filled in parallel", 128, -8, 8);

   // The function used to fill the histograms in each thread.
   auto fillRandomHisto = [&](int seed = 0) {
      TRandom3 rndm(seed);
      // IMPORTANT!
      // It is important to realise that a copy on the stack of the object we
      // would like to perform operations on is the most efficient way of
      // accessing it, in particular in presence of a tight loop like the one
      // below where any overhead put on top of the Fill function call would
      // have an impact.
      auto histogram = ts_h.Get();
      for (auto i : ROOT::TSeqI(1000000)) {
         histogram->Fill(rndm.Gaus(0, 1));
      }
   };

   // The seeds for the random number generators.
   auto seeds = ROOT::TSeqI(1, poolSize+1);

   std::vector<std::thread> pool;

   // A monitoring thread. This is here only to illustrate the functionality of
   // the SnapshotMerge method.
   // It allows "to spy" the multithreaded calculation without the need
   // of interrupting it.
   auto monitor = [&]() {
      for (auto i : ROOT::TSeqI(5)) {
         std::this_thread::sleep_for(std::chrono::duration<double, std::nano>(500));
         auto h = ts_h.SnapshotMerge();
{'fraction_non_alphanumeric': 0.10677143517448578, 'fraction_numerical': 0.01617749017795239, 'mean_word_length': 2.867739052725648, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5517739', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1239, 'n_words': 531}