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_
 
boost::mutex lock_
 
double lowWaterMark_
 
std::atomic< bool > m_stoprequest
 
boost::shared_ptr< boost::thread > m_thread
 
unsigned int sleep_
 
bool throttled_
 
edm::ServiceToken token_
 
Directory whatToThrottleOn_
 

Detailed Description

Definition at line 19 of file EvFBuildingThrottle.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Definition at line 23 of file EvFBuildingThrottle.h.

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

25  : highWaterMark_(pset.getUntrackedParameter<double>("highWaterMark",0.8))
26  , lowWaterMark_(pset.getUntrackedParameter<double>("lowWaterMark",0.5))
27  , m_stoprequest(false)
29  , throttled_(false)
30  , sleep_( pset.getUntrackedParameter<unsigned int>("sleepmSecs",1000))
31  {
35  }
T getUntrackedParameter(std::string const &, T const &) const
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)
evf::EvFBuildingThrottle::~EvFBuildingThrottle ( )
inline

Definition at line 36 of file EvFBuildingThrottle.h.

36 {}

Member Function Documentation

void evf::EvFBuildingThrottle::dowork ( )
inlineprivate

Definition at line 66 of file EvFBuildingThrottle.h.

References baseDir_, gather_cfg::cout, objects.autophobj::float, dedxEstimators_cff::fraction, highWaterMark_, lock_, lowWaterMark_, m_stoprequest, cmsPerfStripChart::operate(), edm::shutdown_flag, sleep_, throttled_, and token_.

Referenced by start().

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

Definition at line 54 of file EvFBuildingThrottle.h.

54  {
55  }
void evf::EvFBuildingThrottle::postEndRun ( edm::GlobalContext const &  gc)
inline

Definition at line 57 of file EvFBuildingThrottle.h.

References stop().

Referenced by EvFBuildingThrottle().

57  {
58  stop();
59  }
void evf::EvFBuildingThrottle::preBeginLumi ( edm::GlobalContext const &  gc)
inline

Definition at line 60 of file EvFBuildingThrottle.h.

References lock_.

Referenced by EvFBuildingThrottle().

60  {
61  lock_.lock();
62  lock_.unlock();
63  }
void evf::EvFBuildingThrottle::preBeginRun ( edm::GlobalContext const &  gc)
inline

Definition at line 37 of file EvFBuildingThrottle.h.

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

Referenced by EvFBuildingThrottle().

37  {
38  //obtain directory to stat on
39  switch(whatToThrottleOn_){
40  case mInvalid:
41  //do nothing
42  break;
43  case mBase:
44  baseDir_ = edm::Service<EvFDaqDirector>()->baseRunDir();
45  break;
46  case mBU:
47  baseDir_ = edm::Service<EvFDaqDirector>()->buBaseRunDir();
48  break;
49  default:
50  baseDir_ = edm::Service<EvFDaqDirector>()->baseRunDir();
51  }
52  start();
53  }
void evf::EvFBuildingThrottle::start ( )
inlineprivate

Definition at line 91 of file EvFBuildingThrottle.h.

References 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().

91  {
92  assert(!m_thread);
94  m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&EvFBuildingThrottle::dowork,this)));
95  std::cout << "throttle thread started - throttle on " << whatToThrottleOn_ << std::endl;
96  }
ServiceToken presentToken() const
static ServiceRegistry & instance()
boost::shared_ptr< boost::thread > m_thread
void evf::EvFBuildingThrottle::stop ( )
inlineprivate

Definition at line 97 of file EvFBuildingThrottle.h.

References m_stoprequest, and m_thread.

Referenced by postEndRun().

97  {
98  assert(m_thread);
99  m_stoprequest=true;
100  m_thread->join();
101  }
std::atomic< bool > m_stoprequest
boost::shared_ptr< boost::thread > m_thread
bool evf::EvFBuildingThrottle::throttled ( ) const
inline

Definition at line 64 of file EvFBuildingThrottle.h.

References throttled_.

Member Data Documentation

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

Definition at line 108 of file EvFBuildingThrottle.h.

Referenced by dowork(), and preBeginRun().

double evf::EvFBuildingThrottle::highWaterMark_
private

Definition at line 103 of file EvFBuildingThrottle.h.

Referenced by dowork().

boost::mutex evf::EvFBuildingThrottle::lock_
private

Definition at line 107 of file EvFBuildingThrottle.h.

Referenced by dowork(), and preBeginLumi().

double evf::EvFBuildingThrottle::lowWaterMark_
private

Definition at line 104 of file EvFBuildingThrottle.h.

Referenced by dowork().

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

Definition at line 105 of file EvFBuildingThrottle.h.

Referenced by dowork(), and stop().

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

Definition at line 106 of file EvFBuildingThrottle.h.

Referenced by start(), and stop().

unsigned int evf::EvFBuildingThrottle::sleep_
private

Definition at line 112 of file EvFBuildingThrottle.h.

Referenced by dowork().

bool evf::EvFBuildingThrottle::throttled_
private

Definition at line 111 of file EvFBuildingThrottle.h.

Referenced by dowork(), and throttled().

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

Definition at line 110 of file EvFBuildingThrottle.h.

Referenced by dowork(), and start().

Directory evf::EvFBuildingThrottle::whatToThrottleOn_
private

Definition at line 109 of file EvFBuildingThrottle.h.

Referenced by preBeginRun(), and start().