27 using namespace jsoncollector;
62 "NewLumiBusyEndingLS",
63 "NewLumiIdleEndingLS",
73 "NoRequestWithIdleThreads",
74 "NoRequestWithGlobalEoL",
75 "NoRequestWithEoLThreads",
78 "SupWaitFreeChunkCopying",
80 "SupWaitFreeThreadCopying",
83 "SupLockPollingCopying",
86 "SupNewFileWaitThreadCopying",
87 "SupNewFileWaitThread",
88 "SupNewFileWaitChunkCopying",
89 "SupNewFileWaitChunk",
90 "WaitInput_fileLimit",
91 "WaitInput_waitFreeChunk",
92 "WaitInput_waitFreeChunkCopying",
93 "WaitInput_waitFreeThread",
94 "WaitInput_waitFreeThreadCopying",
96 "WaitInput_lockPolling",
97 "WaitInput_lockPollingCopying",
101 "WaitInput_newFileWaitThreadCopying",
102 "WaitInput_newFileWaitThread",
103 "WaitInput_newFileWaitChunkCopying",
104 "WaitInput_newFileWaitChunk",
105 "WaitChunk_fileLimit",
106 "WaitChunk_waitFreeChunk",
107 "WaitChunk_waitFreeChunkCopying",
108 "WaitChunk_waitFreeThread",
109 "WaitChunk_waitFreeThreadCopying",
111 "WaitChunk_lockPolling",
112 "WaitChunk_lockPollingCopying",
116 "WaitChunk_newFileWaitThreadCopying",
117 "WaitChunk_newFileWaitThread",
118 "WaitChunk_newFileWaitChunkCopying",
119 "WaitChunk_newFileWaitChunk",
123 const std::string FastMonitoringService::nopath_ =
"NoPath";
130 sleepTime_(iPS.getUntrackedParameter<int>(
"sleepTime", 1)),
131 fastMonIntervals_(iPS.getUntrackedParameter<unsigned int>(
"fastMonIntervals", 2)),
132 fastName_(
"fastmoni"),
133 slowName_(
"slowmoni"),
134 filePerFwkStream_(iPS.getUntrackedParameter<bool>(
"filePerFwkStream",
false)),
135 totalEventsProcessed_(0) {
173 std::string microstateBaseSuffix =
"src/EventFilter/Utilities/plugins/microstatedef.jsd";
175 if (
stat(microstatePath.c_str(), &statbuf)) {
176 microstatePath =
std::string(std::getenv(
"CMSSW_RELEASE_BASE")) +
"/" + microstateBaseSuffix;
177 if (
stat(microstatePath.c_str(), &statbuf)) {
178 microstatePath = microstateBaseSuffix;
179 if (
stat(microstatePath.c_str(), &statbuf))
180 throw cms::Exception(
"FastMonitoringService") <<
"microstate definition file not found";
190 desc.
setComment(
"Service for File-based DAQ monitoring and event accounting");
191 desc.
addUntracked<
int>(
"sleepTime", 1)->setComment(
"Sleep time of the monitoring thread");
193 ->setComment(
"Modulo of sleepTime intervals on which fastmon file is written out");
195 ->setComment(
"Switches on monitoring output per framework stream");
197 descriptions.
add(
"FastMonitoringService", desc);
202 for (
int i = 0;
i <
fmt_->m_data.encPath_[0].current_;
i++)
203 legendaVector.
append(
Json::Value(*(static_cast<const std::string*>(
fmt_->m_data.encPath_[0].decode(
i)))));
206 pathLegend[
"names"] = legendaVector;
207 pathLegend[
"reserved"] = valReserved;
209 return writer.
write(pathLegend);
214 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
216 Json::Value((static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel()));
218 for (
int i = 0;
i <
fmt_->m_data.encModule_.current_;
i++)
220 (static_cast<const edm::ModuleDescription*>(
fmt_->m_data.encModule_.decode(
i)))->moduleLabel() +
"__ACQ"));
225 moduleLegend[
"names"] = legendaVector;
226 moduleLegend[
"reserved"] = valReserved;
227 moduleLegend[
"special"] = valSpecial;
228 moduleLegend[
"output"] = valOutputModules;
230 return writer.
write(moduleLegend);
238 moduleLegend[
"names"] = legendaVector;
240 return writer.
write(moduleLegend);
259 throw cms::Exception(
"FastMonitoringService") <<
"EvFDaqDirector is not present";
270 <<
". No monitoring data will be written.";
273 std::ostringstream fastFileName;
275 fastFileName <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".fast";
277 fast /= fastFileName.str();
281 std::ostringstream fastFileNameTid;
282 fastFileNameTid <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
"_tid" <<
i
285 fastTid /= fastFileNameTid.str();
289 std::ostringstream moduleLegFile;
290 std::ostringstream moduleLegFileJson;
291 moduleLegFile <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
292 moduleLegFileJson <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
296 std::ostringstream pathLegFile;
297 std::ostringstream pathLegFileJson;
298 pathLegFile <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
300 pathLegFileJson <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
303 std::ostringstream inputLegFileJson;
304 inputLegFileJson <<
"inputlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
321 fmt_->m_data.encModule_.completeReservedWithDummies();
326 fmt_->m_data.microstateAcqFlag_.push_back(0);
332 fmt_->m_data.encPath_.emplace_back(0);
333 fmt_->m_data.encPath_[
i].update(static_cast<const void*>(&
nopath_));
336 fmt_->m_data.encPath_[
i].updatePreinit(
path);
338 for (
auto& endPath : pathsInfo.
endPaths()) {
339 fmt_->m_data.encPath_[
i].updatePreinit(endPath);
347 fmt_->m_data.microstateBins_ = 0;
349 fmt_->m_data.ministateBins_ =
fmt_->m_data.encPath_[0].vecsize();
357 fmt_->jsonMonitor_->setNStreams(nStreams_);
359 monInit_.store(
false, std::memory_order_release);
378 context =
" FromThisContext ";
380 context =
" FromAnotherContext";
382 context =
" FromExternalSignal";
386 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
393 context =
" FromThisContext ";
395 context =
" FromAnotherContext";
397 context =
" FromExternalSignal";
401 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
408 context =
" FromThisContext ";
410 context =
" FromAnotherContext";
412 context =
" FromExternalSignal";
414 <<
"earlyTermination -: " <<
context;
415 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
430 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
438 fmt_->m_data.encModule_.updateReserved((
void*)&desc);
441 fmt_->m_data.encModule_.update((
void*)&desc);
457 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
459 fmt_->m_data.microstateBins_ =
fmt_->m_data.encModule_.vecsize() * 2;
473 timeval lumiStartTime;
474 gettimeofday(&lumiStartTime,
nullptr);
478 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
484 LogDebug(
"FastMonitoringService") <<
"Lumi ended. Writing JSON information. LUMI -: " <<
lumi;
485 timeval lumiStopTime;
486 gettimeofday(&lumiStopTime,
nullptr);
488 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
493 unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec) * 1000000 + (lumiStopTime.tv_usec - stt.tv_usec);
496 double throughput =
throughputFactor() * double(accuSize) / double(usecondsForLumi);
498 fmt_->m_data.fastThroughputJ_.value() = throughput;
504 IntJ* lumiProcessedJptr =
dynamic_cast<IntJ*
>(
fmt_->jsonMonitor_->getMergedIntJForLumi(
"Processed", lumi));
505 if (!lumiProcessedJptr)
506 throw cms::Exception(
"FastMonitoringService") <<
"Internal error: got null pointer from FastMonitor";
513 exception_detected =
true;
518 <<
" events were processed in LUMI " <<
lumi;
529 if (sourceReport.first) {
531 throw cms::Exception(
"FastMonitoringService") <<
"MISMATCH with SOURCE update. LUMI -: " << lumi
533 <<
" events(source):" << sourceReport.second;
538 <<
"Statistics for lumisection -: lumi = " << lumi <<
" events = " << lumiProcessedJptr->
value()
539 <<
" time = " << usecondsForLumi / 1000000 <<
" size = " << accuSize <<
" thr = " << throughput;
540 delete lumiProcessedJptr;
547 std::stringstream slowFileNameStem;
548 slowFileNameStem <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) << lumi <<
"_pid" << std::setfill(
'0')
549 << std::setw(5) << getpid();
551 slow /= slowFileNameStem.str();
552 fmt_->jsonMonitor_->outputFullJSONs(slow.string(),
".jsn",
lumi,
output);
554 std::stringstream slowFileName;
555 slowFileName <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4) << lumi <<
"_pid" << std::setfill(
'0')
556 << std::setw(5) << getpid() <<
".jsn";
558 slow /= slowFileName.str();
562 fmt_->jsonMonitor_->discardCollected(lumi);
566 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
580 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
584 *(
fmt_->m_data.processed_[sid]) = 0;
596 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
624 fmt_->m_data.fastPathProcessedJ_ = res + 1;
671 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
698 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
721 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
727 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
731 unsigned int proc = it->second.first;
733 *abortFlag = it->second.second;
737 <<
"output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: "
745 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
749 unsigned int abortFlag = it->second.second;
753 <<
"output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: "
761 monInit_.exchange(
true, std::memory_order_acquire);
762 while (!
fmt_->m_stoprequest) {
763 std::vector<std::vector<unsigned int>> lastEnc;
765 std::lock_guard<std::mutex>
lock(
fmt_->monlock_);
769 lastEnc.emplace_back(
fmt_->m_data.ministateEncoded_);
770 lastEnc.emplace_back(
fmt_->m_data.microstateEncoded_);
774 std::vector<std::string> CSVv;
776 CSVv.push_back(
fmt_->jsonMonitor_->getCSVString((
int)
i));
778 fmt_->monlock_.unlock();
786 fmt_->monlock_.unlock();
794 std::stringstream accum;
795 std::function<void(std::vector<unsigned int>)>
f = [&](std::vector<unsigned int>
p) {
798 accum <<
"[" << p[
i] <<
",";
799 else if (
i <= nStreams_ - 1)
800 accum << p[
i] <<
",";
802 accum << p[
i] <<
"]";
806 accum <<
"Current states: Ms=" <<
fmt_->m_data.fastMacrostateJ_.value() <<
" ms=";
819 fmt_->m_data.fastMacrostateJ_ =
fmt_->m_data.macrostate_;
821 std::vector<const void*> microstateCopy(
fmt_->m_data.microstate_.begin(),
fmt_->m_data.microstate_.end());
822 std::vector<unsigned char> microstateAcqCopy(
fmt_->m_data.microstateAcqFlag_.begin(),
823 fmt_->m_data.microstateAcqFlag_.end());
828 fmt_->m_data.fastAvgLeadTimeJ_ = itd->second;
830 fmt_->m_data.fastAvgLeadTimeJ_ = 0.;
834 fmt_->m_data.fastFilesProcessedJ_ = iti->second;
836 fmt_->m_data.fastFilesProcessedJ_ = 0;
840 fmt_->m_data.fastLockWaitJ_ = itrd->second.first;
841 fmt_->m_data.fastLockCountJ_ = itrd->second.second;
843 fmt_->m_data.fastLockWaitJ_ = 0.;
844 fmt_->m_data.fastLockCountJ_ = 0.;
849 fmt_->m_data.ministateEncoded_[
i] =
fmt_->m_data.encPath_[
i].encodeString(
fmt_->m_data.ministate_[
i]);
850 if (microstateAcqCopy[
i])
851 fmt_->m_data.microstateEncoded_[
i] =
852 fmt_->m_data.microstateBins_ +
fmt_->m_data.encModule_.encode(microstateCopy[i]);
854 fmt_->m_data.microstateEncoded_[
i] =
fmt_->m_data.encModule_.encode(microstateCopy[i]);
857 bool inputStatePerThread =
false;
960 inputStatePerThread =
true;
971 inputStatePerThread =
true;
984 if (!inputStatePerThread)
986 fmt_->m_data.inputState_[
i] =
fmt_->m_data.inputState_[0];
989 fmt_->jsonMonitor_->snapGlobal(ls);
991 fmt_->jsonMonitor_->snap(ls);
void prePathEvent(edm::StreamContext const &, edm::PathContext const &)
std::string const & pathName() const
std::atomic< FastMonState::InputState > inputState_
unsigned int maxNumberOfThreads() const
std::string pathLegendFileJson_
void watchPreStreamEarlyTermination(PreStreamEarlyTermination::slot_type const &iSlot)
static const std::string inputStateNames[FastMonState::inCOUNT]
void watchPreEvent(PreEvent::slot_type const &iSlot)
void postModuleEventAcquire(edm::StreamContext const &, edm::ModuleCallingContext const &)
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)
void watchPreModuleEventAcquire(PreModuleEventAcquire::slot_type const &iSlot)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void preallocate(edm::service::SystemBounds const &)
std::map< unsigned int, timeval > lumiStartTime_
void preGlobalBeginLumi(edm::GlobalContext const &)
void setAllowAnything()
allow any parameter label/value pairs
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void postGlobalEndLumi(edm::GlobalContext const &)
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::filesystem::path workingDirectory_
unsigned int snapCounter_
std::vector< std::atomic< bool > * > streamCounterUpdating_
void watchPostEvent(PostEvent::slot_type const &iSlot)
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)
std::map< unsigned int, unsigned int > filesProcessedDuringLumi_
void preGlobalEndLumi(edm::GlobalContext const &)
void setMicroState(FastMonState::Microstate)
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)
static const edm::ModuleDescription reservedMicroStateNames[FastMonState::mCOUNT]
constexpr int nSpecialModules
std::string inputLegendFileJson_
unsigned int fastMonIntervals_
void watchJobFailure(JobFailure::slot_type const &iSlot)
convenience function for attaching to signal
std::atomic< bool > monInit_
std::vector< std::string > const & endPaths() const
std::string makeModuleLegendaJson()
unsigned int maxNumberOfStreams() const
void preModuleBeginJob(edm::ModuleDescription const &)
void setComment(std::string const &value)
std::string makeInputLegendaJson()
std::map< unsigned int, std::pair< unsigned int, bool > > processedEventsPerLumi_
MicroStateService(const edm::ParameterSet &, edm::ActivityRegistry &)
unsigned int lumiFromSource_
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::atomic< FastMonState::InputState > inputSupervisorState_
if(conf_.getParameter< bool >("UseStripCablingDB"))
static const std::string nopath_
ModuleDescription const * moduleDescription() const
constexpr double throughputFactor()
void watchPostModuleEventAcquire(PostModuleEventAcquire::slot_type const &iSlot)
std::string fastMicrostateDefPath_
std::filesystem::path runDirectory_
void watchPostGlobalEndLumi(PostGlobalEndLumi::slot_type const &iSlot)
std::string moduleLegendFileJson_
virtual ~MicroStateService()
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
void preModuleEventAcquire(edm::StreamContext const &, edm::ModuleCallingContext const &)
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
std::vector< std::string > fastPathList_
constexpr int nReservedPaths
void postStreamBeginLumi(edm::StreamContext const &)
StreamID const & streamID() const
Log< level::Info, false > LogInfo
void preSourceEvent(edm::StreamID)
void postStreamEndLumi(edm::StreamContext const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned int value() const
void preStreamBeginLumi(edm::StreamContext const &)
std::atomic< unsigned long > totalEventsProcessed_
FedRawDataInputSource * inputSource_
std::map< unsigned int, std::pair< double, unsigned int > > lockStatsDuringLumi_
~FastMonitoringService() override
constexpr int nReservedModules
LuminosityBlockNumber_t luminosityBlock() const
void watchPreStreamBeginLumi(PreStreamBeginLumi::slot_type const &iSlot)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< double > leadTimes_
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.
std::vector< std::string > const & paths() const
void postGlobalBeginRun(edm::GlobalContext const &)
void preEvent(edm::StreamContext const &)
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=nullptr)
void preSourceEarlyTermination(edm::TerminationOrigin)
EventID const & eventID() const
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
bool getAbortFlagForLumi(unsigned int lumi)
std::shared_ptr< FastMonitoringThread > fmt_
Log< level::Warning, false > LogWarning
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
Writes a Value in JSON format in a human friendly way.
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)