diff --git a/Online/Dataflow/CMakeLists.txt b/Online/Dataflow/CMakeLists.txt index f6f677464ae40419ed4e2a2316984081ccccdbba..e5f3ca5dffa4a75a12bfc21990ba65f8d377cc30 100755 --- a/Online/Dataflow/CMakeLists.txt +++ b/Online/Dataflow/CMakeLists.txt @@ -25,11 +25,9 @@ gaudi_depends_on_subdirs(Online/dim Online/Tell1Data Online/PCIE40Data Online/GauchoBase - Online/OnlineKernel - Online/PCIE40Data) + Online/OnlineKernel) # include(Numa) -###include(PCIE40) # find_package(Boost REQUIRED COMPONENTS system filesystem regex) find_package(ROOT REQUIRED COMPONENTS Hist RIO) @@ -236,25 +234,9 @@ gaudi_add_dictionary(Dataflow dict/dictionary.h dict/dictionary.xml LINK_LIBRARIES ROOT Boost OnlineBase DataflowLib) # # --------------------------------------------------------------------------------------- -# PCIE40 event builder library -# --------------------------------------------------------------------------------------- -IF (PCIE40_FOUND) - gaudi_add_library(DataflowPCIE40 - src/PCIE40/*.cpp - INCLUDE_DIRS ${PCIE40_INCLUDE_DIR} - NO_PUBLIC_HEADERS - LINK_LIBRARIES ${PCIE40_LIBRARIES} dim Boost OnlineBase Options DataflowLib Tell1Data) - - target_include_directories(DataflowPCIE40 BEFORE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) - gaudi_generate_componentslist(DataflowPCIE40) -ELSE() - message(STATUS "+++ Dataflow: PCIE40 event builder library shall not be built!") -ENDIF() -# -# --------------------------------------------------------------------------------------- macro(df_exe name) gaudi_add_executable(${name} ${ARGN} - LINK_LIBRARIES dim dimlogLib Boost ROOT Options OnlineKernel Parsers Properties DataflowLib) + LINK_LIBRARIES dim Boost ROOT Options OnlineKernel Parsers Properties DataflowLib) endmacro() # df_exe(dataflow_task src/main/Dataflow_task.cpp) diff --git a/Online/Dataflow/src/PCIE40/PCIE40Reader.cpp b/Online/Dataflow/src/PCIE40/PCIE40Reader.cpp deleted file mode 100644 index 20e17e4c2af9a1a58daaf9c5273ba099f132d09c..0000000000000000000000000000000000000000 --- a/Online/Dataflow/src/PCIE40/PCIE40Reader.cpp +++ /dev/null @@ -1,626 +0,0 @@ -//========================================================================== -// LHCb Online software suite -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see OnlineSys/LICENSE. -// -//-------------------------------------------------------------------------- -// PCIE40Reader.h -//-------------------------------------------------------------------------- -// -// Package : GaudiOnline -// -// Author : Markus Frank -//========================================================================== -#ifndef ONLINE_DATAFLOW_PCIE40READER_H -#define ONLINE_DATAFLOW_PCIE40READER_H - -// Framework includes -#include "Dataflow/DataflowComponent.h" -#include "MBM/BufferInfo.h" -#include "MBM/Producer.h" -#include "RTL/rtl.h" -#include "pcie40_localeb/localeb.h" - -// C/C++ include files -#include <sys/stat.h> -#include <mutex> -#include <ctime> -#include <set> - -/// Online namespace declaration -namespace Online { - - /// Basic HLT2 file reader for the deferred triggering - /** Class definition of PCIE40Reader. - * - * This is the online extension of the runnable of the application manager. - * The runable handles the actual run() implementation of the - * ApplicationMgr object. - * - * @author Markus Frank - * - * @version 1.5 - */ - class PCIE40Reader : public DataflowComponent { - public: - protected: - typedef std::vector<std::string> StringV; - typedef std::map<std::string, std::string> StringMap; - /// Flag indicating that MBM event retrieval is active - bool m_receiveEvts; - /// Lock handle - lib_rtl_lock_t m_lock; - /// Reference to buffer manager producer - MBM::Producer* m_producer; - /// Reference to PCIE40 event builder structure - p40_localeb* m_localEB = 0; - /// Property: Run number DIM service name - std::string m_runNoService; - /// Property: Buffer name for data output - std::string m_buffer; - /// Property: Buffer names to be checked on special transitions - StringV m_mbmNames; - /// Property: Maximum number of seconds to wait for consumers (default: 20 seconds) - int m_maxConsWait; - /// Property: Maximum number of seconds to wait for buffers being empty (default: 1000 seconds) - int m_maxPauseWait; - /// Property: Time for initial sleep before starting to process files (default: 10 sec) - int m_initialSleep; - /// Property: Time for sleep before finishing the PAUSE transition (default: 5 sec) - int m_pauseSleep; - /// Property: Flag to require consumer presence checks - int m_requireConsumers; - /// Property: Default packing factor for requesting events - int m_packingFactor; - /// Property: Maximum packing factor for BURST events to be declared to MBM - int m_mbmPacking; - /// Property: MBM request buffer size in KB - int m_bufferSize; - /// Property: Steer PCIE40 resets. Only for SW based test data generator. - int m_resetSimuPCIE40; - /// Property: Steer PCIE40 board start. Only for SW based test data generator. - int m_startSimuPCIE40; - /// Property: Sleep between event BURST declarations - int m_muSleep; - /// Property: Produce bank of this type - int m_bankType = -1; - /// Property: Produce bank of this version - int m_bankVersion = -1; - /// Monitoring quantity: Number of events processed - int m_evtCount; - /// DIM command service to set run number - int m_runNoSvc = -1; - /// Current run number - long m_runNumber = 0; - /// Optimize buffer requests: Store byte count for mean - long long int m_total_bytes; - /// Optimize buffer requests: Store event count for mean - long long int m_total_events; - /// Flag to indicate if PAUSE incident was received or should be sent. - bool m_paused; - /// Buffer information blocks to be checked before special transitions are completed - MBM::BufferInfo* m_mbmInfos; - /// String keyed map of buffer information blocks. - std::map<std::string,MBM::BufferInfo*> m_mbmInfo; - /// Mutex to protect producer from unsolicited cancel requests - std::mutex m_prodLock; - - // Helper routines - /// Wait until event buffers are empty before finishing.... - void waitForPendingEvents(int seconds); - - /// Runable implementation : Run the class implementation - int i_run(); - - public: - /// Standard Constructor - PCIE40Reader(const std::string& nam, DataflowContext& context); - /// Standard Destructor - virtual ~PCIE40Reader(); - /// IService implementation: initialize the service - virtual int initialize() override; - /// Low level overload from Service base class: sysStart - virtual int start() override; - /// IService implementation: finalize the service - virtual int finalize() override; - /// Low level overload from Service base class: sysStop - virtual int stop() override; - /// Cancel I/O operations of the dataflow component - virtual int cancel() override; - /// Stop gracefully execution of the dataflow component - virtual int pause() override; - /// Incident handler implemenentation: Inform that a new incident has occured - virtual void handle(const DataflowIncident& inc) override; - /// IRunable implementation : Run the class implementation - virtual int run() override; - - /// Update run number - void setRunNumber(int runno); - - }; -} // End namespace Online -#endif // ONLINE_DATAFLOW_PCIE40READER_H - -//========================================================================== -// LHCb Online software suite -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see OnlineSys/LICENSE. -// -//-------------------------------------------------------------------------- -// PCIE40Reader.h -//-------------------------------------------------------------------------- -// -// Package : GaudiOnline -// -// Author : Markus Frank -//========================================================================== - -// Framework includes -#include "Dataflow/DataflowTask.h" -#include "Dataflow/ControlPlug.h" -#include "Dataflow/MBMClient.h" -#include "Dataflow/Incidents.h" -#include "Dataflow/Plugins.h" -#include "Tell1Data/Tell1Decoder.h" -#include "RTL/rtl.h" -#include "RTL/readdir.h" -#include <fcntl.h> -#include <cerrno> -#include <cstring> -#include <sstream> -#include "dim/dic.h" -#include "dim/dis.h" -//#include "common/p40.h" - -using namespace Online; -using namespace std; - -// Instantiation of a static factory class used by clients to create instances of this service -DECLARE_DATAFLOW_NAMED_COMPONENT_NS(Online,Dataflow_PCIE40Reader,PCIE40Reader) - -using namespace Online; -using namespace std; - -namespace { - void runno_handler(void* tag, void* address, int* size) { - if ( tag && address && size && *size > 0 ) { - PCIE40Reader* plug = *(PCIE40Reader**)tag; - int runno = *(int*)address; - plug->setRunNumber(runno); - } - } - bool check_consumers(const MBM::BufferInfo& info, int pid, int evtyp) { - return info.num_consumers_partid_evtype(pid,evtyp) != 0; - } - bool check_consumers_partid(const MBM::BufferInfo& info, int pid) { - return info.num_consumers_partid(pid) != 0; - } -} - -/// Standard Constructor -PCIE40Reader::PCIE40Reader(const string& nam, DataflowContext& ctxt) - : DataflowComponent(nam, ctxt), m_receiveEvts(false), m_lock(0), - m_producer(0), m_evtCount(0), m_paused(false), m_mbmInfos(0) -{ - declareProperty("Buffer", m_buffer = "Events"); - declareProperty("BufferSizeKB", m_bufferSize = 10); - declareProperty("ConsumerWait", m_maxConsWait = 20); - declareProperty("MaxPauseWait", m_maxPauseWait = 1000); - declareProperty("InitialSleep", m_initialSleep = 10); - declareProperty("PauseSleep", m_pauseSleep = 5); - declareProperty("PackingFactor", m_packingFactor = 100); - declareProperty("MBMPackingFactor", m_mbmPacking = 1000); - declareProperty("ResetSimuPCIE40", m_resetSimuPCIE40 = 1); - declareProperty("StartSimuPCIE40", m_startSimuPCIE40 = 1); - declareProperty("muSleep", m_muSleep = 0); - declareProperty("BankType", m_bankType = -1 ); // Default: ignore - declareProperty("BankVersion", m_bankVersion = -1 ); // Default: ignore - declareProperty("CheckedBuffers", m_mbmNames); - declareProperty("RequireConsumers", m_requireConsumers = true); - declareProperty("RunNumberService", m_runNoService); - ::lib_rtl_create_lock(0, &m_lock); -} - -/// Standard Destructor -PCIE40Reader::~PCIE40Reader() { - if ( m_lock ) { - ::lib_rtl_delete_lock(m_lock); - } -} - -/// Update run number -void PCIE40Reader::setRunNumber(int runno) { - warning("Setting new run number: %d",runno); - p40_localeb_set_run_number(m_runNumber=runno); -} - -/// IService implementation: initialize the service -int PCIE40Reader::initialize() { - int sc; - string broken_hosts; - if ( (sc = Component::initialize()) != DF_SUCCESS ) - return error("Failed to initialize service base class."); - else if ( !context.mbm ) - return error("Failed to access MBM client."); - m_producer = context.mbm->createProducer(m_buffer, RTL::processName()); - if (0 == m_producer) { - return error("Fatal error: Failed to create MBM producer object."); - } - m_bufferSize *= 1024; // kB --> Bytes - m_total_events = 5; - m_total_bytes = m_total_events*100*1024; // Default: 100 kB / event - // Buffer information blocks - if ( m_mbmNames.empty() ) m_mbmNames.push_back(m_buffer); - m_mbmInfos = new MBM::BufferInfo[m_mbmNames.size()]; - for(size_t i=0; i<m_mbmNames.size(); ++i) { - string nam = m_mbmNames[i]; - string bm_name = context.mbm->bufferName(nam); - m_mbmInfo[nam] = &m_mbmInfos[i]; - m_mbmInfos[i].attach(bm_name.c_str()); - } - /// Monitoring information - subscribeIncident("DAQ_PAUSE"); - subscribeIncident("DAQ_CANCEL"); - subscribeIncident("DAQ_STOP_TRIGGER"); - subscribeIncident("DAQ_START_TRIGGER"); - declareMonitor("EvtCount", m_evtCount=0, "Number of events processed"); - ::lib_rtl_lock(m_lock); - m_paused = false; - m_runNoSvc = -1; - if ( !m_runNoService.empty() ) { - m_runNoSvc = ::dic_info_service(m_runNoService.c_str(),MONITORED,0,0,0,runno_handler,(long)this,0,0); - } - return sc; -} - -/// IService implementation: finalize the service -int PCIE40Reader::finalize() { - if ( m_runNoSvc != -1 ) { - ::dic_release_service(m_runNoSvc); - m_runNoSvc = -1; - } - m_mbmInfo.clear(); - if ( m_mbmInfos ) { - delete [] m_mbmInfos; - m_mbmInfos = 0; - } - m_paused = false; - if ( m_producer ) { - detail::deletePtr(m_producer); - } - return Component::finalize(); -} - -int PCIE40Reader::start() { - m_paused = false; - m_receiveEvts = true; - ::lib_rtl_unlock(m_lock); - if ( m_resetSimuPCIE40 ) { - p40_localeb_reset(); - } - if ( m_startSimuPCIE40 ) { - p40_localeb_start(); - } - if ( m_bankType > 0 ) { - p40_localeb_set_bank_type(m_bankType); - info("PCIE40 reader is now set to produce banks of type: %s", - Tell1Printout::bankType(m_bankType).c_str()); - } - if ( m_bankVersion > 0 ) { - p40_localeb_set_bank_version(m_bankVersion); - info("PCIE40 reader is now set to produce banks of version: %d",m_bankVersion); - } - m_localEB = p40_localeb_new2(1); - if ( 0 == m_localEB ) { - return error("Failed to open PCIE40 device driver."); - } - return DF_SUCCESS; -} - -/// IService implementation: finalize the service -int PCIE40Reader::stop() { - m_paused = false; - m_receiveEvts = false; - unsubscribeIncidents(); - if ( m_receiveEvts ) { - if ( context.mbm ) { - //context.mbm->cancelBuffers(); - int count = 100; - while( --count >= 0 ) { - if ( m_prodLock.try_lock() ) { - context.mbm->cancelBuffers(); - m_prodLock.unlock(); - break; - } - ::lib_rtl_sleep(20); - } - // This only happens if the event loop is stuck somewhere. - if ( count < 0 ) context.mbm->cancelBuffers(); - } - } - ::lib_rtl_unlock(m_lock); - if ( m_localEB ) { - if ( m_resetSimuPCIE40 ) { - p40_localeb_reset(); - } - p40_localeb_free(m_localEB); - m_localEB = 0; - } - return DF_SUCCESS; -} - -/// Cancel I/O operations of the dataflow component -int PCIE40Reader::cancel() { - m_receiveEvts = false; - if (context.mbm) { - //context.mbm->cancelBuffers(); - } - info("Executed cancellation of pending I/O requests."); - ::lib_rtl_unlock(m_lock); - return DF_SUCCESS; -} - -/// Stop gracefully execution of the dataflow component -int PCIE40Reader::pause() { - m_paused = true; - m_receiveEvts = false; - if ( context.mbm ) { - // This is not terribly elegant, but we have to stop the DIM callback - // and wait until the pipeline is empty.... - MBM::BufferInfo mbmInfo; - if (context.mbm) { - int count = 100; - while( --count >= 0 ) { - if ( m_prodLock.try_lock() ) { - context.mbm->cancelBuffers(); - m_prodLock.unlock(); - break; - } - ::lib_rtl_sleep(20); - } - // This only happens if the event loop is stuck somewhere. - if ( count < 0 ) context.mbm->cancelBuffers(); - info("Waiting until event pipeline is empty....."); - waitForPendingEvents(m_maxPauseWait); - } - ::lib_rtl_unlock(m_lock); - info("No events pending anymore...continue with PAUSE processing....."); - } - return DF_SUCCESS; -} - -void PCIE40Reader::waitForPendingEvents(int seconds) { - size_t count; - do { - count = 0; - for(auto i=m_mbmInfo.begin(); i!=m_mbmInfo.end(); ++i) - count += (*i).second->num_events(); - if ( count > 0 ) ::lib_rtl_sleep(1000); - } while ( count > 0 && --seconds >= 0 ); - ::lib_rtl_sleep(1000); -} - -/// Incident handler implemenentation: Inform that a new incident has occured -void PCIE40Reader::handle(const DataflowIncident& inc) -{ - info("Got incident: %s of type %s", inc.name.c_str(), inc.type.c_str()); - if (inc.type == "DAQ_CANCEL" ) { - } - else if ( inc.type == "DAQ_PAUSE" ) { - m_receiveEvts = false; - } - else if (inc.type == "DAQ_ENABLE") { - m_receiveEvts = true; - } - else if (inc.type == "DAQ_STOP_TRIGGER") { - m_receiveEvts = false; - } - else if (inc.type == "DAQ_START_TRIGGER") { - m_receiveEvts = true; - } -} - -/// IRunable implementation : Run the class implementation -int PCIE40Reader::i_run() { - int cons_wait, status; - int partid = context.mbm->partitionID(); - MBM::BufferInfo* mbmInfo = m_mbmInfo[m_buffer]; - - if ( m_initialSleep > 0 ) { - ::lib_rtl_sleep(1000*m_initialSleep); - } - m_receiveEvts = true; - /// Before we start, we need to check if there are consumers present: - if ( m_requireConsumers ) { - for(cons_wait = m_maxConsWait; !check_consumers_partid(*mbmInfo,partid) && --cons_wait>=0; ) - ::lib_rtl_sleep(1000); - - if ( cons_wait <= 0 ) { - ::lib_rtl_sleep(1000); - fireIncident("DAQ_ERROR"); - return error("No consumers present to consume event. ERROR & Return!"); - } - } - - while (1) { - // Again check if the GO value changed, since we may have been waiting in the lock! - if ( !m_receiveEvts ) { - info("Quitting..."); - break; - } - m_evtCount = 0; - // loop over the events - while ( m_receiveEvts ) { - try { - status = m_producer->spaceRearm(m_bufferSize); - } - catch (const exception& e) { - error("Exception while reading input files (spaceRearm): %s " - "Event:%d BuffSize:%d. ",e.what(),m_evtCount,m_bufferSize); - continue; - } - if (status == MBM_NORMAL) { - MBM::EventDesc& dsc = m_producer->event(); - int count = 0; - int num_events = 0; - ssize_t total_size = 0; - uint8_t* ptr = (uint8_t*)dsc.data; - long mean_size = long(double(m_total_bytes)/double(m_total_events)); - size_t packing = m_packingFactor < m_mbmPacking ? m_packingFactor : m_mbmPacking; - for ( status = 0, count = 0;; ++count) { - if ( num_events + packing > size_t(m_mbmPacking) ) { - packing = num_events + packing - m_mbmPacking; - } - ssize_t read_size = ::p40_localeb_read(m_localEB, - ptr+total_size, m_bufferSize-total_size, &packing); - if ( read_size > 0 ) { - m_total_events += packing; - m_total_bytes += read_size; - total_size += read_size; - num_events += packing; - if ( num_events >= m_mbmPacking ) { - break; - } - else if ( m_bufferSize > m_packingFactor*mean_size*1.3 ) { - continue; - } - } - else if ( read_size == 0 ) { - warning("PCIE40 flushed."); - continue; - } - else if ( errno == EAGAIN ) { - ::lib_rtl_usleep(1); - continue; - } - else if ( errno == ENOMEM ) { - if ( total_size > 0 ) - break; - /// Else: ERROR - error("PCIE40 Memory missing [%s ] --> STOP.",RTL::errorString().c_str()); - status = errno; - break; - } - else if ( errno == EBADMSG ) { - /// Goto ERROR and STOP - error("Bad event message received from PCIE40 [%s] --> CONTINUE.",RTL::errorString().c_str()); - status = errno; - break; - } - else if ( errno == EINVAL ) { - /// Real error - error("PCIE40 ERROR [%s ] --> STOP.",RTL::errorString().c_str()); - status = errno; - break; - } - } - if ( status != 0 ) { - m_receiveEvts = false; - /// Before actually declaring ERROR, we wait until no events are pending anymore. - waitForPendingEvents(m_maxConsWait); - ::lib_rtl_sleep(1000); - info("Fire incident ERROR and return."); - fireIncident("DAQ_ERROR"); - return DF_ERROR; - } - if ( m_muSleep > 0 ) { - ::lib_rtl_usleep(m_muSleep); - } - dsc.len = total_size; - dsc.type = EVENT_TYPE_BURST; - ::memset(dsc.mask,0xFF,sizeof(dsc.mask)); - context.manager.setRunNumber(0); - - // Check if there are consumers pending before declaring the event. - // This should be a rare case, since there ARE (were?) consumers. - // Though: In this case the event is really lost! - // But what can I do... - cons_wait = m_maxConsWait; - if ( m_requireConsumers ) { - for(cons_wait = m_maxConsWait; !check_consumers(*mbmInfo,partid,dsc.type) && --cons_wait>=0; ) { - ::lib_rtl_sleep(1000); - if ( !m_receiveEvts ) cons_wait = 0; // Force writing back opened file in case if cancel etc. - } - } - if ( cons_wait <= 0 ) { - error("No consumers (partition:%d event type:%d) present to consume event %d", - partid,dsc.type,m_evtCount); - m_receiveEvts = false; - /// Before actually declaring ERROR, we wait until no events are pending anymore. - waitForPendingEvents(m_maxConsWait); - /// Go to state PAUSED, all the work is done - ::lib_rtl_sleep(1000); - fireIncident("DAQ_ERROR"); - return DF_ERROR; - } - { - lock_guard<mutex> lck (m_prodLock); - // - // Declare the event to the buffer manager - // - try { - status = m_producer->declareEvent(); - } - catch (const exception& e) { - info("Exception while delareEvent: %s Event:%d.",e.what(),m_evtCount); - status = MBM_ERROR; - } - catch(...) { - info("UNKNOWN Exception while delareEvent: Event:%d.",m_evtCount); - status = MBM_ERROR; - } - if (status != MBM_NORMAL) { - continue; - } - // - // Now send space - // - try { - status = m_producer->sendSpace(); - } - catch (const exception& e) { - info("Exception while sendSpace: %s Event:%d.",e.what(),m_evtCount); - status = MBM_ERROR; - } - catch(...) { - info("UNKNOWN Exception while sendSpace: Event:%d.", m_evtCount); - status = MBM_ERROR; - } - } - if (status != MBM_NORMAL) { - continue; - } - else { - m_evtCount++; - } - } - } - // Bad file: Cannot read input (m_evtCount==0) - m_evtCount = 0; - } - /// Before actually declaring PAUSED, we wait until no events are pending anymore. - waitForPendingEvents(m_maxPauseWait); - return DF_SUCCESS; -} - -/// Runable implementation : Run the class implementation -int PCIE40Reader::run() { - try { - int sc = i_run(); - return sc; - } - catch (const exception& e) { - error("Exception while reading MDF files: %s",e.what()); - throw; - } - catch (...) { - error("UNKNWON Exception while reading MDF files."); - throw; - } -} diff --git a/Online/Dataflow/src/Storage/StorageWriter.cpp b/Online/Dataflow/src/Storage/StorageWriter.cpp index 2af4aaff7e9631dcaa26d518059c1e5ce972b379..77fbc9f7246441fd6a499eb91272c35590c072df 100644 --- a/Online/Dataflow/src/Storage/StorageWriter.cpp +++ b/Online/Dataflow/src/Storage/StorageWriter.cpp @@ -157,28 +157,29 @@ StorageWriter::StorageWriter(const string& nam, Context& ctxt) : Component(nam, ctxt) { string fname = "/${PARTITION}/${RUN1000}/Run_${RUN}_${NODE}_${TIME}_${PID}_${SEQ}.mdf"; - declareProperty("Server", m_server); - declareProperty("FDBVersion", m_fdb_version = 0); - declareProperty("BufferSizeMB", m_bufferSize = 1024); - declareProperty("WriteErrorRetry", m_write_error_retry = 10); - declareProperty("WriteErrorSleep", m_write_error_sleep = 2000); - declareProperty("PollTimeout", m_poll_tmo = 1000); - declareProperty("IdleTimeout", m_idle_tmo = 20); - declareProperty("CancelTimeout", m_cancel_tmo = 100); - declareProperty("NumBuffers", m_num_buffers = 2); - declareProperty("NumThreads", m_num_threads = 1); - declareProperty("MinFileSizeMB", m_minFileSizeMB = 5); - declareProperty("MaxFileSizeMB", m_maxFileSizeMB = 5000); - declareProperty("ForceMDF", m_force_mdf = 0); - declareProperty("DebugClient", m_debugClient = 0); - declareProperty("OutputType", m_outputType = "network"); - declareProperty("HaveFileDB", m_haveFileDB = 0); - - declareProperty("Stream", m_stream = "RAW"); - declareProperty("RunType", m_runType = ""); - declareProperty("PartitionName", m_partitionName = "LHCb"); - declareProperty("FileName", m_fileName = fname); - declareProperty("ThreadFileQueues",m_threadFileQueues = false); + declareProperty("Server", m_server); + declareProperty("FDBVersion", m_fdb_version = 0); + declareProperty("BufferSizeMB", m_bufferSize = 1024); + declareProperty("WriteErrorRetry", m_write_error_retry = 10); + declareProperty("WriteErrorSleep", m_write_error_sleep = 2000); + declareProperty("PollTimeout", m_poll_tmo = 1000); + declareProperty("IdleTimeout", m_idle_tmo = 20); + declareProperty("CancelTimeout", m_cancel_tmo = 100); + declareProperty("NumBuffers", m_num_buffers = 2); + declareProperty("NumThreads", m_num_threads = 1); + declareProperty("MinFileSizeMB", m_minFileSizeMB = 5); + declareProperty("MaxFileSizeMB", m_maxFileSizeMB = 5000); + declareProperty("ForceMDF", m_force_mdf = 0); + declareProperty("DebugClient", m_debugClient = 0); + declareProperty("OutputType", m_outputType = "network"); + declareProperty("HaveFileDB", m_haveFileDB = 0); + declareProperty("EnableWriting", m_enableWriting = 1); + + declareProperty("Stream", m_stream = "RAW"); + declareProperty("RunType", m_runType = ""); + declareProperty("PartitionName", m_partitionName = "LHCb"); + declareProperty("FileName", m_fileName = fname); + declareProperty("ThreadFileQueues", m_threadFileQueues = false); } /// Default destructor @@ -214,11 +215,12 @@ int StorageWriter::initialize() { b.pointer = b.buffer; this->m_free.push_back(b); } - this->declareMonitor("Events","OUT", m_eventsOUT=0, "Number of events processed"); - this->declareMonitor("Bursts","OUT", m_burstsOUT=0, "Number of bursts processed"); - this->declareMonitor("FilesOpen", m_filesOpen=0, "Number of output files currently open"); - this->declareMonitor("FilesOpened", m_filesOpened=0, "Number of output files opened"); - this->declareMonitor("FilesClosed", m_filesClosed=0, "Number of output files closed"); + this->declareMonitor("Events","OUT", m_eventsOUT=0, "Number of events processed"); + this->declareMonitor("Events","DROPPED", m_eventsDROP=0, "Number of events processed"); + this->declareMonitor("Bursts","OUT", m_burstsOUT=0, "Number of bursts processed"); + this->declareMonitor("FilesOpen", m_filesOpen=0, "Number of output files currently open"); + this->declareMonitor("FilesOpened", m_filesOpened=0, "Number of output files opened"); + this->declareMonitor("FilesClosed", m_filesClosed=0, "Number of output files closed"); this->m_shutdown = false; for(size_t i=0; i<this->m_num_threads; ++i) this->m_threads.emplace_back(make_unique<thread>([this]{ this->process_buffers(); })); @@ -349,6 +351,9 @@ int StorageWriter::save_buffer(Buffer& buff, const void* data, int64_t length) buff.pointer += length; ++this->m_eventsOUT; } + else { + ++this->m_eventsDROP; + } return sc; } @@ -406,6 +411,9 @@ int StorageWriter::save_pcie40_as_mdf(Buffer& buff, const uint8_t* start, int64_ } ++this->m_eventsOUT; } + else { + ++this->m_eventsDROP; + } } /// Move to the next MEP if any if ( m=mep->next(); m > mep ) { @@ -424,8 +432,8 @@ int StorageWriter::save_mdf_buffer(Buffer& buff, const uint8_t* start, int64_t l for( const uint8_t *begin=start, *end = start + len; start < end; ) { auto* header = (EventHeader*)start; if ( !header->is_mdf() ) { - warning("save_mdf: Encountered invalid MDF header: (%d %d %d). Skip %ld bytes of data.", - header->size0(), header->size1(), header->size2(), start-begin); + this->warning("save_mdf: Encountered invalid MDF header: (%d %d %d). Skip %ld bytes of data.", + header->size0(), header->size1(), header->size2(), start-begin); return DF_SUCCESS; } auto* hdr = header->subHeader().H1; @@ -463,47 +471,51 @@ int StorageWriter::save_mdf_buffer(Buffer& buff, const uint8_t* start, int64_t l /// Data processing overload: Write the data record to disk int StorageWriter::execute(const Context::EventData& event) { int status = DF_SUCCESS; - try { - size_t len = event.length; - auto* start = (uint8_t*)event.data; - auto& buff = get_buffer(); - - /// Check buffer validity - if ( nullptr == buff.buffer ) { - info("Execute: Failed to allocate buffer. Drop event. [%s]", - m_shutdown ? "Shutdown requested" : "??????????"); - return status; - } + if ( this->m_enableWriting ) { + try { + size_t len = event.length; + auto* start = (uint8_t*)event.data; + auto& buff = get_buffer(); + + /// Check buffer validity + if ( nullptr == buff.buffer ) { + info("Execute: Failed to allocate buffer. Drop event. [%s]", + this->m_shutdown ? "Shutdown requested" : "??????????"); + return status; + } - /// Extend idle time if there are still events coming - if ( m_cancelled > 0 ) m_cancelled = ::time(0); + /// Extend idle time if there are still events coming + if ( this->m_cancelled > 0 ) this->m_cancelled = ::time(0); + + /// Auto detect data type: first check for PCIE40 MEP format + auto* mep_hdr = (pcie40::mep_header_t*)start; + if( mep_hdr->is_valid() ) { + status = this->m_force_mdf + ? this->save_pcie40_as_mdf(buff, start, mep_hdr->size*sizeof(uint32_t)) + : this->save_buffer (buff, start, mep_hdr->size*sizeof(uint32_t)); + if ( status == DF_SUCCESS ) ++this->m_burstsOUT; + return status; + } - /// Auto detect data type: first check for PCIE40 MEP format - auto* mep_hdr = (pcie40::mep_header_t*)start; - if( mep_hdr->is_valid() ) { - status = this->m_force_mdf - ? this->save_pcie40_as_mdf(buff, start, mep_hdr->size*sizeof(uint32_t)) - : this->save_buffer (buff, start, mep_hdr->size*sizeof(uint32_t)); - if ( status == DF_SUCCESS ) ++this->m_burstsOUT; + /// Auto detect data type: first check for MDF/BURST format + auto* mdf_hdr = (EventHeader*)start; + if ( mdf_hdr->is_mdf() ) { + status = this->save_mdf_buffer(buff, start, len); + if ( status == DF_SUCCESS ) ++this->m_burstsOUT; + return status; + } + this->error("Execute: Cannot determine event type. Drop event buffer."); return status; } - - /// Auto detect data type: first check for MDF/BURST format - auto* mdf_hdr = (EventHeader*)start; - if ( mdf_hdr->is_mdf() ) { - status = this->save_mdf_buffer(buff, start, len); - if ( status == DF_SUCCESS ) ++this->m_burstsOUT; - return status; + catch(const exception& e) { + this->error(e,"Execute: Error processing event."); + } + catch(...) { + this->error("Execute: UNKOWN error processing event."); } - - this->error("Execute: Cannot determine event type. Drop event buffer."); - return status; - } - catch(const exception& e) { - this->error(e,"Execute: Error processing event."); } - catch(...) { - this->error("Execute: UNKOWN error processing event."); + else { + ++this->m_eventsDROP; } return status; } @@ -512,11 +524,11 @@ int StorageWriter::execute(const Context::EventData& event) { string StorageWriter::makeFileName(int run) { char text[128]; struct timeval tv; - string file_name = m_fileName; + string file_name = this->m_fileName; ::gettimeofday(&tv, nullptr); struct tm *timeinfo = ::localtime(&tv.tv_sec); - ++m_sequenceNumber; + ++this->m_sequenceNumber; ::strftime(text, sizeof(text), "%Y%m%d-%H%M%S-", timeinfo); ::snprintf(text+strlen(text), sizeof(text)-strlen(text),"%03ld", tv.tv_usec/1000); file_name = RTL::str_replace(file_name, "${TIME}", text); @@ -603,7 +615,7 @@ int StorageWriter::process_posix_buffers(mutex& queue_lock, map<int,unique_ptr<O while( 1 ) { Buffer b {nullptr, nullptr}; { lock_guard<mutex> bufferLock(this->m_bufferLock); - if ( this->m_free.size() == m_num_buffers && m_shutdown ) { + if ( this->m_free.size() == this->m_num_buffers && this->m_shutdown ) { lock_guard<mutex> outputLock(queue_lock); /// Shutdown (reset) requested. Close output and register file. If not possible -- nothing we can do! for(auto& output : open_files ) @@ -611,9 +623,9 @@ int StorageWriter::process_posix_buffers(mutex& queue_lock, map<int,unique_ptr<O this->info("process: Exit condition detected. Leaving submit thread."); return DF_SUCCESS; } - else if ( !m_todo.empty() ) { - b = m_todo.back(); - m_todo.pop_back(); + else if ( !this->m_todo.empty() ) { + b = this->m_todo.back(); + this->m_todo.pop_back(); } } time_t now = ::time(0); @@ -654,7 +666,7 @@ int StorageWriter::process_posix_buffers(mutex& queue_lock, map<int,unique_ptr<O if ( !output->isOpen() ) { string fname = this->makeFileName(b.runNumber); if ( output->open(fname) <= 0 ) { - error("Failed to open output %s. [%s]", fname.c_str(), RTL::errorString(errno).c_str()); + this->error("Failed to open output %s. [%s]", fname.c_str(), RTL::errorString(errno).c_str()); this->fireIncident("DAQ_ERROR"); return DF_ERROR; } @@ -734,11 +746,11 @@ int StorageWriter::process_network_buffers() { /// Thread invocation routine to save assembled buffers to the disk server int StorageWriter::process_buffers() { - switch(m_output_type) { + switch(this->m_output_type) { case NETWORK_STORAGE: return this->process_network_buffers(); case ROOT_STORAGE: - if ( m_threadFileQueues ) { + if ( this->m_threadFileQueues ) { std::mutex queue_lock; std::map<int,std::unique_ptr<ROOT_FILE> > files; return this->process_posix_buffers(queue_lock, files); @@ -746,7 +758,7 @@ int StorageWriter::process_buffers() { return this->process_posix_buffers(this->m_outputLock,this->m_open_root_files); case POSIX_STORAGE: default: - if ( m_threadFileQueues ) { + if ( this->m_threadFileQueues ) { std::mutex queue_lock; std::map<int,std::unique_ptr<POSIX_FILE> > files; return this->process_posix_buffers(queue_lock, files); @@ -771,7 +783,7 @@ void StorageWriter::print_reply(const char* prefix, const http::HttpReply& reply case http::HttpReply::accepted: case http::HttpReply::permanent_redirect: line = http::HttpReply::stock_status(reply.status); - info("writeBuffer-reply<%s>: %s", prefix, line.c_str()); + this->info("writeBuffer-reply<%s>: %s", prefix, line.c_str()); break; case http::HttpReply::internal_server_error: @@ -785,17 +797,17 @@ void StorageWriter::print_reply(const char* prefix, const http::HttpReply& reply case http::HttpReply::no_content: default: line = http::HttpReply::stock_status(reply.status); - error("writeBuffer-reply<%s>: %s", prefix, line.c_str()); + this->error("writeBuffer-reply<%s>: %s", prefix, line.c_str()); break; } } /// Write multi event buffer to file. Eventually open a new file.... int StorageWriter::writeBuffer(const Buffer& buff) { - string fname = makeFileName(buff.runNumber); - int num_retries = m_write_error_retry; + string fname = this->makeFileName(buff.runNumber); + int num_retries = this->m_write_error_retry; size_t len = buff.pointer - buff.buffer; - bool process = (m_cancelled == 0) || (::time(0) - m_cancelled < m_cancel_tmo); + bool process = (this->m_cancelled == 0) || (::time(0) - this->m_cancelled < this->m_cancel_tmo); http::HttpReply reply; /// Implement here a retry mechanism starting with registering the DB record @@ -805,7 +817,7 @@ int StorageWriter::writeBuffer(const Buffer& buff) { client_t cl(this->m_fdb_version); storage::uri_t srv(this->m_server); cl.fdbclient = - storage::client::create<storage::client::sync>(srv.host, srv.port, 10000, m_debugClient); + storage::client::create<storage::client::sync>(srv.host, srv.port, 10000, this->m_debugClient); reply = cl.save_object_record(fname, url, len); if ( reply.status == reply.permanent_redirect ) { /// OK. the registration was now successful. Send the data. @@ -830,10 +842,10 @@ int StorageWriter::writeBuffer(const Buffer& buff) { } } catch(const std::exception& e) { - error("writeBuffer: Exception while sending data: %s",e.what()); + this->error("writeBuffer: Exception while sending data: %s",e.what()); } catch(...) { - error("writeBuffer: Exception while sending data: UNKNOWN Exception"); + this->error("writeBuffer: Exception while sending data: UNKNOWN Exception"); } switch(reply.status) { @@ -843,9 +855,9 @@ int StorageWriter::writeBuffer(const Buffer& buff) { case http::HttpReply::unauthorized: case http::HttpReply::forbidden: case http::HttpReply::payment_required: - error("HTTP: %s: [%d] %s. DATA LOSS!!!! (2) Need to throw away data to avoid duplicates!", - fname.c_str(), int(reply.status), - http::HttpReply::stock_status(reply.status).c_str()); + this->error("HTTP: %s: [%d] %s. DATA LOSS!!!! (2) Need to throw away data to avoid duplicates!", + fname.c_str(), int(reply.status), + http::HttpReply::stock_status(reply.status).c_str()); return DF_ERROR; /// These are recoverable errors. We can retry.... @@ -858,22 +870,22 @@ int StorageWriter::writeBuffer(const Buffer& buff) { } process = (m_cancelled == 0) || (::time(0) - m_cancelled < m_cancel_tmo); process &= (--num_retries > 0); - warning("%s: Submission retry(2) %d / %d", - fname.c_str(), m_write_error_retry-num_retries, m_write_error_retry); - ::lib_rtl_sleep(m_write_error_sleep); + this->warning("%s: Submission retry(2) %d / %d", + fname.c_str(), this->m_write_error_retry-num_retries, this->m_write_error_retry); + ::lib_rtl_sleep(this->m_write_error_sleep); } - error("%s DATA LOSS!!!! Failed to transfer data block!", fname.c_str()); + this->error("%s DATA LOSS!!!! Failed to transfer data block!", fname.c_str()); break; } else { - print_reply("dbase-server", reply); + this->print_reply("dbase-server", reply); } } catch(const std::exception& e) { - error("writeBuffer: Exception while connecting: %s",e.what()); + this->error("writeBuffer: Exception while connecting: %s",e.what()); } catch(...) { - error("writeBuffer: Exception while connecting: UNKNOWN Exception"); + this->error("writeBuffer: Exception while connecting: UNKNOWN Exception"); } switch(reply.status) { @@ -883,8 +895,8 @@ int StorageWriter::writeBuffer(const Buffer& buff) { case http::HttpReply::unauthorized: case http::HttpReply::forbidden: case http::HttpReply::payment_required: - error("HTTP: %s DATA LOSS!!!! [%d] %s. (1) Need to throw away data to avoid duplicates!", - fname.c_str(), int(reply.status), http::HttpReply::stock_status(reply.status).c_str()); + this->error("HTTP: %s DATA LOSS!!!! [%d] %s. (1) Need to throw away data to avoid duplicates!", + fname.c_str(), int(reply.status), http::HttpReply::stock_status(reply.status).c_str()); return DF_ERROR; /// These are recoverable errors. We can retry.... @@ -895,12 +907,12 @@ int StorageWriter::writeBuffer(const Buffer& buff) { default: break; } - process = (m_cancelled == 0); - process |= (::time(0) - m_cancelled < m_cancel_tmo); + process = (this->m_cancelled == 0); + process |= (::time(0) - this->m_cancelled < this->m_cancel_tmo); process &= (--num_retries > 0); warning("%s: Submission retry(1) %d / %d", - fname.c_str(), m_write_error_retry-num_retries, m_write_error_retry); - ::lib_rtl_sleep(m_write_error_sleep); + fname.c_str(), this->m_write_error_retry-num_retries, this->m_write_error_retry); + ::lib_rtl_sleep(this->m_write_error_sleep); } return DF_ERROR; } diff --git a/Online/Dataflow/src/Storage/StorageWriter.h b/Online/Dataflow/src/Storage/StorageWriter.h index 19fa01be06a84c71039a472932fbd776e12379dc..1e43de9e8745d38d04c9368e68f7a3792914d6b1 100644 --- a/Online/Dataflow/src/Storage/StorageWriter.h +++ b/Online/Dataflow/src/Storage/StorageWriter.h @@ -81,44 +81,48 @@ namespace Online { /// Property: Buffer size int64_t m_bufferSize; /// Property: Number of parallel event buffers - std::size_t m_num_buffers; + std::size_t m_num_buffers {0}; /// Property: Number of event sender threads - std::size_t m_num_threads {0}; + std::size_t m_num_threads {0}; /// Property: Minimal file size in MBytes - long m_minFileSizeMB {0}; + long m_minFileSizeMB {0}; /// Property: Maximal file size in MBytes (used if writing to posix file system) - long m_maxFileSizeMB {512}; + long m_maxFileSizeMB {512}; /// Property: Sleep in milliseconds between retries when write connection fails int m_write_error_sleep {0}; /// Property: Number of retries when write connection fails int m_write_error_retry {0}; /// Property: Poll timeout to detect transfer buffers [microseconds] - int m_poll_tmo {100}; + int m_poll_tmo {100}; /// Property: Cancel timeout to empty pending buffers [miulli-seconds] - int m_cancel_tmo {100}; + int m_cancel_tmo {100}; /// Property: Idle timeout to close potentially open files [seconds] - int m_idle_tmo {20}; + int m_idle_tmo {20}; /// Property: Force output in MDF format - int m_force_mdf {0}; + int m_force_mdf {0}; /// Property: Use FDB client when writing POSIX/ROOT - int m_haveFileDB {0}; + int m_haveFileDB {0}; /// Property: Debug FDB client - int m_debugClient {0}; + int m_debugClient {0}; /// Property: Have threaded file queues - bool m_threadFileQueues {false}; + int m_fdb_version {0}; + /// Property: Enable/disable output to file + int m_enableWriting {1}; /// Property: Have threaded file queues - int m_fdb_version {0}; + bool m_threadFileQueues {false}; /// Monitoring quantity: Number of events written to output - long m_eventsOUT {0}; + long m_eventsOUT {0}; + /// Monitoring quantity: Number of events not written and dropped + long m_eventsDROP {0}; /// Monitoring quantity: Number of bursts submitted to output - long m_burstsOUT {0}; + long m_burstsOUT {0}; /// Monitoring quantity: Number of files currently open to write output - long m_filesOpen {0}; + long m_filesOpen {0}; /// Monitoring quantity: Number of files opened to write output - long m_filesOpened {0}; + long m_filesOpened {0}; /// Monitoring quantity: Number of files closed to write output - long m_filesClosed {0}; + long m_filesClosed {0}; /// Buffer handling thread std::vector<thread_t> m_threads; diff --git a/Online/Dataflow/src/framework/Dataflow_run.cpp b/Online/Dataflow/src/framework/Dataflow_run.cpp index 5a505e008566e7dd0c883ad69f79e14368136985..3461c2073c44a4826686319b5712aba5a1b5091e 100755 --- a/Online/Dataflow/src/framework/Dataflow_run.cpp +++ b/Online/Dataflow/src/framework/Dataflow_run.cpp @@ -19,7 +19,6 @@ #include "Dataflow/DataflowManager.h" #include "Dataflow/DataflowTask.h" #include "Dataflow/Printout.h" -#include "RTL/FmcLogDevice.h" #include "RTL/Logger.h" #include "RTL/strdef.h" #include "RTL/rtl.h" @@ -32,9 +31,6 @@ using namespace std; using namespace Online; -extern "C" void dimlog_initialize_logger(); -extern "C" void dimlog_finalize_logger(); - namespace { void help() { @@ -94,25 +90,6 @@ namespace { } auto logger = std::make_shared<RTL::Logger::LogDevice>(); - /// Load dim logger if requested. - if ( RTL::str_lower(logger_type).substr(0,3) == "dim" ) { - logger.reset(new RTL::Logger::LogDevice()); - logger_type = "Dataflow_OutputLogger"; - //::dimlog_initialize_logger(); - logger->compileFormat("%-8LEVEL %-24SOURCE"); - } - /// Load dim logger if requested. - else if ( RTL::str_lower(logger_type).substr(0,4) == "fifo" ) { - logger.reset(new RTL::Logger::LogDevice()); - logger_type = "Dataflow_OutputLogger"; - //::fifolog_initialize_logger(); - logger->compileFormat("%-8LEVEL %-24SOURCE"); - } - else if ( logger_type.substr(0,3) == "fmc" ) { - /// Need to install a proper printer, which directy writes in the fifo - logger.reset(new RTL::FmcLogDevice(::getenv("LOGFIFO"))); - logger_type = "Dataflow_FmcLogger"; - } RTL::Logger::LogDevice::setGlobalDevice(logger, print_level); RTL::Logger log(RTL::Logger::LogDevice::getGlobalDevice(),"Controller", print_level); diff --git a/Online/Dataflow/src/main/Dataflow_task.cpp b/Online/Dataflow/src/main/Dataflow_task.cpp index 6052e94610c29828fab54504cae57ccebed0b72f..a6562527db479467d377053ef4e8ba22f42eca06 100644 --- a/Online/Dataflow/src/main/Dataflow_task.cpp +++ b/Online/Dataflow/src/main/Dataflow_task.cpp @@ -15,8 +15,6 @@ // Author : Markus Frank //========================================================================== // -#include <LOG/FifoLog.inl.h> -// extern "C" int dataflow_run_task(int argc, char** argv); int main(int argc, char** argv) { diff --git a/Online/FarmConfig/job/AddersFromArchitecture.py b/Online/FarmConfig/job/AddersFromArchitecture.py index 76c313c843322eb3d350858a2c7d67cb68665edd..7e66cb78e2e53cdc585c12d6bb8d292204001f94 100644 --- a/Online/FarmConfig/job/AddersFromArchitecture.py +++ b/Online/FarmConfig/job/AddersFromArchitecture.py @@ -188,11 +188,13 @@ def AddersfromTasks(tasklist, adder_type, partition, dohostdns): adder_task_class = Class1 for task_name in tasklist: adder = Adder(task_name, "[a-z][a-z]eb[0-9][0-9]", "EBAdder", partition, "counter", "dataflow01", MON_TOP_NODE) - adder.obj.ExpandRate = 1 - #adder.obj.DebugOn = 1 + adder.obj.ExpandRate = 1 + adder.obj.TrackSources = 1 + #adder.obj.DebugOn = 1 service_list.append(adder.obj) adder = Adder(task_name, "[a-z][a-z]eb[0-9][0-9]", "EBAdder", partition, "hists", "dataflow01", MON_TOP_NODE) - #adder.obj.DebugOn = 1 + adder.obj.TrackSources = 1 + #adder.obj.DebugOn = 1 service_list.append(adder.obj) # =========================================================================================== elif adder_type=="EBPartSaver": @@ -200,7 +202,8 @@ def AddersfromTasks(tasklist, adder_type, partition, dohostdns): for task_name in tasklist: adder = Adder(task_name, "dataflow02", "EBPartAdder", partition, "hists", MON_TOP_NODE, MON_TOP_NODE) \ .enableSaving(12, 900, SAVESET_DIRECTORY) - #adder.obj.DebugOn = 1 + adder.obj.TrackSources = 1 + #adder.obj.DebugOn = 1 service_list.append(adder.obj) # =========================================================================================== elif adder_type=="EBPartPublisher": @@ -215,7 +218,8 @@ def AddersfromTasks(tasklist, adder_type, partition, dohostdns): publisher.OutDNS = MON_TOP_NODE publisher.AdderClass = "counter" publisher.ServicePrefix = "/Stat/<part>/"+task_name; - #publisher.DebugOn = True + publisher.TrackSources = 1 + #publisher.DebugOn = True if adder_debug_flag: print("%-8s Service pattern: %s Task pattern: %s"\ %("INFO", publisher.ServicePattern, publisher.TaskPattern, )) @@ -247,7 +251,10 @@ class AdderApp(Application): self.app.AppName = "" # utgid self.app.HistogramPersistency = "NONE" self.app.EvtSel = "NONE" - self.app.ExtSvc = adders + self.setup_monitoring_service() + services = [self.monSvc] + for i in adders: services.append(i) + self.app.ExtSvc = services EventLoopMgr().Warnings = False def run_adder(): diff --git a/Online/FarmConfig/job/BU.sh b/Online/FarmConfig/job/BU.sh index fcb73e7df76a5db6d8dd6d6932c28a48b265145f..9e72a27d4dd6a7de6007b9b0d873287ee12aee9b 100755 --- a/Online/FarmConfig/job/BU.sh +++ b/Online/FarmConfig/job/BU.sh @@ -13,8 +13,8 @@ unset PYTHONPATH; unset PYTHONHOME; eval `/usr/bin/python2 -c "import os;s=os.environ['UTGID'];print 'export BU_OPTIONS='+s[s.find('BU'):]+'.opts'"`; #. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64-centos7-gcc9-opt.vars; -. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-do0.vars; -#. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-opt.vars; +#. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-do0.vars; +. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-opt.vars; # . /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.${CMTCONFIG}.vars; cd ${FARMCONFIGROOT}/job; # diff --git a/Online/FarmConfig/job/RU.sh b/Online/FarmConfig/job/RU.sh index b95211bc333daf24726a1c142f62cb8f120342b0..ec85e7845b79ff3ed9b6ea4de9980b2da65f0352 100755 --- a/Online/FarmConfig/job/RU.sh +++ b/Online/FarmConfig/job/RU.sh @@ -9,8 +9,8 @@ # # ========================================================================= # -#. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-opt.vars; -. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-do0.vars; +. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-opt.vars; +#. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64_v2-centos7-gcc10-do0.vars; # . /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64-centos7-gcc9-opt.vars; #. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.${CMTCONFIG}.vars; cd ${EVENTBUILDINGROOT}/options; diff --git a/Online/FarmConfig/job/preamble.sh b/Online/FarmConfig/job/preamble.sh index 528d00270cc685f4270829ed98d9b52499bc2eff..ade4cc07300bdffbd3f57cd86d641490715cf15b 100755 --- a/Online/FarmConfig/job/preamble.sh +++ b/Online/FarmConfig/job/preamble.sh @@ -9,7 +9,7 @@ dataflow_task() { arg_1=${1}; shift; - echo "exec -a ${UTGID} genRunner.exe libDataflow.so dataflow_run_task -msg=fifo -mon=Dataflow_DIMMonitoring -class=${arg_1} $*"; + echo "exec -a ${UTGID} genRunner.exe libDataflow.so dataflow_run_task -mon=Dataflow_DIMMonitoring -class=${arg_1} $*"; } # gaudi_task() diff --git a/Online/FarmConfig/options/StorageWriter.opts b/Online/FarmConfig/options/StorageWriter.opts index 6ab1a357cbb46e9b8e7aba909695b38727273fe2..a79366004ee073af2946436d7d3f3425ca826bb9 100644 --- a/Online/FarmConfig/options/StorageWriter.opts +++ b/Online/FarmConfig/options/StorageWriter.opts @@ -44,4 +44,5 @@ Writer.NumThreads = 1; Writer.CancelTimeout = 100; // seconds Writer.ForceMDF = true; Writer.OutputType = "NETWORK"; +Writer.EnableWriting = @OnlineEnv.EnableWriting; // diff --git a/Online/GauchoAppl/GauchoAppl/AddTimer.h b/Online/GauchoAppl/GauchoAppl/AddTimer.h index 54eced6d12d0fc531357a571fa095ca0b1744cfa..4bc2ea5f971d970a9c727c29489394be7856e990 100644 --- a/Online/GauchoAppl/GauchoAppl/AddTimer.h +++ b/Online/GauchoAppl/GauchoAppl/AddTimer.h @@ -1,3 +1,4 @@ +#if 0 //========================================================================== // LHCb Online software suite //-------------------------------------------------------------------------- @@ -31,3 +32,4 @@ namespace Online { }; } #endif // ONLINE_GAUCHO_ADDTIMER_H +#endif diff --git a/Online/GauchoAppl/GauchoAppl/AdderSvc.h b/Online/GauchoAppl/GauchoAppl/AdderSvc.h index 9d2de8f70000a89af47b75bb444511b75a5e5e05..3bb227082ba382e065435b2242c97ab5865939b8 100644 --- a/Online/GauchoAppl/GauchoAppl/AdderSvc.h +++ b/Online/GauchoAppl/GauchoAppl/AdderSvc.h @@ -12,8 +12,10 @@ #ifndef ONLINE_GAUCHO_ADDERSVC_H #define ONLINE_GAUCHO_ADDERSVC_H -#include "GaudiKernel/Service.h" -#include "GaudiKernel/IIncidentListener.h" +#include <GauchoAppl/MonAdder.h> +#include <GaudiKernel/Service.h> +#include <GaudiKernel/IMonitorSvc.h> +#include <GaudiKernel/IIncidentListener.h> #include <memory> // Forward declarations @@ -22,6 +24,7 @@ class DimServerDns; class IIncidentSvc; namespace Online { + class mem_buff; class MonAdder; class SaveTimer; class MyDimErrorHandler; @@ -48,16 +51,21 @@ public: std::shared_ptr<Online::MonAdder>& adder, bool is_eor); + void handleCycle(Online::mem_buff& buffer, Online::MonitorItems* items); + /// Reference to the IncidentSvc instance SmartIF<IIncidentSvc> incidentSvc; + /// Reference to the MonitorSvc instance + SmartIF<IMonitorSvc> monitorSvc; std::shared_ptr<Online::MonAdder> intervalAdder; std::unique_ptr<Online::SaveTimer> intervalSaver; std::shared_ptr<Online::MonAdder> eorAdder; std::unique_ptr<Online::SaveTimer> eorSaver; std::shared_ptr<DimService> savesetSvc; - Online::MyDimErrorHandler *m_errh {nullptr}; + Online::MyDimErrorHandler *m_errh {nullptr}; + /// Properties std::string m_inputDNS; std::string m_outputDNS; std::string m_saveRootDir; diff --git a/Online/GauchoAppl/GauchoAppl/AdderSys.h b/Online/GauchoAppl/GauchoAppl/AdderSys.h index 6b2ba69623678ba07a3db8d4fd8196d31177874e..f527f5dddd5387322ea4ac6b57661f07b1c84e00 100644 --- a/Online/GauchoAppl/GauchoAppl/AdderSys.h +++ b/Online/GauchoAppl/GauchoAppl/AdderSys.h @@ -42,6 +42,7 @@ namespace Online { /// DTQ overload to process timeout(s) static void tmo_handler(void* tag); static void feedSources(void* tag, void** address, int* size, int* first); + void publishSources(); public: std::vector<MonAdder*> adderList; @@ -61,6 +62,7 @@ namespace Online { void addSource(const std::string& src); void removeSource(const std::string& src); void trackSources(); + bool is_tracking() const { return this->sourceSvc_id != 0; } }; } #endif /* ADDERSYS_H_ */ diff --git a/Online/GauchoAppl/GauchoAppl/MonAdder.h b/Online/GauchoAppl/GauchoAppl/MonAdder.h index 8cc6310526e3687a90b7c1b36097c98b67348c32..d5a2c0f73d733dac5ef709c73a18c579064a7974 100644 --- a/Online/GauchoAppl/GauchoAppl/MonAdder.h +++ b/Online/GauchoAppl/GauchoAppl/MonAdder.h @@ -36,7 +36,6 @@ namespace Online { class HistServer; class ObjRPC; class MonInfo; - class AddTimer; class ObjService; class RunManager; class DimBuffBase; @@ -83,69 +82,79 @@ namespace Online { public: typedef std::map<std::string, std::unique_ptr<INServiceDescr> > INServiceMap; - std::string name { }; - std::string task { }; - std::string cmdName { }; - std::string namePrefix { }; + + /// Configuration properties: std::string taskPattern { }; std::string servicePattern { }; - std::shared_ptr<DimServerDns> serviceDNS; - INServiceMap inputServicemap { }; - MonitorItems monitorItems { }; long long rectmo { 0 }; - bool saveOnUpdate { false }; - bool expandRate { false }; - bool isEOR { false }; - bool isSaver { false }; - bool test { false }; - bool noRPC { false }; - bool dohisto { false }; - bool disableOutput { false }; - bool debugOn { false }; - bool runAware { false }; - bool trackSources { false }; - bool doPause { false }; + bool saveOnUpdate { false }; + bool expandRate { false }; + bool isEOR { false }; + bool isSaver { false }; + bool test { false }; + bool noRPC { false }; + bool dohisto { false }; + bool disableOutput { false }; + bool debugOn { false }; + bool runAware { false }; + bool trackSources { false }; + bool doPause { false }; + + /// Public monitoring properties: + long numUpdateCycles { 0 }; + int numTasksConnected { 0 }; + int numServicesConnected { 0 }; + + /// Public data members + INServiceMap inputServicemap { }; + MonitorItems monitorItems { }; + std::shared_ptr<DimServerDns> serviceDNS; protected: typedef std::map<std::string, std::set<std::string> > TaskInventory; + class AddTimer; TaskInventory taskInventory; BRTLLock maplock; + BRTLLock invlock; std::unique_ptr<RunManager> runManager; std::unique_ptr<AddTimer> timer; std::unique_ptr<ObjRPC> rpc; - std::string myName { }; - std::string serviceName { }; - boost::regex task_regex { }; - boost::regex service_regex { }; - DimBuffBase *rateBuff { nullptr }; - void *CycleArg { nullptr }; - void *PauseArg { nullptr }; + std::string name { }; + std::string serviceName { }; + std::string cmdName { }; + boost::regex task_regex { }; + boost::regex service_regex { }; + DimBuffBase *rateBuff { nullptr }; + void *CycleArg { nullptr }; + void *PauseArg { nullptr }; void (*CycleFn)(void*, mem_buff&, MonitorItems *, MonAdder *) { nullptr }; - void (*PauseFn)(void*) { nullptr }; - bool isLocked { false }; - - int type { 0 }; - int sourceSvc_id { 0 }; - std::string source_buffer; + void (*PauseFn)(void*) { nullptr }; + bool isLocked { false }; + + int type { 0 }; + int sourceSvc_id { 0 }; + std::string source_buffer { }; static std::string getClassName(const std::string &service); static void feedSources(void* tag, void** address, int* size, int* first); static void load_item_map(MonitorItems& m, mem_buff& buffer); - - unsigned long long gettime(); + static unsigned long long gettime(); void load_item_map(mem_buff& buffer); void process_buffer(void *buffer, int siz, MonInfo *h); void finish_cycle(std::shared_ptr<ClassDescriptor>& cl, bool force=false); + void publishSources(); + virtual void handleTimeout(std::shared_ptr<ClassDescriptor>& clazz); - virtual void AddWhatWeHave(); + void addWhatWeHave(); + public: - MonAdder(const std::string& task, const std::string& myName, const std::string& svcName, int typ); + MonAdder(const std::string& name, const std::string& service_name, int typ); virtual ~MonAdder(); std::string taskName(const std::string& server); @@ -158,10 +167,10 @@ namespace Online { std::pair<std::shared_ptr<ClassMap>, unsigned int> get_class_map(const std::string& service, bool create); - void addService(const std::string& task_name, const std::string& svc_name); - void removeService(const std::string& task_name, const std::string& svc_name); - void addTask(const std::string& task); - void removeTask(const std::string& task); + bool addService(const std::string& task_name, const std::string& svc_name); + bool removeService(const std::string& task_name, const std::string& svc_name); + bool addTask(const std::string& task); + bool removeTask(const std::string& task); void update(ClassDescriptor* clazz); /// Callback to sum up all items of a source frame diff --git a/Online/GauchoAppl/GauchoAppl/SaveTimer.h b/Online/GauchoAppl/GauchoAppl/SaveTimer.h index aae490661cde5eac395f3f53a63101d2010f1b56..bd94b3f3b9d47719d68f7664051ae0bb472d3a0f 100644 --- a/Online/GauchoAppl/GauchoAppl/SaveTimer.h +++ b/Online/GauchoAppl/GauchoAppl/SaveTimer.h @@ -22,15 +22,10 @@ namespace Online { class SaveTimer : public GenTimer, public HistSaver { public: std::shared_ptr<MonAdder> adder; - + long numSaveCycles { 0 }; public: SaveTimer(std::shared_ptr<MonAdder>& adder, int period = 900); ~SaveTimer() = default; -#if 0 - void setSaveSetService(std::shared_ptr<DimService> svc) { - this->savesetSvc = std::move(svc); - } -#endif virtual void timerHandler() override; }; } diff --git a/Online/GauchoAppl/src/AddTimer.cpp b/Online/GauchoAppl/src/AddTimer.cpp index 7b35dbd2306718ce7d00f94fad8b341f840bc5d1..62f98abcae307aff9cd04e79375be422f25d6f9b 100644 --- a/Online/GauchoAppl/src/AddTimer.cpp +++ b/Online/GauchoAppl/src/AddTimer.cpp @@ -1,3 +1,4 @@ +#if 0 //========================================================================== // LHCb Online software suite //-------------------------------------------------------------------------- @@ -41,3 +42,4 @@ void AddTimer::stop() { this->m_stopped = true; this->GenTimer::stop(); } +#endif diff --git a/Online/GauchoAppl/src/AdderSvc.cpp b/Online/GauchoAppl/src/AdderSvc.cpp index 4fd1e216b4101f5bcfafe18ea65585fd6c0744ba..0697bd767c2adf30169aea0d1a46c82de5273ee6 100644 --- a/Online/GauchoAppl/src/AdderSvc.cpp +++ b/Online/GauchoAppl/src/AdderSvc.cpp @@ -98,6 +98,10 @@ StatusCode AdderSvc::initialize() { if( !this->incidentSvc.get() ) { return StatusCode::FAILURE; } + this->monitorSvc = serviceLocator()->service("MonitorSvc",true); + if( !this->monitorSvc.get() ) { + return StatusCode::FAILURE; + } this->incidentSvc->addListener(this,"APP_INITIALIZED"); this->incidentSvc->addListener(this,"APP_RUNNING"); this->incidentSvc->addListener(this,"APP_STOPPED"); @@ -163,7 +167,6 @@ StatusCode AdderSvc::start() { m_outputDNS = RTL::str_replace(m_outputDNS,"<node>",nodename); m_outputDNS = RTL::str_replace(m_outputDNS,"<dns>",ddns); } - if ( m_trackSources ) sys.trackSources(); std::shared_ptr<DimServerDns> service_dns = sys.getDNS(m_outputDNS); m_errh->start(); if (m_started) return StatusCode::SUCCESS; @@ -171,6 +174,7 @@ StatusCode AdderSvc::start() { if (m_errh != 0) DimServer::addErrorHandler(m_errh); ::lib_rtl_output(LIB_RTL_INFO,"AdderSvc Pattern: Task: %s Service: %s + Data/EOR", m_taskPattern.c_str(), m_servicePattern.c_str()); + if ( m_trackSources ) sys.trackSources(); if (!m_inputDNS.empty()) DimClient::setDnsNode(m_inputDNS.c_str()); m_infoFileStatus = "SAVESETLOCATION/......................................................"; @@ -183,8 +187,12 @@ StatusCode AdderSvc::start() { } if ( m_isSaver ) { this->setup_saver(this->intervalSaver, this->intervalAdder, false); + this->monitorSvc->declareInfo("SaveCycles", this->intervalSaver->numSaveCycles, "", this); this->intervalSaver->start(); } + this->monitorSvc->declareInfo("UpdateCycles", this->intervalAdder->numUpdateCycles, "", this); + this->monitorSvc->declareInfo("NumTasksConnected", this->intervalAdder->numTasksConnected, "", this); + this->monitorSvc->declareInfo("NumServicesConnected",this->intervalAdder->numServicesConnected, "", this); if ( !this->setup_adder(this->eorAdder, service_dns, true).isSuccess() ) { ::lib_rtl_output(LIB_RTL_FATAL,"+++ Failed to configure adder...."); @@ -192,9 +200,7 @@ StatusCode AdderSvc::start() { } if ( m_isSaver ) { this->setup_saver(this->eorSaver, this->eorAdder, true); - if ( !m_saveOnUpdate ) { - this->eorAdder->SetCycleFn(EORSaver, this->eorSaver.get()); - } + this->eorAdder->SetCycleFn(EORSaver, this->eorSaver.get()); } m_started = true; return StatusCode::SUCCESS; @@ -217,16 +223,15 @@ StatusCode AdderSvc::setup_adder(std::shared_ptr<MonAdder>& adder, myservicename = RTL::str_replace(myservicename, "<part>", this->m_partitionName); myservicename = RTL::str_replace(myservicename, "<node>", nodename); if ( m_adderClass == "hists" ) { - adder = std::make_shared<HistAdder>(this->name(), myservicename, is_eor ? "EOR" : "Data", ADD_HISTO); + adder = std::make_shared<HistAdder>(myservicename, is_eor ? "EOR" : "Data", ADD_HISTO); } else if ( m_adderClass == "counter" ) { - adder = std::make_shared<CounterAdder>(this->name(), myservicename, is_eor ? "EOR" : "Data", ADD_COUNTER); + adder = std::make_shared<CounterAdder>(myservicename, is_eor ? "EOR" : "Data", ADD_COUNTER); } else { ::lib_rtl_output(LIB_RTL_FATAL,"+++ Invalid adder class specified: '%s'", m_adderClass.c_str()); return StatusCode::FAILURE; } - //adder->parent = this; adder->test = m_test; adder->debugOn = m_debugOn; adder->taskPattern = m_taskPattern; @@ -241,7 +246,6 @@ StatusCode AdderSvc::setup_adder(std::shared_ptr<MonAdder>& adder, if ( !is_eor ) { if ( m_doPause ) adder->SetPauseFn(::doPause, this); - adder->namePrefix = m_partitionName+"_"; adder->runAware = m_runAware; adder->servicePattern = m_servicePattern + (m_runAware ? "[[:digit:]]*/Data(.*)" : "Data(.*)"); @@ -259,12 +263,17 @@ StatusCode AdderSvc::setup_adder(std::shared_ptr<MonAdder>& adder, StatusCode AdderSvc::stop() { m_errh->stop(); + if ( this->monitorSvc ) { + this->monitorSvc->undeclareAll(this); + } return Service::stop(); } StatusCode AdderSvc::finalize() { MsgStream msg( msgSvc(), name() ); - msg << MSG::DEBUG << "AdderSvc finalize called" << endmsg; { + msg << MSG::DEBUG << "AdderSvc finalize called" << endmsg; + this->monitorSvc.reset(); + { DimLock lock; MonInfo::setShutdownInProgress(true); if ( this->incidentSvc ) { diff --git a/Online/GauchoAppl/src/AdderSys.cpp b/Online/GauchoAppl/src/AdderSys.cpp index 4b3ce216c1a501ab06c0af47b48981aeed27dfce..a53726f739475a7c7ecb8aa92d8cd66de0bb7456 100644 --- a/Online/GauchoAppl/src/AdderSys.cpp +++ b/Online/GauchoAppl/src/AdderSys.cpp @@ -45,6 +45,12 @@ AdderSys::~AdderSys() { this->sourceSvc_id = 0; } +void AdderSys::publishSources() { + if ( this->sourceSvc_id ) { + ::dis_update_service(this->sourceSvc_id); + } +} + void AdderSys::add(MonAdder *a) { for ( const auto* i : this->adderList ) { if (i == a) @@ -62,24 +68,24 @@ void AdderSys::trackSources() { void AdderSys::addSource(const std::string& src) { this->sources.emplace(src); - if ( this->sourceSvc_id ) ::dis_update_service(this->sourceSvc_id); + this->publishSources(); } void AdderSys::removeSource(const std::string& src) { auto i = this->sources.find(src); if ( i != this->sources.end() ) { this->sources.erase(i); - if ( this->sourceSvc_id ) { - ::dis_update_service(this->sourceSvc_id); - } } + this->publishSources(); } void AdderSys::remove(MonAdder *a) { while( true ) { auto i = std::find(this->adderList.begin(), this->adderList.end(), a); - if ( i == this->adderList.end() ) + if ( i == this->adderList.end() ) { + this->publishSources(); return; + } this->adderList.erase(i); } } diff --git a/Online/GauchoAppl/src/InfoHandlers.cpp b/Online/GauchoAppl/src/InfoHandlers.cpp index e89b2e9488a0284ba0c59690088ce1908a35339c..b6036087134be38d34e8adc76088bef0ab0d4215 100644 --- a/Online/GauchoAppl/src/InfoHandlers.cpp +++ b/Online/GauchoAppl/src/InfoHandlers.cpp @@ -51,15 +51,16 @@ void HAdderServiceInfoHandler::callback(void* tag, void* address, int* size) { } void HAdderServiceInfoHandler::analyze_services(const char* input) { - auto& alist = AdderSys::instance().adderList; - int level = AdderSys::instance().debugOn ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; + auto& sys = AdderSys::instance(); + auto& alist = sys.adderList; + int level = sys.debugOn /* || sys.is_tracking() */ ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; //level = LIB_RTL_ALWAYS; if ( !input || ::strlen(input) == 0 ) { ::lib_rtl_output(level,"received empty message from %s.... Ignoring...\n",task.c_str()); return; } - ::lib_rtl_output(level,"Service List %s data: %s",task.c_str(), input); + // ::lib_rtl_output(level,"Service List %s data: %s",task.c_str(), input); if ( ::strcmp(input, "DEAD" ) == 0 ) { ::lib_rtl_output(level,"Service Info Handler from %s DEAD",task.c_str()); for ( auto* i : alist ) @@ -85,20 +86,37 @@ void HAdderServiceInfoHandler::analyze_services(const char* input) { break; } if ( !service_list.empty() && (action == 1 || action == -1) ) { - ::lib_rtl_output(LIB_RTL_DEBUG,"Processing incremental list %s", task.c_str()); + //::lib_rtl_output(LIB_RTL_DEBUG,"Processing incremental list %s", task.c_str()); + int added = 0, removed = 0; + string all; for ( string svc : service_list ) { svc = svc.substr(0, svc.find('|')); + size_t idx = svc.find('/'); + all += svc.substr(idx == string::npos ? 0 : idx+1) + " "; if ( action == 1 ) { - ::lib_rtl_output(level,"Selective New Service: %s",svc.c_str()); + ::lib_rtl_output(level,"Selective New Service: %s -> %s", task.c_str(), svc.c_str()); for ( auto* i : alist ) - i->addService(task, svc); + if ( i->addService(task, svc) ) ++added; } else { - ::lib_rtl_output(level,"Selective Removed Service: %s",svc.c_str()); + ::lib_rtl_output(level,"Selective Removed Service: %s -> %s", task.c_str(), svc.c_str()); for ( auto* i : alist ) - i->removeService(task, svc); + if ( i->removeService(task, svc) ) ++removed; + } + } +#if 0 + if ( action == 1 && sys.is_tracking() ) { + if ( added == 0 && removed == 0 ) { + if ( all.length() > 200 ) all = all.substr(0, 200) + "..."; + ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ IGNORED service update: %s -> %s", task.c_str(), all.c_str()); + } + else { + if ( all.length() > 200 ) all = all.substr(0, 200) + "..."; + ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Service update: %s Added: %d Removed: %d %s", + task.c_str(), added, removed, all.c_str()); } } +#endif } } @@ -129,7 +147,7 @@ void HAdderTaskInfoHandler::stop() { void HAdderTaskInfoHandler::analyze_tasks(const char* input) { auto& sys = AdderSys::instance(); - int level = sys.debugOn ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; + int level = sys.debugOn || sys.is_tracking() ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; //level = LIB_RTL_ALWAYS; if (strcmp(input, "DEAD") == 0) { ::lib_rtl_output(level,"Task Info Handler from DNS DEAD"); @@ -141,7 +159,7 @@ void HAdderTaskInfoHandler::analyze_tasks(const char* input) { int action = 0; vector<string> server_list; - ::lib_rtl_output(level,"Task Info Handler Input %s",input); + //::lib_rtl_output(level,"Task Info Handler Input %s",input); switch(input[0]) { case '+': @@ -163,34 +181,42 @@ void HAdderTaskInfoHandler::analyze_tasks(const char* input) { return; } + int total_actions = 0, total_matches = 0; auto& alist = AdderSys::instance().adderList; for (auto server : server_list ) { - ::lib_rtl_output(level,"Differential Server List: Server Name %s... New: %d Dead: %d", - server.c_str(), action>0 ? 1 : 0, action<0 ? 1 : 0); + int added = 0, removed = 0, create = 0; + //::lib_rtl_output(level,"Differential Server List: Server Name %s... New: %d Dead: %d", + // server.c_str(), action>0 ? 1 : 0, action<0 ? 1 : 0); server = server.substr(0,server.find("@")); for (auto* adder : alist ) { string tname = adder->taskName(server); if ( !tname.empty() ) { + ++total_matches; + auto i = this->taskMap.find(tname); if ( action == 1 ) { - auto i = this->taskMap.find(tname); - if (i == this->taskMap.end()) { - string svc = tname + "/SERVICE_LIST"; - this->taskMap.emplace(tname, make_unique<HAdderServiceInfoHandler>(svc)); - ::lib_rtl_output(level,"Added service list handler: %s",svc.c_str()); - sys.addSource(tname); - } - adder->addTask(tname); + if ( i == this->taskMap.end() ) create = 1; + if ( adder->addTask(tname) ) ++added, ++total_actions; } else if ( action == -1 ) { - auto i = this->taskMap.find(tname); if (i != this->taskMap.end()) { this->taskMap.erase(i); sys.removeSource(tname); } - adder->removeTask(tname); + if ( adder->removeTask(tname) ) ++removed, ++total_actions; } } } + if ( added > 0 && create ) { + string svc = server + "/SERVICE_LIST"; + this->taskMap.emplace(server, make_unique<HAdderServiceInfoHandler>(svc)); + //::lib_rtl_output(level,"+++ Add service list handler (%d clients): %s", added, server.c_str()); + sys.addSource(server); + } + } +#if 0 + if ( total_actions == 0 ) { + ::lib_rtl_output(level,"+++ IGNORED Task Info: %s",input); } +#endif } diff --git a/Online/GauchoAppl/src/MonAdder.cpp b/Online/GauchoAppl/src/MonAdder.cpp index 99f0ba1e53a0968259826468ba6b0594da2c1c76..cd18f9d03b612b2851cb4b07b3c8ee9c315fb0ef 100644 --- a/Online/GauchoAppl/src/MonAdder.cpp +++ b/Online/GauchoAppl/src/MonAdder.cpp @@ -17,8 +17,7 @@ #include <Gaucho/ObjService.h> #include <Gaucho/SerialHeader.h> -#include <GauchoAppl/AddTimer.h> -//#include <GauchoAppl/AdderSvc.h> +#include "Gaucho/GenTimer.h" #include <GauchoAppl/AdderSys.h> #include <GauchoAppl/SaveTimer.h> #include <GauchoAppl/RunManager.h> @@ -36,10 +35,30 @@ using namespace Online; #define offsetinBounds(base,recl,offs) !((add_ptr(base,offs)>add_ptr(base,recl))||(add_ptr(base,offs)<base)) -MonAdder::MonAdder(const std::string& tsk, const std::string& myNam, const std::string& svcNam, int typ) { - this->serviceName = svcNam; - this->myName = myNam; - this->task = tsk; + +class MonAdder::AddTimer : public GenTimer { + MonAdder *owner; + +public: + AddTimer(MonAdder *tis, int period = 5, int typ = 0); + virtual ~AddTimer(void) = default; + void timerHandler ( void ) override { + int arg = 1; + if ( !this->isRunning() ) { + DimClient::sendCommandNB(this->owner->cmdName.c_str(),&arg,sizeof(arg)); + } + } +}; + +MonAdder::AddTimer::AddTimer(MonAdder *tis, int period, int typ) : GenTimer(period*1000,typ) { + this->owner = tis; + this->m_dueTime = 0; + this->m_dontdimlock = true; +} + +MonAdder::MonAdder(const std::string& nam, const std::string& service_nam, int typ) { + this->serviceName = service_nam; + this->name = nam; this->type = typ; this->runManager = make_unique<RunManager>(); AdderSys::instance().add(this); @@ -73,9 +92,21 @@ void MonAdder::feedSources(void* tag, void** address, int* size, int* /* first * if ( tag && address && size ) { std::stringstream str; MonAdder* adder = *(MonAdder**)tag; + str << "ServiceSources:{"; + for(const auto& i : adder->taskInventory) { + str << "'" << i.first << "': {"; + for (auto s = i.second.begin(); s != i.second.end(); ) + str << "'" << *s << "'" << (++s == i.second.end() ? "" : ","); + str << "}"; + } + adder->source_buffer = str.str(); + *size = adder->source_buffer.length()+1; + *address = (void*)adder->source_buffer.c_str(); + return; +#if 0 auto [m, run] = adder->get_class_map("",false); if ( m ) { - str << "Service-Sources:" << m->size() << '#'; + str << "ServiceSources:" << m->size() << '#'; for( const auto& cl : *m ) { const auto& m = cl.second->inputServices; str << '{' << (cl.first.empty() ? "**default**" : cl.first.c_str()) << ":{"; @@ -88,47 +119,46 @@ void MonAdder::feedSources(void* tag, void** address, int* size, int* /* first * *address = (void*)adder->source_buffer.c_str(); return; } +#endif } *size = 0; *address = (char*)""; } void MonAdder::configure() { - string dim_svc = RTL::processName() + "/Debug/" + this->task; - string nodename = RTL::str_lower(RTL::nodeNameShort()); - this->name= "MON_" + this->myName; - + string dim_svc = RTL::processName() + "/" + this->name + "/Debug/Sources"; + string nam_svc = "MON_" + this->name; this->runManager->clear(); if (this->type == ADD_COUNTER) { - dim_svc += "/counter_sources/" + this->serviceName; + dim_svc += "/Cntr/"+this->serviceName; this->serviceName = (this->runAware ? "/Counter/<runno>/" : "/Counter/") + this->serviceName; } else if (this->type == ADD_HISTO) { - dim_svc += "/histo_sources/" + this->serviceName; + dim_svc += "/Hist/"+this->serviceName; this->serviceName = (this->runAware ? "/Histos/<runno>/" : "/Histos/") + this->serviceName; } if ( this->trackSources && 0 == this->sourceSvc_id ) { this->sourceSvc_id = ::dis_add_service(dim_svc.c_str(),"C",0,0,feedSources,(long)this); } - - this->cmdName = nodename+"_"+RTL::processName() + "/" + myName + this->serviceName+"/Timeout"; - this->timer = make_unique<AddTimer>(this); + this->invlock.name = nam_svc + "InventoryLock"; + this->cmdName = RTL::processName() + "/" + this->name + this->serviceName+"/Timeout"; + this->timer = make_unique<AddTimer>(this); this->service_regex = boost::regex(this->servicePattern.c_str(),boost::regex_constants::icase); - this->task_regex = boost::regex(this->taskPattern.c_str(),boost::regex_constants::icase); + this->task_regex = boost::regex(this->taskPattern.c_str(),boost::regex_constants::icase); if ( this->isSaver ) { this->lockid = make_unique<BRTLLock>(); - this->lockid->name = this->name+"AdderLock"; + this->lockid->name = nam_svc + "AdderLock"; } this->rpc.reset(); if ( !this->noRPC ) { string rpcName; if ( this->type == ADD_HISTO ) - rpcName = this->name + "/Histos/HistCommand"; + rpcName = nam_svc + "/Histos/HistCommand"; else if ( this->type == ADD_COUNTER ) - rpcName = this->name+"/Counter/HistCommand"; + rpcName = nam_svc+"/Counter/HistCommand"; this->maplock.name = rpcName; this->rpc = make_unique<ObjRPC>(this->serviceDNS, @@ -168,7 +198,7 @@ void MonAdder::load_item_map(mem_buff& buffer) { void MonAdder::load_item_map(MonitorItems& m, mem_buff& buffer) { void* bend = add_ptr(buffer.begin(), buffer.used()); void* hstart = buffer.at<SerialHeader>(0)->endPtr(); - auto* pp = (DimBuffBase*)hstart; + auto* pp = ptr_as<DimBuffBase>(hstart); const char *nam = ""; m.clear(); while ( pp < bend ) { @@ -189,17 +219,17 @@ void MonAdder::load_item_map(MonitorItems& m, mem_buff& buffer) { std::pair<std::shared_ptr<ClassMap>, unsigned int> MonAdder::get_class_map(const std::string& service, bool create) { if ( this->runAware && !service.empty() ) { - auto items = RTL::str_split(service,"/"); - string rnstring = items.at(items.size()-2); - unsigned int rn = stoi(rnstring); - auto i = this->runManager->find(rn); + auto items = RTL::str_split(service,"/"); + string run = items.at(items.size()-2); + unsigned int runno = ::stoi(run); + auto i = this->runManager->find(runno); if (i != this->runManager->end()) { - return make_pair(i->second, rn); + return make_pair(i->second, runno); } if ( create ) { - auto m = std::make_shared<ClassMap>(); - this->runManager->emplace(rn, m); - return make_pair(m, rn); + auto class_map = std::make_shared<ClassMap>(); + this->runManager->emplace(runno, class_map); + return make_pair(class_map, runno); } return make_pair(std::shared_ptr<ClassMap>(), 0); } @@ -208,13 +238,19 @@ MonAdder::get_class_map(const std::string& service, bool create) { return make_pair(i->second, 0); } if ( create ) { - auto m = std::make_shared<ClassMap>(); - this->runManager->emplace(0, m); - return make_pair(m, 0); + auto class_map = std::make_shared<ClassMap>(); + this->runManager->emplace(0, class_map); + return make_pair(class_map, 0); } return make_pair(std::shared_ptr<ClassMap>(), 0); } +void MonAdder::publishSources() { + if ( 0 != this->sourceSvc_id ) { + ::dis_update_service(this->sourceSvc_id); + } +} + string MonAdder::taskName(const string &server) { bool status = false; boost::cmatch what; @@ -230,22 +266,29 @@ string MonAdder::taskName(const string &server) { return (status) ? server : string(); } -void MonAdder::addTask(const string &task) { +bool MonAdder::addTask(const string &task) { + BRTLLock::_Lock lock(&this->invlock); auto i = this->taskInventory.find(task); if ( i == this->taskInventory.end() ) { int level = AdderSys::instance().debugOn ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; this->taskInventory[task] = std::set<std::string>(); ::lib_rtl_output(level,"Adder[%s] add task: %s", name.c_str(), task.c_str()); + ++this->numTasksConnected; + return true; } + return false; } -void MonAdder::removeTask(const string& task) { +bool MonAdder::removeTask(const string& task) { int level = AdderSys::instance().debugOn ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; + BRTLLock::_Lock lock(&this->invlock); auto tsk = this->taskInventory.find(task); if ( tsk == this->taskInventory.end() ) { ::lib_rtl_output(level,"TaskDied: Task = %s, not found in TaskInventory\n",task.c_str()); - return; + return false; } + this->numServicesConnected -= tsk->second.size(); + --this->numTasksConnected; ::lib_rtl_output(level,"TaskDied: Task = %s, found. Scanning Services\n",task.c_str()); auto class_name = getClassName(task); for (const auto& serv : tsk->second ) { @@ -271,9 +314,11 @@ void MonAdder::removeTask(const string& task) { } } this->taskInventory.erase(tsk); + this->publishSources(); + return true; } -void MonAdder::addService(const string& task, const string& service) { +bool MonAdder::addService(const string& task, const string& service) { int level = AdderSys::instance().debugOn ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; boost::cmatch what; int status = 0; @@ -287,15 +332,20 @@ void MonAdder::addService(const string& task, const string& service) { ::lib_rtl_output(LIB_RTL_ERROR,"Caught unspecific exception in addService"); } if ( !status ) { - return; + return false; } ::lib_rtl_output(level,"MATCHED: %s with Pattern %s...",service.c_str(),this->servicePattern.c_str()); - if (this->taskInventory.find(task) == this->taskInventory.end()) { + BRTLLock::_Lock lock(&this->invlock); + auto i = this->taskInventory.find(task); + if ( i == this->taskInventory.end() ) { ::lib_rtl_output(level,"New Service '%s' called, add task '%s' to inventory \n", service.c_str(),task.c_str()); + i = this->taskInventory.emplace(task, set<string>()).first; } - this->taskInventory[task].insert(service); + if ( i->second.find(service) == i->second.end() ) + ++this->numServicesConnected; + i->second.insert(service); auto [class_map, run] = this->get_class_map(service, true); string classnam = getClassName(service); @@ -305,29 +355,33 @@ void MonAdder::addService(const string& task, const string& service) { if (cindx == class_map->end()) { cindx = class_map->emplace(classnam, make_shared<ClassDescriptor>(classnam, this)).first; } - + bool ret_code = false; auto& cdesc = cindx->second; if ( cdesc->addService(service, task) ) { - if ( 0 != this->sourceSvc_id ) { - ::dis_update_service(this->sourceSvc_id); - } + ret_code = true; } if ( !this->disableOutput && !cdesc->outputservice ) { - cdesc->enableOutput(this->serviceDNS, this->name + this->serviceName, run); + cdesc->enableOutput(this->serviceDNS, "MON_" + this->name + this->serviceName, run); } if ( !cdesc->tmo_command ) { string tmo_cmd = classnam.empty() ? this->cmdName : this->cmdName + "." + classnam; cdesc->tmo_command = make_unique<TimeoutCmd>(tmo_cmd, service, this); } this->serviceDNS ? DimServer::start(this->serviceDNS.get()) : DimServer::start(); + this->publishSources(); + return ret_code; } -void MonAdder::removeService(const string &task, const string &service) { +bool MonAdder::removeService(const string &task, const string &service) { + bool ret_code = false; + BRTLLock::_Lock lock(&this->invlock); auto tsk = this->taskInventory.find(task); if ( tsk != this->taskInventory.end() ) { auto svc = tsk->second.find(service); if ( svc != tsk->second.end() ) { + --this->numServicesConnected; tsk->second.erase(svc); + ret_code = true; } auto [class_map, run] = this->get_class_map(service, false); if ( class_map ) { @@ -345,17 +399,15 @@ void MonAdder::removeService(const string &task, const string &service) { } } } + this->publishSources(); + return ret_code; } unsigned long long MonAdder::gettime() { -#define onesec_nano (unsigned long long)(1000000000) - unsigned long long timstamp; +#define onesec_nano 1000000000ULL struct timeval tv; - struct timezone *tz; - tz = 0; - gettimeofday(&tv, tz); - timstamp = tv.tv_sec; - timstamp *= onesec_nano; + ::gettimeofday(&tv, nullptr); + unsigned long long timstamp = tv.tv_sec * onesec_nano; timstamp += tv.tv_usec*1000; return timstamp; } @@ -402,7 +454,7 @@ void MonAdder::handleTimeout(std::shared_ptr<ClassDescriptor>& cl) { this->finish_cycle(cl, true); } -void MonAdder::AddWhatWeHave() { +void MonAdder::addWhatWeHave() { auto [m, run] = this->get_class_map("", false); auto& cl = m->begin()->second; // SEGV -- don't call cl->buffer->reset(); @@ -422,8 +474,8 @@ void MonAdder::AddWhatWeHave() { } } -void MonAdder::process_buffer(void *buff, int siz, MonInfo *h) { - SerialHeader* header = ((SerialHeader*)buff); +void MonAdder::process_buffer(void *buff, int data_size, MonInfo *h) { + SerialHeader* header = ptr_as<SerialHeader>(buff); const string service = h->getName(); const string classname = getClassName(service); auto [class_map, run] = this->get_class_map(service, true); @@ -435,20 +487,20 @@ void MonAdder::process_buffer(void *buff, int siz, MonInfo *h) { } auto& cl = itcl->second; - if (siz == 4) { + if ( data_size == 4 ) { ::lib_rtl_output(LIB_RTL_ERROR,"======> No Link from %s. Update counts...",service.c_str()); cl->received++; this->finish_cycle(cl); return; } - if (header->m_magic != SERIAL_MAGIC) { + if ( header->m_magic != SERIAL_MAGIC ) { ::lib_rtl_output(LIB_RTL_ERROR,"========> Serial Magic Word Missing from connection %s\n",service.c_str()); cl->received++; this->finish_cycle(cl); return; } auto it= cl->inputServices.find(service.c_str()); - if (it == cl->inputServices.end()) { + if ( it == cl->inputServices.end() ) { ::lib_rtl_output(LIB_RTL_ERROR,"!!!!!Logic Error Adder add method called with service that's not in the input service map %s\n",service.c_str()); return; } @@ -456,7 +508,7 @@ void MonAdder::process_buffer(void *buff, int siz, MonInfo *h) { int level = this->debugOn ? LIB_RTL_ALWAYS : LIB_RTL_VERBOSE; unique_ptr<INServiceDescr>& descr = it->second; - descr->buffer.copy(buff, siz); + descr->buffer.copy(buff, data_size); descr->m_pid = DimClient::getServerPid(); descr->m_timeouts = 0; if ( descr->info.get() != h ) descr->info.reset(h); // can this ever happen ?? @@ -464,7 +516,7 @@ void MonAdder::process_buffer(void *buff, int siz, MonInfo *h) { cl->expected = cl->inputServices.size(); cl->received++; - long long current = (this->isEOR) ? (unsigned int)header->run_number : header->ser_tim; + long long current = (this->isEOR) ? header->run_number : header->ser_tim; descr->last_update = current; this->rateBuff = 0; @@ -525,7 +577,7 @@ void MonAdder::process_buffer(void *buff, int siz, MonInfo *h) { this->isLocked = true; } cl->reference = current; - cl->adoptItems(buff, siz); + cl->adoptItems(buff, data_size); } else if ( cl->reference == current ) { this->add_items(cl.get(), descr->buffer, h); @@ -560,7 +612,7 @@ void MonAdder::finish_cycle(std::shared_ptr<ClassDescriptor>& cl, bool force) { if ( h->run_number != 0 ) { header->run_number = h->run_number; if (this->debugOn) ::lib_rtl_output(LIB_RTL_INFO,"For Adder %s Run Number Fixed to %ld.\n", - this->myName.c_str(), header->run_number); + this->name.c_str(), header->run_number); fixed = true; } } @@ -571,14 +623,10 @@ void MonAdder::finish_cycle(std::shared_ptr<ClassDescriptor>& cl, bool force) { ::lib_rtl_output(level,"MonAdder::finish_cycle: updating Output Service %s", this->serviceName.c_str()); this->update(cl.get()); cl->updateStamp = cl->reference; -#if 0 - if ( this->isSaver && this->saveOnUpdate ) { - auto* p = this->parent; - (this->isEOR) ? p->eorSaver->timerHandler() : p->intervalSaver->timerHandler(); - } -#endif + ++this->numUpdateCycles; if ( this->CycleFn ) { (*this->CycleFn)(this->CycleArg, *cl->buffer, &cl->monitorItems, this); + this->publishSources(); } if (this->doPause && this->PauseFn ) { (*this->PauseFn)(this->PauseArg); diff --git a/Online/GauchoAppl/src/SaveTimer.cpp b/Online/GauchoAppl/src/SaveTimer.cpp index 779a58f29eb61880945760a6c95532afbf552589..b6e0874ab4d2ecda16946db6d4e61f36b063171c 100644 --- a/Online/GauchoAppl/src/SaveTimer.cpp +++ b/Online/GauchoAppl/src/SaveTimer.cpp @@ -30,7 +30,7 @@ using namespace Online; SaveTimer::SaveTimer(std::shared_ptr<MonAdder>& add, int period) - : GenTimer((void*)add.get(),period*1000,TIMER_TYPE_PERIODIC), HistSaver(add), adder(add) + : GenTimer(period*1000,TIMER_TYPE_PERIODIC), HistSaver(add), adder(add) { this->m_dueTime = 0; this->m_dontdimlock = true; @@ -41,6 +41,7 @@ SaveTimer::SaveTimer(std::shared_ptr<MonAdder>& add, int period) void SaveTimer::timerHandler(void) { static std::mutex _l; std::lock_guard<std::mutex> lock(_l); + ++this->numSaveCycles; if ( this->adder ) { // Need protection against the adder updating to buffers. ObjectLock<MonAdder> adder_lock(this->adder.get()); diff --git a/Online/GauchoAppl/src/components/BusySvc.cpp b/Online/GauchoAppl/src/components/BusySvc.cpp index 7e2d5e5c9bef9c695d74847a095143e9df5a3ce1..cce57009ebbf6ff261dd7c67477f91264dde3ce4 100644 --- a/Online/GauchoAppl/src/components/BusySvc.cpp +++ b/Online/GauchoAppl/src/components/BusySvc.cpp @@ -12,68 +12,98 @@ #include "BusySvc.h" #include <Gaucho/IGauchoMonitorSvc.h> +#include <Gaucho/GenTimer.h> #include <RTL/strdef.h> DECLARE_COMPONENT( BusySvc ) -void IdleTimer::timerHandler(void) { - m_bsysvc->calcIdle(); +namespace { + inline long mem_unit(const std::string& unit) { + long fact=1; + if (unit == "kB") + fact = 1000; + else if (unit == "B") + fact = 1; + else if (unit == "MB") + fact = 1000000; + return fact; + } + long mem_in_bytes(const std::vector<std::string>& toks) { + return std::stol(toks.at(1)) * ((toks.size() > 2) ? mem_unit(toks.at(2)) : 1); + } } -IdleTimer::~IdleTimer() { -} +class BusySvc::IdleTimer : public Online::GenTimer { +public: + BusySvc *m_bsysvc; + IdleTimer(BusySvc *master, int period = 5000) : GenTimer(period), m_bsysvc(master) { + } + ~IdleTimer() = default; + void timerHandler(void) override { + m_bsysvc->calcIdle(); + } +}; StatusCode BusySvc::initialize() { StatusCode sc = Service::initialize(); if( !sc.isSuccess() ) { return StatusCode::FAILURE; } - sc = serviceLocator()->service("MonitorSvc", m_pMonitorSvc, true); - if( !sc.isSuccess() ) { + m_monitorSvc = this->service("MonitorSvc", true); + if( m_monitorSvc ) { return StatusCode::FAILURE; } if (m_bogus == 0.0) { getBogus(m_Mybogus); } - m_NodeName = RTL::nodeNameShort(); - for (unsigned int i = 0; i < m_NodeName.size(); i++) - { - m_NodeName[i] = toupper(m_NodeName[i]); - } + m_NodeName = RTL::str_upper(RTL::nodeNameShort()); NodeClass(m_NodeClass); m_NodeClass = "PLUS"; m_bogus = m_Mybogus; m_numCores = m_NumCores; calcIdle(); - m_timer = new IdleTimer(this); - m_pMonitorSvc->declareInfo(m_NodeName+"/NodeBusy",m_BusyFraction,"",this); -// m_pMonitorSvc->declareInfo("IdleFraction",m_idlebogus,"",this); -// m_pMonitorSvc->declareInfo("BogoMIPS",m_bogus,"",this); -// m_pMonitorSvc->declareInfo("BusyFraction",m_busybogus,"",this); -// m_pMonitorSvc->declareInfo("NumCores",m_numCores,"",this); + m_timer = std::make_unique<IdleTimer>(this); + m_monitorSvc->declareInfo(m_NodeName+"/NodeBusy",m_BusyFraction,"",this); +// m_monitorSvc->declareInfo("IdleFraction",m_idlebogus,"",this); +// m_monitorSvc->declareInfo("BogoMIPS",m_bogus,"",this); +// m_monitorSvc->declareInfo("BusyFraction",m_busybogus,"",this); +// m_monitorSvc->declareInfo("NumCores",m_numCores,"",this); // -// m_pMonitorSvc->declareInfo("TotMemory",m_Memtot,"",this); -// m_pMonitorSvc->declareInfo("FreeMemory",m_Memfree,"",this); -// m_pMonitorSvc->declareInfo("MemBuffers",m_Membuff,"",this); -// m_pMonitorSvc->declareInfo("SwapSpaceTot",m_MemSwaptot,"",this); -// m_pMonitorSvc->declareInfo("SwapSpaceFree",m_MemSwapfree,"",this); -// m_pMonitorSvc->declareInfo("MemAvail",m_MemAvail,"",this); +// m_monitorSvc->declareInfo("TotMemory",m_Memtot,"",this); +// m_monitorSvc->declareInfo("FreeMemory",m_Memfree,"",this); +// m_monitorSvc->declareInfo("MemBuffers",m_Membuff,"",this); +// m_monitorSvc->declareInfo("SwapSpaceTot",m_MemSwaptot,"",this); +// m_monitorSvc->declareInfo("SwapSpaceFree",m_MemSwapfree,"",this); +// m_monitorSvc->declareInfo("MemAvail",m_MemAvail,"",this); // -// m_pMonitorSvc->declareInfo(m_NodeClass+"/IdleFraction",m_idlebogus,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/BogoMIPS",m_bogus,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/BusyFraction",m_busybogus,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/NumCores",m_numCores,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/IdleFraction",m_idlebogus,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/BogoMIPS",m_bogus,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/BusyFraction",m_busybogus,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/NumCores",m_numCores,"",this); // -// m_pMonitorSvc->declareInfo(m_NodeClass+"/TotMemory",m_Memtot,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/FreeMemory",m_Memfree,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/MemBuffers",m_Membuff,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/SwapSpaceTot",m_MemSwaptot,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/SwapSpaceFree",m_MemSwapfree,"",this); -// m_pMonitorSvc->declareInfo(m_NodeClass+"/MemAvail",m_MemAvail,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/TotMemory",m_Memtot,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/FreeMemory",m_Memfree,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/MemBuffers",m_Membuff,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/SwapSpaceTot",m_MemSwaptot,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/SwapSpaceFree",m_MemSwapfree,"",this); +// m_monitorSvc->declareInfo(m_NodeClass+"/MemAvail",m_MemAvail,"",this); return StatusCode::SUCCESS; } -void BusySvc::NodeClass(std::string &c) -{ + +StatusCode BusySvc::finalize() { + this->m_timer->stop(); + this->m_timer.reset(); + return this->Service::finalize(); +} + +StatusCode BusySvc::start() { + StatusCode sc = this->Service::start(); + this->m_bogus = m_Mybogus; + this->m_timer->start(); + return StatusCode::SUCCESS; +} + +void BusySvc::NodeClass(std::string &c) { FILE *f=fopen("/group/online/ecs/FarmNodes.txt","r"); c = ""; if ( f == 0 ) { @@ -93,17 +123,8 @@ void BusySvc::NodeClass(std::string &c) fclose(f); return; } -StatusCode BusySvc::start() { - StatusCode sc; - sc = Service::start(); - m_bogus = m_Mybogus; - m_timer->start(); - return StatusCode::SUCCESS; -} - -BusySvc::BusySvc(const std::string& name, ISvcLocator* sl) : Service(name,sl) -{ +BusySvc::BusySvc(const std::string& name, ISvcLocator* sl) : Service(name,sl) { m_idlebogus=0.0; m_busybogus=0.0; m_bogus=0.0; @@ -119,32 +140,8 @@ BusySvc::BusySvc(const std::string& name, ISvcLocator* sl) : Service(name,sl) m_MemAvail = 0; declareProperty("BogusMips", m_bogus = 0.0); m_first = true; - m_pMonitorSvc = 0; } -BusySvc::~BusySvc() -{ -} - -//StatusCode BusySvc::queryInterface(const InterfaceID& riid, void** ppvIF) { -// return Service::queryInterface(riid, ppvIF); -// addRef(); -// return StatusCode::SUCCESS; -//} - -//StatusCode BusySvc::queryInterface(const InterfaceID& riid, void** ppvIF) -//{ -// if ( IService::interfaceID().versionMatch(riid) ) -// { -// *ppvIF = (IService*)this; -// } -// else -// { -// return Service::queryInterface(riid, ppvIF); -// } -// addRef(); -// return StatusCode::SUCCESS; -//} void BusySvc::getBogus(double &bogus) { char line[256]; char bogoline[256]; @@ -228,171 +225,27 @@ void BusySvc::calcIdle() m_BusyFraction = (1.0-p_id); m_busybogus = (1.0-p_id)*m_bogus; m_numCores = m_NumCores; -// printf ("Idle Percentage %f weighted %f\n",p_id, m_idlebogus); fclose(f); -// -// -// -// -// + f = fopen("/proc/meminfo","r"); stat = line; - while (stat != 0) - { - std::string tok; - stat = fgets(line,sizeof(line),f); + while (stat != 0) { + stat = fgets(line, sizeof(line), f); if (stat == 0) break; auto toks = RTL::str_split(line," "); - tok = toks.at(0); - if (toks.at(0).find("MemTotal") != std::string::npos) - { - tok = toks.at(1); - m_Memtot = std::stol(toks.at(1)); - long fact=1; - if (toks.size()>2) - { - tok = toks.at(2); - if (toks.at(2) == "kB") - { - fact = 1000; - } - else if (toks.at(2) == "B") - { - fact = 1; - } - else if (toks.at(2) == "MB") - { - fact = 1000000; - } - } - m_Memtot *= fact; - continue; - } - tok = toks.at(0); + const auto& tok = toks.at(0); + if (tok.find("MemTotal") != std::string::npos) + m_Memtot = mem_in_bytes(toks); if (toks.at(0).find("MemFree") != std::string::npos) - { - tok = toks.at(1); - m_Memfree = std::stol(toks.at(1)); - long fact=1; - if (toks.size()>2) - { - tok = toks.at(2); - if (toks.at(2) == "kB") - { - fact = 1000; - } - else if (toks.at(2) == "B") - { - fact = 1; - } - else if (toks.at(2) == "MB") - { - fact = 1000000; - } - } - m_Memfree *= fact; - continue; - } - tok = toks.at(0); - if (toks.at(0).find("Buffers") != std::string::npos) - { - tok = toks.at(1); - m_Membuff = std::stol(toks.at(1)); - long fact=1; - if (toks.size()>2) - { - tok = toks.at(2); - if (toks.at(2) == "kB") - { - fact = 1000; - } - else if (toks.at(2) == "B") - { - fact = 1; - } - else if (toks.at(2) == "MB") - { - fact = 1000000; - } - } - m_Membuff *= fact; - continue; - } - tok = toks.at(0); - if (toks.at(0).find("SwapTotal") != std::string::npos) - { - tok = toks.at(1); - m_MemSwaptot = std::stol(toks.at(1)); - long fact=1; - if (toks.size()>2) - { - tok = toks.at(2); - if (toks.at(2) == "kB") - { - fact = 1000; - } - else if (toks.at(2) == "B") - { - fact = 1; - } - else if (toks.at(2) == "MB") - { - fact = 1000000; - } - } - m_MemSwaptot *= fact; - continue; - } - tok = toks.at(0); - if (toks.at(0).find("SwapFree") != std::string::npos) - { - tok = toks.at(1); - m_MemSwapfree = std::stol(toks.at(1)); - long fact=1; - if (toks.size()>2) - { - tok = toks.at(2); - if (toks.at(2) == "kB") - { - fact = 1000; - } - else if (toks.at(2) == "B") - { - fact = 1; - } - else if (toks.at(2) == "MB") - { - fact = 1000000; - } - } - m_MemSwapfree *= fact; - continue; - } - tok = toks.at(0); - if (toks.at(0).find("MemAvailable") != std::string::npos) - { - tok = toks.at(1); - m_MemAvail = std::stol(toks.at(1)); - long fact=1; - if (toks.size()>2) - { - tok = toks.at(2); - if (toks.at(2) == "kB") - { - fact = 1000; - } - else if (toks.at(2) == "B") - { - fact = 1; - } - else if (toks.at(2) == "MB") - { - fact = 1000000; - } - } - m_MemSwapfree *= fact; - continue; - } + m_Memfree = mem_in_bytes(toks); + else if (toks.at(0).find("Buffers") != std::string::npos) + m_Membuff = mem_in_bytes(toks); + else if (tok.find("SwapTotal") != std::string::npos) + m_MemSwaptot = mem_in_bytes(toks); + else if (tok.find("SwapFree") != std::string::npos) + m_MemSwapfree = mem_in_bytes(toks); + else if (tok.find("MemAvailable") != std::string::npos) + m_MemAvail = mem_in_bytes(toks); } fclose(f); } diff --git a/Online/GauchoAppl/src/components/BusySvc.h b/Online/GauchoAppl/src/components/BusySvc.h index b863bc1a680a1137f97ba3381949c3e3269b365b..2bc139da424c7a2f91ffd0cf748551d957d1ef55 100644 --- a/Online/GauchoAppl/src/components/BusySvc.h +++ b/Online/GauchoAppl/src/components/BusySvc.h @@ -9,54 +9,44 @@ // Author : B.Jost // //========================================================================== -#ifndef BUSYSVC_H -#define BUSYSVC_H +#ifndef ONLINE_GAUCHO_BUSYSVC_H +#define ONLINE_GAUCHO_BUSYSVC_H -#include "GaudiKernel/Service.h" -#include "Gaucho/GenTimer.h" -class IGauchoMonitorSvc; -class BusySvc; +#include <GaudiKernel/Service.h> class IMonitorSvc; -class IdleTimer : public Online::GenTimer { -public: - BusySvc *m_bsysvc; - IdleTimer(BusySvc *master, int period = 5000) : GenTimer(master,period) - { - m_bsysvc = master; - }; - ~IdleTimer(); - void timerHandler(void) override; -}; +class BusySvc : public Service { +private: + class IdleTimer; + + std::string m_NodeClass; + std::string m_NodeName; + long m_times_old[7]; + double m_idlebogus; + double m_busybogus; + double m_bogus; + double m_Mybogus; + double m_BusyFraction; + long m_Memtot; + long m_Memfree; + long m_Membuff; + long m_MemSwaptot; + long m_MemSwapfree; + long m_MemAvail; + int m_NumCores; + int m_numCores; + bool m_first; + SmartIF<IMonitorSvc> m_monitorSvc; + std::unique_ptr<IdleTimer> m_timer; -class BusySvc : public Service -{ -public: - std::string m_NodeClass; - std::string m_NodeName; - long m_times_old[7]; - double m_idlebogus; - double m_busybogus; - double m_bogus; - double m_Mybogus; - double m_BusyFraction; - long m_Memtot; - long m_Memfree; - long m_Membuff; - long m_MemSwaptot; - long m_MemSwapfree; - long m_MemAvail; - int m_NumCores; - int m_numCores; - bool m_first; - IMonitorSvc *m_pMonitorSvc { nullptr }; - IdleTimer *m_timer { nullptr }; - BusySvc(const std::string& name, ISvcLocator* sl); - virtual ~BusySvc(); - StatusCode start() override; - StatusCode initialize() override; void calcIdle(); void getBogus(double &bogus); void NodeClass(std::string &); + public: + BusySvc(const std::string& name, ISvcLocator* sl); + virtual ~BusySvc() = default; + StatusCode start() override; + StatusCode initialize() override; + StatusCode finalize() override; }; -#endif // BUSYSVC_H +#endif // ONLINE_GAUCHO_BUSYSVC_H diff --git a/Online/GauchoAppl/src/components/PubSvc.cpp b/Online/GauchoAppl/src/components/PubSvc.cpp index d43227f7abea9f04e94f6fa1fd983d86733b704b..36256598be37c301e19396fb1eeff6c62b5481ef 100644 --- a/Online/GauchoAppl/src/components/PubSvc.cpp +++ b/Online/GauchoAppl/src/components/PubSvc.cpp @@ -59,6 +59,7 @@ PubSvc::PubSvc(const std::string& name, ISvcLocator* sl) declareProperty("ServicePattern", m_ServicePattern = ""); declareProperty("DebugOn", m_debugOn = false); declareProperty("isEOR", m_isEOR = false); + declareProperty("TrackSources", m_trackSources = false); declareProperty("AdderClass", m_AdderClass = "counter"); //Possible values are 'hists' for histigrams or 'counter' for counters. } @@ -163,11 +164,12 @@ StatusCode PubSvc::start() DimClient::setDnsNode(m_InputDNS.c_str()); } if ( m_AdderClass == "counter" ) - m_adder = std::make_unique<CounterAdder>(m_myservicename, m_myservicename, "Data", ADD_COUNTER); + m_adder = std::make_unique<CounterAdder>(m_myservicename, "Data", ADD_COUNTER); else - m_adder = std::make_unique<HistAdder>(m_myservicename, m_myservicename, "Data", ADD_HISTO); + m_adder = std::make_unique<HistAdder>(m_myservicename, "Data", ADD_HISTO); auto dns = AdderSys::instance().getDNS(m_OutputDNS,m_myservicename); + if ( m_trackSources ) AdderSys::instance().trackSources(); m_adder->serviceDNS = dns; m_adder->isSaver = false; m_adder->isEOR = m_isEOR; @@ -179,6 +181,7 @@ StatusCode PubSvc::start() m_adder->disableOutput = true; m_adder->noRPC = true; m_adder->debugOn = m_debugOn; + m_adder->trackSources = m_trackSources; m_adder->configure(); dns->autoStartOn(); m_started = true; diff --git a/Online/GauchoAppl/src/components/PubSvc.h b/Online/GauchoAppl/src/components/PubSvc.h index 23446b343b30baeeb4a16cde0a3f0240e928a20f..50da3e90c3be5f902f0849def2bf32a065e1d0c2 100644 --- a/Online/GauchoAppl/src/components/PubSvc.h +++ b/Online/GauchoAppl/src/components/PubSvc.h @@ -82,5 +82,6 @@ public: bool m_started { false }; bool m_isEOR { false }; bool m_debugOn { false }; + bool m_trackSources { false }; }; #endif // ONLINE_GAUCHO_PUBSVC_H diff --git a/Online/GauchoAppl/test/Addertst.cpp b/Online/GauchoAppl/test/Addertst.cpp index 0a232d0be80c74652d718ae7bb30a336bf57ddf5..37542650ff206a0b40e33cd21a9b47c8ecb68c0c 100644 --- a/Online/GauchoAppl/test/Addertst.cpp +++ b/Online/GauchoAppl/test/Addertst.cpp @@ -107,7 +107,7 @@ int main (int argc, char *argv[]) { gROOT->Draw(); canv->Show(); canv->Draw(); - HistAdder *a = new HistAdder("Test","Adder","Histos/Data", ADD_HISTO); + HistAdder *a = new HistAdder("Adder","Histos/Data", ADD_HISTO); a->SetCycleFn(&CycleFn,0); app->Run(); sleep(1000000000); diff --git a/Online/GauchoBase/Gaucho/CntrMgr.h b/Online/GauchoBase/Gaucho/CntrMgr.h deleted file mode 100644 index 86c2cc9fc5dadb40b6842d102ea5daa3a98ce34b..0000000000000000000000000000000000000000 --- a/Online/GauchoBase/Gaucho/CntrMgr.h +++ /dev/null @@ -1,93 +0,0 @@ -//========================================================================== -// LHCb Online software suite -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see OnlineSys/LICENSE. -// -// Author : B.Jost -// -//========================================================================== -#ifndef GAUCHO_CNTRMGR_H -#define GAUCHO_CNTRMGR_H 1 - -#include <map> -#include <string> - -class StatEntity; - -/// Online namespace declaration -namespace Online { - - class CntrMgr { - public: - typedef std::map<std::string, std::pair<std::string,std::pair<std::string, const void*> > > CounterMap; - typedef CounterMap::iterator counterMapIt; - - protected: - int *m_runNumber; // Maybe we have to use double - int *m_cycleNumber; - unsigned int *m_triggerConfigurationKey; - void *m_deltaT; - double *m_offsetTimeFirstEvInRun; - double *m_offsetTimeLastEvInCycle; - double *m_offsetGpsTimeLastEvInCycle; - - bool m_AllowAdd; - - public: - bool m_newcounter; - CounterMap m_counterMap; - - CntrMgr(const std::string& source, int version=0); - virtual ~CntrMgr(); - const CounterMap& mapping() const { return m_counterMap; } - - void i_addCounter(const std::string& nam, const std::string& descr, const std::string& type, const void* count); - - void addCounter(const std::string& countName, const std::string& countDescription, const double& count) { - i_addCounter(countName,countDescription,"double",&count); - } - void addCounter(const std::string& countName, const std::string& countDescription, const int& count) { - i_addCounter(countName,countDescription,"int",&count); - } - void addCounter(const std::string& countName, const std::string& countDescription, const long& count) { - i_addCounter(countName,countDescription,"long",&count); - } - void addCounter(const std::string& countName, const std::string& countDescription, const StatEntity& count) { - i_addCounter(countName+"-flag",countDescription+"-flag","StatEntityflag",&count); - i_addCounter(countName+"-nEntries",countDescription+"-nEntries","StatEntitynEntries",&count); - } - void removeCounter (const std::string &name) { - counterMapIt it = m_counterMap.find(name); - if (it != m_counterMap.end()) { - m_counterMap.erase(it); - } - } - void removeCounterAll() { - m_counterMap.clear(); - } - - void addComplement(int* runNumber, unsigned int* triggerConfigurationKey, int* cycleNumber, double* deltaT, double* offsetTimeFirstEvInRun, double* offsetTimeLastEvInCycle, double* offsetGpsTimeLastEvInCycle) { - m_runNumber = runNumber; - m_triggerConfigurationKey = triggerConfigurationKey; - m_cycleNumber = cycleNumber; - m_deltaT = (void*)deltaT; - m_offsetTimeFirstEvInRun = offsetTimeFirstEvInRun; - m_offsetTimeLastEvInCycle = offsetTimeLastEvInCycle; - m_offsetGpsTimeLastEvInCycle = offsetGpsTimeLastEvInCycle; - } - - double offsetTimeFirstEvInRun() const { return (m_offsetTimeFirstEvInRun!=0 ? *m_offsetTimeFirstEvInRun : 0);} - double offsetTimeLastEvInCycle() const { return (m_offsetTimeLastEvInCycle != 0 ? *m_offsetTimeLastEvInCycle : 0);} - double offsetGpsTimeLastEvInCycle() const { return (m_offsetGpsTimeLastEvInCycle != 0 ? *m_offsetGpsTimeLastEvInCycle : 0);} - int runNumber() const { return (m_runNumber != 0 ? *m_runNumber : 0);} - unsigned int triggerConfigurationKey() const { return (m_triggerConfigurationKey != 0 ? *m_triggerConfigurationKey : 0);} - int cycleNumber() const { return (m_cycleNumber != 0 ? *m_cycleNumber : 0);} - double deltaT() const { return (m_deltaT != 0 ? (double)*(unsigned long *)m_deltaT : 0);} - void open() { m_AllowAdd = true;return;} - void close() { m_AllowAdd = false;return;} - }; -} -#endif //GAUCHO_CNTRMGR_H diff --git a/Online/GauchoBase/Gaucho/GenTimer.h b/Online/GauchoBase/Gaucho/GenTimer.h index 6916f65c0d7e82b140cf9d1b524d3a2b5568b747..8ff0d836c89136625d7881c3df1092e8f2fcee4f 100644 --- a/Online/GauchoBase/Gaucho/GenTimer.h +++ b/Online/GauchoBase/Gaucho/GenTimer.h @@ -29,29 +29,31 @@ namespace Online { public: bool periodic; bool synched; - bool m_ForceExit { true }; - bool m_timeout { false }; - void *arg { nullptr }; + bool forceExit { true }; + bool timeout { false }; + protected: unsigned long period; + unsigned long m_dueTime { 0 }; unsigned long m_lastfire { 0 }; unsigned long m_lastdelta { 0 }; unsigned long *m_extlastdelta { nullptr }; - int m_ThreadBalance { 0 }; - bool m_stopSeen { false }; - pid_t m_threadpid { 0 }; + int m_ThreadBalance { 0 }; + bool m_stopSeen { false }; + pid_t pid { 0 }; std::unique_ptr<std::thread> m_thread; - int type; - void makeDeltaT(void); + int type; + void makeDeltaT(); public: bool m_dontdimlock { true }; - GenTimer(void *arg, int period = 10000,int typ=TIMER_TYPE_PERIODIC+TIMER_MODIFYER_SYNCHRONIZED); + GenTimer(int period = 10000,int typ=TIMER_TYPE_PERIODIC+TIMER_MODIFYER_SYNCHRONIZED); // Period is in milli-seconds... virtual ~GenTimer(void); virtual void timerHandler ( void ) = 0; virtual void start(); virtual void startPeriodic(int period); virtual void stop(); + bool isRunning() const { return this->m_thread.get() != nullptr && !this->forceExit; } void setExtLastDelta(unsigned long *a){m_extlastdelta = a;return;}; unsigned long getDeltaTime(int incr=0); void *ThreadRoutine(); diff --git a/Online/GauchoBase/Gaucho/HistSerDes.h b/Online/GauchoBase/Gaucho/HistSerDes.h index 9d7c8bd4f11c0152541f8b5cc06192f5139a638d..eec09d00c1e9f2922644cd235ac6dceb085a7859 100644 --- a/Online/GauchoBase/Gaucho/HistSerDes.h +++ b/Online/GauchoBase/Gaucho/HistSerDes.h @@ -1,10 +1,14 @@ -/* - * HistSerdes.h - * - * Created on: Jan 7, 2021 - * Author: beat - */ - +//========================================================================== +// LHCb Online software suite +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see OnlineSys/LICENSE. +// +// Author : B.Jost +// +//========================================================================== #ifndef ONLINE_GAUCHOBASE_GAUCHO_HISTSERDES_H_ #define ONLINE_GAUCHOBASE_GAUCHO_HISTSERDES_H_ diff --git a/Online/GauchoBase/Gaucho/Misc.h b/Online/GauchoBase/Gaucho/Misc.h deleted file mode 100644 index 41f912a478cccfd3eb85ec19f5971fac82aee1db..0000000000000000000000000000000000000000 --- a/Online/GauchoBase/Gaucho/Misc.h +++ /dev/null @@ -1,36 +0,0 @@ -//========================================================================== -// LHCb Online software suite -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see OnlineSys/LICENSE. -// -// Author : B.Jost -// -//========================================================================== -#ifndef Misc_H -#define Misc_H 1 - -// Author: jotalo, 14/04/2008 - -class Misc { - -public: - Misc(); - virtual ~Misc(); - - static std::vector<std::string> splitString(const std::string &str, const char *s); - static bool matchString(const std::string &str, const std::vector<std::string> &strV); - static bool matchStringCaseIns(const std::string &str, const std::vector<std::string> &strV); - static bool isStringInVector(const std::string &str, const std::vector<std::string> &strV); - static size_t findCaseIns(const std::string& str1, const std::string& str2); - static bool compareCharsCaseIns(char ch1, char ch2); - static std::string stringToUpper(std::string strToConvert); - static int min(int a, int b) {if (a < b) return a; return b;} - static void printSerializedString(const char * c, int size); - static std::string charToString(char * c, int size); - -}; - -#endif // Misc_H diff --git a/Online/GauchoBase/Gaucho/MonBase.h b/Online/GauchoBase/Gaucho/MonBase.h index d11e919007128b62adf3ef342a0fe4590d238d4c..234169ed58fb9b18034d336f13891fb334272b31 100644 --- a/Online/GauchoBase/Gaucho/MonBase.h +++ b/Online/GauchoBase/Gaucho/MonBase.h @@ -9,12 +9,6 @@ // Author : B.Jost // //========================================================================== -/* - * MonBase.h - * - * Created on: Dec 7, 2016 - * Author: beat - */ #pragma once #include <Gaucho/MonTypes.h> diff --git a/Online/GauchoBase/Gaucho/MonHist.h b/Online/GauchoBase/Gaucho/MonHist.h index c1ba03ee4cbc4abdbb4695bcec32bb2ae664c4fc..27d8d2c14d2c3ea9f61ed4dc83d1af4c65d2a657 100644 --- a/Online/GauchoBase/Gaucho/MonHist.h +++ b/Online/GauchoBase/Gaucho/MonHist.h @@ -23,8 +23,6 @@ class StatEntity; /// Online namespace declaration namespace Online { - class CntrMgr; - class StatEntityShadow { public: /// number of calls @@ -118,19 +116,7 @@ namespace Online { MonHist(const std::string& source, const std::string& desc, const T& hist); - MonHist(const std::string& source, const CntrMgr &cm) = delete; - - virtual ~MonHist() { - Bool_t dirstat = TH1::AddDirectoryStatus(); - TH1::AddDirectory (kFALSE); - for (size_t i=0; i<this->axes.size();i++) { - this->axes[i].labels.clear(); - this->axes[i].lablen = -1; - } - this->axes.clear(); - this->object = nullptr; - TH1::AddDirectory(dirstat); - } + virtual ~MonHist(); virtual int hdrlen() const override { return this->headerLen; @@ -175,6 +161,14 @@ namespace Online { this->type = this->analyzeType(hist); setup(); } + + template <typename T> inline MonHist<T>::~MonHist() { + Bool_t dirstat = TH1::AddDirectoryStatus(); + TH1::AddDirectory (kFALSE); + this->axes.clear(); + this->object = nullptr; + TH1::AddDirectory(dirstat); + } template <typename T> inline void DimHistbuff1::setup_buffer(Online::MonHist<T>& hist) { diff --git a/Online/GauchoBase/Gaucho/MonTimer.h b/Online/GauchoBase/Gaucho/MonTimer.h index 8ecc638af78d8cb3fda6c1166e9ebcd47894fa79..551b6bda2240c94d5ca3ac28b53872078c0bfb1b 100644 --- a/Online/GauchoBase/Gaucho/MonTimer.h +++ b/Online/GauchoBase/Gaucho/MonTimer.h @@ -13,7 +13,6 @@ #define ONLINE_GAUCHO_MONTIMER_H #include "Gaucho/GenTimer.h" -#include "Gaucho/BRTL_Lock.h" /// Online namespace declaration namespace Online { diff --git a/Online/GauchoBase/Gaucho/RPCRec.h b/Online/GauchoBase/Gaucho/RPCRec.h index 2a88b341691547d46e4582fb5da418df2e8c9d45..06593297299c1897103a501c2575bc2723ea7971 100644 --- a/Online/GauchoBase/Gaucho/RPCRec.h +++ b/Online/GauchoBase/Gaucho/RPCRec.h @@ -24,9 +24,9 @@ namespace Online { class RPCRec : public DimRpcInfo { public: - typedef std::vector<char*> NAMEVEC; - typedef std::vector<std::string> STRVEC; - typedef std::map<char*, void*> PTRMAP; + typedef std::vector<const char*> NAMEVEC; + typedef std::vector<std::string> STRVEC; + typedef std::map<const char*, void*> PTRMAP; private: bool m_synch; RPCCommType m_reply; @@ -43,9 +43,9 @@ namespace Online { void declareDirectoryCallback(void (*CBfn)(const NAMEVEC&)) { DirCB = CBfn; } void declareDataCallback(void (*CBfn)(const PTRMAP&)) { DatCB = CBfn; } int analyseReply(); - int analyseReply(NAMEVEC &); - int analyseReply(PTRMAP &); - int analyseReply(STRVEC &); + int analyseReply(NAMEVEC& names); + int analyseReply(PTRMAP& objects); + int analyseReply(STRVEC& names); }; } #endif // ONLINE_GAUCHO_RPCREC_H diff --git a/Online/GauchoBase/Gaucho/RootHists.h b/Online/GauchoBase/Gaucho/RootHists.h index d5fa29007a3dd1c29d826802f76075d508680b4b..3f0781c3837483b7736e482e0dada6a7c8c33da5 100644 --- a/Online/GauchoBase/Gaucho/RootHists.h +++ b/Online/GauchoBase/Gaucho/RootHists.h @@ -9,6 +9,9 @@ // Author : B.Jost // //========================================================================== +#ifndef ONLINE_GAUCHO_ROOTHISTS_H +#define ONLINE_GAUCHO_ROOTHISTS_H + #include "TH1D.h" #include "TH2D.h" #include "TH3D.h" @@ -187,3 +190,4 @@ namespace Online { } }; } +#endif // ONLINE_GAUCHO_ROOTHISTS_H diff --git a/Online/GauchoBase/Gaucho/Utilities.h b/Online/GauchoBase/Gaucho/Utilities.h index acf606bd742a9e95a9e963e1f2741567b5a1dd59..089e1d8e606a2dbf0c88ab2ddd51d724aa65f4f4 100644 --- a/Online/GauchoBase/Gaucho/Utilities.h +++ b/Online/GauchoBase/Gaucho/Utilities.h @@ -16,8 +16,8 @@ * Author: beat */ -#ifndef UTILITIES_H_ -#define UTILITIES_H_ +#ifndef ONLINE_GAUCHO_UTILITIES_H_ +#define ONLINE_GAUCHO_UTILITIES_H_ #include <string> @@ -29,6 +29,12 @@ namespace { template <typename T=void> inline const T* add_ptr(const void* ptr, unsigned long offs) { return reinterpret_cast<const T*>(((const char*)ptr + offs)); } + template <typename T=void> inline T* ptr_as(void* ptr) { + return reinterpret_cast<T*>(ptr); + } + template <typename T=void> inline const T* ptr_as(const void* ptr) { + return reinterpret_cast<const T*>(ptr); + } inline size_t sum_string_length(size_t length, const std::string& str) { return length + str.length(); } @@ -55,4 +61,5 @@ namespace { func(); } } -#endif /* UTILITIES_H_ */ +#endif /* ONLINE_GAUCHO_UTILITIES_H_ */ + diff --git a/Online/GauchoBase/src/CntrMgr.cpp b/Online/GauchoBase/src/CntrMgr.cpp deleted file mode 100644 index 8d0c4e1488c43f8e78edfedf317d3f174f9f8e20..0000000000000000000000000000000000000000 --- a/Online/GauchoBase/src/CntrMgr.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//========================================================================== -// LHCb Online software suite -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see OnlineSys/LICENSE. -// -// Author : B.Jost -// -//========================================================================== -#include "Gaucho/CntrMgr.h" - -using namespace Online; - -CntrMgr::CntrMgr(const std::string& , int ) -{ - m_runNumber = 0; - m_triggerConfigurationKey = 0; - m_cycleNumber = 0; - m_deltaT = 0; - m_offsetTimeFirstEvInRun = 0; - m_offsetTimeLastEvInCycle = 0; - m_offsetGpsTimeLastEvInCycle = 0; - open(); -} - -CntrMgr::~CntrMgr() -{ -} - -void CntrMgr::i_addCounter(const std::string& nam, const std::string& descr, const std::string& type, const void* count) -{ - if (m_AllowAdd) - { - m_counterMap[nam] = std::make_pair(descr,std::make_pair(type,&count)); - m_newcounter = true; - } -} diff --git a/Online/GauchoBase/src/CounterTask.cpp b/Online/GauchoBase/src/CounterTask.cpp index 3e4f341840930d9dd7a9cda89943219961ed7594..aed2b6e07f79876cbe43b25315f0a43497253814 100644 --- a/Online/GauchoBase/src/CounterTask.cpp +++ b/Online/GauchoBase/src/CounterTask.cpp @@ -9,13 +9,6 @@ // Author : B.Jost // //========================================================================== -/* - * CounterTask.cpp - * - * Created on: Jan 31, 2011 - * Author: beat - */ - #include <Gaucho/CounterTask.h> #include <Gaucho/MonCounter.h> #include <Gaucho/Utilities.h> @@ -48,7 +41,7 @@ CounterTask::CounterTask(const std::string &task, const std::string &dns) { } } -int CounterTask::Directory(std::vector<std::string> &counters) { +int CounterTask::Directory(std::vector<std::string>& counters) { if ( m_RPC ) { int dat = RPCCDirectory; m_RPC->setData(dat); @@ -57,7 +50,7 @@ int CounterTask::Directory(std::vector<std::string> &counters) { return 1; } -int CounterTask::Counters(const std::vector<std::string> &names,std::vector<CntrDescr*> &counters) { +int CounterTask::Counters(const std::vector<std::string>& names, std::vector<CntrDescr*>& counters) { if ( m_RPC ) { int cmdlen = std::accumulate(names.begin(), names.end(), names.size()+sizeof(RPCCommRead), sum_string_length); RPCCommRead *cmd = RPCComm::make_command<RPCCommRead>(cmdlen, RPCCRead); @@ -75,7 +68,7 @@ int CounterTask::Counters(const std::vector<std::string> &names,std::vector<Cntr return 1; } -int CounterTask::Counters(const std::vector<std::string> &names) { +int CounterTask::Counters(const std::vector<std::string>& names) { if ( m_RPC ) { int cmdlen = std::accumulate(names.begin(), names.end(), names.size()+sizeof(RPCCommRead), sum_string_length); RPCCommRead *cmd = RPCComm::make_command<RPCCommRead>(cmdlen, RPCCRead); @@ -86,7 +79,7 @@ int CounterTask::Counters(const std::vector<std::string> &names) { return 1; } -int CounterTask::Counters(const std::vector<std::string> &names, std::map<std::string,CntrDescr*> &counters) { +int CounterTask::Counters(const std::vector<std::string>& names, std::map<std::string,CntrDescr*>& counters) { int status = Counters(names); if ( status == 0 ) { for (auto k=m_RPC->hists.begin() ;k!=m_RPC->hists.end();k++) { @@ -97,7 +90,7 @@ int CounterTask::Counters(const std::vector<std::string> &names, std::map<std::s return status; } -template <typename CONT> int CounterTask::TaskList(std::string dns, CONT &tasklist) { +template <typename CONT> int CounterTask::TaskList(std::string dns, CONT& tasklist) { if ( dns.empty() ) { dns = std::string(getenv("DIM_DNS_NODE")); } @@ -115,7 +108,7 @@ template <typename CONT> int CounterTask::TaskList(std::string dns, CONT &taskli return 0; } -template int CounterTask::TaskList(std::string dns, std::vector<std::string> &tasklist); -template int CounterTask::TaskList(std::string dns, std::list<std::string> &tasklist); -template int CounterTask::TaskList(std::string dns, std::set<std::string> &tasklist); -template int CounterTask::TaskList(std::string dns, std::unordered_set<std::string> &tasklist); +template int CounterTask::TaskList(std::string dns, std::vector<std::string>& tasklist); +template int CounterTask::TaskList(std::string dns, std::list<std::string>& tasklist); +template int CounterTask::TaskList(std::string dns, std::set<std::string>& tasklist); +template int CounterTask::TaskList(std::string dns, std::unordered_set<std::string>& tasklist); diff --git a/Online/GauchoBase/src/GenTimer.cpp b/Online/GauchoBase/src/GenTimer.cpp index 427578de59fa2bf17531747561203b3c1f040c0b..7a3e77519bdf24d5b6f1b714007b864839464e58 100644 --- a/Online/GauchoBase/src/GenTimer.cpp +++ b/Online/GauchoBase/src/GenTimer.cpp @@ -28,42 +28,30 @@ using namespace Online; -namespace { - int ThreadRoutine_C(void* arg) { - GenTimer *t = (GenTimer*)arg; - t->ThreadRoutine(); - t->m_threadpid = 0; - return 1; - } -} - -GenTimer::GenTimer(void *arg, int periodicity, int typ) -{ - this->arg = arg; +GenTimer::GenTimer(int periodicity, int typ) { this->period = periodicity; this->type = typ; this->periodic = (typ & TIMER_TYPE_PERIODIC) != 0; this->synched = (typ & TIMER_MODIFYER_SYNCHRONIZED) != 0; } -GenTimer::~GenTimer( ) -{ +GenTimer::~GenTimer( ) { this->stop(); } void GenTimer::start() { if ( m_thread == 0 ) { - m_ForceExit = false; + this->forceExit = false; this->m_stopSeen = false; - m_thread = std::make_unique<std::thread>(ThreadRoutine_C,this); - m_ThreadBalance++; + this->m_thread = std::make_unique<std::thread>([this]() { this->ThreadRoutine(); this->pid = 0; } ); + this->m_ThreadBalance++; } else { if ( !this->periodic ) { - stop(); - m_ForceExit = false; - m_thread = std::make_unique<std::thread>(ThreadRoutine_C,this); - m_ThreadBalance++; + this->stop(); + this->forceExit = false; + this->m_thread = std::make_unique<std::thread>([this]() { this->ThreadRoutine(); this->pid = 0; } ); + this->m_ThreadBalance++; } } } @@ -77,17 +65,17 @@ void GenTimer::stop() { if (!this->m_dontdimlock) dim_lock(); if (m_thread != 0) { - m_stopSeen = false; - m_ForceExit = true; + this->m_stopSeen = false; + this->forceExit = true; int ncnt=0; while (!m_stopSeen && ncnt < 5) { - m_ForceExit = true; - usleep(10000); + this->forceExit = true; + ::usleep(10000); ncnt++; } - m_thread->detach(); - m_thread.reset(); - m_ThreadBalance--; + this->m_thread->detach(); + this->m_thread.reset(); + this->m_ThreadBalance--; } if (!this->m_dontdimlock) dim_unlock(); @@ -107,8 +95,8 @@ void GenTimer::makeDeltaT() GetLocalTime(&tim); SystemTimeToFileTime(&tim, (LPFILETIME)&timstamp); timestamp *= 10; - ntim = (timstamp/(m_period*onesec_nano))*(m_period*onesec_nano)+(m_period*onesec_nano); - m_dueTime = ntim; + ntim = (timstamp/(m_period*onesec_nano))*(m_period*onesec_nano)+(this->m_period*onesec_nano); + this->m_dueTime = ntim; unsigned long dtim = (ntim-timstamp); return dtim; #else @@ -120,10 +108,10 @@ void GenTimer::makeDeltaT() timstamp = tv.tv_sec; timstamp *= onesec_nano; timstamp += tv.tv_usec*1000; - m_lastdelta = timstamp-m_lastfire; - if (m_extlastdelta != 0) + this->m_lastdelta = timstamp-this->m_lastfire; + if (this->m_extlastdelta != 0) { - *m_extlastdelta = m_lastdelta; + *this->m_extlastdelta = this->m_lastdelta; } return; #endif @@ -174,100 +162,77 @@ unsigned long GenTimer::getDeltaTime(int incr) #endif } -int GenTimer::NanoSleep(struct timespec *req, struct timespec *) -{ - unsigned long nslice; - unsigned long slicetime; - unsigned long tottime; - slicetime = onesec_nano/20; - tottime = req->tv_sec*onesec_nano+req->tv_nsec; - nslice = tottime/slicetime; - unsigned long resttime = tottime-nslice*slicetime; - struct timespec req1; + +int GenTimer::NanoSleep(struct timespec *req, struct timespec *){ + unsigned long slicetime = onesec_nano/20; + unsigned long tottime = req->tv_sec*onesec_nano+req->tv_nsec; + unsigned long nslice = tottime/slicetime; + unsigned long resttime = tottime-nslice*slicetime; int status; - for (unsigned long i = 0;i<nslice;i++) - { + struct timespec req1; + for (unsigned long i = 0; i < nslice; i++ ) { req1.tv_sec = slicetime/onesec_nano; req1.tv_nsec = slicetime % onesec_nano; - status = -1; - while (status != 0) - { + for( status = -1; status != 0; ) { status = nanosleep(&req1,&req1); - if (m_ForceExit) return -1; + if ( this->forceExit ) return -1; } } if (resttime == 0) return 0; req1.tv_sec = resttime/onesec_nano; req1.tv_nsec = resttime % onesec_nano; - status = -1; - while (status != 0) - { + for( status = -1; status != 0; ) { status = nanosleep(&req1,&req1); - if (m_ForceExit) return -1; + if ( this->forceExit ) return -1; } return status; } -#include <syscall.h> -#define gettid() ((int)syscall(SYS_gettid)) +#include <syscall.h> +static inline int gettid() { return ((int)syscall(SYS_gettid)); } #include <sys/time.h> #include <sys/resource.h> + + void *GenTimer::ThreadRoutine() { - unsigned long delta; - struct timespec req; - int status; - this->m_threadpid = gettid(); - setpriority(PRIO_PROCESS,m_threadpid,0); - m_timeout = false; - while (1 && !m_ForceExit) - { - delta = getDeltaTime(0); + this->pid = ::gettid(); + this->timeout = false; + setpriority(PRIO_PROCESS, this->pid, 0); + + while ( !this->forceExit ) { + unsigned long delta = getDeltaTime(0); #ifdef WIN32 Sleep(delta/onemilli_nano); #else - unsigned long s=delta/onesec_nano; + unsigned long s = delta/onesec_nano; + struct timespec req; req.tv_sec = (time_t)s; req.tv_nsec = delta % onesec_nano; - status = -1; - while (status != 0) - { + + for(int status = -1; status != 0; ) { status = NanoSleep(&req,&req); - if (m_ForceExit) - { - m_stopSeen = true; + if (this->forceExit) { + this->m_stopSeen = true; return 0; } - if (status == 0) - { -// m_lock.lockMutex(); -// if (!m_dontdimlock) dim_lock(); - m_timeout = true; - makeDeltaT(); -// int dum; -// pthread_setcanceltype(PTHREAD_CANCEL_DISABLE,&dum); - timerHandler(); -// pthread_setcanceltype(PTHREAD_CANCEL_ENABLE,&dum); -// if (!m_dontdimlock) dim_unlock(); -// m_lock.unlockMutex(); + if (status == 0) { + this->timeout = true; + this->makeDeltaT(); + this->timerHandler(); break; } - else if (errno == EINTR) - { + else if (errno == EINTR) { ::lib_rtl_output(LIB_RTL_WARNING,"EINTR in nanosleep \n"); continue; } - else - { - break; - } + break; } #endif - if (m_ForceExit) - { - m_stopSeen = true; + if (this->forceExit) { + this->m_stopSeen = true; return 0; } - if (!this->periodic) { + if ( !this->periodic ) { break; } } diff --git a/Online/GauchoBase/src/HistSaver.cpp b/Online/GauchoBase/src/HistSaver.cpp index 619ac3e3a3cf552083961a44c8951e2ad221c3f3..0514902a2835ac283dcd0c36869477c8ef7b5a12 100644 --- a/Online/GauchoBase/src/HistSaver.cpp +++ b/Online/GauchoBase/src/HistSaver.cpp @@ -136,7 +136,6 @@ void HistSaver::makeDirs(int runno) { locked_execution(this->lockable, [this,runno]() { this->i_makeDirs(runno); }); } - void HistSaver::i_makeDirs(int runno) { char timestr[64], year[5], month[3], day[3]; time_t rawTime = ::time(NULL); @@ -156,7 +155,7 @@ void HistSaver::i_makeDirs(int runno) { std::stringstream str; str << dir << "/" << this->taskname << "-" << runno << "-" << timestr << (this->EOR ? "-EOR.root" : ".root"); - this->currFileName = str.str(); + this->currFileName = std::move(str.str()); } std::unique_ptr<TFile> HistSaver::openFile() { diff --git a/Online/GauchoBase/src/HistTask.cpp b/Online/GauchoBase/src/HistTask.cpp index 8fda42da44ea10a36e12c3acfe50f239bec22e31..4ae5c8c332e0f1849063c1d89ca06e3bfb6bedc4 100644 --- a/Online/GauchoBase/src/HistTask.cpp +++ b/Online/GauchoBase/src/HistTask.cpp @@ -34,7 +34,7 @@ namespace { HistTask::~HistTask() { } -HistTask::HistTask(const std::string &task,const std::string &dns, int tmo) +HistTask::HistTask(const std::string& task,const std::string& dns, int tmo) : m_DNS(dns), m_task(task) { if ( m_DNS.empty() ) { @@ -49,7 +49,7 @@ HistTask::HistTask(const std::string &task,const std::string &dns, int tmo) } } -int HistTask::Directory(std::vector<std::string> &hists) +int HistTask::Directory(std::vector<std::string>& hists) { if (m_RPC != 0) { int rpc_data = RPCCDirectory; @@ -62,7 +62,7 @@ int HistTask::Directory(std::vector<std::string> &hists) return 1; } -int HistTask::Histos(std::vector<std::string> &names,std::vector<TObject*> &histos) { +int HistTask::Histos(std::vector<std::string>& names,std::vector<TObject*>& histos) { if (m_RPC != 0) { int cmdlen = std::accumulate(names.begin(), names.end(), names.size()+sizeof(RPCCommRead), sum_string_length); RPCCommRead *cmd = RPCComm::make_command<RPCCommRead>(cmdlen, RPCCRead); @@ -80,7 +80,7 @@ int HistTask::Histos(std::vector<std::string> &names,std::vector<TObject*> &hist return 1; } -int HistTask::Histos(std::vector<std::string> &names) { +int HistTask::Histos(std::vector<std::string>& names) { if (m_RPC != 0) { int cmdlen = std::accumulate(names.begin(), names.end(), names.size()+sizeof(RPCCommRead), sum_string_length); RPCCommRead *cmd = RPCComm::make_command<RPCCommRead>(cmdlen, RPCCRead); @@ -91,7 +91,7 @@ int HistTask::Histos(std::vector<std::string> &names) { return 1; } -int HistTask::Histos(std::vector<std::string> &names,std::map<std::string,TObject*> &histos) { +int HistTask::Histos(std::vector<std::string>& names,std::map<std::string,TObject*>& histos) { int status = this->Histos(names); if ( status == 0 ) { for( const auto& k : m_RPC->hists ) { @@ -103,7 +103,7 @@ int HistTask::Histos(std::vector<std::string> &names,std::map<std::string,TObjec } template <typename CONT> -int HistTask::TaskList(std::string dns, CONT &tasklist) { +int HistTask::TaskList(std::string dns, CONT& tasklist) { if ( dns.empty() ) { dns = std::string(::getenv("DIM_DNS_NODE")); } @@ -121,7 +121,7 @@ int HistTask::TaskList(std::string dns, CONT &tasklist) { return 0; } -template int HistTask::TaskList(std::string dns, std::vector<std::string> &tasklist); -template int HistTask::TaskList(std::string dns, std::list<std::string> &tasklist); -template int HistTask::TaskList(std::string dns, std::set<std::string> &tasklist); -template int HistTask::TaskList(std::string dns, std::unordered_set<std::string> &tasklist); +template int HistTask::TaskList(std::string dns, std::vector<std::string>& tasklist); +template int HistTask::TaskList(std::string dns, std::list<std::string>& tasklist); +template int HistTask::TaskList(std::string dns, std::set<std::string>& tasklist); +template int HistTask::TaskList(std::string dns, std::unordered_set<std::string>& tasklist); diff --git a/Online/GauchoBase/src/Misc.cpp b/Online/GauchoBase/src/Misc.cpp deleted file mode 100644 index b2513d381a02e41eed854ed0ab51cb2d65945198..0000000000000000000000000000000000000000 --- a/Online/GauchoBase/src/Misc.cpp +++ /dev/null @@ -1,124 +0,0 @@ -//========================================================================== -// LHCb Online software suite -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see OnlineSys/LICENSE. -// -// Author : B.Jost -// -//========================================================================== -#include <cstring> -#include <stdlib.h> -#include <iostream> -#include <string> -#include <vector> -#include <algorithm> -#include "Gaucho/Misc.h" - -Misc::Misc() -{ -} -Misc::~Misc() -{ -} - -std::vector<std::string> Misc::splitString(const std::string &str, const char *s){ - - std::vector<std::string> found; - - std::size_t begin = 0; - while (true){ - std::size_t end = str.find(s, begin); - if (std::string::npos == end) break; - - found.push_back(str.substr(begin, end - begin)); - begin = end + 1; - } - - if (begin < str.size()) found.push_back(str.substr(begin, str.size())); - - return found; -} - -bool Misc::matchString(const std::string &str, const std::vector<std::string> &strV) { - std::vector<std::string>::const_iterator strVIt; - size_t begin = 0; - for(strVIt=strV.begin(); strVIt!=strV.end(); ++strVIt){ - if (begin >= str.size()) return false; - size_t pos = str.find((*strVIt), begin); - if (pos == std::string::npos) return false; - begin = pos + (*strVIt).size(); - } - return true; -} - -bool Misc::matchStringCaseIns (const std::string &str, const std::vector<std::string> &strV) { - std::vector<std::string>::const_iterator strVIt; - size_t begin = 0; - for(strVIt=strV.begin(); strVIt!=strV.end(); ++strVIt) { - if (begin >= str.size()) return false; - std::string lastPart = str.substr(begin); - size_t pos = Misc::findCaseIns(lastPart, (*strVIt)); - if (pos == std::string::npos) return false; - begin = begin + pos + (*strVIt).size(); - } - return true; -} - - -bool Misc::isStringInVector(const std::string &str, const std::vector<std::string> &strV) { - std::vector<std::string>::const_iterator it; - for(it=strV.begin(); it!=strV.end(); ++it) - if (str.compare(*it) ==0) return true; - return false; -} - -size_t Misc::findCaseIns(const std::string& str1, const std::string& str2) { - std::string::const_iterator pos = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), Misc::compareCharsCaseIns); - if (pos == str1.end()) return std::string::npos; - return pos - str1.begin(); -} - -bool Misc::compareCharsCaseIns(char ch1, char ch2) { - return toupper((unsigned char)ch1) == toupper((unsigned char)ch2); -} - -std::string Misc::stringToUpper(std::string strToConvert) -{//change each element of the string to upper case - for(unsigned int i=0;i<strToConvert.length();i++) - { - strToConvert[i] = toupper(strToConvert[i]); - } - return strToConvert;//return the converted string -} - - -void Misc::printSerializedString(const char * c, int size) -{ - int i=0; - std::cout << "content (" << size << " bytes):" << std::endl; - while(i < size && c != 0) - { - if( c[i] >= 33 && c[i] <= 126) std::cout << c[i]; - else std::cout << "."; - i++; - } - std::cout << std::endl << "/content" << std::endl; -} - -std::string Misc::charToString(char * c, int size) -{ - int i=0; - - // cout << "content (" << size << " bytes):" << endl; - std::string value = ""; - while(i < size && c != 0) - { - if( c[i] >= 33 && c[i] <= 126) value = value + c[i]; - else value = value + "."; - i++; - } - return value; -} diff --git a/Online/GauchoBase/src/MonRate.cpp b/Online/GauchoBase/src/MonRate.cpp index c3e33ec278cf264e54ffec47ba8186669f520c5f..734d84b03c2b554f56b16c7a18f9110cd4051497 100644 --- a/Online/GauchoBase/src/MonRate.cpp +++ b/Online/GauchoBase/src/MonRate.cpp @@ -11,18 +11,18 @@ //========================================================================== #include <Gaucho/MonRate.h> -Online::MonBase* Online::CREATERate(const std::string &nam,const std::string &tit,double &rate) { - return new MonCounter<double>(nam, tit, rate); +Online::MonBase* Online::CREATERate(const std::string &name,const std::string &title, double &rate) { + return new MonCounter<double>(name, title, rate); } -Online::MonRateBase::MonRateBase(const std::string& nam, const std::string& tit, MonBase *bse) - : MonBase(C_RATEDOUBLESTAR, nam, tit), m_OrigCounter(bse) +Online::MonRateBase::MonRateBase(const std::string& nam, const std::string& tit, MonBase *original) + : MonBase(C_RATEDOUBLESTAR, nam, tit), m_OrigCounter(original) { } -void Online::MonRateBase::create_OutputService(const std::string &s) { +void Online::MonRateBase::create_OutputService(const std::string& service) { if ( this->m_rateCounter ) - this->m_rateCounter->create_OutputService(s); + this->m_rateCounter->create_OutputService(service); } void Online::MonRateBase::update_OutputService() { diff --git a/Online/GauchoBase/src/MonTimer.cpp b/Online/GauchoBase/src/MonTimer.cpp index 8960833fd4731518a59fb96a3f8c7ebbcf57912c..5c7baf9265902d4eaa4e8c7e89ad09386930e303 100644 --- a/Online/GauchoBase/src/MonTimer.cpp +++ b/Online/GauchoBase/src/MonTimer.cpp @@ -19,15 +19,16 @@ using namespace Online; -MonTimer::MonTimer(MonitorClass *HSys, int periodicity) : GenTimer((void*)HSys,periodicity*1000) { +MonTimer::MonTimer(MonitorClass *HSys, int periodicity) : GenTimer(periodicity*1000) { m_Hsys = HSys; m_dueTime = 0; m_dontdimlock = true; } void MonTimer::timerHandler ( void ) { - if (m_ForceExit) return; - if (!m_dontdimlock) dim_lock(); + if ( this->forceExit ) return; + + if (!m_dontdimlock) dim_lock(); { bool need_return = false; diff --git a/Online/GauchoBase/src/MonitorClass.cpp b/Online/GauchoBase/src/MonitorClass.cpp index 4ca778301642124fd7cc2bcd9cf5ba7aed0070e1..c21fe0ca215bc65cc7288dd4e4d0e4e7e028029e 100644 --- a/Online/GauchoBase/src/MonitorClass.cpp +++ b/Online/GauchoBase/src/MonitorClass.cpp @@ -92,7 +92,7 @@ void MonitorClass::setup(const string& clazz_name, bool expnd, const string &inf this->genSrv = make_unique<ObjService>(make_unique<ObjSerializer>(this, this->expand), nam, "C", &s_empty, 4); } if ( !this->eor_service ) { - nam = nam = "MON_" + utgid + "/" + this->name + "/EOR"; + nam = "MON_" + utgid + "/" + this->name + "/EOR"; if (this->ID != MonitorClass::DefaultClassName) nam = "MON_" + utgid + "/" + this->name + "/EOR." + this->ID; this->eor_service = make_unique<ObjService>(make_unique<ObjSerializer>(this, false), nam, "C", &s_empty, 4); diff --git a/Online/GauchoBase/src/ObjService.cpp b/Online/GauchoBase/src/ObjService.cpp index 5e07fe0f357d96f4a202c44cf090ed087db2543b..cc7addd5baf58ae896be7476c2d2f7d1eadaafa2 100644 --- a/Online/GauchoBase/src/ObjService.cpp +++ b/Online/GauchoBase/src/ObjService.cpp @@ -28,7 +28,7 @@ ObjService::ObjService (std::shared_ptr<DimServerDns>& dns, std::unique_ptr<Seri ObjService::ObjService (std::unique_ptr<Serializer>&& s, const std::string& name, const char *format, void *buff, size_t siz) : DimService(name.c_str(), format, buff, siz), serializer(std::move(s)) { - add_updater(); + add_updater(nullptr); } ObjService::ObjService (std::shared_ptr<DimServerDns>& dns, std::unique_ptr<Serializer>&& s, const std::string& name, const char *format, void *buff, size_t siz, std::shared_ptr<mem_buff> extbuff) @@ -40,15 +40,21 @@ ObjService::ObjService (std::shared_ptr<DimServerDns>& dns, std::unique_ptr<Seri ObjService::ObjService (std::unique_ptr<Serializer>&& s, const std::string& name, const char *format, void *buff, size_t siz, std::shared_ptr<mem_buff> extbuff) : DimService(name.c_str(), format, buff, siz), serializer(std::move(s)), extBuffer(extbuff) { - add_updater(); + add_updater(nullptr); } void ObjService::add_updater(DimServerDns* dns) { - std::string nn = RTL::str_replace(this->getName(),"/","_"); + std::string nn = RTL::processName() + "/" + RTL::str_replace(this->getName(),"MON_",""); + nn = RTL::str_replace(nn,"/Histos/","/Debug/Update/Hist/"); + nn = RTL::str_replace(nn,"/Counter/","/Debug/Update/Cntr/"); + if ( dns ) {} + this->num_update_svc.reset(new DimService(nn.c_str(),"I", &this->num_updates, sizeof(this->num_updates))); + /* if ( dns ) - this->num_update_svc.reset(new DimService(dns, ("Updates/"+nn).c_str(),"I", &this->num_updates, sizeof(this->num_updates))); + this->num_update_svc.reset(new DimService(dns, nn.c_str(),"I", &this->num_updates, sizeof(this->num_updates))); else - this->num_update_svc.reset(new DimService(("Updates/"+nn).c_str(),"I", &this->num_updates, sizeof(this->num_updates))); + this->num_update_svc.reset(new DimService(nn.c_str(),"I", &this->num_updates, sizeof(this->num_updates))); + */ } const void* ObjService::serialized_buffer() const { diff --git a/Online/GauchoBase/src/RPCRec.cpp b/Online/GauchoBase/src/RPCRec.cpp index 5f2faab4077a1118bcf1ff7cdd10b721440941de..20dd1812b23e9ab4ebfffca3b73c863fe8b53a26 100644 --- a/Online/GauchoBase/src/RPCRec.cpp +++ b/Online/GauchoBase/src/RPCRec.cpp @@ -9,13 +9,8 @@ // Author : B.Jost // //========================================================================== -#include "Gaucho/RPCRec.h" -#include "Gaucho/ObjRPC.h" -#include "Gaucho/MonTypes.h" -#include "Gaucho/dimhist.h" -#include "Gaucho/RPCdefs.h" -#include "Gaucho/Utilities.h" -#include "Gaucho/HistSerDes.h" +#include <Gaucho/RPCRec.h> +#include <Gaucho/ObjRPC.h> #include <cstdio> @@ -101,14 +96,14 @@ int RPCRec::analyseReply() { int RPCRec::analyseReply(NAMEVEC& v) { int stat = analyseReply(); - if (stat == 0) + if ( stat == 0 ) v = names; return stat; } int RPCRec::analyseReply(PTRMAP& p) { int stat = analyseReply(); - if (stat == 0) + if ( stat == 0 ) p = hists; return stat; @@ -116,7 +111,7 @@ int RPCRec::analyseReply(PTRMAP& p) { int RPCRec::analyseReply(STRVEC& v) { int stat = analyseReply(); v.clear(); - if (stat == 0) { + if ( stat == 0 ) { for (auto i=names.begin();i!=names.end();i++) v.push_back(*i); } diff --git a/Online/GauchoBase/src/TaskSaveTimer.cpp b/Online/GauchoBase/src/TaskSaveTimer.cpp index ab980666ac9b22facbf91607466959a9503c600d..0c30065634c459ec798020a5b72383651900dd2e 100644 --- a/Online/GauchoBase/src/TaskSaveTimer.cpp +++ b/Online/GauchoBase/src/TaskSaveTimer.cpp @@ -18,7 +18,7 @@ using namespace Online; TaskSaveTimer::TaskSaveTimer(std::shared_ptr<MonSubSys> add, int period) - : GenTimer(add.get(), period * 1000, TIMER_TYPE_PERIODIC), HistSaver(add) + : GenTimer(period * 1000, TIMER_TYPE_PERIODIC), HistSaver(add) { m_dueTime = 0; m_dontdimlock = true; diff --git a/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py b/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py index aad2689c7a9bc3a31025f7277c10692935b7dc4d..e47de731d71269107f4e42651bc9f8af86e8cc27 100644 --- a/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py +++ b/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py @@ -143,7 +143,7 @@ class Application(object): self.input = input return self.input - def setup_monitoring(self, task_name=None, have_odin=True): + def setup_monitoring_service(self, task_name=None): config = self.config config.monitorType = 'MonitorSvc' # No monitoring counters declared if the type is empty! mon = Configurables.MonitorSvc(config.monitorType) @@ -156,9 +156,12 @@ class Application(object): mon.CounterUpdateInterval = 5 if task_name: mon.ProgramName = task_name - self.app.ExtSvc.insert(0, mon) self.monSvc = mon + return self.monSvc + + def setup_monitoring(self, task_name=None, have_odin=True): + self.setup_monitoring_service(task_name) self.updateAndReset = None update = Configurables.Online__UpdateAndReset('UpdateAndReset') update.resetOnStart = False; diff --git a/Online/SmiController/scripts/runTask.sh b/Online/SmiController/scripts/runTask.sh index ccc31287fafdbdfdf3f3b510ece4e532f3d30dc3..9feaad964f96d8d0b8d7a40b1ac1d26db35b834c 100755 --- a/Online/SmiController/scripts/runTask.sh +++ b/Online/SmiController/scripts/runTask.sh @@ -47,7 +47,7 @@ dataflow_default_options() } # dataflow_task() -{ echo "exec -a ${UTGID} genRunner.exe libDataflow.so dataflow_run_task -msg=fifo -mon=Dataflow_DIMMonitoring -class=$1"; } +{ echo "exec -a ${UTGID} genRunner.exe libDataflow.so dataflow_run_task -mon=Dataflow_DIMMonitoring -class=$1"; } # ## echo "ERROR: INFO_OPTIONS ${INFO_OPTIONS}"; if test "${TASK_TYPE}" = "Controller"; then