CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
tfaot::BatchRule Class Reference

#include <Batching.h>

Public Member Functions

 BatchRule (size_t batchSize, const std::vector< size_t > &sizes, size_t lastPadding=0)
 
 BatchRule (const std::string &ruleString)
 
size_t getBatchSize () const
 
size_t getLastPadding () const
 
size_t getSize (size_t i) const
 
const std::vector< size_t > & getSizes () const
 
size_t nSizes () const
 
 ~BatchRule ()=default
 

Private Member Functions

void validate () const
 

Private Attributes

size_t batchSize_
 
size_t lastPadding_
 
std::vector< size_t > sizes_
 

Detailed Description

Definition at line 19 of file Batching.h.

Constructor & Destructor Documentation

◆ BatchRule() [1/2]

tfaot::BatchRule::BatchRule ( size_t  batchSize,
const std::vector< size_t > &  sizes,
size_t  lastPadding = 0 
)
explicit

Definition at line 16 of file Batching.cc.

References validate().

17  : batchSize_(batchSize), sizes_(sizes), lastPadding_(lastPadding) {
18  validate();
19  }
size_t lastPadding_
Definition: Batching.h:49
void validate() const
Definition: Batching.cc:54
std::vector< size_t > sizes_
Definition: Batching.h:48
size_t batchSize_
Definition: Batching.h:47

◆ BatchRule() [2/2]

tfaot::BatchRule::BatchRule ( const std::string &  ruleString)

Definition at line 21 of file Batching.cc.

References HLT_FULL_cff::batchSize, batchSize_, Exception, lastPadding_, sizes_, AlCaHLTBitMon_QueryRunRegistry::string, and validate().

21  {
22  // extract the target batch size from the front
23  std::string rule = ruleString;
24  auto pos = rule.find(":");
25  if (pos == std::string::npos) {
26  throw cms::Exception("InvalidBatchRule") << "invalid batch rule format: " << ruleString;
27  }
28  size_t batchSize = std::stoi(rule.substr(0, pos));
29  rule = rule.substr(pos + 1);
30 
31  // loop through remaining comma-separated sizes
32  std::vector<size_t> sizes;
33  size_t sumSizes = 0;
34  while (!rule.empty()) {
35  pos = rule.find(",");
36  sizes.push_back(std::stoi(rule.substr(0, pos)));
37  sumSizes += sizes.back();
38  rule = pos == std::string::npos ? "" : rule.substr(pos + 1);
39  }
40 
41  // the sum of composite batch sizes should never be smaller than the target batch size
42  if (sumSizes < batchSize) {
43  throw cms::Exception("InvalidBatchRule")
44  << "sum of composite batch sizes is smaller than target batch size: " << ruleString;
45  }
46 
47  // set members and validate
49  sizes_ = sizes;
50  lastPadding_ = sumSizes - batchSize;
51  validate();
52  }
size_t lastPadding_
Definition: Batching.h:49
void validate() const
Definition: Batching.cc:54
std::vector< size_t > sizes_
Definition: Batching.h:48
size_t batchSize_
Definition: Batching.h:47

◆ ~BatchRule()

tfaot::BatchRule::~BatchRule ( )
default

Member Function Documentation

◆ getBatchSize()

size_t tfaot::BatchRule::getBatchSize ( ) const
inline

Definition at line 32 of file Batching.h.

References batchSize_.

Referenced by tfaot::operator<<(), and tfaot::BatchStrategy::setRule().

32 { return batchSize_; }
size_t batchSize_
Definition: Batching.h:47

◆ getLastPadding()

size_t tfaot::BatchRule::getLastPadding ( ) const
inline

Definition at line 38 of file Batching.h.

References lastPadding_.

Referenced by tfaot::operator<<(), and tfaot::Model< W >::run().

38 { return lastPadding_; }
size_t lastPadding_
Definition: Batching.h:49

◆ getSize()

size_t tfaot::BatchRule::getSize ( size_t  i) const
inline

Definition at line 44 of file Batching.h.

References mps_fire::i, and sizes_.

Referenced by tfaot::Model< W >::run().

44 { return sizes_[i]; }
std::vector< size_t > sizes_
Definition: Batching.h:48

◆ getSizes()

const std::vector<size_t>& tfaot::BatchRule::getSizes ( ) const
inline

Definition at line 35 of file Batching.h.

References sizes_.

Referenced by tfaot::operator<<().

35 { return sizes_; }
std::vector< size_t > sizes_
Definition: Batching.h:48

◆ nSizes()

size_t tfaot::BatchRule::nSizes ( ) const
inline

Definition at line 41 of file Batching.h.

References sizes_.

Referenced by tfaot::operator<<(), and tfaot::Model< W >::run().

41 { return sizes_.size(); }
std::vector< size_t > sizes_
Definition: Batching.h:48

◆ validate()

void tfaot::BatchRule::validate ( ) const
private

Definition at line 54 of file Batching.cc.

References batchSize_, Exception, lastPadding_, alignCSCRings::s, and sizes_.

Referenced by BatchRule().

54  {
55  // sizes must not be empty
56  if (sizes_.size() == 0) {
57  throw cms::Exception("EmptySizes") << "no batch sizes provided for stitching";
58  }
59 
60  // the padding must be smaller than the last size
61  size_t lastSize = sizes_[sizes_.size() - 1];
62  if (lastPadding_ >= lastSize) {
63  throw cms::Exception("WrongPadding")
64  << "padding " << lastPadding_ << " must be smaller than last size " << lastSize;
65  }
66 
67  // compute the covered batch size
68  size_t sizeSum = 0;
69  for (const size_t& s : sizes_) {
70  sizeSum += s;
71  }
72  if (lastPadding_ > sizeSum) {
73  throw cms::Exception("WrongPadding")
74  << "padding " << lastPadding_ << " must not be larger than sum of sizes " << sizeSum;
75  }
76  sizeSum -= lastPadding_;
77 
78  // compare to given batch size
79  if (batchSize_ != sizeSum) {
80  throw cms::Exception("WrongBatchSize")
81  << "batch size " << batchSize_ << " does not match sum of sizes - padding " << sizeSum;
82  }
83  }
size_t lastPadding_
Definition: Batching.h:49
std::vector< size_t > sizes_
Definition: Batching.h:48
size_t batchSize_
Definition: Batching.h:47

Member Data Documentation

◆ batchSize_

size_t tfaot::BatchRule::batchSize_
private

Definition at line 47 of file Batching.h.

Referenced by BatchRule(), getBatchSize(), and validate().

◆ lastPadding_

size_t tfaot::BatchRule::lastPadding_
private

Definition at line 49 of file Batching.h.

Referenced by BatchRule(), getLastPadding(), and validate().

◆ sizes_

std::vector<size_t> tfaot::BatchRule::sizes_
private

Definition at line 48 of file Batching.h.

Referenced by BatchRule(), getSize(), getSizes(), nSizes(), and validate().