34 const std::string FastMonitoringService::macroStateNames[FastMonitoringThread::MCOUNT] =
35 {
"Init",
"JobReady",
"RunGiven",
"Running",
36 "Stopping",
"Done",
"JobEnded",
"Error",
"ErrorEnded",
"End",
39 const std::string FastMonitoringService::inputStateNames[FastMonitoringThread::inCOUNT] =
40 {
"Ignore",
"Init",
"WaitInput",
"NewLumi",
"NewLumiBusyEndingLS",
"NewLumiIdleEndingLS",
"RunEnd",
"ProcessingFile",
"WaitChunk",
"ChunkReceived",
41 "ChecksumEvent",
"CachedEvent",
"ReadEvent",
"ReadCleanup",
"NoRequest",
"NoRequestWithIdleThreads",
42 "NoRequestWithGlobalEoL",
"NoRequestWithEoLThreads",
43 "SupFileLimit",
"SupWaitFreeChunk",
"SupWaitFreeChunkCopying",
"SupWaitFreeThread",
"SupWaitFreeThreadCopying",
44 "SupBusy",
"SupLockPolling",
"SupLockPollingCopying",
45 "SupNoFile",
"SupNewFile",
"SupNewFileWaitThreadCopying",
"SupNewFileWaitThread",
46 "SupNewFileWaitChunkCopying",
"SupNewFileWaitChunk",
47 "WaitInput_fileLimit",
"WaitInput_waitFreeChunk",
"WaitInput_waitFreeChunkCopying",
"WaitInput_waitFreeThread",
"WaitInput_waitFreeThreadCopying",
48 "WaitInput_busy",
"WaitInput_lockPolling",
"WaitInput_lockPollingCopying",
"WaitInput_runEnd",
49 "WaitInput_noFile",
"WaitInput_newFile",
"WaitInput_newFileWaitThreadCopying",
"WaitInput_newFileWaitThread",
50 "WaitInput_newFileWaitChunkCopying",
"WaitInput_newFileWaitChunk",
51 "WaitChunk_fileLimit",
"WaitChunk_waitFreeChunk",
"WaitChunk_waitFreeChunkCopying",
"WaitChunk_waitFreeThread",
"WaitChunk_waitFreeThreadCopying",
52 "WaitChunk_busy",
"WaitChunk_lockPolling",
"WaitChunk_lockPollingCopying",
"WaitChunk_runEnd",
53 "WaitChunk_noFile",
"WaitChunk_newFile",
"WaitChunk_newFileWaitThreadCopying",
"WaitChunk_newFileWaitThread",
54 "WaitChunk_newFileWaitChunkCopying",
"WaitChunk_newFileWaitChunk" 58 const std::string FastMonitoringService::nopath_ =
"NoPath";
65 ,sleepTime_(iPS.getUntrackedParameter<
int>(
"sleepTime", 1))
66 ,fastMonIntervals_(iPS.getUntrackedParameter<unsigned
int>(
"fastMonIntervals", 2))
67 ,fastName_(
"fastmoni")
68 ,slowName_(
"slowmoni")
69 ,filePerFwkStream_(iPS.getUntrackedParameter<
bool>(
"filePerFwkStream",
false))
70 ,totalEventsProcessed_(0)
106 std::string microstateBaseSuffix =
"src/EventFilter/Utilities/plugins/microstatedef.jsd";
108 if (
stat(microstatePath.c_str(), &statbuf)) {
109 microstatePath =
std::string(getenv(
"CMSSW_RELEASE_BASE")) +
"/" + microstateBaseSuffix;
110 if (
stat(microstatePath.c_str(), &statbuf)) {
111 microstatePath = microstateBaseSuffix;
112 if (
stat(microstatePath.c_str(), &statbuf))
113 throw cms::Exception(
"FastMonitoringService") <<
"microstate definition file not found";
127 desc.
setComment(
"Service for File-based DAQ monitoring and event accounting");
128 desc.
addUntracked<
int> (
"sleepTime",1)->setComment(
"Sleep time of the monitoring thread");
129 desc.
addUntracked<
unsigned int> (
"fastMonIntervals",2)->setComment(
"Modulo of sleepTime intervals on which fastmon file is written out");
130 desc.
addUntracked<
bool> (
"filePerFwkStream",
false)->setComment(
"Switches on monitoring output per framework stream");
132 descriptions.
add(
"FastMonitoringService", desc);
142 pathLegend[
"names"]=legendaVector;
143 pathLegend[
"reserved"]=valReserved;
145 return writer.
write(pathLegend);
156 moduleLegend[
"names"]=legendaVector;
157 moduleLegend[
"reserved"]=valReserved;
158 moduleLegend[
"special"]=valSpecial;
159 moduleLegend[
"output"]=valOutputModules;
161 return writer.
write(moduleLegend);
169 moduleLegend[
"names"]=legendaVector;
171 return writer.
write(moduleLegend);
192 throw cms::Exception(
"FastMonitoringService") <<
"EvFDaqDirector is not present";
204 <<
". No monitoring data will be written.";
207 std::ostringstream fastFileName;
209 fastFileName <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".fast";
211 fast /= fastFileName.str();
215 std::ostringstream fastFileNameTid;
216 fastFileNameTid <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
"_tid" <<
i <<
".fast";
218 fastTid /= fastFileNameTid.str();
222 std::ostringstream moduleLegFile;
223 std::ostringstream moduleLegFileJson;
224 moduleLegFile <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
225 moduleLegFileJson <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
229 std::ostringstream pathLegFile;
230 std::ostringstream pathLegFileJson;
231 pathLegFile <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
233 pathLegFileJson <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
236 std::ostringstream inputLegFileJson;
237 inputLegFileJson <<
"inputlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
240 LogDebug(
"FastMonitoringService") <<
"Initializing FastMonitor with microstate def path -: " 253 for(
unsigned int i = 0;
i < (
mCOUNT);
i++)
289 monInit_.store(
false,std::memory_order_release);
323 edm::LogWarning(
"FastMonitoringService") <<
" GLOBAL " <<
"earlyTermination -: LS:" 335 edm::LogWarning(
"FastMonitoringService") <<
" SOURCE " <<
"earlyTermination -: " << context;
396 timeval lumiStartTime;
397 gettimeofday(&lumiStartTime,
nullptr);
410 LogDebug(
"FastMonitoringService") <<
"Lumi ended. Writing JSON information. LUMI -: " 412 timeval lumiStopTime;
413 gettimeofday(&lumiStopTime,
nullptr);
420 unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec)*1000000
421 + (lumiStopTime.tv_usec - stt.tv_usec);
424 double throughput =
throughputFactor()* double(accuSize) / double(usecondsForLumi);
433 if (!lumiProcessedJptr)
434 throw cms::Exception(
"FastMonitoringService") <<
"Internal error: got null pointer from FastMonitor";
440 if (lumi == ex) exception_detected=
true;
443 edm::LogInfo(
"FastMonitoringService") <<
"Run interrupted. Skip writing EoL information -: " 456 if (sourceReport.first) {
458 throw cms::Exception(
"FastMonitoringService") <<
"MISMATCH with SOURCE update. LUMI -: " 461 <<
" events(source):" << sourceReport.second;
465 edm::LogInfo(
"FastMonitoringService") <<
"Statistics for lumisection -: lumi = " << lumi <<
" events = " 466 << lumiProcessedJptr->
value() <<
" time = " << usecondsForLumi/1000000
467 <<
" size = " << accuSize <<
" thr = " << throughput;
468 delete lumiProcessedJptr;
474 std::stringstream slowFileNameStem;
475 slowFileNameStem <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4)
476 << lumi <<
"_pid" << std::setfill(
'0')
477 << std::setw(5) << getpid();
479 slow /= slowFileNameStem.str();
483 std::stringstream slowFileName;
484 slowFileName <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4)
485 << lumi <<
"_pid" << std::setfill(
'0')
486 << std::setw(5) << getpid() <<
".jsn";
488 slow /= slowFileName.str();
693 unsigned int proc = it->second.first;
694 if (abortFlag) *abortFlag=it->second.second;
698 throw cms::Exception(
"FastMonitoringService") <<
"output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: "<<
lumi;
709 unsigned int abortFlag = it->second.second;
713 throw cms::Exception(
"FastMonitoringService") <<
"output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: "<<
lumi;
752 bool inputStatePerThread=
false;
858 inputStatePerThread=
true;
870 inputStatePerThread=
true;
881 if (!inputStatePerThread)
int encode(const void *add)
void prePathEvent(edm::StreamContext const &, edm::PathContext const &)
std::string const & pathName() const
unsigned int maxNumberOfThreads() const
std::string pathLegendFileJson_
EventNumber_t event() const
void watchPreStreamEarlyTermination(PreStreamEarlyTermination::slot_type const &iSlot)
void watchPreEvent(PreEvent::slot_type const &iSlot)
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=0)
static const edm::ModuleDescription reservedMicroStateNames[mCOUNT]
std::vector< ContainableAtomic< const void * > > microstate_
std::string pathLegendFile_
void postSourceEvent(edm::StreamID)
std::string makePathLegendaJson()
std::atomic< bool > isInitTransition_
void watchPrePathEvent(PrePathEvent::slot_type const &iSlot)
void watchPreallocate(Preallocate::slot_type const &iSlot)
void startedLookingForFile()
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void setExceptionDetected(unsigned int ls)
boost::filesystem::path runDirectory_
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void preallocate(edm::service::SystemBounds const &)
std::map< unsigned int, timeval > lumiStartTime_
void start(void(FastMonitoringService::*fp)(), FastMonitoringService *cp)
void preGlobalBeginLumi(edm::GlobalContext const &)
void setAllowAnything()
allow any parameter label/value pairs
double throughputFactor()
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void postGlobalEndLumi(edm::GlobalContext const &)
TrainProcessor *const proc
void postEvent(edm::StreamContext const &)
void accumulateFileSize(unsigned int lumi, unsigned long fileSize)
void watchPreGlobalEndLumi(PreGlobalEndLumi::slot_type const &iSlot)
std::map< unsigned int, unsigned long > accuSize_
std::atomic< FastMonitoringThread::InputState > inputSupervisorState_
FastMonitoringThread fmt_
unsigned int microstateBins_
std::vector< std::atomic< bool > * > streamCounterUpdating_
void watchPostEvent(PostEvent::slot_type const &iSlot)
jsoncollector::DoubleJ fastThroughputJ_
static const int nReservedPaths
volatile std::atomic< bool > shutdown_flag
LuminosityBlockID const & luminosityBlockID() const
void watchPostStreamEndLumi(PostStreamEndLumi::slot_type const &iSlot)
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
unsigned int nOutputModules_
std::string const & moduleName() const
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
Value & append(const Value &value)
Append value to array at the end.
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
void doStreamEOLSnapshot(const unsigned int ls, const unsigned int streamID)
std::map< unsigned int, unsigned int > filesProcessedDuringLumi_
void preGlobalEndLumi(edm::GlobalContext const &)
unsigned int lastGlobalLumi_
LuminosityBlockNumber_t luminosityBlock() const
void watchPreStreamEndLumi(PreStreamEndLumi::slot_type const &iSlot)
void preGlobalEarlyTermination(edm::GlobalContext const &, edm::TerminationOrigin)
void watchPreSourceEarlyTermination(PreSourceEarlyTermination::slot_type const &iSlot)
std::string inputLegendFileJson_
unsigned int inputstateBins_
jsoncollector::IntJ fastMacrostateJ_
void watchJobFailure(JobFailure::slot_type const &iSlot)
convenience function for attaching to signal
void registerVariables(jsoncollector::FastMonitor *fm, unsigned int nStreams, unsigned int nThreads)
std::atomic< bool > monInit_
std::string makeModuleLegendaJson()
unsigned int maxNumberOfStreams() const
void preModuleBeginJob(edm::ModuleDescription const &)
static const std::string inputStateNames[FastMonitoringThread::inCOUNT]
void setMicroState(MicroStateService::Microstate) override
void setComment(std::string const &value)
std::string makeInputLegendaJson()
void updateReserved(const void *add)
unsigned int lumiFromSource_
std::vector< std::atomic< bool > * > collectedPathList_
std::string microstateDefPath_
void preStreamEndLumi(edm::StreamContext const &)
std::map< unsigned int, double > avgLeadTime_
std::string moduleLegendFile_
void watchPostStreamBeginLumi(PostStreamBeginLumi::slot_type const &iSlot)
void doSnapshot(const unsigned int ls, const bool isGlobalEOL)
void preStreamEarlyTermination(edm::StreamContext const &, edm::TerminationOrigin)
void watchPreGlobalEarlyTermination(PreGlobalEarlyTermination::slot_type const &iSlot)
std::unique_ptr< jsoncollector::FastMonitor > jsonMonitor_
jsoncollector::IntJ fastFilesProcessedJ_
jsoncollector::DoubleJ fastAvgLeadTimeJ_
static const std::string nopath_
ModuleDescription const * moduleDescription() const
void resetFastMonitor(std::string const µStateDefPath, std::string const &fastMicroStateDefPath)
std::string fastMicrostateDefPath_
static const int nReservedModules
void watchPostGlobalEndLumi(PostGlobalEndLumi::slot_type const &iSlot)
std::map< unsigned int, std::pair< double, unsigned int > > lockStatsDuringLumi_
std::string moduleLegendFileJson_
std::vector< unsigned long > firstEventId_
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
jsoncollector::DoubleJ fastLockWaitJ_
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
std::vector< std::string > fastPathList_
std::vector< ContainableAtomic< unsigned int > > eventCountForPathInit_
void postStreamBeginLumi(edm::StreamContext const &)
void completeReservedWithDummies()
std::atomic< FastMonitoringThread::InputState > inputState_
StreamID const & streamID() const
void preSourceEvent(edm::StreamID)
void postStreamEndLumi(edm::StreamContext const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< unsigned int > microstateEncoded_
unsigned int value() const
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
void preStreamBeginLumi(edm::StreamContext const &)
std::atomic< unsigned long > totalEventsProcessed_
FedRawDataInputSource * inputSource_
~FastMonitoringService() override
std::atomic< FastMonitoringThread::Macrostate > macrostate_
static const int nSpecialModules
std::vector< ContainableAtomic< const void * > > ministate_
LuminosityBlockNumber_t luminosityBlock() const
void watchPreStreamBeginLumi(PreStreamBeginLumi::slot_type const &iSlot)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< double > leadTimes_
jsoncollector::IntJ fastPathProcessedJ_
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &pc)
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
void stoppedLookingForFile(unsigned int lumi)
std::string write(const Value &root) override
Serialize a Value in JSON format.
boost::filesystem::path workingDirectory_
jsoncollector::IntJ fastLockCountJ_
std::vector< jsoncollector::AtomicMonUInt * > processed_
void postGlobalBeginRun(edm::GlobalContext const &)
void preEvent(edm::StreamContext const &)
void preSourceEarlyTermination(edm::TerminationOrigin)
EventID const & eventID() const
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
bool getAbortFlagForLumi(unsigned int lumi)
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
Writes a Value in JSON format in a human friendly way.
unsigned int macrostateBins_
const void * decode(unsigned int index)
std::vector< unsigned int > streamLumi_
void update(const void *add)
unsigned int ministateBins_
std::vector< Encoding > encPath_
std::vector< unsigned int > inputState_
std::vector< unsigned int > ministateEncoded_
void reportLockWait(unsigned int ls, double waitTime, unsigned int lockCount)
std::vector< unsigned int > exceptionInLS_
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
array value (ordered list)