CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
evf::FastMonitoringService Class Reference

#include <FastMonitoringService.h>

Inheritance diagram for evf::FastMonitoringService:
evf::MicroStateService

Classes

struct  Encoding
 

Public Member Functions

void accumulateFileSize (unsigned int lumi, unsigned long fileSize)
 
 FastMonitoringService (const edm::ParameterSet &, edm::ActivityRegistry &)
 
bool getAbortFlagForLumi (unsigned int lumi)
 
unsigned int getEventsProcessedForLumi (unsigned int lumi, bool *abortFlag=0)
 
std::string getRunDirName () const
 
void jobFailure ()
 
std::string makeModuleLegendaJson ()
 
std::string makePathLegendaJson ()
 
void postBeginJob ()
 
void postEndJob ()
 
void postEvent (edm::StreamContext const &)
 
void postGlobalBeginRun (edm::GlobalContext const &)
 
void postGlobalEndLumi (edm::GlobalContext const &)
 
void postModuleEvent (edm::StreamContext const &, edm::ModuleCallingContext const &)
 
void postSourceEvent (edm::StreamID)
 
void postStreamBeginLumi (edm::StreamContext const &)
 
void postStreamEndLumi (edm::StreamContext const &)
 
void preallocate (edm::service::SystemBounds const &)
 
void preBeginJob (edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &pc)
 
void preEvent (edm::StreamContext const &)
 
void preGlobalBeginLumi (edm::GlobalContext const &)
 
void preGlobalEarlyTermination (edm::GlobalContext const &, edm::TerminationOrigin)
 
void preGlobalEndLumi (edm::GlobalContext const &)
 
void preModuleBeginJob (edm::ModuleDescription const &)
 
void preModuleEvent (edm::StreamContext const &, edm::ModuleCallingContext const &)
 
void prePathEvent (edm::StreamContext const &, edm::PathContext const &)
 
void preSourceEarlyTermination (edm::TerminationOrigin)
 
void preSourceEvent (edm::StreamID)
 
void preStreamBeginLumi (edm::StreamContext const &)
 
void preStreamEarlyTermination (edm::StreamContext const &, edm::TerminationOrigin)
 
void preStreamEndLumi (edm::StreamContext const &)
 
void reportLockWait (unsigned int ls, double waitTime, unsigned int lockCount)
 
void setExceptionDetected (unsigned int ls)
 
void setInputSource (FedRawDataInputSource *inputSource)
 
void setMicroState (MicroStateService::Microstate)
 
void setMicroState (edm::StreamID, MicroStateService::Microstate)
 
bool shouldWriteFiles (unsigned int lumi, unsigned int *proc=0)
 
void startedLookingForFile ()
 
void stoppedLookingForFile (unsigned int lumi)
 
 ~FastMonitoringService ()
 
- Public Member Functions inherited from evf::MicroStateService
virtual std::string getMicroState1 ()
 
virtual std::string const & getMicroState2 ()
 
 MicroStateService (const edm::ParameterSet &, edm::ActivityRegistry &)
 
virtual ~MicroStateService ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Static Public Attributes

static const std::string macroStateNames [FastMonitoringThread::MCOUNT]
 
static const std::string nopath_ = "NoPath"
 
- Static Public Attributes inherited from evf::MicroStateService
static const edm::ModuleDescription reservedMicroStateNames [mCOUNT]
 

Private Member Functions

void doSnapshot (const unsigned int ls, const bool isGlobalEOL)
 
void doStreamEOLSnapshot (const unsigned int ls, const unsigned int streamID)
 
void dowork ()
 

Private Attributes

std::map< unsigned int,
unsigned long > 
accuSize_
 
std::map< unsigned int, double > avgLeadTime_
 
std::vector< std::atomic< bool > * > collectedPathList_
 
bool emptyLumisectionMode_ = false
 
Encoding encModule_
 
std::vector< EncodingencPath_
 
std::vector< unsigned int > eventCountForPathInit_
 
bool exception_detected_ = false
 
std::vector< unsigned int > exceptionInLS_
 
std::string fastMicrostateDefPath_
 
unsigned int fastMonIntervals_
 
std::string fastName_
 
std::string fastPath_
 
timeval fileLookStart_
 
timeval fileLookStop_
 
std::map< unsigned int,
unsigned int > 
filesProcessedDuringLumi_
 
std::vector< unsigned long > firstEventId_
 
FastMonitoringThread fmt_
 
FedRawDataInputSourceinputSource_ = 0
 
bool isGlobalLumiTransition_
 
unsigned int lastGlobalLumi_
 
std::queue< unsigned int > lastGlobalLumisClosed_
 
std::vector< double > leadTimes_
 
std::map< unsigned int,
std::pair< double, unsigned
int > > 
lockStatsDuringLumi_
 
unsigned int lumiFromSource_
 
std::map< unsigned int, timeval > lumiStartTime_
 
FastMonitoringThread::Macrostate macrostate_
 
std::vector< const void * > microstate_
 
std::string microstateDefPath_
 
std::vector< const void * > ministate_
 
std::string moduleLegendFile_
 
std::string moduleLegendFileJson_
 
std::atomic< bool > monInit_
 
unsigned int nOutputModules_ =0
 
unsigned int nStreams_
 
unsigned int nThreads_
 
std::string pathLegendFile_
 
std::string pathLegendFileJson_
 
bool pathLegendWritten_ = false
 
std::vector< bool > pathNamesReady_
 
std::map< unsigned int,
std::pair< unsigned int, bool > > 
processedEventsPerLumi_
 
boost::filesystem::path runDirectory_
 
int sleepTime_
 
std::string slowName_
 
unsigned int snapCounter_ = 0
 
std::vector< std::atomic< bool > * > streamCounterUpdating_
 
bool threadIDAvailable_ = false
 
std::vector< const void * > threadMicrostate_
 
std::atomic< unsigned long > totalEventsProcessed_
 
boost::filesystem::path workingDirectory_
 

Additional Inherited Members

- Public Types inherited from evf::MicroStateService
enum  Microstate {
  mInvalid = 0, mFwkOvh, mIdle, mInput,
  mInputDone, mDqm, mEoL, mCOUNT
}
 
- Static Protected Attributes inherited from evf::MicroStateService
static const std::string default_return_ ="NotImplemented"
 

Detailed Description

Definition at line 57 of file FastMonitoringService.h.

Constructor & Destructor Documentation

evf::FastMonitoringService::FastMonitoringService ( const edm::ParameterSet iPS,
edm::ActivityRegistry reg 
)

Definition at line 41 of file FastMonitoringService.cc.

References Exception, fastMicrostateDefPath_, jobFailure(), microstateDefPath_, postBeginJob(), postEndJob(), postEvent(), postGlobalEndLumi(), postModuleEvent(), postSourceEvent(), postStreamBeginLumi(), postStreamEndLumi(), preallocate(), preBeginJob(), preEvent(), preGlobalBeginLumi(), preGlobalEarlyTermination(), preGlobalEndLumi(), preModuleBeginJob(), preModuleEvent(), prePathEvent(), preSourceEarlyTermination(), preSourceEvent(), preStreamBeginLumi(), preStreamEarlyTermination(), preStreamEndLumi(), AlCaHLTBitMon_QueryRunRegistry::string, edm::ActivityRegistry::watchJobFailure(), edm::ActivityRegistry::watchPostBeginJob(), edm::ActivityRegistry::watchPostEndJob(), edm::ActivityRegistry::watchPostEvent(), edm::ActivityRegistry::watchPostGlobalEndLumi(), edm::ActivityRegistry::watchPostModuleEvent(), edm::ActivityRegistry::watchPostSourceEvent(), edm::ActivityRegistry::watchPostStreamBeginLumi(), edm::ActivityRegistry::watchPostStreamEndLumi(), edm::ActivityRegistry::watchPreallocate(), edm::ActivityRegistry::watchPreBeginJob(), edm::ActivityRegistry::watchPreEvent(), edm::ActivityRegistry::watchPreGlobalBeginLumi(), edm::ActivityRegistry::watchPreGlobalEarlyTermination(), edm::ActivityRegistry::watchPreGlobalEndLumi(), edm::ActivityRegistry::watchPreModuleBeginJob(), edm::ActivityRegistry::watchPreModuleEvent(), edm::ActivityRegistry::watchPrePathEvent(), edm::ActivityRegistry::watchPreSourceEarlyTermination(), edm::ActivityRegistry::watchPreSourceEvent(), edm::ActivityRegistry::watchPreStreamBeginLumi(), edm::ActivityRegistry::watchPreStreamEarlyTermination(), and edm::ActivityRegistry::watchPreStreamEndLumi().

42  :
43  MicroStateService(iPS,reg)
45  ,nStreams_(0)//until initialized
46  ,sleepTime_(iPS.getUntrackedParameter<int>("sleepTime", 1))
47  ,fastMonIntervals_(iPS.getUntrackedParameter<unsigned int>("fastMonIntervals", 2))
48  ,fastName_("fastmoni")
49  ,slowName_("slowmoni")
51  {
52  reg.watchPreallocate(this, &FastMonitoringService::preallocate);//receiving information on number of threads
54 
59 
63 
68 
70 
73 
74  reg.watchPreSourceEvent(this,&FastMonitoringService::preSourceEvent);//source (with streamID of requestor)
76 
79 
83 
84  //find microstate definition path (required by the module)
85  struct stat statbuf;
86  std::string microstateBaseSuffix = "src/EventFilter/Utilities/plugins/microstatedef.jsd";
87  std::string microstatePath = std::string(getenv("CMSSW_BASE")) + "/" + microstateBaseSuffix;
88  if (stat(microstatePath.c_str(), &statbuf)) {
89  microstatePath = std::string(getenv("CMSSW_RELEASE_BASE")) + "/" + microstateBaseSuffix;
90  if (stat(microstatePath.c_str(), &statbuf)) {
91  microstatePath = microstateBaseSuffix;
92  if (stat(microstatePath.c_str(), &statbuf))
93  throw cms::Exception("FastMonitoringService") << "microstate definition file not found";
94  }
95  }
96  fastMicrostateDefPath_ = microstateDefPath_ = microstatePath;
97  }
void prePathEvent(edm::StreamContext const &, edm::PathContext const &)
void watchPreStreamEarlyTermination(PreStreamEarlyTermination::slot_type const &iSlot)
T getUntrackedParameter(std::string const &, T const &) const
void watchPreEvent(PreEvent::slot_type const &iSlot)
void watchPrePathEvent(PrePathEvent::slot_type const &iSlot)
void watchPreallocate(Preallocate::slot_type const &iSlot)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void preallocate(edm::service::SystemBounds const &)
void preGlobalBeginLumi(edm::GlobalContext const &)
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void postGlobalEndLumi(edm::GlobalContext const &)
void postEvent(edm::StreamContext const &)
void watchPreGlobalEndLumi(PreGlobalEndLumi::slot_type const &iSlot)
void watchPostEvent(PostEvent::slot_type const &iSlot)
void watchPostStreamEndLumi(PostStreamEndLumi::slot_type const &iSlot)
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
void preGlobalEndLumi(edm::GlobalContext const &)
void watchPreStreamEndLumi(PreStreamEndLumi::slot_type const &iSlot)
void preGlobalEarlyTermination(edm::GlobalContext const &, edm::TerminationOrigin)
void watchPreSourceEarlyTermination(PreSourceEarlyTermination::slot_type const &iSlot)
void watchJobFailure(JobFailure::slot_type const &iSlot)
convenience function for attaching to signal
void preModuleBeginJob(edm::ModuleDescription const &)
MicroStateService(const edm::ParameterSet &, edm::ActivityRegistry &)
void preStreamEndLumi(edm::StreamContext const &)
void watchPostStreamBeginLumi(PostStreamBeginLumi::slot_type const &iSlot)
void preStreamEarlyTermination(edm::StreamContext const &, edm::TerminationOrigin)
void watchPreGlobalEarlyTermination(PreGlobalEarlyTermination::slot_type const &iSlot)
static const int nReservedModules
void watchPostGlobalEndLumi(PostGlobalEndLumi::slot_type const &iSlot)
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
void postStreamBeginLumi(edm::StreamContext const &)
void postStreamEndLumi(edm::StreamContext const &)
void preStreamBeginLumi(edm::StreamContext const &)
std::atomic< unsigned long > totalEventsProcessed_
void watchPreStreamBeginLumi(PreStreamBeginLumi::slot_type const &iSlot)
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &pc)
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
void preEvent(edm::StreamContext const &)
void preSourceEarlyTermination(edm::TerminationOrigin)
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
evf::FastMonitoringService::~FastMonitoringService ( )

Definition at line 100 of file FastMonitoringService.cc.

101  {
102  }

Member Function Documentation

void evf::FastMonitoringService::accumulateFileSize ( unsigned int  lumi,
unsigned long  fileSize 
)

Definition at line 596 of file FastMonitoringService.cc.

References accuSize_, filesProcessedDuringLumi_, fmt_, CommonMethods::lock(), fjr2json::lumi, and evf::FastMonitoringThread::monlock_.

Referenced by evf::EvFDaqDirector::bumpFile().

596  {
597  std::lock_guard<std::mutex> lock(fmt_.monlock_);
598 
599  if (accuSize_.find(lumi)==accuSize_.end()) accuSize_[lumi] = fileSize;
600  else accuSize_[lumi] += fileSize;
601 
604  else
606  }
std::map< unsigned int, unsigned long > accuSize_
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, unsigned int > filesProcessedDuringLumi_
void evf::FastMonitoringService::doSnapshot ( const unsigned int  ls,
const bool  isGlobalEOL 
)
private

Definition at line 680 of file FastMonitoringService.cc.

References avgLeadTime_, encModule_, evf::FastMonitoringService::Encoding::encode(), encPath_, evf::FastMonitoringThread::MonitorData::fastAvgLeadTimeJ_, evf::FastMonitoringThread::MonitorData::fastFilesProcessedJ_, evf::FastMonitoringThread::MonitorData::fastLockCountJ_, evf::FastMonitoringThread::MonitorData::fastLockWaitJ_, evf::FastMonitoringThread::MonitorData::fastMacrostateJ_, filesProcessedDuringLumi_, fmt_, i, isGlobalLumiTransition_, evf::FastMonitoringThread::jsonMonitor_, lockStatsDuringLumi_, evf::FastMonitoringThread::m_data, macrostate_, microstate_, evf::FastMonitoringThread::MonitorData::microstateEncoded_, ministate_, evf::FastMonitoringThread::MonitorData::ministateEncoded_, and nStreams_.

Referenced by dowork(), and preGlobalEndLumi().

680  {
681  // update macrostate
683 
684  //update these unless in the midst of a global transition
686 
687  auto itd = avgLeadTime_.find(ls);
688  if (itd != avgLeadTime_.end())
689  fmt_.m_data.fastAvgLeadTimeJ_ = itd->second;
690  else fmt_.m_data.fastAvgLeadTimeJ_=0.;
691 
692  auto iti = filesProcessedDuringLumi_.find(ls);
693  if (iti != filesProcessedDuringLumi_.end())
694  fmt_.m_data.fastFilesProcessedJ_ = iti->second;
696 
697  auto itrd = lockStatsDuringLumi_.find(ls);
698  if (itrd != lockStatsDuringLumi_.end()) {
699  fmt_.m_data.fastLockWaitJ_ = itrd->second.first;
700  fmt_.m_data.fastLockCountJ_ = itrd->second.second;
701  }
702  else {
705  }
706 
707  }
708  else return;
709 
710  //capture latest mini/microstate of streams
711  for (unsigned int i=0;i<nStreams_;i++) {
714  }
715  //for (unsigned int i=0;i<nThreads_;i++)
716  // fmt_.m_data.threadMicrostateEncoded_[i] = encModule_.encode(threadMicrostate_[i]);
717 
718  if (isGlobalEOL)
719  {//only update global variables
720  fmt_.jsonMonitor_->snapGlobal(ls);
721  }
722  else
723  fmt_.jsonMonitor_->snap(ls);
724  }
int i
Definition: DBlmapReader.cc:9
def ls
Definition: eostools.py:348
std::map< unsigned int, unsigned int > filesProcessedDuringLumi_
std::map< unsigned int, double > avgLeadTime_
std::unique_ptr< jsoncollector::FastMonitor > jsonMonitor_
std::map< unsigned int, std::pair< double, unsigned int > > lockStatsDuringLumi_
std::vector< const void * > microstate_
std::vector< unsigned int > microstateEncoded_
FastMonitoringThread::Macrostate macrostate_
std::vector< const void * > ministate_
std::vector< Encoding > encPath_
std::vector< unsigned int > ministateEncoded_
void evf::FastMonitoringService::doStreamEOLSnapshot ( const unsigned int  ls,
const unsigned int  streamID 
)
inlineprivate

Definition at line 177 of file FastMonitoringService.h.

References fmt_, and evf::FastMonitoringThread::jsonMonitor_.

Referenced by preStreamEndLumi().

177  {
178  //pick up only event count here
179  fmt_.jsonMonitor_->snapStreamAtomic(ls,streamID);
180  }
def ls
Definition: eostools.py:348
std::unique_ptr< jsoncollector::FastMonitor > jsonMonitor_
void evf::FastMonitoringService::dowork ( )
inlineprivate

Definition at line 182 of file FastMonitoringService.h.

References doSnapshot(), encModule_, evf::FastMonitoringService::Encoding::encode(), encPath_, evf::FastMonitoringThread::MonitorData::fastMacrostateJ_, fastMonIntervals_, fastPath_, fmt_, evf::FastMonitoringThread::jsonMonitor_, lastGlobalLumi_, CommonMethods::lock(), evf::FastMonitoringThread::m_data, evf::FastMonitoringThread::m_stoprequest, microstate_, ministate_, monInit_, evf::FastMonitoringThread::monlock_, sleepTime_, snapCounter_, AlCaHLTBitMon_QueryRunRegistry::string, and jsoncollector::IntJ::value().

Referenced by preBeginJob().

182  { // the function to be called in the thread. Thread completes when function returns.
183  monInit_.exchange(true,std::memory_order_acquire);
184  while (!fmt_.m_stoprequest) {
185  edm::LogInfo("FastMonitoringService") << "Current states: Ms=" << fmt_.m_data.fastMacrostateJ_.value()
186  << " ms=" << encPath_[0].encode(ministate_[0])
187  << " us=" << encModule_.encode(microstate_[0]) << std::endl;
188 
189  {
190  std::lock_guard<std::mutex> lock(fmt_.monlock_);
191 
193 
195  std::string CSV = fmt_.jsonMonitor_->getCSVString();
196  //release mutex before writing out fast path file
197  fmt_.monlock_.unlock();
198  if (CSV.size())
199  fmt_.jsonMonitor_->outputCSV(fastPath_,CSV);
200  }
201 
202  snapCounter_++;
203 
204  }
205  ::sleep(sleepTime_);
206  }
207  }
void doSnapshot(const unsigned int ls, const bool isGlobalEOL)
std::unique_ptr< jsoncollector::FastMonitor > jsonMonitor_
std::vector< const void * > microstate_
std::atomic< bool > m_stoprequest
std::vector< const void * > ministate_
std::vector< Encoding > encPath_
void evf::FastMonitoringService::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 104 of file FastMonitoringService.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), edm::ParameterSetDescription::setAllowAnything(), and edm::ParameterSetDescription::setComment().

105  {
107  desc.setComment("Service for File-based DAQ monitoring and event accounting");
108  desc.addUntracked<int> ("sleepTime",1)->setComment("Sleep time of the monitoring thread");
109  desc.addUntracked<unsigned int> ("fastMonIntervals",2)->setComment("Modulo of sleepTime intervals on which fastmon file is written out");
110  desc.setAllowAnything();
111  descriptions.add("FastMonitoringService", desc);
112  }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void setAllowAnything()
allow any parameter label/value pairs
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool evf::FastMonitoringService::getAbortFlagForLumi ( unsigned int  lumi)

Definition at line 666 of file FastMonitoringService.cc.

References Exception, fmt_, CommonMethods::lock(), fjr2json::lumi, evf::FastMonitoringThread::monlock_, and processedEventsPerLumi_.

Referenced by shouldWriteFiles().

666  {
667  std::lock_guard<std::mutex> lock(fmt_.monlock_);
668 
669  auto it = processedEventsPerLumi_.find(lumi);
670  if (it!=processedEventsPerLumi_.end()) {
671  unsigned int abortFlag = it->second.second;
672  return abortFlag;
673  }
674  else {
675  throw cms::Exception("FastMonitoringService") << "output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: "<<lumi;
676  return 0;
677  }
678  }
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
unsigned int evf::FastMonitoringService::getEventsProcessedForLumi ( unsigned int  lumi,
bool *  abortFlag = 0 
)

Definition at line 650 of file FastMonitoringService.cc.

References Exception, fmt_, CommonMethods::lock(), fjr2json::lumi, evf::FastMonitoringThread::monlock_, proc, and processedEventsPerLumi_.

Referenced by dqm::DQMFileSaverPB::fillJson(), DQMFileSaver::fillJson(), DQMFileSaver::saveForFilterUnit(), dqm::DQMFileSaverPB::saveLumi(), and shouldWriteFiles().

650  {
651  std::lock_guard<std::mutex> lock(fmt_.monlock_);
652 
653  auto it = processedEventsPerLumi_.find(lumi);
654  if (it!=processedEventsPerLumi_.end()) {
655  unsigned int proc = it->second.first;
656  if (abortFlag) *abortFlag=it->second.second;
657  return proc;
658  }
659  else {
660  throw cms::Exception("FastMonitoringService") << "output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: "<<lumi;
661  return 0;
662  }
663  }
TrainProcessor *const proc
Definition: MVATrainer.cc:101
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
std::string evf::FastMonitoringService::getRunDirName ( ) const
inline

Definition at line 170 of file FastMonitoringService.h.

References runDirectory_.

170 { return runDirectory_.stem().string(); }
boost::filesystem::path runDirectory_
void evf::FastMonitoringService::jobFailure ( )
std::string evf::FastMonitoringService::makeModuleLegendaJson ( )

Definition at line 127 of file FastMonitoringService.cc.

References Json::Value::append(), Json::arrayValue, evf::FastMonitoringService::Encoding::current_, evf::FastMonitoringService::Encoding::decode(), encModule_, i, nOutputModules_, nReservedModules, nSpecialModules, and Json::StyledWriter::write().

Referenced by postBeginJob().

127  {
128  Json::Value legendaVector(Json::arrayValue);
129  for(int i = 0; i < encModule_.current_; i++)
130  legendaVector.append(Json::Value((static_cast<const edm::ModuleDescription *>(encModule_.decode(i)))->moduleLabel()));
131  Json::Value valReserved(nReservedModules);
132  Json::Value valSpecial(nSpecialModules);
133  Json::Value valOutputModules(nOutputModules_);
134  Json::Value moduleLegend;
135  moduleLegend["names"]=legendaVector;
136  moduleLegend["reserved"]=valReserved;
137  moduleLegend["special"]=valSpecial;
138  moduleLegend["output"]=valOutputModules;
139  Json::StyledWriter writer;
140  return writer.write(moduleLegend);
141  }
int i
Definition: DBlmapReader.cc:9
Represents a JSON value.
Definition: value.h:111
static const int nReservedModules
virtual std::string write(const Value &root)
Serialize a Value in JSON format.
static const int nSpecialModules
Writes a Value in JSON format in a human friendly way.
Definition: writer.h:65
const void * decode(unsigned int index)
array value (ordered list)
Definition: value.h:31
std::string evf::FastMonitoringService::makePathLegendaJson ( )

Definition at line 115 of file FastMonitoringService.cc.

References Json::Value::append(), Json::arrayValue, encPath_, i, nReservedPaths, and Json::StyledWriter::write().

Referenced by prePathEvent().

115  {
116  Json::Value legendaVector(Json::arrayValue);
117  for(int i = 0; i < encPath_[0].current_; i++)
118  legendaVector.append(Json::Value(*(static_cast<const std::string *>(encPath_[0].decode(i)))));
119  Json::Value valReserved(nReservedPaths);
120  Json::Value pathLegend;
121  pathLegend["names"]=legendaVector;
122  pathLegend["reserved"]=valReserved;
123  Json::StyledWriter writer;
124  return writer.write(pathLegend);
125  }
int i
Definition: DBlmapReader.cc:9
static const int nReservedPaths
Represents a JSON value.
Definition: value.h:111
virtual std::string write(const Value &root)
Serialize a Value in JSON format.
Writes a Value in JSON format in a human friendly way.
Definition: writer.h:65
std::vector< Encoding > encPath_
array value (ordered list)
Definition: value.h:31
void evf::FastMonitoringService::postBeginJob ( )

Definition at line 324 of file FastMonitoringService.cc.

References encModule_, fmt_, CommonMethods::lock(), evf::FastMonitoringThread::m_data, macrostate_, makeModuleLegendaJson(), evf::FastMonitoringThread::MonitorData::microstateBins_, moduleLegendFileJson_, evf::FastMonitoringThread::monlock_, evf::FastMonitoringThread::sJobReady, AlCaHLTBitMon_QueryRunRegistry::string, and evf::FastMonitoringService::Encoding::vecsize().

Referenced by FastMonitoringService().

325  {
326  std::string && moduleLegStrJson = makeModuleLegendaJson();
327  FileIO::writeStringToFile(moduleLegendFileJson_, moduleLegStrJson);
328 
330 
331  //update number of entries in module histogram
332  std::lock_guard<std::mutex> lock(fmt_.monlock_);
334  }
FastMonitoringThread::Macrostate macrostate_
void evf::FastMonitoringService::postEndJob ( )
void evf::FastMonitoringService::postEvent ( edm::StreamContext const &  sc)

Definition at line 531 of file FastMonitoringService.cc.

References eventCountForPathInit_, evf::FastMonitoringThread::MonitorData::fastPathProcessedJ_, fmt_, evf::FastMonitoringThread::m_data, microstate_, evf::MicroStateService::mIdle, ministate_, nopath_, evf::FastMonitoringThread::MonitorData::processed_, evf::MicroStateService::reservedMicroStateNames, streamCounterUpdating_, edm::StreamContext::streamID(), and totalEventsProcessed_.

Referenced by FastMonitoringService().

532  {
533  microstate_[sc.streamID()] = &reservedMicroStateNames[mIdle];
534 
535  ministate_[sc.streamID()] = &nopath_;
536 
537  #if ATOMIC_LEVEL>=2
538  //use atomic flag to make sure end of lumi sees this
539  streamCounterUpdating_[sc.streamID()]->store(true,std::memory_order_release);
540  fmt_.m_data.processed_[sc.streamID()]->fetch_add(1,std::memory_order_release);
541  streamCounterUpdating_[sc.streamID()]->store(false,std::memory_order_release);
542 
543  #elif ATOMIC_LEVEL==1
544  //writes are atomic, we assume writes propagate to memory before stream EOL snap
545  fmt_.m_data.processed_[sc.streamID()]->fetch_add(1,std::memory_order_relaxed);
546 
547  #elif ATOMIC_LEVEL==0 //default
548  (*(fmt_.m_data.processed_[sc.streamID()]))++;
549  #endif
550  eventCountForPathInit_[sc.streamID()]++;
551 
552  //fast path counter (events accumulated in a run)
553  unsigned long res = totalEventsProcessed_.fetch_add(1,std::memory_order_relaxed);
555  //fmt_.m_data.fastPathProcessedJ_ = totalEventsProcessed_.load(std::memory_order_relaxed);
556  }
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
std::vector< unsigned int > eventCountForPathInit_
std::vector< std::atomic< bool > * > streamCounterUpdating_
static const std::string nopath_
std::vector< const void * > microstate_
std::atomic< unsigned long > totalEventsProcessed_
std::vector< jsoncollector::AtomicMonUInt * > processed_
std::vector< const void * > ministate_
void evf::FastMonitoringService::postGlobalBeginRun ( edm::GlobalContext const &  gc)
void evf::FastMonitoringService::postGlobalEndLumi ( edm::GlobalContext const &  gc)

Definition at line 448 of file FastMonitoringService.cc.

References lastGlobalLumisClosed_, edm::LuminosityBlockID::luminosityBlock(), and edm::GlobalContext::luminosityBlockID().

Referenced by FastMonitoringService().

449  {
450  //mark closed lumis (still keep map entries until next one)
451  lastGlobalLumisClosed_.push(gc.luminosityBlockID().luminosityBlock());
452  }
std::queue< unsigned int > lastGlobalLumisClosed_
void evf::FastMonitoringService::postModuleEvent ( edm::StreamContext const &  sc,
edm::ModuleCallingContext const &  mcc 
)

Definition at line 573 of file FastMonitoringService.cc.

References evf::MicroStateService::mFwkOvh, microstate_, evf::MicroStateService::reservedMicroStateNames, edm::StreamContext::streamID(), and edm::StreamID::value().

Referenced by FastMonitoringService().

574  {
575  //microstate_[sc.streamID().value()] = (void*)(mcc.moduleDescription());
576  microstate_[sc.streamID().value()] = &reservedMicroStateNames[mFwkOvh];
577  }
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
std::vector< const void * > microstate_
void evf::FastMonitoringService::postSourceEvent ( edm::StreamID  sid)

Definition at line 563 of file FastMonitoringService.cc.

References evf::MicroStateService::mFwkOvh, microstate_, evf::MicroStateService::reservedMicroStateNames, and edm::StreamID::value().

Referenced by FastMonitoringService().

564  {
566  }
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
std::vector< const void * > microstate_
unsigned int value() const
Definition: StreamID.h:46
void evf::FastMonitoringService::postStreamBeginLumi ( edm::StreamContext const &  sc)
void evf::FastMonitoringService::postStreamEndLumi ( edm::StreamContext const &  sc)
void evf::FastMonitoringService::preallocate ( edm::service::SystemBounds const &  bounds)

Definition at line 143 of file FastMonitoringService.cc.

References edm::service::SystemBounds::maxNumberOfStreams(), edm::service::SystemBounds::maxNumberOfThreads(), nStreams_, and nThreads_.

Referenced by FastMonitoringService().

144  {
145  nStreams_=bounds.maxNumberOfStreams();
146  nThreads_=bounds.maxNumberOfThreads();
147  //this should already be >=1
148  if (nStreams_==0) nStreams_=1;
149  if (nThreads_==0) nThreads_=1;
150  }
void evf::FastMonitoringService::preBeginJob ( edm::PathsAndConsumesOfModulesBase const &  ,
edm::ProcessContext const &  pc 
)

Definition at line 152 of file FastMonitoringService.cc.

References collectedPathList_, evf::FastMonitoringService::Encoding::completeReservedWithDummies(), dowork(), emptyLumisectionMode_, encModule_, encPath_, eventCountForPathInit_, Exception, fastMicrostateDefPath_, fastName_, fastPath_, firstEventId_, fmt_, i, isGlobalLumiTransition_, evf::FastMonitoringThread::jsonMonitor_, lastGlobalLumi_, LogDebug, lumiFromSource_, evf::FastMonitoringThread::m_data, macrostate_, evf::FastMonitoringThread::MonitorData::macrostateBins_, evf::FastMonitoringThread::MCOUNT, evf::MicroStateService::mCOUNT, microstate_, evf::FastMonitoringThread::MonitorData::microstateBins_, microstateDefPath_, ministate_, evf::FastMonitoringThread::MonitorData::ministateBins_, evf::MicroStateService::mInvalid, moduleLegendFile_, moduleLegendFileJson_, monInit_, nopath_, nStreams_, nThreads_, cppFunctionSkipper::operator, fed_dqm_sourceclient-live_cfg::path, pathLegendFile_, pathLegendFileJson_, evf::FastMonitoringThread::MonitorData::registerVariables(), evf::MicroStateService::reservedMicroStateNames, evf::FastMonitoringThread::resetFastMonitor(), runDirectory_, evf::FastMonitoringThread::sInit, evf::FastMonitoringThread::start(), streamCounterUpdating_, threadIDAvailable_, evf::FastMonitoringService::Encoding::updateReserved(), and workingDirectory_.

Referenced by FastMonitoringService().

154  {
155 
156  // FIND RUN DIRECTORY
157  // The run dir should be set via the configuration of EvFDaqDirector
158 
159  if (edm::Service<evf::EvFDaqDirector>().operator->()==nullptr)
160  {
161  throw cms::Exception("FastMonitoringService") << "EvFDaqDirector is not present";
162 
163  }
164  emptyLumisectionMode_ = edm::Service<evf::EvFDaqDirector>()->emptyLumisectionMode();
165  boost::filesystem::path runDirectory(edm::Service<evf::EvFDaqDirector>()->baseRunDir());
166  workingDirectory_ = runDirectory_ = runDirectory;
167  workingDirectory_ /= "mon";
168 
169  if ( !boost::filesystem::is_directory(workingDirectory_)) {
170  LogDebug("FastMonitoringService") << "<MON> DIR NOT FOUND! Trying to create -: " << workingDirectory_.string() ;
171  boost::filesystem::create_directories(workingDirectory_);
172  if ( !boost::filesystem::is_directory(workingDirectory_))
173  edm::LogWarning("FastMonitoringService") << "Unable to create <MON> DIR -: " << workingDirectory_.string()
174  << ". No monitoring data will be written.";
175  }
176 
177  std::ostringstream fastFileName;
178 
179  fastFileName << fastName_ << "_pid" << std::setfill('0') << std::setw(5) << getpid() << ".fast";
181  fast /= fastFileName.str();
182  fastPath_ = fast.string();
183 
184  std::ostringstream moduleLegFile;
185  std::ostringstream moduleLegFileJson;
186  moduleLegFile << "microstatelegend_pid" << std::setfill('0') << std::setw(5) << getpid() << ".leg";
187  moduleLegFileJson << "microstatelegend_pid" << std::setfill('0') << std::setw(5) << getpid() << ".jsn";
188  moduleLegendFile_ = (workingDirectory_/moduleLegFile.str()).string();
189  moduleLegendFileJson_ = (workingDirectory_/moduleLegFileJson.str()).string();
190 
191  std::ostringstream pathLegFile;
192  std::ostringstream pathLegFileJson;
193  pathLegFile << "pathlegend_pid" << std::setfill('0') << std::setw(5) << getpid() << ".leg";
194  pathLegendFile_ = (workingDirectory_/pathLegFile.str()).string();
195  pathLegFileJson << "pathlegend_pid" << std::setfill('0') << std::setw(5) << getpid() << ".jsn";
196  pathLegendFileJson_ = (workingDirectory_/pathLegFileJson.str()).string();
197 
198  LogDebug("FastMonitoringService") << "Initializing FastMonitor with microstate def path -: "
200  //<< encPath_.current_ + 1 << " " << encModule_.current_ + 1
201 
202  /*
203  * initialize the fast monitor with:
204  * vector of pointers to monitorable parameters
205  * path to definition
206  *
207  */
208 
210 
211  for(unsigned int i = 0; i < (mCOUNT); i++)
212  encModule_.updateReserved(static_cast<const void*>(reservedMicroStateNames+i));
214 
215  for (unsigned int i=0;i<nStreams_;i++) {
216  ministate_.push_back(&nopath_);
218 
219  //for synchronization
220  streamCounterUpdating_.push_back(new std::atomic<bool>(0));
221 
222  //path (mini) state
223  encPath_.emplace_back(0);
224  encPath_[i].update(static_cast<const void*>(&nopath_));
225  eventCountForPathInit_.push_back(0);
226  firstEventId_.push_back(0);
227  collectedPathList_.push_back(new std::atomic<bool>(0));
228 
229  }
230  //for (unsigned int i=0;i<nThreads_;i++)
231  // threadMicrostate_.push_back(&reservedMicroStateNames[mInvalid]);
232 
233  //initial size until we detect number of bins
237 
238  lastGlobalLumi_=0;
240  lumiFromSource_=0;
241 
242  //startup monitoring
244  fmt_.jsonMonitor_->setNStreams(nStreams_);
246  monInit_.store(false,std::memory_order_release);
248 
249  //this definition needs: #include "tbb/compat/thread"
250  //however this would results in TBB imeplementation replacing std::thread
251  //(both supposedly call pthread_self())
252  //number of threads created in process could be obtained from /proc,
253  //assuming that all posix threads are true kernel threads capable of running in parallel
254 
255  //#if TBB_IMPLEMENT_CPP0X
257  //threadIDAvailable_=true;
258  //#endif
259 
260  }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
boost::filesystem::path runDirectory_
void start(void(FastMonitoringService::*fp)(), FastMonitoringService *cp)
std::vector< unsigned int > eventCountForPathInit_
std::vector< std::atomic< bool > * > streamCounterUpdating_
void registerVariables(jsoncollector::FastMonitor *fm, unsigned int nStreams, unsigned int nThreads)
std::vector< std::atomic< bool > * > collectedPathList_
std::unique_ptr< jsoncollector::FastMonitor > jsonMonitor_
static const std::string nopath_
void resetFastMonitor(std::string const &microStateDefPath, std::string const &fastMicroStateDefPath)
std::vector< unsigned long > firstEventId_
std::vector< const void * > microstate_
FastMonitoringThread::Macrostate macrostate_
boost::filesystem::path workingDirectory_
std::vector< const void * > ministate_
std::vector< Encoding > encPath_
void evf::FastMonitoringService::preEvent ( edm::StreamContext const &  sc)

Definition at line 527 of file FastMonitoringService.cc.

Referenced by FastMonitoringService().

528  {
529  }
void evf::FastMonitoringService::preGlobalBeginLumi ( edm::GlobalContext const &  gc)

Definition at line 347 of file FastMonitoringService.cc.

References accuSize_, avgLeadTime_, filesProcessedDuringLumi_, fmt_, isGlobalLumiTransition_, lastGlobalLumi_, lastGlobalLumisClosed_, CommonMethods::lock(), lockStatsDuringLumi_, edm::LuminosityBlockID::luminosityBlock(), edm::GlobalContext::luminosityBlockID(), lumiStartTime_, evf::FastMonitoringThread::monlock_, and processedEventsPerLumi_.

Referenced by FastMonitoringService().

348  {
349 
350  timeval lumiStartTime;
351  gettimeofday(&lumiStartTime, 0);
352  unsigned int newLumi = gc.luminosityBlockID().luminosityBlock();
353 
354  std::lock_guard<std::mutex> lock(fmt_.monlock_);
355 
356  lumiStartTime_[newLumi]=lumiStartTime;
357  while (!lastGlobalLumisClosed_.empty()) {
358  //wipe out old map entries as they aren't needed and slow down access
359  unsigned int oldLumi = lastGlobalLumisClosed_.back();
361  lumiStartTime_.erase(oldLumi);
362  avgLeadTime_.erase(oldLumi);
363  filesProcessedDuringLumi_.erase(oldLumi);
364  accuSize_.erase(oldLumi);
365  lockStatsDuringLumi_.erase(oldLumi);
366  processedEventsPerLumi_.erase(oldLumi);
367  }
368  lastGlobalLumi_= newLumi;
370  }
std::map< unsigned int, timeval > lumiStartTime_
std::map< unsigned int, unsigned long > accuSize_
std::map< unsigned int, unsigned int > filesProcessedDuringLumi_
std::queue< unsigned int > lastGlobalLumisClosed_
std::map< unsigned int, double > avgLeadTime_
std::map< unsigned int, std::pair< double, unsigned int > > lockStatsDuringLumi_
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
void evf::FastMonitoringService::preGlobalEarlyTermination ( edm::GlobalContext const &  gc,
edm::TerminationOrigin  to 
)

Definition at line 274 of file FastMonitoringService.cc.

References edm::ExceptionFromAnotherContext, edm::ExceptionFromThisContext, exceptionInLS_, edm::ExternalSignal, fmt_, CommonMethods::lock(), edm::LuminosityBlockID::luminosityBlock(), edm::GlobalContext::luminosityBlockID(), evf::FastMonitoringThread::monlock_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FastMonitoringService().

275  {
276  std::string context;
277  if (to==edm::TerminationOrigin::ExceptionFromThisContext) context = " FromThisContext ";
278  if (to==edm::TerminationOrigin::ExceptionFromAnotherContext) context = " FromAnotherContext";
279  if (to==edm::TerminationOrigin::ExternalSignal) context = " FromExternalSignal";
280  edm::LogWarning("FastMonitoringService") << " GLOBAL " << "earlyTermination -: LS:"
281  << gc.luminosityBlockID().luminosityBlock() << " " << context;
282  std::lock_guard<std::mutex> lock(fmt_.monlock_);
283  exceptionInLS_.push_back(gc.luminosityBlockID().luminosityBlock());
284  }
std::vector< unsigned int > exceptionInLS_
void evf::FastMonitoringService::preGlobalEndLumi ( edm::GlobalContext const &  gc)

Definition at line 372 of file FastMonitoringService.cc.

References accuSize_, doSnapshot(), Exception, exception_detected_, exceptionInLS_, evf::FastMonitoringThread::MonitorData::fastThroughputJ_, fmt_, FedRawDataInputSource::getEventReport(), inputSource_, isGlobalLumiTransition_, evf::FastMonitoringThread::jsonMonitor_, CommonMethods::lock(), LogDebug, fjr2json::lumi, edm::LuminosityBlockID::luminosityBlock(), edm::GlobalContext::luminosityBlockID(), lumiStartTime_, evf::FastMonitoringThread::m_data, evf::FastMonitoringThread::monlock_, fed_dqm_sourceclient-live_cfg::path, processedEventsPerLumi_, edm::shutdown_flag, slowName_, throughputFactor(), jsoncollector::IntJ::value(), jsoncollector::DoubleJ::value(), and workingDirectory_.

Referenced by FastMonitoringService().

373  {
374  unsigned int lumi = gc.luminosityBlockID().luminosityBlock();
375  LogDebug("FastMonitoringService") << "Lumi ended. Writing JSON information. LUMI -: "
376  << lumi;
377  timeval lumiStopTime;
378  gettimeofday(&lumiStopTime, 0);
379 
380  std::lock_guard<std::mutex> lock(fmt_.monlock_);
381 
382  // Compute throughput
383  timeval stt = lumiStartTime_[lumi];
384  unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec)*1000000
385  + (lumiStopTime.tv_usec - stt.tv_usec);
386  unsigned long accuSize = accuSize_.find(lumi)==accuSize_.end() ? 0 : accuSize_[lumi];
387  double throughput = throughputFactor()* double(accuSize) / double(usecondsForLumi);
388  //store to registered variable
389  fmt_.m_data.fastThroughputJ_.value() = throughput;
390 
391  //update
392  doSnapshot(lumi,true);
393 
394  // create file name for slow monitoring file
395  std::stringstream slowFileName;
396  slowFileName << slowName_ << "_ls" << std::setfill('0') << std::setw(4)
397  << lumi << "_pid" << std::setfill('0')
398  << std::setw(5) << getpid() << ".jsn";
400  slow /= slowFileName.str();
401 
402  //retrieve one result we need (todo: sanity check if it's found)
403  IntJ *lumiProcessedJptr = dynamic_cast<IntJ*>(fmt_.jsonMonitor_->getMergedIntJForLumi("Processed",lumi));
404  if (!lumiProcessedJptr)
405  throw cms::Exception("FastMonitoringService") << "Internal error: got null pointer from FastMonitor";
406  processedEventsPerLumi_[lumi] = std::pair<unsigned int,bool>(lumiProcessedJptr->value(),false);
407 
408  //checking if exception has been thrown (in case of Global/Stream early termination, for this LS)
409  bool exception_detected = exception_detected_;
410  for (auto ex : exceptionInLS_)
411  if (lumi == ex) exception_detected=true;
412 
413  if (edm::shutdown_flag || exception_detected) {
414  edm::LogInfo("FastMonitoringService") << "Run interrupted. Skip writing EoL information -: "
415  << processedEventsPerLumi_[lumi].first << " events were processed in LUMI " << lumi;
416  //this will prevent output modules from producing json file for possibly incomplete lumi
417  processedEventsPerLumi_[lumi].first=0;
418  processedEventsPerLumi_[lumi].second=true;
419  //disable this exception, so service can be used standalone (will be thrown if output module asks for this information)
420  //throw cms::Exception("FastMonitoringService") << "SOURCE did not send update for lumi block. LUMI -:" << lumi;
421  return;
422 
423  }
424 
425  if (inputSource_) {
426  auto sourceReport = inputSource_->getEventReport(lumi, true);
427  if (sourceReport.first) {
428  if (sourceReport.second!=processedEventsPerLumi_[lumi].first) {
429  throw cms::Exception("FastMonitoringService") << "MISMATCH with SOURCE update. LUMI -: "
430  << lumi
431  << ", events(processed):" << processedEventsPerLumi_[lumi].first
432  << " events(source):" << sourceReport.second;
433  }
434  }
435  }
436  edm::LogInfo("FastMonitoringService") << "Statistics for lumisection -: lumi = " << lumi << " events = "
437  << lumiProcessedJptr->value() << " time = " << usecondsForLumi/1000000
438  << " size = " << accuSize << " thr = " << throughput;
439  delete lumiProcessedJptr;
440 
441  //full global and stream merge&output for this lumi
442  fmt_.jsonMonitor_->outputFullJSON(slow.string(),lumi);//full global and stream merge and JSON write for this lumi
443  fmt_.jsonMonitor_->discardCollected(lumi);//we don't do further updates for this lumi
444 
446  }
#define LogDebug(id)
std::map< unsigned int, timeval > lumiStartTime_
std::pair< bool, unsigned int > getEventReport(unsigned int lumi, bool erase)
double throughputFactor()
std::map< unsigned int, unsigned long > accuSize_
tuple lumi
Definition: fjr2json.py:35
volatile std::atomic< bool > shutdown_flag
void doSnapshot(const unsigned int ls, const bool isGlobalEOL)
std::unique_ptr< jsoncollector::FastMonitor > jsonMonitor_
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
FedRawDataInputSource * inputSource_
boost::filesystem::path workingDirectory_
std::vector< unsigned int > exceptionInLS_
void evf::FastMonitoringService::preModuleBeginJob ( edm::ModuleDescription const &  desc)

Definition at line 308 of file FastMonitoringService.cc.

References encModule_, fmt_, CommonMethods::lock(), edm::ModuleDescription::moduleName(), evf::FastMonitoringThread::monlock_, nOutputModules_, evf::FastMonitoringService::Encoding::update(), and evf::FastMonitoringService::Encoding::updateReserved().

Referenced by FastMonitoringService().

309  {
310  std::lock_guard<std::mutex> lock(fmt_.monlock_);
311  //std::cout << " Pre module Begin Job module: " << desc.moduleName() << std::endl;
312 
313  //build a map of modules keyed by their module description address
314  //here we need to treat output modules in a special way so they can be easily singled out
315  if(desc.moduleName() == "Stream" || desc.moduleName() == "ShmStreamConsumer" || desc.moduleName() == "EvFOutputModule" ||
316  desc.moduleName() == "EventStreamFileWriter" || desc.moduleName() == "PoolOutputModule") {
317  encModule_.updateReserved((void*)&desc);
318  nOutputModules_++;
319  }
320  else
321  encModule_.update((void*)&desc);
322  }
void evf::FastMonitoringService::preModuleEvent ( edm::StreamContext const &  sc,
edm::ModuleCallingContext const &  mcc 
)

Definition at line 568 of file FastMonitoringService.cc.

References microstate_, edm::ModuleCallingContext::moduleDescription(), edm::StreamContext::streamID(), and edm::StreamID::value().

Referenced by FastMonitoringService().

569  {
570  microstate_[sc.streamID().value()] = (void*)(mcc.moduleDescription());
571  }
std::vector< const void * > microstate_
void evf::FastMonitoringService::prePathEvent ( edm::StreamContext const &  sc,
edm::PathContext const &  pc 
)

Definition at line 494 of file FastMonitoringService.cc.

References collectedPathList_, encPath_, edm::EventID::event(), eventCountForPathInit_, edm::StreamContext::eventID(), firstEventId_, fmt_, CommonMethods::lock(), evf::FastMonitoringThread::m_data, makePathLegendaJson(), ministate_, evf::FastMonitoringThread::MonitorData::ministateBins_, evf::FastMonitoringThread::monlock_, pathLegendFileJson_, pathLegendWritten_, edm::PathContext::pathName(), edm::StreamContext::streamID(), AlCaHLTBitMon_QueryRunRegistry::string, and unlikely.

Referenced by FastMonitoringService().

495  {
496  //make sure that all path names are retrieved before allowing ministate to change
497  //hack: assume memory is synchronized after ~50 events seen by each stream
498  if (unlikely(eventCountForPathInit_[sc.streamID()]<50) && false==collectedPathList_[sc.streamID()]->load(std::memory_order_acquire))
499  {
500  //protection between stream threads, as well as the service monitoring thread
501  std::lock_guard<std::mutex> lock(fmt_.monlock_);
502 
503  if (firstEventId_[sc.streamID()]==0)
504  firstEventId_[sc.streamID()]=sc.eventID().event();
505  if (sc.eventID().event()==firstEventId_[sc.streamID()])
506  {
507  encPath_[sc.streamID()].update((void*)&pc.pathName());
508  return;
509  }
510  else {
511  //finished collecting path names
512  collectedPathList_[sc.streamID()]->store(true,std::memory_order_seq_cst);
513  fmt_.m_data.ministateBins_=encPath_[sc.streamID()].vecsize();
514  if (!pathLegendWritten_) {
515  std::string pathLegendStrJson = makePathLegendaJson();
516  FileIO::writeStringToFile(pathLegendFileJson_, pathLegendStrJson);
517  pathLegendWritten_=true;
518  }
519  }
520  }
521  else {
522  ministate_[sc.streamID()] = &(pc.pathName());
523  }
524  }
std::vector< unsigned int > eventCountForPathInit_
#define unlikely(x)
std::vector< std::atomic< bool > * > collectedPathList_
std::vector< unsigned long > firstEventId_
std::vector< const void * > ministate_
std::vector< Encoding > encPath_
void evf::FastMonitoringService::preSourceEarlyTermination ( edm::TerminationOrigin  to)
void evf::FastMonitoringService::preSourceEvent ( edm::StreamID  sid)

Definition at line 558 of file FastMonitoringService.cc.

References microstate_, evf::MicroStateService::mInput, evf::MicroStateService::reservedMicroStateNames, and edm::StreamID::value().

Referenced by FastMonitoringService().

559  {
561  }
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
std::vector< const void * > microstate_
unsigned int value() const
Definition: StreamID.h:46
void evf::FastMonitoringService::preStreamBeginLumi ( edm::StreamContext const &  sc)

Definition at line 454 of file FastMonitoringService.cc.

References edm::StreamContext::eventID(), fmt_, CommonMethods::lock(), edm::EventID::luminosityBlock(), evf::FastMonitoringThread::m_data, evf::MicroStateService::mFwkOvh, microstate_, ministate_, evf::FastMonitoringThread::monlock_, nopath_, evf::FastMonitoringThread::MonitorData::processed_, evf::MicroStateService::reservedMicroStateNames, edm::StreamContext::streamID(), evf::FastMonitoringThread::MonitorData::streamLumi_, and edm::StreamID::value().

Referenced by FastMonitoringService().

455  {
456  unsigned int sid = sc.streamID().value();
457  std::lock_guard<std::mutex> lock(fmt_.monlock_);
458  fmt_.m_data.streamLumi_[sid] = sc.eventID().luminosityBlock();
459 
460  //reset collected values for this stream
461  *(fmt_.m_data.processed_[sid])=0;
462 
463  ministate_[sid]=&nopath_;
465  }
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
static const std::string nopath_
std::vector< const void * > microstate_
std::vector< jsoncollector::AtomicMonUInt * > processed_
std::vector< const void * > ministate_
std::vector< unsigned int > streamLumi_
void evf::FastMonitoringService::preStreamEarlyTermination ( edm::StreamContext const &  sc,
edm::TerminationOrigin  to 
)

Definition at line 262 of file FastMonitoringService.cc.

References edm::StreamContext::eventID(), edm::ExceptionFromAnotherContext, edm::ExceptionFromThisContext, exceptionInLS_, edm::ExternalSignal, fmt_, CommonMethods::lock(), edm::EventID::luminosityBlock(), evf::FastMonitoringThread::monlock_, edm::StreamContext::streamID(), AlCaHLTBitMon_QueryRunRegistry::string, and edm::StreamID::value().

Referenced by FastMonitoringService().

263  {
264  std::string context;
265  if (to==edm::TerminationOrigin::ExceptionFromThisContext) context = " FromThisContext ";
266  if (to==edm::TerminationOrigin::ExceptionFromAnotherContext) context = " FromAnotherContext";
267  if (to==edm::TerminationOrigin::ExternalSignal) context = " FromExternalSignal";
268  edm::LogWarning("FastMonitoringService") << " STREAM " << sc.streamID().value() << " earlyTermination -: ID:"<< sc.eventID()
269  << " LS:" << sc.eventID().luminosityBlock() << " " << context;
270  std::lock_guard<std::mutex> lock(fmt_.monlock_);
271  exceptionInLS_.push_back(sc.eventID().luminosityBlock());
272  }
std::vector< unsigned int > exceptionInLS_
void evf::FastMonitoringService::preStreamEndLumi ( edm::StreamContext const &  sc)

Definition at line 472 of file FastMonitoringService.cc.

References doStreamEOLSnapshot(), edm::StreamContext::eventID(), fmt_, load(), CommonMethods::lock(), edm::EventID::luminosityBlock(), evf::MicroStateService::mEoL, microstate_, ministate_, evf::FastMonitoringThread::monlock_, nopath_, evf::MicroStateService::reservedMicroStateNames, streamCounterUpdating_, edm::StreamContext::streamID(), and edm::StreamID::value().

Referenced by FastMonitoringService().

473  {
474  unsigned int sid = sc.streamID().value();
475  std::lock_guard<std::mutex> lock(fmt_.monlock_);
476 
477  #if ATOMIC_LEVEL>=2
478  //spinlock to make sure we are not still updating event counter somewhere
479  while (streamCounterUpdating_[sid]->load(std::memory_order_acquire)) {}
480  #endif
481 
482  //update processed count to be complete at this time
483  doStreamEOLSnapshot(sc.eventID().luminosityBlock(),sid);
484  //reset this in case stream does not get notified of next lumi (we keep processed events only)
485  ministate_[sid]=&nopath_;
487  }
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
std::vector< std::atomic< bool > * > streamCounterUpdating_
void doStreamEOLSnapshot(const unsigned int ls, const unsigned int streamID)
static const std::string nopath_
std::vector< const void * > microstate_
void load(int perCUT=90)
Definition: getMaxPt.h:59
std::vector< const void * > ministate_
void evf::FastMonitoringService::reportLockWait ( unsigned int  ls,
double  waitTime,
unsigned int  lockCount 
)

Definition at line 642 of file FastMonitoringService.cc.

References fmt_, CommonMethods::lock(), lockStatsDuringLumi_, eostools::ls(), and evf::FastMonitoringThread::monlock_.

Referenced by FedRawDataInputSource::readSupervisor().

643  {
644  std::lock_guard<std::mutex> lock(fmt_.monlock_);
645  lockStatsDuringLumi_[ls]=std::pair<double,unsigned int>(waitTime,lockCount);
646 
647  }
def ls
Definition: eostools.py:348
std::map< unsigned int, std::pair< double, unsigned int > > lockStatsDuringLumi_
void evf::FastMonitoringService::setExceptionDetected ( unsigned int  ls)

Definition at line 297 of file FastMonitoringService.cc.

References exception_detected_, and exceptionInLS_.

Referenced by FedRawDataInputSource::getNextEvent().

297  {
298  if (!ls) exception_detected_=true;
299  else exceptionInLS_.push_back(ls);
300  }
def ls
Definition: eostools.py:348
std::vector< unsigned int > exceptionInLS_
void evf::FastMonitoringService::setInputSource ( FedRawDataInputSource inputSource)
inline

Definition at line 171 of file FastMonitoringService.h.

References inputSource_.

Referenced by FedRawDataInputSource::FedRawDataInputSource().

171 {inputSource_=inputSource;}
FedRawDataInputSource * inputSource_
void evf::FastMonitoringService::setMicroState ( MicroStateService::Microstate  m)
virtual

Implements evf::MicroStateService.

Definition at line 583 of file FastMonitoringService.cc.

References i, microstate_, nStreams_, and evf::MicroStateService::reservedMicroStateNames.

584  {
585  for (unsigned int i=0;i<nStreams_;i++)
587  }
int i
Definition: DBlmapReader.cc:9
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
std::vector< const void * > microstate_
void evf::FastMonitoringService::setMicroState ( edm::StreamID  sid,
MicroStateService::Microstate  m 
)
virtual
bool evf::FastMonitoringService::shouldWriteFiles ( unsigned int  lumi,
unsigned int *  proc = 0 
)
inline

Definition at line 164 of file FastMonitoringService.h.

References emptyLumisectionMode_, getAbortFlagForLumi(), getEventsProcessedForLumi(), and proc.

Referenced by DQMFileSaver::globalEndLuminosityBlock(), and TriggerJSONMonitoring::globalEndLuminosityBlockSummary().

165  {
166  unsigned int processed = getEventsProcessedForLumi(lumi);
167  if (proc) *proc = processed;
168  return !getAbortFlagForLumi(lumi) && (processed || emptyLumisectionMode_);
169  }
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=0)
TrainProcessor *const proc
Definition: MVATrainer.cc:101
tuple lumi
Definition: fjr2json.py:35
bool getAbortFlagForLumi(unsigned int lumi)
void evf::FastMonitoringService::startedLookingForFile ( )

Definition at line 608 of file FastMonitoringService.cc.

References fileLookStart_.

Referenced by FedRawDataInputSource::readSupervisor().

608  {
609  gettimeofday(&fileLookStart_, 0);
610  /*
611  std::cout << "Started looking for .raw file at: s=" << fileLookStart_.tv_sec << ": ms = "
612  << fileLookStart_.tv_usec / 1000.0 << std::endl;
613  */
614  }
void evf::FastMonitoringService::stoppedLookingForFile ( unsigned int  lumi)

Definition at line 616 of file FastMonitoringService.cc.

References avgLeadTime_, fileLookStart_, fileLookStop_, fmt_, i, leadTimes_, CommonMethods::lock(), fjr2json::lumi, lumiFromSource_, and evf::FastMonitoringThread::monlock_.

Referenced by FedRawDataInputSource::readSupervisor().

616  {
617  gettimeofday(&fileLookStop_, 0);
618  /*
619  std::cout << "Stopped looking for .raw file at: s=" << fileLookStop_.tv_sec << ": ms = "
620  << fileLookStop_.tv_usec / 1000.0 << std::endl;
621  */
622  std::lock_guard<std::mutex> lock(fmt_.monlock_);
623 
624  if (lumi>lumiFromSource_) {
626  leadTimes_.clear();
627  }
628  unsigned long elapsedTime = (fileLookStop_.tv_sec - fileLookStart_.tv_sec) * 1000000 // sec to us
629  + (fileLookStop_.tv_usec - fileLookStart_.tv_usec); // us
630  // add this to lead times for this lumi
631  leadTimes_.push_back((double)elapsedTime);
632 
633  // recompute average lead time for this lumi
634  if (leadTimes_.size() == 1) avgLeadTime_[lumi] = leadTimes_[0];
635  else {
636  double totTime = 0;
637  for (unsigned int i = 0; i < leadTimes_.size(); i++) totTime += leadTimes_[i];
638  avgLeadTime_[lumi] = 0.001*(totTime / leadTimes_.size());
639  }
640  }
int i
Definition: DBlmapReader.cc:9
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, double > avgLeadTime_
std::vector< double > leadTimes_

Member Data Documentation

std::map<unsigned int, unsigned long> evf::FastMonitoringService::accuSize_
private
std::map<unsigned int, double> evf::FastMonitoringService::avgLeadTime_
private

Definition at line 243 of file FastMonitoringService.h.

Referenced by doSnapshot(), preGlobalBeginLumi(), and stoppedLookingForFile().

std::vector<std::atomic<bool>*> evf::FastMonitoringService::collectedPathList_
private

Definition at line 258 of file FastMonitoringService.h.

Referenced by preBeginJob(), and prePathEvent().

bool evf::FastMonitoringService::emptyLumisectionMode_ = false
private

Definition at line 278 of file FastMonitoringService.h.

Referenced by preBeginJob(), and shouldWriteFiles().

Encoding evf::FastMonitoringService::encModule_
private
std::vector<Encoding> evf::FastMonitoringService::encPath_
private
std::vector<unsigned int> evf::FastMonitoringService::eventCountForPathInit_
private

Definition at line 259 of file FastMonitoringService.h.

Referenced by postEvent(), preBeginJob(), and prePathEvent().

bool evf::FastMonitoringService::exception_detected_ = false
private
std::vector<unsigned int> evf::FastMonitoringService::exceptionInLS_
private
std::string evf::FastMonitoringService::fastMicrostateDefPath_
private

Definition at line 220 of file FastMonitoringService.h.

Referenced by FastMonitoringService(), and preBeginJob().

unsigned int evf::FastMonitoringService::fastMonIntervals_
private

Definition at line 218 of file FastMonitoringService.h.

Referenced by dowork().

std::string evf::FastMonitoringService::fastName_
private

Definition at line 221 of file FastMonitoringService.h.

Referenced by preBeginJob().

std::string evf::FastMonitoringService::fastPath_
private

Definition at line 221 of file FastMonitoringService.h.

Referenced by dowork(), and preBeginJob().

timeval evf::FastMonitoringService::fileLookStart_
private

Definition at line 226 of file FastMonitoringService.h.

Referenced by startedLookingForFile(), and stoppedLookingForFile().

timeval evf::FastMonitoringService::fileLookStop_
private

Definition at line 226 of file FastMonitoringService.h.

Referenced by stoppedLookingForFile().

std::map<unsigned int, unsigned int> evf::FastMonitoringService::filesProcessedDuringLumi_
private

Definition at line 244 of file FastMonitoringService.h.

Referenced by accumulateFileSize(), doSnapshot(), and preGlobalBeginLumi().

std::vector<unsigned long> evf::FastMonitoringService::firstEventId_
private

Definition at line 257 of file FastMonitoringService.h.

Referenced by preBeginJob(), and prePathEvent().

FastMonitoringThread evf::FastMonitoringService::fmt_
private
FedRawDataInputSource* evf::FastMonitoringService::inputSource_ = 0
private

Definition at line 213 of file FastMonitoringService.h.

Referenced by preGlobalEndLumi(), and setInputSource().

bool evf::FastMonitoringService::isGlobalLumiTransition_
private
unsigned int evf::FastMonitoringService::lastGlobalLumi_
private

Definition at line 228 of file FastMonitoringService.h.

Referenced by dowork(), preBeginJob(), and preGlobalBeginLumi().

std::queue<unsigned int> evf::FastMonitoringService::lastGlobalLumisClosed_
private

Definition at line 229 of file FastMonitoringService.h.

Referenced by postGlobalEndLumi(), and preGlobalBeginLumi().

std::vector<double> evf::FastMonitoringService::leadTimes_
private

Definition at line 247 of file FastMonitoringService.h.

Referenced by stoppedLookingForFile().

std::map<unsigned int, std::pair<double,unsigned int> > evf::FastMonitoringService::lockStatsDuringLumi_
private

Definition at line 248 of file FastMonitoringService.h.

Referenced by doSnapshot(), preGlobalBeginLumi(), and reportLockWait().

unsigned int evf::FastMonitoringService::lumiFromSource_
private

Definition at line 231 of file FastMonitoringService.h.

Referenced by preBeginJob(), and stoppedLookingForFile().

std::map<unsigned int, timeval> evf::FastMonitoringService::lumiStartTime_
private

Definition at line 225 of file FastMonitoringService.h.

Referenced by preGlobalBeginLumi(), and preGlobalEndLumi().

FastMonitoringThread::Macrostate evf::FastMonitoringService::macrostate_
private
const std::string evf::FastMonitoringService::macroStateNames
static
Initial value:
=
{"Init","JobReady","RunGiven","Running",
"Stopping","Done","JobEnded","Error","ErrorEnded","End",
"Invalid"}

Definition at line 114 of file FastMonitoringService.h.

std::vector<const void*> evf::FastMonitoringService::microstate_
private
std::string evf::FastMonitoringService::microstateDefPath_
private

Definition at line 220 of file FastMonitoringService.h.

Referenced by FastMonitoringService(), and preBeginJob().

std::vector<const void*> evf::FastMonitoringService::ministate_
private
std::string evf::FastMonitoringService::moduleLegendFile_
private

Definition at line 268 of file FastMonitoringService.h.

Referenced by preBeginJob().

std::string evf::FastMonitoringService::moduleLegendFileJson_
private

Definition at line 269 of file FastMonitoringService.h.

Referenced by postBeginJob(), and preBeginJob().

std::atomic<bool> evf::FastMonitoringService::monInit_
private

Definition at line 275 of file FastMonitoringService.h.

Referenced by dowork(), and preBeginJob().

const std::string evf::FastMonitoringService::nopath_ = "NoPath"
static
unsigned int evf::FastMonitoringService::nOutputModules_ =0
private

Definition at line 273 of file FastMonitoringService.h.

Referenced by makeModuleLegendaJson(), and preModuleBeginJob().

unsigned int evf::FastMonitoringService::nStreams_
private

Definition at line 215 of file FastMonitoringService.h.

Referenced by doSnapshot(), preallocate(), preBeginJob(), and setMicroState().

unsigned int evf::FastMonitoringService::nThreads_
private

Definition at line 216 of file FastMonitoringService.h.

Referenced by preallocate(), and preBeginJob().

std::string evf::FastMonitoringService::pathLegendFile_
private

Definition at line 270 of file FastMonitoringService.h.

Referenced by preBeginJob().

std::string evf::FastMonitoringService::pathLegendFileJson_
private

Definition at line 271 of file FastMonitoringService.h.

Referenced by preBeginJob(), and prePathEvent().

bool evf::FastMonitoringService::pathLegendWritten_ = false
private

Definition at line 272 of file FastMonitoringService.h.

Referenced by prePathEvent().

std::vector<bool> evf::FastMonitoringService::pathNamesReady_
private

Definition at line 260 of file FastMonitoringService.h.

std::map<unsigned int, std::pair<unsigned int,bool> > evf::FastMonitoringService::processedEventsPerLumi_
private
boost::filesystem::path evf::FastMonitoringService::runDirectory_
private

Definition at line 262 of file FastMonitoringService.h.

Referenced by getRunDirName(), and preBeginJob().

int evf::FastMonitoringService::sleepTime_
private

Definition at line 217 of file FastMonitoringService.h.

Referenced by dowork().

std::string evf::FastMonitoringService::slowName_
private

Definition at line 221 of file FastMonitoringService.h.

Referenced by preGlobalEndLumi().

unsigned int evf::FastMonitoringService::snapCounter_ = 0
private

Definition at line 219 of file FastMonitoringService.h.

Referenced by dowork().

std::vector<std::atomic<bool>*> evf::FastMonitoringService::streamCounterUpdating_
private

Definition at line 255 of file FastMonitoringService.h.

Referenced by postEvent(), preBeginJob(), and preStreamEndLumi().

bool evf::FastMonitoringService::threadIDAvailable_ = false
private

Definition at line 264 of file FastMonitoringService.h.

Referenced by preBeginJob().

std::vector<const void*> evf::FastMonitoringService::threadMicrostate_
private

Definition at line 239 of file FastMonitoringService.h.

std::atomic<unsigned long> evf::FastMonitoringService::totalEventsProcessed_
private

Definition at line 266 of file FastMonitoringService.h.

Referenced by postEvent().

boost::filesystem::path evf::FastMonitoringService::workingDirectory_
private

Definition at line 262 of file FastMonitoringService.h.

Referenced by preBeginJob(), and preGlobalEndLumi().