<commit_before>/// \file RNTupleOptions.cxx
/// \ingroup NTuple ROOT7
/// \author <NAME> <<EMAIL>>
/// \date 2021-07-28
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
 * Copyright (C) 1995-2021, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include <ROOT/RError.hxx>
#include <ROOT/RNTupleOptions.hxx>

#include <utility>

namespace {

void EnsureValidTunables(std::size_t zippedClusterSize, std::size_t unzippedClusterSize, std::size_t unzippedPageSize)
{
   using RException = ROOT::Experimental::RException;
   if (zippedClusterSize == 0) {
      throw RException(R__FAIL("invalid target cluster size: 0"));
   }
   if (zippedClusterSize > unzippedClusterSize) {
      throw RException(R__FAIL("compressed target cluster size must not be larger than "
                               "maximum uncompressed cluster size"));
   }
   if (unzippedPageSize > unzippedClusterSize) {
      throw RException(R__FAIL("target page size must not be larger than "
                               "maximum uncompressed cluster size"));
   }
   if (unzippedPageSize == 0) {
      throw RException(R__FAIL("invalid target page size: 0"));
   }
}

} // anonymous namespace

std::unique_ptr<ROOT::Experimental::RNTupleWriteOptions>
ROOT::Experimental::RNTupleWriteOptions::Clone() const
{
   return std::make_unique<RNTupleWriteOptions>(*this);
}

void ROOT::Experimental::RNTupleWriteOptions::SetApproxZippedClusterSize(std::size_t val)
{
   EnsureValidTunables(val, fMaxUnzippedClusterSize, fApproxUnzippedPageSize);
   fApproxZippedClusterSize = val;
}

void ROOT::Experimental::RNTupleWriteOptions::SetMaxUnzippedClusterSize(std::size_t val)
{
   EnsureValidTunables(fApproxZippedClusterSize, val, fApproxUnzippedPageSize);
   fMaxUnzippedClusterSize = val;
}

void ROOT::Experimental::RNTupleWriteOptions::SetApproxUnzippedPageSize(std::size_t val)
{
   EnsureValidTunables(fApproxZippedClusterSize, fMaxUnzippedClusterSize, val);
   fApproxUnzippedPageSize = val;
}
<commit_msg>[ntuple] Improve input check ordering in RNTupleWriteOptions<commit_after>/// \file RNTupleOptions.cxx
/// \ingroup NTuple ROOT7
/// \author <NAME> <<EMAIL>>
/// \date 2021-07-28
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
 * Copyright (C) 1995-2021, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include <ROOT/RError.hxx>
#include <ROOT/RNTupleOptions.hxx>

#include <utility>

namespace {

void EnsureValidTunables(std::size_t zippedClusterSize, std::size_t unzippedClusterSize, std::size_t unzippedPageSize)
{
   using RException = ROOT::Experimental::RException;
   if (zippedClusterSize == 0) {
      throw RException(R__FAIL("invalid target cluster size: 0"));
   }
   if (unzippedPageSize == 0) {
      throw RException(R__FAIL("invalid target page size: 0"));
   }
   if (zippedClusterSize > unzippedClusterSize) {
      throw RException(R__FAIL("compressed target cluster size must not be larger than "
                               "maximum uncompressed cluster size"));
   }
   if (unzippedPageSize > unzippedClusterSize) {
      throw RException(R__FAIL("target page size must not be larger than "
                               "maximum uncompressed cluster size"));
   }
}

} // anonymous namespace

std::unique_ptr<ROOT::Experimental::RNTupleWriteOptions>
ROOT::Experimental::RNTupleWriteOptions::Clone() const
{
   return std::make_unique<RNTupleWriteOptions>(*this);
}

void ROOT::Experimental::RNTupleWriteOptions::SetApproxZippedClusterSize(std::size_t val)
{
   EnsureValidTunables(val, fMaxUnzippedClusterSize, fApproxUnzippedPageSize);
   fApproxZippedClusterSize = val;
}

void ROOT::Experimental::RNTupleWriteOptions::SetMaxUnzippedClusterSize(std::size_t val)
{
   EnsureValidTunables(fApproxZippedClusterSize, val, fApproxUnzippedPageSize);
   fMaxUnzippedClusterSize = val;
}

void ROOT::Experimental::RNTupleWriteOptions::SetApproxUnzippedPageSize(std::size_t val)
{
   EnsureValidTunables(fApproxZippedClusterSize, fMaxUnzippedClusterSize, val);
   fApproxUnzippedPageSize = val;
}

{'fraction_non_alphanumeric': 0.15408991879580114, 'fraction_numerical': 0.008714596949891068, 'mean_word_length': 3.449339207048458, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '234292', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1418, 'n_words': 312}