21 using namespace jsoncollector;
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::nopath_ =
"NoPath";
46 ,sleepTime_(iPS.getUntrackedParameter<int>(
"sleepTime", 1))
47 ,fastMonIntervals_(iPS.getUntrackedParameter<unsigned int>(
"fastMonIntervals", 2))
48 ,fastName_(
"fastmoni")
49 ,slowName_(
"slowmoni")
50 ,totalEventsProcessed_(0)
85 std::string microstateBaseSuffix =
"src/EventFilter/Utilities/plugins/microstatedef.jsd";
87 if (stat(microstatePath.c_str(), &statbuf)) {
88 microstatePath =
std::string(getenv(
"CMSSW_RELEASE_BASE")) +
"/" + microstateBaseSuffix;
89 if (stat(microstatePath.c_str(), &statbuf)) {
90 microstatePath = microstateBaseSuffix;
91 if (stat(microstatePath.c_str(), &statbuf))
92 throw cms::Exception(
"FastMonitoringService") <<
"microstate definition file not found";
106 desc.
setComment(
"Service for File-based DAQ monitoring and event accounting");
107 desc.
addUntracked<
int> (
"sleepTime",1)->setComment(
"Sleep time of the monitoring thread");
108 desc.
addUntracked<
unsigned int> (
"fastMonIntervals",2)->setComment(
"Modulo of sleepTime intervals on which fastmon file is written out");
110 descriptions.
add(
"FastMonitoringService", desc);
120 pathLegend[
"names"]=legendaVector;
121 pathLegend[
"reserved"]=valReserved;
123 return writer.
write(pathLegend);
134 moduleLegend[
"names"]=legendaVector;
135 moduleLegend[
"reserved"]=valReserved;
136 moduleLegend[
"special"]=valSpecial;
137 moduleLegend[
"output"]=valOutputModules;
139 return writer.
write(moduleLegend);
150 throw cms::Exception(
"FastMonitoringService") <<
"EvFDaqDirector is not present";
163 <<
". No monitoring data will be written.";
166 std::ostringstream fastFileName;
168 fastFileName <<
fastName_ <<
"_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".fast";
170 fast /= fastFileName.str();
173 std::ostringstream moduleLegFile;
174 std::ostringstream moduleLegFileJson;
175 moduleLegFile <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
176 moduleLegFileJson <<
"microstatelegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
180 std::ostringstream pathLegFile;
181 std::ostringstream pathLegFileJson;
182 pathLegFile <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".leg";
184 pathLegFileJson <<
"pathlegend_pid" << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
187 LogDebug(
"FastMonitoringService") <<
"Initializing FastMonitor with microstate def path -: "
207 for(
unsigned int i = 0;
i < (
mCOUNT);
i++)
242 monInit_.store(
false,std::memory_order_release);
276 edm::LogWarning(
"FastMonitoringService") <<
" GLOBAL " <<
"earlyTermination -: LS:"
288 edm::LogWarning(
"FastMonitoringService") <<
" SOURCE " <<
"earlyTermination -: " << context;
346 timeval lumiStartTime;
347 gettimeofday(&lumiStartTime, 0);
371 LogDebug(
"FastMonitoringService") <<
"Lumi ended. Writing JSON information. LUMI -: "
373 timeval lumiStopTime;
374 gettimeofday(&lumiStopTime, 0);
380 unsigned long usecondsForLumi = (lumiStopTime.tv_sec - stt.tv_sec)*1000000
381 + (lumiStopTime.tv_usec - stt.tv_usec);
383 double throughput =
throughputFactor()* double(accuSize) / double(usecondsForLumi);
391 std::stringstream slowFileName;
392 slowFileName <<
slowName_ <<
"_ls" << std::setfill(
'0') << std::setw(4)
393 << lumi <<
"_pid" << std::setfill(
'0')
394 << std::setw(5) << getpid() <<
".jsn";
396 slow /= slowFileName.str();
400 if (!lumiProcessedJptr)
401 throw cms::Exception(
"FastMonitoringService") <<
"Internal error: got null pointer from FastMonitor";
407 if (lumi == ex) exception_detected=
true;
410 edm::LogInfo(
"FastMonitoringService") <<
"Run interrupted. Skip writing EoL information -: "
423 if (sourceReport.first) {
425 throw cms::Exception(
"FastMonitoringService") <<
"MISMATCH with SOURCE update. LUMI -: "
428 <<
" events(source):" << sourceReport.second;
432 edm::LogInfo(
"FastMonitoringService") <<
"Statistics for lumisection -: lumi = " << lumi <<
" events = "
433 << lumiProcessedJptr->
value() <<
" time = " << usecondsForLumi/1000000
434 <<
" size = " << accuSize <<
" thr = " << throughput;
435 delete lumiProcessedJptr;
539 #elif ATOMIC_LEVEL==1
543 #elif ATOMIC_LEVEL==0 //default
651 unsigned int proc = it->second.first;
652 if (abortFlag) *abortFlag=it->second.second;
656 throw cms::Exception(
"FastMonitoringService") <<
"output module wants already deleted (or never reported by SOURCE) lumisection event count for LUMI -: "<<
lumi;
667 unsigned int abortFlag = it->second.second;
671 throw cms::Exception(
"FastMonitoringService") <<
"output module wants already deleted (or never reported by SOURCE) lumisection status for LUMI -: "<<
lumi;
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::string pathLegendFile_
void postSourceEvent(edm::StreamID)
std::string makePathLegendaJson()
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_
FastMonitoringThread fmt_
unsigned int microstateBins_
std::vector< unsigned int > eventCountForPathInit_
std::vector< std::atomic< bool > * > streamCounterUpdating_
void watchPostEvent(PostEvent::slot_type const &iSlot)
jsoncollector::DoubleJ fastThroughputJ_
static const int nReservedPaths
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)
volatile std::atomic< bool > shutdown_flag
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)
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 &)
void setComment(std::string const &value)
void updateReserved(const void *add)
unsigned int lumiFromSource_
std::vector< std::atomic< bool > * > collectedPathList_
std::queue< unsigned int > lastGlobalLumisClosed_
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_
bool emptyLumisectionMode_
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 &)
virtual std::string write(const Value &root)
Serialize a Value in JSON format.
void postStreamBeginLumi(edm::StreamContext const &)
void completeReservedWithDummies()
StreamID const & streamID() const
void preSourceEvent(edm::StreamID)
void postStreamEndLumi(edm::StreamContext const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< const void * > microstate_
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_
static const int nSpecialModules
LuminosityBlockNumber_t luminosityBlock() const
void watchPreStreamBeginLumi(PreStreamBeginLumi::slot_type const &iSlot)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
FastMonitoringThread::Macrostate macrostate_
std::vector< double > leadTimes_
jsoncollector::IntJ fastPathProcessedJ_
void stoppedLookingForFile(unsigned int lumi)
void setMicroState(MicroStateService::Microstate)
boost::filesystem::path workingDirectory_
jsoncollector::IntJ fastLockCountJ_
std::vector< jsoncollector::AtomicMonUInt * > processed_
void postGlobalBeginRun(edm::GlobalContext const &)
void preEvent(edm::StreamContext const &)
bool isGlobalLumiTransition_
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.
std::vector< const void * > ministate_
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 > 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)