CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
evf::EvFBuildingThrottle Class Reference

#include <EvFBuildingThrottle.h>

Public Types

enum  Directory { mInvalid = 0, mBase, mBU, mCOUNT }
 

Public Member Functions

 EvFBuildingThrottle (const edm::ParameterSet &pset, edm::ActivityRegistry &reg)
 
void postBeginRun (edm::GlobalContext const &gc)
 
void postEndRun (edm::GlobalContext const &gc)
 
void preBeginLumi (edm::GlobalContext const &gc)
 
void preBeginRun (edm::GlobalContext const &gc)
 
bool throttled () const
 
 ~EvFBuildingThrottle ()
 

Private Member Functions

void dowork ()
 
void start ()
 
void stop ()
 

Private Attributes

std::string baseDir_
 
double highWaterMark_
 
std::mutex lock_
 
double lowWaterMark_
 
std::atomic< bool > m_stoprequest
 
std::shared_ptr< std::thread > m_thread
 
unsigned int sleep_
 
bool throttled_
 
edm::ServiceToken token_
 
Directory whatToThrottleOn_
 

Detailed Description

Definition at line 18 of file EvFBuildingThrottle.h.

Member Enumeration Documentation

◆ Directory

Constructor & Destructor Documentation

◆ EvFBuildingThrottle()

evf::EvFBuildingThrottle::EvFBuildingThrottle ( const edm::ParameterSet pset,
edm::ActivityRegistry reg 
)
inlineexplicit

Definition at line 21 of file EvFBuildingThrottle.h.

References postEndRun(), preBeginLumi(), preBeginRun(), edm::ActivityRegistry::watchPostGlobalEndRun(), edm::ActivityRegistry::watchPreGlobalBeginLumi(), and edm::ActivityRegistry::watchPreGlobalBeginRun().

22  : highWaterMark_(pset.getUntrackedParameter<double>("highWaterMark", 0.8)),
23  lowWaterMark_(pset.getUntrackedParameter<double>("lowWaterMark", 0.5)),
24  m_stoprequest(false),
25  whatToThrottleOn_(Directory(pset.getUntrackedParameter<int>("dirCode", mBase))),
26  throttled_(false),
27  sleep_(pset.getUntrackedParameter<unsigned int>("sleepmSecs", 1000)) {
31  }
std::atomic< bool > m_stoprequest
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
void preBeginLumi(edm::GlobalContext const &gc)
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
void watchPostGlobalEndRun(PostGlobalEndRun::slot_type const &iSlot)
void preBeginRun(edm::GlobalContext const &gc)
void postEndRun(edm::GlobalContext const &gc)

◆ ~EvFBuildingThrottle()

evf::EvFBuildingThrottle::~EvFBuildingThrottle ( )
inline

Definition at line 32 of file EvFBuildingThrottle.h.

32 {}

Member Function Documentation

◆ dowork()

void evf::EvFBuildingThrottle::dowork ( )
inlineprivate

Definition at line 60 of file EvFBuildingThrottle.h.

References baseDir_, visDQMUpload::buf, gather_cfg::cout, nano_mu_digi_cff::float, HLT_2024v14_cff::fraction, highWaterMark_, lock_, lowWaterMark_, m_stoprequest, edm::shutdown_flag, sleep_, throttled_, and token_.

Referenced by start().

60  {
62  struct statvfs buf;
63  while (!m_stoprequest) {
64  int retval = statvfs(baseDir_.c_str(), &buf);
65  if (retval != 0) {
66  std::cout << " building throttle - unable to stat " << baseDir_ << std::endl;
67  m_stoprequest = true;
68  continue;
69  }
70  double fraction = 1. - float(buf.f_bfree * buf.f_bsize) / float(buf.f_blocks * buf.f_frsize);
71  bool highwater_ = fraction > highWaterMark_;
72  bool lowwater_ = fraction < lowWaterMark_;
73  if (highwater_ && !throttled_) {
74  lock_.lock();
75  throttled_ = true;
76  std::cout << ">>>>throttling on " << std::endl;
77  }
78  if (lowwater_ && throttled_) {
79  lock_.unlock();
80  throttled_ = false;
81  }
82  std::cout << " building throttle on " << baseDir_ << " is " << fraction * 100 << " %full " << std::endl;
83  //edm::Service<EvFDaqDirector>()->writeDiskAndThrottleStat(fraction,highwater_,lowwater_);
84  ::usleep(sleep_ * 1000);
85  if (edm::shutdown_flag) {
86  std::cout << " Shutdown flag set: stop throttling" << std::endl;
87  break;
88  }
89  }
90  if (throttled_)
91  lock_.unlock();
92  }
std::atomic< bool > m_stoprequest
volatile std::atomic< bool > shutdown_flag

◆ postBeginRun()

void evf::EvFBuildingThrottle::postBeginRun ( edm::GlobalContext const &  gc)
inline

Definition at line 50 of file EvFBuildingThrottle.h.

50 {}

◆ postEndRun()

void evf::EvFBuildingThrottle::postEndRun ( edm::GlobalContext const &  gc)
inline

Definition at line 52 of file EvFBuildingThrottle.h.

References stop().

Referenced by EvFBuildingThrottle().

◆ preBeginLumi()

void evf::EvFBuildingThrottle::preBeginLumi ( edm::GlobalContext const &  gc)
inline

Definition at line 53 of file EvFBuildingThrottle.h.

References lock_.

Referenced by EvFBuildingThrottle().

53  {
54  lock_.lock();
55  lock_.unlock();
56  }

◆ preBeginRun()

void evf::EvFBuildingThrottle::preBeginRun ( edm::GlobalContext const &  gc)
inline

Definition at line 33 of file EvFBuildingThrottle.h.

References baseDir_, mBase, mBU, mInvalid, start(), and whatToThrottleOn_.

Referenced by EvFBuildingThrottle().

33  {
34  //obtain directory to stat on
35  switch (whatToThrottleOn_) {
36  case mInvalid:
37  //do nothing
38  break;
39  case mBase:
40  baseDir_ = edm::Service<EvFDaqDirector>()->baseRunDir();
41  break;
42  case mBU:
43  baseDir_ = edm::Service<EvFDaqDirector>()->buBaseRunDir();
44  break;
45  default:
46  baseDir_ = edm::Service<EvFDaqDirector>()->baseRunDir();
47  }
48  start();
49  }

◆ start()

void evf::EvFBuildingThrottle::start ( )
inlineprivate

Definition at line 93 of file EvFBuildingThrottle.h.

References cms::cuda::assert(), gather_cfg::cout, dowork(), edm::ServiceRegistry::instance(), m_thread, edm::ServiceRegistry::presentToken(), token_, and whatToThrottleOn_.

Referenced by progressbar.ProgressBar::__next__(), Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), and preBeginRun().

93  {
94  assert(!m_thread);
96  m_thread = std::make_shared<std::thread>(std::bind(&EvFBuildingThrottle::dowork, this));
97  std::cout << "throttle thread started - throttle on " << whatToThrottleOn_ << std::endl;
98  }
assert(be >=bs)
static ServiceRegistry & instance()
std::shared_ptr< std::thread > m_thread
ServiceToken presentToken() const

◆ stop()

void evf::EvFBuildingThrottle::stop ( )
inlineprivate

Definition at line 99 of file EvFBuildingThrottle.h.

References cms::cuda::assert(), m_stoprequest, and m_thread.

Referenced by postEndRun().

99  {
100  assert(m_thread);
101  m_stoprequest = true;
102  m_thread->join();
103  }
std::atomic< bool > m_stoprequest
assert(be >=bs)
std::shared_ptr< std::thread > m_thread

◆ throttled()

bool evf::EvFBuildingThrottle::throttled ( ) const
inline

Definition at line 57 of file EvFBuildingThrottle.h.

References throttled_.

Member Data Documentation

◆ baseDir_

std::string evf::EvFBuildingThrottle::baseDir_
private

Definition at line 110 of file EvFBuildingThrottle.h.

Referenced by dowork(), and preBeginRun().

◆ highWaterMark_

double evf::EvFBuildingThrottle::highWaterMark_
private

Definition at line 105 of file EvFBuildingThrottle.h.

Referenced by dowork().

◆ lock_

std::mutex evf::EvFBuildingThrottle::lock_
private

Definition at line 109 of file EvFBuildingThrottle.h.

Referenced by dowork(), and preBeginLumi().

◆ lowWaterMark_

double evf::EvFBuildingThrottle::lowWaterMark_
private

Definition at line 106 of file EvFBuildingThrottle.h.

Referenced by dowork().

◆ m_stoprequest

std::atomic<bool> evf::EvFBuildingThrottle::m_stoprequest
private

Definition at line 107 of file EvFBuildingThrottle.h.

Referenced by dowork(), and stop().

◆ m_thread

std::shared_ptr<std::thread> evf::EvFBuildingThrottle::m_thread
private

Definition at line 108 of file EvFBuildingThrottle.h.

Referenced by start(), and stop().

◆ sleep_

unsigned int evf::EvFBuildingThrottle::sleep_
private

Definition at line 114 of file EvFBuildingThrottle.h.

Referenced by dowork().

◆ throttled_

bool evf::EvFBuildingThrottle::throttled_
private

Definition at line 113 of file EvFBuildingThrottle.h.

Referenced by dowork(), and throttled().

◆ token_

edm::ServiceToken evf::EvFBuildingThrottle::token_
private

Definition at line 112 of file EvFBuildingThrottle.h.

Referenced by dowork(), and start().

◆ whatToThrottleOn_

Directory evf::EvFBuildingThrottle::whatToThrottleOn_
private

Definition at line 111 of file EvFBuildingThrottle.h.

Referenced by preBeginRun(), and start().