diff --git a/Online/Dataflow/CMakeLists.txt b/Online/Dataflow/CMakeLists.txt index cb0298eea914a8ec15efa141b45781ed2f0d8ef3..f6f677464ae40419ed4e2a2316984081ccccdbba 100755 --- a/Online/Dataflow/CMakeLists.txt +++ b/Online/Dataflow/CMakeLists.txt @@ -54,7 +54,7 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}) # --------------------------------------------------------------------------------------- gaudi_add_library(DataflowLib src/framework/*.cpp - INCLUDE_DIRS dim Boost ROOT + INCLUDE_DIRS dim Boost ROOT Tell1Data PCIE40Data PUBLIC_HEADERS Dataflow LINK_LIBRARIES dim dimlogLib Boost ROOT Options OnlineKernel Parsers Properties Tell1Data) # Do not depend on ROOT @@ -83,7 +83,7 @@ gaudi_generate_componentslist(Dataflow) # --------------------------------------------------------------------------------------- gaudi_add_library(DataflowInt src/interactive/*.cpp - INCLUDE_DIRS ROOT + INCLUDE_DIRS dim Boost ROOT NO_PUBLIC_HEADERS LINK_LIBRARIES dim Options Boost Parsers Properties RPC ROOT OnlineBase UPI DataflowLib) diff --git a/Online/Dataflow/Dataflow/DataflowContext.h b/Online/Dataflow/Dataflow/DataflowContext.h index e11dd519e2d0d5d0639414bfd6a63786b2c32e8f..1da21eaf7c6c2ed48af8002d02269a9f85e0fad6 100755 --- a/Online/Dataflow/Dataflow/DataflowContext.h +++ b/Online/Dataflow/Dataflow/DataflowContext.h @@ -87,6 +87,10 @@ namespace Online { ~EventData(); /// Assignment operator EventData& operator=(const EventData& copy) = default; + /// Get data by proper type + template <typename T> T* as() { return (T*)data; } + /// Get data by proper type (const) + template <typename T> const T* as() const { return (T*)data; } }; diff --git a/Online/Dataflow/options/StorageWriter.opts b/Online/Dataflow/options/StorageWriter.opts index 9e8652c19df3d9bbd8e129240798ca03a80df7a8..412f33da907120d279a72e98efd13c8b48ca4ee6 100644 --- a/Online/Dataflow/options/StorageWriter.opts +++ b/Online/Dataflow/options/StorageWriter.opts @@ -27,9 +27,9 @@ Manager.Algorithms = {"Dataflow_StorageWriter/Writer"}; Writer.PartitionName = @OnlineEnv.PartitionName; Writer.RunType = @OnlineEnv.RunType; Writer.Stream = "HLT1"; -Writer.FileName = "/objects/data/${PARTITION}/${STREAM}/${RUN1000}/${RUN}/Run_${RUN}_${NODE}_${TIME}_${SEQ}.mdf"; +Writer.FileName = "/objects/data/${PARTITION}/${STREAM}/${RUN1000}/${RUN}/Run_${RUN}_${NODE}_${TIME}_${PID}_${SEQ}.mdf"; Writer.Server = "XXEB09.lbdaq.cern.ch:8000"; -Writer.FileSizeMB = 2000; +Writer.BufferSizeMB = 2000; Writer.MinFileSizeMB = 0; Writer.WriteErrorRetry = 100000; Writer.WriteErrorSleep = 3000; @@ -38,6 +38,16 @@ Writer.NumBuffers = 2; Writer.NumThreads = 1; Writer.CancelTimeout = 100; // seconds Writer.ForceMDF = true; +Writer.OutputType = "NETWORK"; +// +Writer.BufferSizeMB = 980; +//Writer.BufferSizeMB = 4500; +Writer.NumBuffers = 3; +Writer.FileName = "/daqarea1/objects/nfs_data/${PARTITION}/${STREAM}/${RUN1000}/${RUN}/Run_${RUN}_${NODE}_${TIME}_${PID}_${SEQ}.mdf"; +Writer.FileName = "file:/daqarea1/objects/nfs_data/${PARTITION}/${STREAM}/${RUN1000}/${RUN}/Run_${RUN}_${NODE}_${TIME}_${PID}_${SEQ}.mdf"; +Writer.OutputType = "NFS"; +Writer.MaxFileSizeMB = 5000; +Writer.HaveFileDB = 2; // Logger.OutputLevel = @OnlineEnv.OutputLevel; // diff --git a/Online/Dataflow/src/Storage/StorageWriter.cpp b/Online/Dataflow/src/Storage/StorageWriter.cpp index cda1535fb7477c357bce176ab406ac1e63c9ee84..133d8c5442c41df877a8548780418b6c17f98640 100644 --- a/Online/Dataflow/src/Storage/StorageWriter.cpp +++ b/Online/Dataflow/src/Storage/StorageWriter.cpp @@ -19,6 +19,7 @@ #include "StorageWriter.h" #include <Dataflow/Plugins.h> #include <Storage/fdb_client.h> +#include <Tell1Data/RawFile.h> #include <Tell1Data/Tell1Decoder.h> #include <PCIE40Data/pcie40decoder.h> #include <PCIE40Data/sodin.h> @@ -26,14 +27,20 @@ #include <RTL/rtl.h> /// C/C++ include files +#include <filesystem> #include <sys/types.h> #include <sys/stat.h> +#include <sys/time.h> #include <unistd.h> #include <fcntl.h> #include <cstring> #include <sstream> #include <ctime> +namespace { + static constexpr std::size_t MBYTE = (1024e0*1024e0); +} + using namespace std; using namespace Online; DECLARE_DATAFLOW_NAMED_COMPONENT_NS(Online,Dataflow_StorageWriter,StorageWriter) @@ -42,9 +49,9 @@ DECLARE_DATAFLOW_NAMED_COMPONENT_NS(Online,Dataflow_StorageWriter,StorageWriter) StorageWriter::StorageWriter(const string& nam, Context& ctxt) : Component(nam, ctxt) { - string fname = "/${PARTITION}/${RUN1000}/Run_${RUN}_${NODE}_${TIME}_${SEQ}.mdf"; + string fname = "/${PARTITION}/${RUN1000}/Run_${RUN}_${NODE}_${TIME}_${PID}_${SEQ}.mdf"; declareProperty("Server", m_server); - declareProperty("FileSizeMB", m_bufferSize = 1024); + 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); @@ -52,8 +59,11 @@ StorageWriter::StorageWriter(const string& nam, Context& ctxt) 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 = ""); @@ -70,12 +80,21 @@ int StorageWriter::initialize() { int sc = Component::initialize(); if ( sc == DF_SUCCESS ) { storage::uri_t url(m_server); - m_bufferSize *= 1024*1024; + m_bufferSize *= MBYTE; m_curr_run = 0; m_cancelled = 0; - // m_client.fdbclient = - // storage::client::create<storage::client::sync>(url.host, url.port, 10000, m_debugClient); - // m_client.create_client = std::function(storage::client::create<storage::client::sync>); + + if ( m_fileName.find(":") != string::npos ) + m_output_type = ROOT_STORAGE, m_outputType = "ROOT"; + else if ( ::strcasecmp(m_outputType.c_str(), "NFS") == 0 ) + m_output_type = POSIX_STORAGE; + else if ( ::strcasecmp(m_outputType.c_str(), "ROOT") == 0 ) + m_output_type = ROOT_STORAGE; + else if ( ::strcasecmp(m_outputType.c_str(), "POSIX") == 0 ) + m_output_type = POSIX_STORAGE; + else if ( ::strcasecmp(m_outputType.c_str(), "NETWORK") == 0 ) + m_output_type = NETWORK_STORAGE; + for(Buffer& b : m_free) ::free(b.buffer); m_free.clear(); @@ -181,7 +200,7 @@ void StorageWriter::flush_buffer(Buffer& buff) { } /// Manage buffer to ensure the next data block will fit -int StorageWriter::ensure_buffer(Buffer& buff, long length) { +int StorageWriter::ensure_buffer(Buffer& buff, int64_t length) { if ( nullptr == buff.buffer ) { info("Execute: Failed to allocate buffer. Drop MEP buffer. [%s]", m_shutdown ? "Shutdown requested" : "??????????"); @@ -208,7 +227,7 @@ int StorageWriter::ensure_buffer(Buffer& buff, long length) { } /// Append data to current buffer. If too small allocate a new buffer -int StorageWriter::save_buffer(Buffer& buff, const void* data, long length) { +int StorageWriter::save_buffer(Buffer& buff, const void* data, int64_t length) { int sc = ensure_buffer(buff, length); if ( sc == DF_SUCCESS ) { buff.runNumber = m_curr_run; @@ -219,11 +238,11 @@ int StorageWriter::save_buffer(Buffer& buff, const void* data, long length) { } /// Convert PCIE40 MEP to MDF and save it. -int StorageWriter::save_pcie40_as_mdf(Buffer& buff, const uint8_t* start, long len) { +int StorageWriter::save_pcie40_as_mdf(Buffer& buff, const uint8_t* start, int64_t len) { auto* mep_start = (pcie40::mep_header_t*)start; auto* mep_end = pcie40::add_ptr<pcie40::mep_header_t>(start, len); pcie40::decoder_t decoder; - long nev = 0; + int64_t nev = 0; for(const pcie40::mep_header_t *m, *mep = mep_start; mep < mep_end; ) { if ( mep->is_valid() ) { @@ -284,7 +303,7 @@ int StorageWriter::save_pcie40_as_mdf(Buffer& buff, const uint8_t* start, long l } /// Save MDF frame or MDF burst -int StorageWriter::save_mdf_buffer(Buffer& buff, const uint8_t* start, long len) { +int StorageWriter::save_mdf_buffer(Buffer& buff, const uint8_t* start, int64_t len) { /// Auto detect data type: now check for MDF data type for( const uint8_t *begin=start, *end = start + len; start < end; ) { auto* header = (EventHeader*)start; @@ -293,9 +312,9 @@ int StorageWriter::save_mdf_buffer(Buffer& buff, const uint8_t* start, long len) header->size0(), header->size1(), header->size2(), start-begin); return DF_SUCCESS; } - auto* hdr = header->subHeader().H1; - long length = header->size0(); - long run = hdr->runNumber(); + auto* hdr = header->subHeader().H1; + int64_t length = header->size0(); + int64_t run = hdr->runNumber(); if ( 0 == m_curr_run ) { /// First event in this buffer: store the current run number m_curr_run = run; @@ -369,13 +388,219 @@ int StorageWriter::execute(const Context::EventData& event) { } /// Thread invocation routine to save assembled buffers to the disk server -void StorageWriter::process_buffers() { +template <typename OUT_TYPE> +int StorageWriter::process_posix_buffers() { + OUT_TYPE output; while( 1 ) { Buffer b {nullptr, nullptr}; { lock_guard<mutex> bufferLock(m_mutex); if ( m_free.size() == m_num_buffers && m_shutdown ) { info("process: Exit condition detected. Leaving submit thread."); - return; + return DF_SUCCESS; + } + else if ( !m_todo.empty() ) { + b = m_todo.back(); + m_todo.pop_back(); + } + } + if ( b.buffer ) { + std::size_t len = b.pointer - b.buffer; + if ( output.isOpen() ) { + if ( output.length + len > m_maxFileSizeMB * MBYTE ) { + warning("Closed output %s after %ld bytes [size-limit].", output.name(), output.length); + output.close(); + } + else if ( output.run != b.runNumber ) { + warning("Closed output %s after %ld bytes [run-change].", output.name(), output.length); + output.close(); + } + } + if ( !output.isOpen() ) { + string fname = makeFileName(b.runNumber); + if ( m_haveFileDB ) { + http::HttpReply reply; + try { + string url; + client_t cl; + storage::uri_t srv(m_server); + storage::client::reqheaders_t hdrs; + cl.fdbclient = + storage::client::create<storage::client::sync>(srv.host, srv.port, 10000, m_debugClient); + if ( m_haveFileDB == 2 ) { + hdrs.emplace_back(http::constants::location, fname); + } + reply = cl.save_object_record(fname, url, len, hdrs); + if ( reply.status == reply.temp_redirect ) { + /// OK. the registration was now successful + fname = url; + } + else { + error("posix_buffers: FAILED accessing FDB server: %s", + http::HttpReply::stock_status(reply.status).c_str()); + ::lib_rtl_usleep(m_poll_tmo); + continue; + } + } + catch(const std::exception& e) { + error("posix_buffers: Exception accessing FDB server: %s", e.what()); + ::lib_rtl_usleep(m_poll_tmo); + continue; + } + catch(...) { + error("posix: UNKNOWN Exception accessing FDB server"); + ::lib_rtl_usleep(m_poll_tmo); + continue; + } + } + if ( output.open(fname) <= 0 ) { + error("Failed to open output %s. [%s]", fname.c_str(), RTL::errorString(errno).c_str()); + this->fireIncident("DAQ_ERROR"); + return DF_ERROR; + } + warning("Opened output %s", output.name()); + output.run = b.runNumber; + } + long ret = output.write(b.buffer, len); + if ( ret == long(len) ) { + output.length += len; + } + else { + error("Failed to write buffer to file %s [%s]", output.name(), RTL::errorString(errno).c_str()); + output.close(); + } + { + lock_guard<mutex> bufferLock(m_mutex); + b.pointer = b.buffer; + m_free.push_back(b); + } + continue; + } + if ( m_poll_tmo > 0 ) { + ::lib_rtl_usleep(m_poll_tmo); + } + } + return DF_SUCCESS; +} + +namespace { + struct _OUT { + RawFile file; + std::size_t length = 0; + uint32_t run = 0; + _OUT() = default; + void close() { + length = 0; + run = 0; + file.close(); + file = RawFile(); + } + int open(const std::string& fname) { + filesystem::path parent = filesystem::path(fname).parent_path(); + if ( 0 == RawFile::mkdir(parent.c_str(),0777) ) { + file = RawFile(fname); + length = 0; + run = 0; + return file.openWrite(false); + } + return -1; + } + const char* name() const { + return file.cname(); + } + bool isOpen() const { + return file.isOpen(); + } + long write(const void* b, std::size_t l) { + return file.write(b, l); + } + }; +} +#include <TFile.h> +#include "TSystem.h" +#include "TUrl.h" +namespace { + /// To be done: ROOT implementation + struct _ROOT { + unique_ptr<TFile> file; + std::size_t length = 0; + uint32_t run = 0; + _ROOT() = default; + ~_ROOT() = default; + void close() { + length = 0; + run = 0; + if ( file ) file->Close(); + file.reset(); + } + int open(const std::string& fname) { + static int fSeq = 10; + filesystem::path parent = filesystem::path(fname).parent_path(); + void* dir = gSystem->OpenDirectory(parent.c_str()); + if ( dir ) { + gSystem->FreeDirectory(dir); + } + else if ( 0 != gSystem->mkdir(parent.c_str(), kTRUE) ) { + errno = gSystem->GetErrno(); + return -1; + } + TUrl url(fname.c_str()); + TString opts = "filetype=raw", proto, spec, tmp = url.GetOptions(); + if ( tmp.Length() > 0 ) { + opts += "&"; + opts += url.GetOptions(); + } + url.SetOptions( opts ); + proto = url.GetProtocol(); + spec = (proto == "file" || proto == "http") + ? fname + "?filetype=raw" : url.GetUrl(); + file.reset(TFile::Open(spec, "RECREATE", "", 0)); + length = 0; + run = 0; + if ( file && !file->IsZombie() ) + return ++fSeq; + errno = gSystem->GetErrno(); + file.reset(); + return -1; + } + const char* name() const { + return file->GetName(); + } + bool isOpen() const { + return file.get() ? file->IsOpen() : false; + } + long write(const void* buff, std::size_t length) { + Bool_t ret = file->WriteBuffer((const char*)buff, length); + if ( kTRUE == ret ) { + errno = gSystem->GetErrno(); + return -1; + } + return length; + } + }; +} + +/// Thread invocation routine to save assembled buffers to the disk server +int StorageWriter::process_buffers() { + switch(m_output_type) { + case NETWORK_STORAGE: + return process_network_buffers(); + case ROOT_STORAGE: + return process_posix_buffers<_ROOT>(); + case POSIX_STORAGE: + return process_posix_buffers<_OUT>(); + default: + return process_posix_buffers<_OUT>(); + } +} + +/// Thread invocation routine to save assembled buffers to the disk server +int StorageWriter::process_network_buffers() { + while( 1 ) { + Buffer b {nullptr, nullptr}; { + lock_guard<mutex> bufferLock(m_mutex); + if ( m_free.size() == m_num_buffers && m_shutdown ) { + info("process: Exit condition detected. Leaving submit thread."); + return DF_SUCCESS; } else if ( !m_todo.empty() ) { b = m_todo.back(); @@ -385,13 +610,13 @@ void StorageWriter::process_buffers() { if ( b.buffer ) { size_t len = b.pointer - b.buffer; /// Skip files with less than a minimum bytes - if ( len > m_minFileSizeMB*(1024e0*1024e0) ) { + if ( len > m_minFileSizeMB*MBYTE ) { if ( writeBuffer(b) != DF_SUCCESS ) { error("Execute: Failed to write buffer to file. [%s]",::strerror(errno)); } } else { - info("Skip mini-file with only %ld bytes",long(len)); + info("Skip mini-file with only %ld bytes",int64_t(len)); } { lock_guard<mutex> bufferLock(m_mutex); @@ -404,6 +629,7 @@ void StorageWriter::process_buffers() { ::lib_rtl_usleep(m_poll_tmo); } } + return DF_SUCCESS; } /// Print server's HttpReply structure @@ -463,6 +689,8 @@ string StorageWriter::makeFileName(int run) { file_name = RTL::str_replace(file_name, "${RUN}", text); ::snprintf(text, sizeof(text), "%04ld", m_sequenceNumber); file_name = RTL::str_replace(file_name, "${SEQ}", text); + ::snprintf(text, sizeof(text), "%06d", ::lib_rtl_pid()); + file_name = RTL::str_replace(file_name, "${PID}", text); return file_name; } @@ -470,7 +698,7 @@ string StorageWriter::makeFileName(int run) { int StorageWriter::writeBuffer(const Buffer& buff) { string fname = makeFileName(buff.runNumber); int num_retries = m_write_error_retry; - size_t len = buff.pointer-buff.buffer; + size_t len = buff.pointer - buff.buffer; bool process = (m_cancelled == 0) || (::time(0) - m_cancelled < m_cancel_tmo); http::HttpReply reply; diff --git a/Online/Dataflow/src/Storage/StorageWriter.h b/Online/Dataflow/src/Storage/StorageWriter.h index 177d8ff0a7d6ac4f58e54b4ab4b42ae4cf811f26..12180648b903a7067fec7ba3849b34eef2de6e54 100644 --- a/Online/Dataflow/src/Storage/StorageWriter.h +++ b/Online/Dataflow/src/Storage/StorageWriter.h @@ -68,14 +68,18 @@ namespace Online { std::string m_stream; /// File Name Pattern std::string m_fileName; + /// Steer disk type processing (nfs, network, ...) + std::string m_outputType; /// Property: Buffer size - long m_bufferSize; + int64_t m_bufferSize; /// Property: Number of parallel event buffers - size_t m_num_buffers; + std::size_t m_num_buffers; /// Property: Number of event sender threads - size_t m_num_threads; + std::size_t m_num_threads; /// Property: Minimal file size in MBytes - size_t m_minFileSizeMB; + std::size_t m_minFileSizeMB; + /// Property: Maximal file size in MBytes (used if writing to posix file system) + std::size_t m_maxFileSizeMB; /// Property: Sleep in milliseconds between retries when write connection fails int m_write_error_sleep; /// Property: Number of retries when write connection fails @@ -86,6 +90,8 @@ namespace Online { int m_cancel_tmo {100}; /// Property: Force output in MDF format int m_force_mdf {0}; + /// Property: Use FDB client when writing POSIX/ROOT + int m_haveFileDB {0}; /// Property: Debug FDB client int m_debugClient {0}; @@ -100,11 +106,15 @@ namespace Online { std::vector<Buffer> m_todo; Buffer m_current; - size_t m_sequenceNumber {0}; + std::size_t m_sequenceNumber {0}; /// Unique event properties to construct the output file name unsigned int m_curr_run {0}; unsigned int m_curr_orbit {0}; unsigned int m_curr_bunch {0}; + + enum output_type_t { NETWORK_STORAGE = 1, POSIX_STORAGE = 2, ROOT_STORAGE = 3 }; + /// Flag with preprocessed output type + output_type_t m_output_type { NETWORK_STORAGE }; /// Flag to detect cancellation in the event processing thread time_t m_cancelled {0}; /// Flag to indicate the ongoing shutdown process @@ -112,7 +122,10 @@ namespace Online { protected: /// Thread entry routine to process buffers - void process_buffers(); + int process_buffers(); + int process_network_buffers(); + template <typename OUT_TYPE> int process_posix_buffers(); + /// Flush existing buffer to the storage using fdb void flush_buffer(Buffer& buffer); /// Construct file name @@ -120,16 +133,16 @@ namespace Online { /// Get current buffer. If empty check for new one... Buffer& get_buffer(); /// Manage buffer to ensure the next data block will fit - int ensure_buffer(Buffer& buff, long length); + int ensure_buffer(Buffer& buff, int64_t length); /// Append data to current buffer. If too small allocate a new buffer - int save_buffer(Buffer& buffer, const void* data, long length); + int save_buffer(Buffer& buffer, const void* data, int64_t length); /// Convert PCIE40 MEP to MDF and save it. - int save_pcie40_as_mdf(Buffer& buffer, const uint8_t* start, long length); + int save_pcie40_as_mdf(Buffer& buffer, const uint8_t* start, int64_t length); /// Save MDF frame or MDF burst - int save_mdf_buffer(Buffer& buffer, const uint8_t* start, long length); + int save_mdf_buffer(Buffer& buffer, const uint8_t* start, int64_t length); /// Maximum available buffer size - long maxBufferSize() const { return m_bufferSize; } + int64_t maxBufferSize() const { return m_bufferSize; } /// Write multi event buffer to file. Eventually open a new file.... int writeBuffer(const Buffer& buffer); /// Print server's HttpReply structure diff --git a/Online/Dataflow/src/components/FileWriter.cpp b/Online/Dataflow/src/components/FileWriter.cpp index 612ad918e381317b0874aa073849c4fb19e31f1e..08240caa38794cdd6e5423c0777105c109d25509 100755 --- a/Online/Dataflow/src/components/FileWriter.cpp +++ b/Online/Dataflow/src/components/FileWriter.cpp @@ -40,8 +40,8 @@ #include <sys/types.h> #include <sys/statvfs.h> #include <dim/dic.hxx> -namespace fs = std::filesystem; +namespace fs = std::filesystem; using MBM::EventDesc; using namespace std; using namespace Online; @@ -52,19 +52,17 @@ public: int *m_variable {nullptr}; FileWriter *m_parent {nullptr}; - SteeringInfo(std::string nam, int &var, FileWriter *parent) + SteeringInfo(string nam, int &var, FileWriter *parent) : DimInfo(nam.c_str(), -1) { m_variable = &var; m_parent = parent; } - void infoHandler() override - { + void infoHandler() override { *m_variable = getInt(); - if (*m_variable != 0) - { - m_parent->clearCounters(); - } + if (*m_variable != 0) { + m_parent->clearCounters(); + } return; } }; @@ -74,10 +72,9 @@ public: * @author Beat Jost * @version 1.0 */ -class FileWriter::FileDescr -{ +class FileWriter::FileDescr { public: - std::string fileName; + string fileName; RunDesc *runDescriptor {nullptr}; unsigned int runNumber {0}; unsigned int seqNumber {0}; @@ -109,9 +106,9 @@ public: // Standard Constructor FileWriter::FileWriter(const string& nam, Context& ctxt) : - Processor(nam, ctxt), m_FileDesc(0), m_SteeringSvc(0) + Processor(nam, ctxt), m_fileDesc(0), m_SteeringSvc(0) { - m_EvIn = m_EvOut = 0; + m_evIn = m_evOut = 0; declareProperty("DeviceList", m_DeviceList= { "/localdisk","/localdisk1","/localdisk2"}); declareProperty("FilePrefix", m_filePrefix = "/HLT1/Run_"); @@ -138,8 +135,7 @@ FileWriter::FileWriter(const string& nam, Context& ctxt) : } // Standard Destructor -FileWriter::~FileWriter() -{ +FileWriter::~FileWriter() { m_texit = true; m_thread->join(); m_thread.reset(); @@ -151,8 +147,8 @@ int FileWriter::initialize() bool matchstat; m_BytesOut = 0; m_node = RTL::nodeNameShort(); - m_EvIn = 0; - m_EvOut = 0; + m_evIn = 0; + m_evOut = 0; m_num_bad_frames = 0; m_writeEnabled = true; if ( !m_nodePattern.empty() ) { @@ -163,73 +159,62 @@ int FileWriter::initialize() // matchstat ? "matched" : "does NOT match", m_nodePattern.c_str()); m_writeEnabled = matchstat; } - if (sc == DF_SUCCESS) - { - char path[PATH_MAX]; - vector<string> to_keep; - declareMonitor("EvtsIn", m_EvIn, "Number of Events received."); - declareMonitor("EvtsOut", m_EvOut, "Number of Events written."); - declareMonitor("BytesOut", m_BytesOut, "Number of Bytes Written to File"); - m_sizeLimit *= 1024 * 1024; - for (string dir_name : m_DeviceList) - { - dir_name = RTL::str_replace(dir_name, "${NODE}", m_node); - dir_name = RTL::str_replace(dir_name, "${STREAM}", m_stream); - dir_name = RTL::str_replace(dir_name, "${RUNTYPE}", m_runType); - dir_name = RTL::str_replace(dir_name, "${PARTITION}", m_partitionName); - fs::path dir(dir_name); - warning("Check directory: %s",dir_name.c_str()); - if ( fs::exists(dir) ) - { - char* ptr = ::realpath(dir.c_str(),path); - warning("Use directory: %s",ptr); - to_keep.push_back(ptr); - } - else if ( fs::create_directories(dir)) - { - char* ptr = ::realpath(dir.c_str(),path); - warning("Use directory: %s",ptr); - to_keep.push_back(ptr); - } - else - { - error("Cannot Create Directory %s", dir.c_str()); - } - } - m_DeviceList = to_keep; - if (m_DeviceList.empty()) - { - m_disabled = true; - } - return DF_SUCCESS; + if (sc == DF_SUCCESS) { + char path[PATH_MAX]; + vector<string> to_keep; + declareMonitor("EvtsIn", m_evIn, "Number of Events received."); + declareMonitor("EvtsOut", m_evOut, "Number of Events written."); + declareMonitor("BytesOut", m_BytesOut, "Number of Bytes Written to File"); + m_sizeLimit *= 1024 * 1024; + for (string dir_name : m_DeviceList) { + dir_name = RTL::str_replace(dir_name, "${NODE}", m_node); + dir_name = RTL::str_replace(dir_name, "${STREAM}", m_stream); + dir_name = RTL::str_replace(dir_name, "${RUNTYPE}", m_runType); + dir_name = RTL::str_replace(dir_name, "${PARTITION}", m_partitionName); + fs::path dir(dir_name); + warning("Check directory: %s",dir_name.c_str()); + if ( fs::exists(dir) ) { + char* ptr = ::realpath(dir.c_str(),path); + warning("Use directory: %s",ptr); + to_keep.push_back(ptr); + } + else if ( fs::create_directories(dir)) { + char* ptr = ::realpath(dir.c_str(),path); + warning("Use directory: %s",ptr); + to_keep.push_back(ptr); + } + else { + error("Cannot Create Directory %s", dir.c_str()); + } } + m_DeviceList = to_keep; + if (m_DeviceList.empty()) { + m_disabled = true; + } + return DF_SUCCESS; + } return error("Failed to initialize service base class."); } -int FileWriter::start() -{ +int FileWriter::start() { Processor::start(); - if (m_dimSteering != 0) - { - if (m_SteeringSvc == 0) - { - string svcnam = m_partitionName + "/" + name + "/Control"; - m_SteeringSvc = new SteeringInfo(svcnam, m_Steeringdata, this); - } - m_maxevts = -1; - m_EvOut = 0; + if (m_dimSteering != 0) { + if (m_SteeringSvc == 0) { + string svcnam = m_partitionName + "/" + name + "/Control"; + m_SteeringSvc = new SteeringInfo(svcnam, m_Steeringdata, this); } + m_maxevts = -1; + m_evOut = 0; + } return DF_SUCCESS; } -void FileWriter::clearCounters() -{ - m_EvOut = 0; - m_EvIn = 0; +void FileWriter::clearCounters() { + m_evOut = 0; + m_evIn = 0; } -int FileWriter::stop() -{ +int FileWriter::stop() { // deletePtr(m_SteeringSvc); // // Scan the run list and check for the files @@ -241,8 +226,7 @@ int FileWriter::stop() return Processor::stop(); } -int FileWriter::finalize() -{ +int FileWriter::finalize() { detail::deletePtr(m_SteeringSvc); clearCounters(); unsubscribeIncidents(); @@ -251,30 +235,31 @@ int FileWriter::finalize() } /// Process single event. Input buffer is ALWAYS in mdf event or burst format. -int FileWriter::execute(const Context::EventData& e) -{ - if (this->m_dimSteering != 0 && this->m_Steeringdata == 0) +int FileWriter::execute(const Context::EventData& e) { + if (this->m_dimSteering != 0 && this->m_Steeringdata == 0) { return DF_SUCCESS; - else if (!m_writeEnabled) + } + else if (!m_writeEnabled) { return DF_SUCCESS; - - m_EvIn++; - if (m_disabled) + } + m_evIn++; + if ( m_disabled ) { return DF_SUCCESS; - else if (m_evt_number >= m_maxevts && m_maxevts > 0) + } + else if (m_evt_number >= m_maxevts && m_maxevts > 0) { return DF_SUCCESS; - - int status = DF_SUCCESS; + } EventHeader *mdf = (EventHeader*)e.data; if ( !mdf->is_mdf() ) { error("Bad MDF frame encountered. Skipping frame with %ld bytes.", size_t(e.length)); if ( ++m_num_bad_frames > 3 ) ::lib_rtl_sleep(10000); return DF_SUCCESS; } - size_t count = 0; - size_t len = e.length; - char* beg = (char*)e.data; - char* end = beg + len; + int status = DF_SUCCESS; + size_t count = 0; + size_t len = e.length; + char* beg = (char*)e.data; + char* end = beg + len; Context::EventData event; while ( beg < end ) { auto* hdr = (EventHeader*)beg; @@ -284,7 +269,7 @@ int FileWriter::execute(const Context::EventData& e) break; } auto m = hdr->subHeader().H1->triggerMask(); - ++m_EvIn; + ++m_evIn; ++count; event.release = 0; event.data = beg; @@ -321,108 +306,100 @@ int FileWriter::writeEvent(const Context::EventData& e) { time_t now = ::time(nullptr); unsigned int runnr = mdf->subHeader().H1->runNumber(); RunDesc *run_desc = m_RunList[runnr]; - if (run_desc == 0) - { - run_desc = new RunDesc; - run_desc->runNumber = runnr; - m_RunList[runnr] = run_desc; - createMonitoringInfo(runnr); - } + if (run_desc == 0) { + run_desc = new RunDesc; + run_desc->runNumber = runnr; + m_RunList[runnr] = run_desc; + createMonitoringInfo(runnr); + } - m_FileDesc = run_desc->fileDescr; + m_fileDesc = run_desc->fileDescr; /// If there is no file attached to this run: open a new one - if (m_FileDesc == 0) - { - run_desc->fileDescr = nullptr; - m_FileDesc = openFile(run_desc); - if ( m_FileDesc ) { - long num_close_queue = 0; - { - lock_guard<mutex> lock(this->m_listlock); - num_close_queue = m_FileCloseList.size(); + if (m_fileDesc == 0) { + run_desc->fileDescr = nullptr; + m_fileDesc = openFile(run_desc); + if ( m_fileDesc ) { + long num_close_queue = 0; + { + lock_guard<mutex> lock(this->m_listlock); + num_close_queue = m_fileCloseList.size(); + } + run_desc->fileDescr = m_fileDesc; + ++run_desc->num_files; + ++m_filesOpen; + if ( (m_filesOpen - num_close_queue) > m_maxFilesOpen ) { + /// Scan the run list and check for the files + /// which were not written the longest. + map<unsigned int,vector<FileDescr*> > files; + for(const auto& r : m_RunList ) { + if ( r.second->fileDescr ) { + files[r.second->fileDescr->lastWrite].emplace_back(r.second->fileDescr); + } } - run_desc->fileDescr = m_FileDesc; - ++run_desc->num_files; - ++m_filesOpen; - if ( (m_filesOpen - num_close_queue) > m_maxFilesOpen ) { - /// Scan the run list and check for the files - /// which were not written the longest. - std::map<unsigned int,std::vector<FileDescr*> > files; - for(const auto& r : m_RunList ) { - if ( r.second->fileDescr ) { - files[r.second->fileDescr->lastWrite].emplace_back(r.second->fileDescr); - } - } - for(auto i=files.begin(); i!=files.end(); ++i) { - for( auto* f : i->second ) - markClose(f, 0); - if ( (m_filesOpen - num_close_queue) < m_maxFilesOpen ) - break; - } + for(auto i=files.begin(); i!=files.end(); ++i) { + for( auto* f : i->second ) + markClose(f, 0); + if ( (m_filesOpen - num_close_queue) < m_maxFilesOpen ) + break; } } } - if (m_FileDesc == 0) { + } + if (m_fileDesc == 0) { + auto ec = make_error_code(errc(errno)); error("File Write Error: Cannot open output file: Run: %d Error: %d: [%s]", - runnr, errno, ::strerror(errno)); + runnr, ec.value(), ec.message().c_str()); ::lib_rtl_sleep(2000); return DF_ERROR; } - ssize_t status = this->write(m_FileDesc, mdf, e.length); - if (status != -1) - { - m_EvOut++; - run_desc->num_events++; - m_BytesOut += e.length; - m_FileDesc->lastWrite = now; - m_FileDesc->bytesWritten += e.length; - run_desc->bytesWritten += e.length; - if ( m_FileDesc->bytesWritten > this->m_sizeLimit ) - markClose(m_FileDesc, m_fileCloseDelay); - return DF_SUCCESS; - } - error("Failed to write event for run:%d to file %s.", runnr,m_FileDesc->fileName.c_str()); + ssize_t status = this->write(m_fileDesc, mdf, e.length); + if (status != -1) { + m_evOut++; + run_desc->num_events++; + m_BytesOut += e.length; + m_fileDesc->lastWrite = now; + m_fileDesc->bytesWritten += e.length; + run_desc->bytesWritten += e.length; + if ( m_fileDesc->bytesWritten > this->m_sizeLimit ) + markClose(m_fileDesc, m_fileCloseDelay); + return DF_SUCCESS; + } + error("Failed to write event for run:%d to file %s.", runnr,m_fileDesc->fileName.c_str()); return DF_ERROR; } -void FileWriter::close_files() -{ - while (!this->m_texit) - { +void FileWriter::close_files() { + while ( !this->m_texit ) { { /// This needs to be protected. Beware of scope! - { - time_t now = time(0); - lock_guard<mutex> lock(this->m_listlock); - for (auto i = this->m_FileCloseList.begin(); i != this->m_FileCloseList.end(); ++i) - { - auto* file = *i; - if (now > file->closeAt) - { - debug("Close file run:%6d seq:%5d %s [%7d kB]", - file->runNumber, file->seqNumber, file->fileName.c_str(), - int(file->bytesWritten/1024)); - ::close(file->fileHandle); - this->m_FileCloseList.erase(i); - delete file; - i = this->m_FileCloseList.begin(); - if ( 0 == ((++m_filesClosed)%100) ) { - info("Wrote a total of %ld files Events: %8ld [%7.1f GB]", - m_filesClosed, m_EvOut, - double(m_BytesOut)/double(1024*1024*1024)); - } - } + time_t now = ::time(0); + lock_guard<mutex> lock(this->m_listlock); + for (auto i = this->m_fileCloseList.begin(); i != this->m_fileCloseList.end(); ++i) { + auto* file = *i; + if (now > file->closeAt) { + debug("Close file run:%6d seq:%5d %s [%7d kB]", + file->runNumber, file->seqNumber, file->fileName.c_str(), + int(file->bytesWritten/1024)); + ::close(file->fileHandle); + this->m_fileCloseList.erase(i); + delete file; + i = this->m_fileCloseList.begin(); + if ( 0 == ((++m_filesClosed)%100) ) { + info("Wrote a total of %ld files Events: %8ld [%7.1f GB]", + m_filesClosed, m_evOut, + double(m_BytesOut)/double(1024*1024*1024)); } + } } - ::lib_rtl_sleep(1000); } + ::lib_rtl_sleep(1000); + } } -void FileWriter::markClose(FileDescr* file, int delay) -{ +void FileWriter::markClose(FileDescr* file, int delay) { /// First part is all synchronous file->runDescriptor->fileDescr = nullptr; - file->closeAt = time(0) + delay; + file->closeAt = ::time(0) + delay; file->state = C_CLOSED; --m_filesOpen; @@ -432,11 +409,10 @@ void FileWriter::markClose(FileDescr* file, int delay) /// This needs to be protected lock_guard<mutex> lock(m_listlock); - m_FileCloseList.push_back(file); + m_fileCloseList.push_back(file); } -FileWriter::FileDescr *FileWriter::openFile(RunDesc* run_desc) -{ +FileWriter::FileDescr *FileWriter::openFile(RunDesc* run_desc) { char text[80]; unsigned int runn = run_desc->runNumber; string file_name = m_filePrefix; @@ -453,50 +429,45 @@ FileWriter::FileDescr *FileWriter::openFile(RunDesc* run_desc) file_name = RTL::str_replace(file_name, "${RUN}", text); ::snprintf(text, sizeof(text), "%07ld", run_desc->num_files); file_name = RTL::str_replace(file_name, "${SEQ}", text); + ::snprintf(text, sizeof(text), "%06d", ::lib_rtl_pid()); + file_name = RTL::str_replace(file_name, "${PID}", text); int indx = getDevice(m_DeviceList); - string flname; - if ( indx >= 0 ) - { - flname = this->m_DeviceList[indx] + "/" + file_name; - flname = fs::path(flname).lexically_normal().string(); + if ( indx < 0 ) { + if ( m_ExitOnError ) { + fatal("===========> FATAL: Cannot find a device with free space. Exiting..."); + ::exit(0); } - else - { - if ( m_ExitOnError ) - { - fatal("===========> FATAL: Cannot find a device with free space. Exiting..."); - ::exit(0); - } - else - { - info("Cannot find a device with free space."); - return nullptr; - } + else { + info("Cannot find a device with free space."); + return nullptr; } + } + string flname = this->m_DeviceList[indx] + "/" + file_name; + flname = fs::path(flname).lexically_normal().string(); fs::path dir = fs::path(flname).parent_path(); - if (!fs::exists(dir)) - { - if (!fs::create_directories(dir)) - { - error("Cannot Create Directory %s %d: [%s]", - dir.c_str(), flname.c_str(), errno, ::strerror(errno)); - return nullptr; - } + if ( !fs::exists(dir) ) { + error_code ec; + if ( !fs::create_directories(dir,ec) ) { + error("Cannot Create Directory %s %d: [%s]", + dir.c_str(), flname.c_str(), ec.value(), ec.message().c_str()); + return nullptr; } + } int fh = ::open(flname.c_str(), O_RDWR + O_CREAT + O_APPEND + O_LARGEFILE + O_NOATIME, S_IRWXU | S_IRWXG | S_IRWXO); - if (fh ==-1) - { - string fmt = "===========> Cannot open file %s %d: [%s]"; - if (errno == EROFS) - fmt = "===========> File System is Read-Only. Cannot open file %s %d: [%s]"; - warning(fmt.c_str(), flname.c_str(), errno, ::strerror(errno)); - return nullptr; + if ( fh ==-1 ) { + auto ec = make_error_code(errc(errno)); + string fmt = "===========> Cannot open file %s %d: [%s]"; + if (errno == EROFS) { + fmt = "===========> File System is Read-Only. Cannot open file %s %d: [%s]"; } + warning(fmt.c_str(), flname.c_str(), errno, ec.message().c_str()); + return nullptr; + } FileDescr *f = new FileDescr(fh, run_desc); f->seqNumber = (run_desc->num_files + 1); @@ -508,74 +479,62 @@ FileWriter::FileDescr *FileWriter::openFile(RunDesc* run_desc) return f; } -void FileWriter::getRODevices() -{ - std::ifstream infile("/proc/mounts"); - std::string line; +void FileWriter::getRODevices() { + ifstream infile("/proc/mounts"); + string line; this->m_roDevices.clear(); - while (std::getline(infile,line)) - { - const char* ptr = line.c_str(); - size_t idx = line.find(' '); - size_t idq = line.find(' ', idx+1); - line[idx] = line[idq] = 0; - for (const auto& dev : m_DeviceList ) - { - if (dev.find(ptr+idx+1) != string::npos) - { - if (line.find(" ro,", idq+1) == string::npos) - { - m_roDevices.insert(dev); - } - } + while ( getline(infile,line) ) { + const char* ptr = line.c_str(); + size_t idx = line.find(' '); + size_t idq = line.find(' ', idx+1); + line[idx] = line[idq] = 0; + for ( const auto& dev : m_DeviceList ) { + if ( dev.find(ptr+idx+1) != string::npos ) { + if ( line.find(" ro,", idq+1) == string::npos ) { + m_roDevices.insert(dev); } + } } + } infile.close(); } -bool FileWriter::roDevice(const std::string& dev) -{ +bool FileWriter::roDevice(const string& dev) { return (m_roDevices.find(dev) != m_roDevices.end()); } -int FileWriter::getDevice(std::vector<std::string> &devlist) -{ - +int FileWriter::getDevice(vector<string> &devlist) { struct statvfs fsstat; fsblkcnt_t fblock = 0; size_t maxindx = -1; getRODevices(); - for (size_t i = 0; i < devlist.size(); i++) - { - size_t idx = devlist[i].find("/",1); - std::string root = idx == std::string::npos ? devlist[i] : devlist[i].substr(0,idx); - if ( roDevice(root) ) continue; - int stat = ::statvfs(root.c_str(), &fsstat); - if (stat == 0) - { - if (fsstat.f_bfree > fblock) - { - fblock = fsstat.f_bfree; - maxindx = i; - } - } + for (size_t i = 0; i < devlist.size(); i++) { + size_t idx = devlist[i].find("/",1); + string root = idx == string::npos ? devlist[i] : devlist[i].substr(0,idx); + if ( roDevice(root) ) continue; + int stat = ::statvfs(root.c_str(), &fsstat); + if (stat == 0) { + if (fsstat.f_bfree > fblock) { + fblock = fsstat.f_bfree; + maxindx = i; + } } + } return maxindx; } -void FileWriter::createMonitoringInfo(unsigned int runn) -{ +void FileWriter::createMonitoringInfo(unsigned int runn) { if ( m_dimMonitoring ) { RunDesc *run_desc = m_RunList[runn]; - std::string namePref; + string namePref; char cRunNo[255]; sprintf(cRunNo, "%d/", runn); // namePref = m_input+"/"; namePref += cRunNo; - std::string comm; + string comm; comm = "Number of Files"; - std::string mnam = namePref + "NoFiles"; + string mnam = namePref + "NoFiles"; declareMonitor(namePref + "NoFiles", run_desc->num_files, comm.c_str()); comm = "Number of MEPs"; mnam = namePref + "MEPs"; @@ -586,8 +545,7 @@ void FileWriter::createMonitoringInfo(unsigned int runn) } } -std::string FileWriter::fileTime() -{ +string FileWriter::fileTime() { struct timeval tv; char buffer[128]; @@ -595,72 +553,62 @@ std::string FileWriter::fileTime() struct tm *timeinfo = ::localtime(&tv.tv_sec); ::strftime(buffer, sizeof(buffer), "%Y%m%d-%H%M%S-", timeinfo); ::snprintf(buffer+strlen(buffer), sizeof(buffer)-strlen(buffer),"%03ld", tv.tv_usec/1000); - return std::string(buffer); + return string(buffer); } -void FileWriter::handleFileWriteError() -{ - std::string node = m_node; +void FileWriter::handleFileWriteError() { + string node = m_node; for (unsigned int i = 0; i < node.size(); i++) node[i] = toupper(node[i]); - std::string cmdname = node + "_MEPRx_01/setOverflow"; + string cmdname = node + "_MEPRx_01/setOverflow"; DimClient::sendCommand(cmdname.c_str(), 2); } -ssize_t FileWriter::write(FileDescr* dsc, const void *buf, size_t n) -{ +ssize_t FileWriter::write(FileDescr* dsc, const void *buf, size_t n) { const char *cbuf = (const char*) buf; size_t towrite = n; int status = 0; int nintr_max = 2; int fd = dsc->fileHandle; - while (towrite > 0) - { - status = ::write(fd, cbuf, towrite); - if (status > 0) - { - towrite = towrite - status; - cbuf += status; + while (towrite > 0) { + status = ::write(fd, cbuf, towrite); + if (status > 0) { + towrite = towrite - status; + cbuf += status; + continue; + } + else if (status == 0) { + info("0 Bytes written! Ignoring MEP"); + status = -1; + return status; + } + else if (status == -1) { + auto err = make_error_code(errc(errno)); + if (err.value() == EIO || err.value() == ENOSPC) { + info("File Write Error (IO or NoSpace): Errno = %d [%s]",err.value(),err.message().c_str()); + handleFileWriteError(); + status = -1; + return status; + } + else if (err.value() == EINTR) { + nintr_max--; + if (nintr_max > 0) { continue; } - else if (status == 0) - { - info("0 Bytes written! Ignoring MEP"); + else { status = -1; return status; } - else if (status == -1) - { - if (errno == EIO || errno == ENOSPC) - { - info("File Write Error (IO or NoSpace): Errno = %d [%s]",errno,::strerror(errno)); - handleFileWriteError(); - status = -1; - return status; - } - else if (errno == EINTR) - { - nintr_max--; - if (nintr_max > 0) - { - continue; - } - else - { - status = -1; - return status; - } - } - else - { - info("File Write Error: Errno = %d [%s]",errno,::strerror(errno)); - handleFileWriteError(); - status = -1; - return status; - } - } + } + else { + info("File Write Error: Errno = %d [%s]",err.value(),err.message().c_str()); + handleFileWriteError(); + status = -1; + return status; + } } + } status = 0; return status; } diff --git a/Online/Dataflow/src/components/FileWriter.h b/Online/Dataflow/src/components/FileWriter.h index ff9a06f8b945f0044e8163a0a74d930ef1efc479..8c4a24dc2018efbf471de12b7fe3ac9cb5626d46 100755 --- a/Online/Dataflow/src/components/FileWriter.h +++ b/Online/Dataflow/src/components/FileWriter.h @@ -58,7 +58,7 @@ namespace Online { /// Property: Request specification Requirements m_req; - ///File Prefix String. Filename wil be m_FilePrefix + Runnumber + _FileWriter+.mdf + ///File Prefix String. Filename wil be m_filePrefix + Runnumber + _FileWriter+.mdf std::string m_filePrefix; ///Limit on the filesize in MB=1024*1024 Bytes std::vector<std::string> m_DeviceList; @@ -88,15 +88,15 @@ namespace Online { /// Monitoring quantity: Bytes Written to file long m_BytesOut; /// Monitoring quantity: Number of Event in - long m_EvIn; + long m_evIn; /// Monitoring quantity: Number of Event out - long m_EvOut; + long m_evOut; - FileDescr *m_FileDesc; + FileDescr *m_fileDesc; std::string m_node; ///List of runs and descriptors; std::map<unsigned int,RunDesc*> m_RunList; - std::list<FileDescr*> m_FileCloseList; + std::list<FileDescr*> m_fileCloseList; std::set<std::string> m_roDevices; std::unique_ptr<std::thread> m_thread; long m_evt_number {0}; diff --git a/Online/Dataflow/src/framework/ComponentHandler.cpp b/Online/Dataflow/src/framework/ComponentHandler.cpp index 53c99842ed456244c1eebf960fb67cf27eaa907d..506ef89fe470e47fcc3c87e7f1e5505da328b630 100755 --- a/Online/Dataflow/src/framework/ComponentHandler.cpp +++ b/Online/Dataflow/src/framework/ComponentHandler.cpp @@ -38,7 +38,7 @@ int ComponentHandler::destruct(Component* c) const { int ComponentHandler::setProperties(Component* c) const { int sc = c->setProperties(); if ( sc == DF_SUCCESS ) { - c->info("Successfully set properties to component."); + c->debug("Successfully set properties to component."); return sc; } return fail(c,"Failed to set the component properties. Initialization will stop."); diff --git a/Online/Dataflow/src/framework/DataflowManager.cpp b/Online/Dataflow/src/framework/DataflowManager.cpp index a788e9777e2ef3cfb9e311906dad0b1349f475ed..e8c29b96b3168d70a473ab3f5bb1e304eef386ad 100755 --- a/Online/Dataflow/src/framework/DataflowManager.cpp +++ b/Online/Dataflow/src/framework/DataflowManager.cpp @@ -23,6 +23,8 @@ #include <Dataflow/Incidents.h> #include <Dataflow/Plugins.h> #include <Tell1Data/Tell1Decoder.h> +#include <PCIE40Data/pcie40.h> +#include <PCIE40Data/sodin.h> #include <MBM/bmdef.h> // C/C++ include files @@ -33,29 +35,68 @@ using namespace Online; #include <setjmp.h> #include <signal.h> #include <string.h> -static jmp_buf __ReadCheckEnv; -static void segvTestHandler(int , siginfo_t *, void *) -{ - longjmp(__ReadCheckEnv,27); -} -int CheckRead(void *add) -{ - struct sigaction act; - struct sigaction oldact; - memset (&act,0,sizeof(act)); - act.sa_sigaction = &segvTestHandler; - act.sa_flags = SA_SIGINFO; - sigaction(SIGSEGV,&act,&oldact); - int ret=setjmp(__ReadCheckEnv); - if (ret == 27) - { - sigaction(SIGSEGV,&oldact,0); - return 1; - } - char dummy = *(char*)add; - if ( dummy ) {} - ::sigaction(SIGSEGV,&oldact,0); - return 0; + +namespace { + + static jmp_buf __ReadCheckEnv; + + static void segvTestHandler(int , siginfo_t *, void *) { + longjmp(__ReadCheckEnv,27); + } + + int CheckRead(void *add) { + struct sigaction act; + struct sigaction oldact; + memset (&act,0,sizeof(act)); + act.sa_sigaction = &segvTestHandler; + act.sa_flags = SA_SIGINFO; + sigaction(SIGSEGV,&act,&oldact); + int ret=setjmp(__ReadCheckEnv); + if (ret == 27) + { + sigaction(SIGSEGV,&oldact,0); + return 1; + } + char dummy = *(char*)add; + if ( dummy ) {} + ::sigaction(SIGSEGV,&oldact,0); + return 0; + } + + int _get_run_number(const DataflowContext::EventData& event) { + EventHeader* mdf = event.header; + if ( mdf->is_mdf() ) { + // We got an MDF header. Determine the run number and pass it to the monitoring service + return mdf->subHeader().H1->runNumber(); + } + const pcie40::mep_header_t* mep = event.as<pcie40::mep_header_t>(); + if ( mep->is_valid() ) { + if ( mep->num_source > 0 ) { + for(uint32_t i=0; i<mep->num_source; ++i) { + const auto *mfp = mep->multi_fragment(i); + const uint8_t *typs = mfp->types(); + if ( mfp->packingFactor() > 0 && *typs != RawBank40::ODIN ) + continue; + const uint8_t version = mfp->header.version; + if ( version < 7 ) { + const auto *odin = (const RunInfo*)mfp->data(); + return odin->run_number(); + } + else { + const auto *odin = (const pcie40::sodin_t*)mfp->data(); + return odin->run_number(); + } + } + // In case there is no ODIN: + return 0; + } + return -1; + } + if ( event.type == EVENT_TYPE_MEP ) { + return 0; + } + return -1; + } } /// Initializing constructor @@ -455,20 +496,14 @@ int DataflowManager::execute(const DataflowContext::EventData& event) { try { ComponentHandler handler(context); - EventHeader* mdf = event.header; - int rchk; - rchk = CheckRead(mdf); + int rchk = CheckRead(event.header); if (rchk != 0) { error("=======> Got Event without Data (event start at address %p not readable).", (void*)event.data); return DF_ERROR; } - if ( mdf->size0() == mdf->size1() && mdf->size0() == mdf->size2() ) { - // We got an MDF header. Determine the run number and pass it to the monitoring service - setRunNumber(mdf->subHeader().H1->runNumber()); - m_numBadEvent = 0; - } - else if ( event.type == EVENT_TYPE_MEP ) { - setRunNumber(0); + int runno = _get_run_number(event); + if ( runno >= 0 ) { + setRunNumber(runno); m_numBadEvent = 0; } else { diff --git a/Online/Dataflow/src/framework/MBMClient.cpp b/Online/Dataflow/src/framework/MBMClient.cpp index c0c215ea6ac9d16e5868b8435eb9d94c67972538..e720be2e2a40076093968ebd9f059417505b9ce0 100755 --- a/Online/Dataflow/src/framework/MBMClient.cpp +++ b/Online/Dataflow/src/framework/MBMClient.cpp @@ -84,9 +84,9 @@ int MBMClient::stop() { int MBMClient::i_init() { setProperties(); m_procName = RTL::processName(); - info("%s> Connecting to MBM Buffers.",m_connectWhen.c_str()); if ( DF_SUCCESS != connectBuffers() ) - return error("Failed to connect to MBM buffers!"); + return error("%s: Failed to connect to MBM buffers!",m_connectWhen.c_str()); + debug("%s: Connecting to MBM Buffers.",m_connectWhen.c_str()); return DF_SUCCESS; } @@ -134,13 +134,13 @@ int MBMClient::connectBuffer(const std::string& nam) { bmid = ::mbm_include(bm_name.c_str(),m_procName.c_str(),m_partitionID,BM_COM_UNIX,flags); if ( bmid == MBM_INV_DESC ) { - return error("Failed to connect to buffer '%s' as '%s'", - bm_name.c_str(),m_procName.c_str()); + return error("%s: Failed to connect to buffer '%s' as '%s'", + m_connectWhen.c_str(), bm_name.c_str(), m_procName.c_str()); } - //info("MBM Client : adding MBM %s \n", ((std::string*)bmid)->c_str()); m_bmIDs.push_back(bmid); m_buffMap[bm_name] = bmid; m_buffMap[nam] = bmid; + debug("%s: Included in MBM buffer: '%s'", m_connectWhen.c_str(), nam.c_str()); } return DF_SUCCESS; } @@ -148,12 +148,9 @@ int MBMClient::connectBuffer(const std::string& nam) { /// Connect to specified buffers int MBMClient::connectBuffers() { if ( m_buffers.size() > 0 ) { - for(auto i=m_buffers.begin(); i != m_buffers.end(); ++i ) { - const string& nam = *i; - if ( DF_SUCCESS != connectBuffer(nam) ) - return error("Failed to connect to MBM buffer: '%s'",nam.c_str()); - else - debug("Included in MBM buffer: '%s'",nam.c_str()); + for(const auto& nam : m_buffers ) { + int sc = connectBuffer(nam); + if ( DF_SUCCESS != sc ) return DF_ERROR; } } return DF_SUCCESS; @@ -161,10 +158,10 @@ int MBMClient::connectBuffers() { /// Cancel MBM connections int MBMClient::cancelBuffers() { - for(auto i=m_bmIDs.begin(); i != m_bmIDs.end(); ++i) { - if ( *i != MBM_INV_DESC ) ::mbm_cancel_request(*i); + for(auto bmid : m_bmIDs) { + if ( bmid != MBM_INV_DESC ) ::mbm_cancel_request(bmid); } - info("Executed cancellation of pending I/O requests."); + info("Cancelled pending MBM I/O requests."); return DF_SUCCESS; } diff --git a/Online/Dataflow/src/framework/Receiver.cpp b/Online/Dataflow/src/framework/Receiver.cpp index b4f9f7792b47578409f54e0a8fe5ecc6505544cd..391fd16108fa7e7001dab17a80cdbe94e18ec7eb 100755 --- a/Online/Dataflow/src/framework/Receiver.cpp +++ b/Online/Dataflow/src/framework/Receiver.cpp @@ -209,6 +209,7 @@ void Receiver::setMbmMask(MBM::EventDesc& e) const { e.mask[1] = ~0x0; e.mask[2] = ~0x0; e.type = EVENT_TYPE_MEP; + context.manager.setRunNumber(0); } else if ( hd->is_mdf() && e.len > hd->size0() ) { /// Need to set all mask values to not block sub-events @@ -216,6 +217,7 @@ void Receiver::setMbmMask(MBM::EventDesc& e) const { e.mask[1] = ~0x0; e.mask[2] = ~0x0; e.type = EVENT_TYPE_EVENT; // burst type not used anymore! + context.manager.setRunNumber(hd->subHeader().H1->runNumber()); } else if ( hd->is_mdf() && e.len == hd->size0() ) { auto m = hd->subHeader().H1->triggerMask(); @@ -223,6 +225,7 @@ void Receiver::setMbmMask(MBM::EventDesc& e) const { e.mask[1] = m[1]; e.mask[2] = m[2]; e.type = EVENT_TYPE_EVENT; + context.manager.setRunNumber(hd->subHeader().H1->runNumber()); } if ( 0 != m_routingMask ) { e.mask[3] &= ~m_vetoMask; diff --git a/Online/EventData/EventData/EventAccess.h b/Online/EventData/EventData/EventAccess.h index 9189237d885c405cc637f8508226b80ea2b6ab9a..78bdf0d2490b02851cd2117f2a9237a0ddc88125 100644 --- a/Online/EventData/EventData/EventAccess.h +++ b/Online/EventData/EventData/EventAccess.h @@ -64,7 +64,7 @@ namespace Online { class guard_t { public: std::atomic<std::size_t> consumed_len { 0 }; - std::size_t frame_curr { 0 }; + std::atomic<std::size_t> frame_curr { 0 }; protected: std::size_t bx_len { 0 }; std::size_t frame_len { 0 }; diff --git a/Online/EventData/src/EventAccess.cpp b/Online/EventData/src/EventAccess.cpp index 8ae066d4c9979c34c9b998cdb1b54df5451becf7..3365096b335cdc4b67a8e6ea6ced87ba62a584a8 100644 --- a/Online/EventData/src/EventAccess.cpp +++ b/Online/EventData/src/EventAccess.cpp @@ -87,6 +87,7 @@ namespace { EventAccess::event_t event(eid+hw, guard); size_t len = 2*hw; guard->consumed_len += len; + ++guard->frame_curr; { EventAccess::lock_t lock(acc->m_eventLock); acc->monitor.framesTAE += 1; @@ -107,6 +108,10 @@ namespace { } return event; } + EventAccess::event_t _extract_pcie40(EventAccess* /* acc */, size_t eid, EventAccess::shared_guard_t& guard) { + ++guard->frame_curr; + return {eid, guard}; + } } /// Standard constructor @@ -225,11 +230,32 @@ EventAccess::event_t EventAccess::dequeueEvent(shared_guard_t& loop_context) { // We exclude [-laf-window, +half-window] events from the iteration // We need to attach the prevX, nextN fragments // later at the proper locations in the TES - if( record.tell40_event->is_tae() ) { - event = _extract_tae_pcie40(this, eid, loop_context); + if( record.tell40_event->is_tae_central() ) { + event = ::_extract_tae_pcie40(this, eid, loop_context); + } + else if( !record.tell40_event->is_tae() ) { + event = ::_extract_pcie40(this, eid, loop_context); } - else { - event = event_t(eid, loop_context); + else { + /// Skip all TAE fragments until we got the central TAE event. + /// Return the central TAE event or the next regular event + for( uint8_t iw=1, hw = record.tell40_event->tae_half_window(); iw<=2*hw; ++iw ) { + std::size_t id = eid+iw; + if ( id >= loop_context->num_bx() ) { + loop_context.reset(); + return event_t(0, shared_guard_t()); + } + const auto* ev = record_t(loop_context->at(id)).tell40_event; + if ( ev->is_tae_central() ) { + event = ::_extract_tae_pcie40(this, id, loop_context); + break; + } + if ( !ev->is_tae() ) { + event = ::_extract_pcie40(this, id, loop_context); + break; + } + continue; + } } } else if( loop_context->type() == event_traits::tell1::data_type ) { @@ -371,51 +397,36 @@ EventAccess::convertPCIE40MEP(datapointer_t start, size_t len) { m_logger->info("convertMEP: Event with TOO MANY banks encountered"); } /// frame counter with correction for TAE multi-frames - coll = ev->bank_collection(pcie40::params::collection_id_ODIN); - if ( coll && coll->num_banks() > 0 ) { - auto* sodin = coll->at(0)->begin<pcie40::sodin_t>(); - auto central = sodin->tae_central(); - auto window = sodin->tae_window(); - if ( central ) - ++events.first; - else if ( window == 0 ) - ++events.first; + auto window = ev->tae_half_window(); + if ( ev->is_tae_central() || window == 0 ) + ++events.first; - /// Run a few basic checks over the resulting TAE frame - if ( central ) { - bool error = false; - for(int iw = -window; iw <= window; ++iw) { - int id = i+iw; - auto* e = events.second->at(id); - if ( e->tae_half_window() != window ) { - error = true; - m_logger->warning("+++ Inconsistent TAE half window %d != %d BX: %ld", - int(e->tae_half_window()), int(window), id); - } - if ( iw == 0 && !e->is_tae_central() ) { - error = true; - m_logger->warning("+++ Detected missing TAE central BX %ld", id); - } - else if ( iw != 0 && e->is_tae_central() ) { - error = true; - m_logger->warning("+++ Detected false TAE central BX %ld", id); - } - } - if ( error ) { - --events.first; + /// Run a few basic checks over the resulting TAE frame + if ( ev->is_tae_central() ) { + for(int iw = -window; iw <= window; ++iw) { + int id = i+iw; + auto* e = events.second->at(id); + if ( e->tae_half_window() != window ) { + m_logger->warning("+++ Inconsistent TAE half window %d != %d BX: %ld", + int(e->tae_half_window()), int(window), id); } - } - if ( dbg ) { - int hw = sodin->tae_window(); - if ( sodin->tae_central() ) { - m_logger->always("convertMEP: TAE at %ld window: %d [%ld, %ld, %ld] frames:%ld", - i, hw, i-hw, i, i+hw, events.first); + if ( iw == 0 && !e->is_tae_central() ) { + m_logger->warning("+++ Detected missing TAE central BX %ld", id); } - else if ( hw == 0 ) { - m_logger->always("convertMEP: Evt at %ld frames:%ld", i, events.first); + else if ( iw != 0 && e->is_tae_central() ) { + m_logger->warning("+++ Detected false TAE central BX %ld", id); } } } + if ( dbg ) { + if ( ev->is_tae_central() ) { + m_logger->always("convertMEP: TAE at %ld window: %d [%ld, %ld, %ld] frames:%ld", + i, window, i-window, i, i+window, events.first); + } + else if ( window == 0 ) { + m_logger->always("convertMEP: Evt at %ld frames:%ld", i, events.first); + } + } } if ( dbg ) { m_logger->warning("convertMEP: Got MEP with %ld frames", events.first); diff --git a/Online/EventData/src/EventHandler.cpp b/Online/EventData/src/EventHandler.cpp index b5ec8db06ab4f3911f1dad39018b696c3eba351f..0ffb6c94a679d1b16922f70b419e2281b065b631 100644 --- a/Online/EventData/src/EventHandler.cpp +++ b/Online/EventData/src/EventHandler.cpp @@ -183,6 +183,7 @@ namespace Online { return {bank, bank->data()}; size_t len = bank->totalSize(); start += len; + // Protect against infinite loop in case of data corruption if ( 0 == len ) break; } } diff --git a/Online/FarmConfig/job/AddersFromArchitecture.py b/Online/FarmConfig/job/AddersFromArchitecture.py index 2a0b1b9c32b9503d8277e208ec2be4c19271a497..877a6da36e3416ff8a695190c34322be0f7bcc41 100644 --- a/Online/FarmConfig/job/AddersFromArchitecture.py +++ b/Online/FarmConfig/job/AddersFromArchitecture.py @@ -1,14 +1,18 @@ from xml.dom import minidom -import sys import os -import OnlineEnvBase -import re -import socket +import Gaudi +import Configurables +from GaudiOnline import Application +from GauchoAppl import GauchoApplConf + +ApplicationMgr = Gaudi.Configuration.ApplicationMgr CounterDebugSvcs = ["DskWriter"] -HistDebugSvcs =["AligWrk"] -vnode=False +HistDebugSvcs = ["AligWrk"] +vnode = False def VictimNode(): + import socket + import re victimnodes_re = [] vnodes="" vnodes=os.getenv("victimnodes","") @@ -16,7 +20,7 @@ def VictimNode(): victimnodes = vnodes.split(",") for i in victimnodes: victimnodes_re.append(re.compile(i,re.IGNORECASE)) - hname=socket.gethostname().split('.')[0] + hname = socket.gethostname().split('.')[0] for i in victimnodes_re: if i.match(hname) != None: return True @@ -29,424 +33,136 @@ def TaskListfromArch(arch, tasklist): nam = s.attributes['name'] # if not nam.find('MEPR')>=0: tasklist.append(s.attributes['name'].value) -def AddersfromTasks -def OptionsfromTasks(tasklist,level,ofile,pname,dohostdns): - f = open(ofile,'w') - f.write("// Adder Level "+level+"=====================\n") - if vnode: - f.write("// This is a victim node\n") - if level=="1": - if pname=="LHCb": - f.write("""#include "$INFO_OPTIONS" -ApplicationMgr.ExtSvc += {"MonitorSvc"}; - -ApplicationMgr.EventLoop = "LHCb::OnlineRunable/EmptyEventLoop"; -ApplicationMgr.Runable = "LHCb::OnlineRunable/Runable"; -ApplicationMgr.HistogramPersistency = "NONE"; -ApplicationMgr.EvtSel = "NONE"; - -Runable.Wait = 3; // 1 of running as daemon (Class1 task) - -MessageSvc.fifoPath = "$LOGFIFO"; -MessageSvc.OutputLevel = @OnlineEnv.OutputLevel; -MonitorSvc.OutputLevel = @OnlineEnv.OutputLevel; -HistogramPersistencySvc.Warnings = false; -MonitorSvc.CounterUpdateInterval = 5; -""") - else: - f.write("""#include "$INFO_OPTIONS" -ApplicationMgr.ExtSvc += {"MonitorSvc"}; - -ApplicationMgr.EventLoop = "LHCb::OnlineRunable/EmptyEventLoop"; -ApplicationMgr.Runable = "LHCb::OnlineRunable/Runable"; -ApplicationMgr.HistogramPersistency = "NONE"; -ApplicationMgr.EvtSel = "NONE"; - -Runable.Wait = 3; // 1 of running as daemon (Class1 task) - -MessageSvc.fifoPath = "$LOGFIFO"; -MessageSvc.OutputLevel = @OnlineEnv.OutputLevel; -MonitorSvc.OutputLevel = @OnlineEnv.OutputLevel; -HistogramPersistencySvc.Warnings = false; -MonitorSvc.CounterUpdateInterval = 5; -""") + +class AdderApp(Application): + def __init__(self, outputLevel, partitionName='OFFLINE', partitionID=0xFFFF, adders=[]): + import _fifo_log + Application.__init__(self, + outputLevel=outputLevel, + partitionName=partitionName, + partitionID=partitionID) + # First setup printing device: + self.config.logDeviceType = 'RTL::Logger::LogDevice' + self.config.logDeviceFormat = '%-8LEVEL %-24SOURCE' + self.config.logDeviceType = 'fifo' + _fifo_log.logger_set_tag(partitionName) + _fifo_log.logger_start() + # Now the rest: + self.config.numEventThreads = 0 + self.config.numStatusThreads = 0 + utgid = os.getenv("UTGID","") + self.config.autoStart = False + self.app = ApplicationMgr() + self.app.MessageSvcType = 'MessageSvc' + self.app.EvtSel = 'NONE' + self.app.EvtMax = -1 + self.app.AppName = utgid + self.app.HistogramPersistency = "NONE" + self.app.EvtSel = "NONE"; + self.app.ExtSvc = adders + +def AddersfromTasks(tasklist, level, pname, dohostdns, alist): + if level=="1": + InDns = os.getenv("InDns","<dns>") + OutDns = os.getenv("OutDns","<dns>") + elif level=="2" or level=="2.1": + InDns = os.getenv("InDns","<node>") + OutDns = os.getenv("OutDns","mon01") + elif level=="2.0" or level=="2.1": + InDns = os.getenv("InDns","<node>") + OutDns = os.getenv("OutDns","mon01") + elif level == "3": + InDns = os.getenv("InDns","hlt01") + OutDns = os.getenv("OutDns","mon01") + elif level == "3.1": + InDns = os.getenv("InDns","mon01") + OutDns = os.getenv("OutDns","mon01") + elif level == "4": + InDns = os.getenv("InDns","mon01") + OutDns = os.getenv("OutDns","mon01") + if level=="1": + for t in tasklist: + if 'NodeAdder' in t: + continue + if 'AligAdder' in t: + continue + tn = str(t) + myname = "<part>_<node>_"+tn + + adder = GauchoApplConf.AdderSvc("C_"+tn) + adder.InDNS = InDns + adder.OutDNS = OutDns + adder.MyName = myname + adder.PartitionName = pname + adder.TaskPattern = "<part>_<node>_"+tn + adder.ServicePattern = "MON_<part>_<node>_"+tn+"_(.*)/Counter/" + adder.RunAware = False + adder.AdderClass="counter" + adder.DebugOn=False + alist.append(adder) + + adder = GauchoApplConf.AdderSvc("H_"+tn) + adder.InDNS = InDns + adder.OutDNS = OutDns + adder.MyName = myname + adder.PartitionName = pname + adder.TaskPattern = "<part>_<node>_"+tn + adder.ServicePattern = "MON_<part>_<node>_"+tn+"_(.*)/Histos/" + adder.RunAware = False + adder.AdderClass="hists" + # CAddSv.RunAware=True + adder.DebugOn=False + alist.append(adder) + + elif level=="2.0" or level=="2.1": + tpatt="" + if level=="2.0": + nodpatt="<part>_[a-z][a-z]eb[0-9][0-9]"#_EBNodeAdder_" + tpatt=nodpatt+"_EBNodeAdder_" else: - f.write("""#include "$INFO_OPTIONS" -ApplicationMgr.ExtSvc += {"MonitorSvc"}; -ApplicationMgr.EventLoop = "LHCb::OnlineRunable/EmptyEventLoop"; -ApplicationMgr.Runable = "LHCb::OnlineRunable/Runable"; -ApplicationMgr.HistogramPersistency = "NONE"; -ApplicationMgr.EvtSel = "NONE"; - -Runable.Wait = 3; // 1 of running as daemon (Class1 task) - -MessageSvc.fifoPath = "$LOGFIFO"; -MessageSvc.OutputLevel = @OnlineEnv.OutputLevel; -MonitorSvc.OutputLevel = @OnlineEnv.OutputLevel; -HistogramPersistencySvc.Warnings = false; -MonitorSvc.CounterUpdateInterval = 5; -""") - - if level=="1": - InDns = os.getenv("InDns","<dns>") - OutDns = os.getenv("OutDns","<dns>") - InDns = "\""+InDns+"\"" - OutDns = "\""+OutDns+"\"" - if level =="2": - InDns = os.getenv("InDns","<node>") - OutDns = os.getenv("OutDns","hlt01") - InDns = "\""+InDns+"\"" - OutDns = "\""+OutDns+"\"" - elif level == "3": - InDns = os.getenv("InDns","hlt01") - OutDns = os.getenv("OutDns","mona08") - InDns = "\""+InDns+"\"" - OutDns = "\""+OutDns+"\"" - elif level == "3.1": - InDns = os.getenv("InDns","mona08") - OutDns = os.getenv("OutDns","mona08") - InDns = "\""+InDns+"\"" - OutDns = "\""+OutDns+"\"" - elif level == "4": - InDns = os.getenv("InDns","mona08") - OutDns = os.getenv("OutDns","mona08") - InDns = "\""+InDns+"\"" - OutDns = "\""+OutDns+"\"" - if level == "1": - histsvc = [] - cntsvc = [] - for s in tasklist: - if 'NodeAdder' in s: - continue - if 'AligAdder' in s: - continue - hsvc = s#+"HistAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+hsvc+"HistAdder\"};\n") - csvc = s#+"CountAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+csvc+"CountAdder\"};\n") - histsvc.append(hsvc) - cntsvc.append(csvc) - f.write("\n") + nodpatt="<part>_<node>[0-9][0-9]"#_NodeAdder_" + tpatt=nodpatt+"_NodeAdder_" + for t in tasklist: + tn = str(t) + myname = "<part>_<node>_"+tn + adder = GauchoApplConf.AdderSvc("C_"+tn) + adder.InDNS = InDns + adder.OutDNS = OutDns + # CAddSv.OutDNS = "fmc01" + adder.MyName=myname + adder.PartitionName = pname + adder.TaskPattern = tpatt + adder.ServicePattern = "MON_"+nodpatt+"_"+tn+"/Counter/" + adder.RunAware = False + adder.AdderClass="counter" + # CAddSv.RunAware=True + adder.DebugOn=False + alist.append(adder) + adder = GauchoApplConf.AdderSvc("H_"+tn) + adder.InDNS = InDns + adder.OutDNS = OutDns + # CAddSv.OutDNS = "fmc01" + adder.MyName=myname + adder.PartitionName = pname + adder.TaskPattern = tpatt + adder.ServicePattern = "MON_"+nodpatt+"_"+tn+"/Histos/" + adder.RunAware = False + adder.AdderClass="hists" + # CAddSv.RunAware=True + adder.DebugOn=False + alist.append(adder) - for s in histsvc: - svc = s+"HistAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_<node>_"+s+"\";\n") - f.write(svc+".TaskPattern = \"<part>_<node>_"+s+"_(.*)\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_<node>_"+s+"_(.*)/Histos/\";\n") - f.write(svc+".AdderClass = \"hists\";\n") - f.write(svc+".ReceiveTimeout = 5;\n") - f.write("\n") - if dohostdns: - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - if pname == "LHCbA": # overwrite certain options for the Alignment... - f.write(svc+".SaveInterval = -1;\n"); - f.write(svc+".SaveonUpdate = false;\n"); - f.write(svc+".SaveSetTaskName= \""+svc+"\";\n"); - f.write(svc+".ReceiveTimeout = 1;\n") - if pname =="LHCbA": - f.write(svc+".EoRTmoFactor = 2;\n") -# f.write(svc+".DebugOn = true;\n") - f.write(svc+".GotoPause = false;\n") -# f.write(svc+".DebugOn = true;\n") - if vnode: - if s in HistDebugSvcs: - f.write(svc+".DebugOn = true;\n") - for s in cntsvc: - svc = s+"CountAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_<node>_"+s+"\";\n") - f.write(svc+".TaskPattern = \"<part>_<node>_"+s+"_(.*)\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_<node>_"+s+"_(.*)/Counter/\";\n") - f.write(svc+".AdderClass = \"Counter\";\n") - f.write(svc+".ReceiveTimeout = 4;\n") - if vnode: - if s in CounterDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA": - f.write(svc+".GotoPause = false;\n") - f.write(svc+".ReceiveTimeout = 0;\n") - if dohostdns: - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - f.write("\n") -# s = "BusyMon" -# svc = s+"CountAdder" -# f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") -# f.write(svc+".MyName = \"<part>_<node>_"+s+"\";\n") -# f.write(svc+".TaskPattern = \"GEN_<node>_"+s+"\";\n") -# f.write(svc+".ServicePattern = \"MON_GEN_<node>_"+s+"/Counter/\";\n") -# f.write(svc+".AdderClass = \"Counter\";\n") -# f.write(svc+".ReceiveTimeout = 2;\n") - if vnode: - if s in CounterDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA": - f.write(svc+".GotoPause = false;\n") - f.write(svc+".ReceiveTimeout = 0;\n") - if dohostdns: - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - f.write("\n") - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+svc+"\"};\n") - elif level == "2": -# f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+"BusyAdder"+"CountAdder\"};\n") -# f.write(""" -# BusyAdderCountAdder.MyName = "<part>_<node>_BusySvc"; -# BusyAdderCountAdder.PartitionName = @OnlineEnv.PartitionName; -# BusyAdderCountAdder.TaskPattern = "<part>_<node>[0-9][0-9]_NodeAdder_0"; -# BusyAdderCountAdder.ServicePattern = "MON_<part>_<node>[0-9][0-9]_BusyMon/Counter/"; -# BusyAdderCountAdder.AdderClass = "Counter"; -# BusyAdderCountAdder.ReceiveTimeout = 6; -# """) -# f.write("BusyAdderCountAdder.InDns = "+InDns+";\n") -# f.write("BusyAdderCountAdder.OutDns = "+OutDns+";\n") - histsvc = [] - cntsvc = [] - for s in tasklist: - if 'SubFarmAdder' in s: - continue - hsvc = s#+"HistAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+hsvc+"HistAdder\"};\n") - csvc = s#+"CountAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+csvc+"CountAdder\"};\n") - histsvc.append(hsvc) - cntsvc.append(csvc) - f.write("\n") - - for s in histsvc: - svc = s+"HistAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_<node>_"+s+"\";\n") - f.write(svc+".TaskPattern = \"<part>_<node>[0-9][0-9]_NodeAdder_0\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_<node>[0-9][0-9]_"+s+"/Histos/\";\n") - f.write(svc+".AdderClass = \"hists\";\n") - f.write(svc+".ReceiveTimeout = 8;\n") - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - if vnode: - if s in HistDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA": # overwrite certain options for the Alignment... - f.write(svc+".SaveInterval = -1;\n"); - f.write(svc+".SaveonUpdate = false;\n"); - f.write(svc+".SaveSetTaskName= \""+svc+"\";\n"); - f.write(svc+".ReceiveTimeout = 2;\n") - f.write(svc+".EoRTmoFactor = 8;\n") -# f.write(svc+".DebugOn = true;\n") - f.write("\n") - - - for s in cntsvc: - svc = s+"CountAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_<node>_"+s+"\";\n") - f.write(svc+".TaskPattern = \"<part>_<node>[0-9][0-9]_NodeAdder_0\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_<node>[0-9][0-9]_"+s+"/Counter/\";\n") - f.write(svc+".ReceiveTimeout = 8;\n") - f.write(svc+".AdderClass = \"Counter\";\n") - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - if vnode: - if s in CounterDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA": - f.write(svc+".GotoPause = true;\n") - f.write(svc+".ReceiveTimeout = 0;\n") - f.write("\n") - elif level == "3": -# f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+"BusyAdder"+"CountAdder\"};\n") -# f.write(""" -# BusyAdderCountAdder.MyName = "<part>_Busy_00"; -# BusyAdderCountAdder.PartitionName = @OnlineEnv.PartitionName; -# BusyAdderCountAdder.TaskPattern = "<part>_hlt[a-z][0-9][0-9]_SubFarmAdder_0"; -# BusyAdderCountAdder.ServicePattern = "MON_<part>_hlt[a-z][0-9][0-9]_BusySvc/Counter/"; -# BusyAdderCountAdder.AdderClass = "Counter"; -# BusyAdderCountAdder.ReceiveTimeout = 8; -# """) -# f.write("BusyAdderCountAdder.InDns = "+InDns+";\n") -# f.write("BusyAdderCountAdder.OutDns = "+OutDns+";\n") - histsvc = [] - cntsvc = [] -# histsvc.append("Adder") -# cntsvc.append("BusySvc") -# tasklist.remove("MEPrx") - for s in tasklist: - hsvc = s#+"HistAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+hsvc+"HistAdder\"};\n") - csvc = s#+"CountAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+csvc+"CountAdder\"};\n") - histsvc.append(hsvc) - cntsvc.append(csvc) - f.write("\n") - - for s in histsvc: - svc = s+"HistAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_hlt01_"+s+"_00\";\n") - f.write(svc+".TaskPattern = \"<part>_HLT[a-z][0-9][0-9]_SubFarmAdder_(.*)\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_hlt[a-z][0-9][0-9]_"+s+"/Histos/\";\n") - f.write(svc+".AdderClass = \"hists\";\n") - f.write(svc+".ReceiveTimeout = 12;\n") - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") -# f.write(svc+".SaveRootDir = \"/hist/Savesets\";\n"); -# f.write(svc+".IsSaver = true;\n"); -# f.write(svc+".SaveInterval = -1;\n"); -# f.write(svc+".SaveonUpdate = false;\n"); -# f.write(svc+".SaveSetTaskName= \""+svc+"\";\n"); - if vnode: - if s in HistDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA" and s=="AligWrk": # overwrite certain options for the Alignment... -# f.write(svc+".DebugOn = true;\n") - act = "" - act=OnlineEnvBase.Activity - acts = act.split('|') - if len(acts) > 1: - altype = acts[1] - else: - altype = acts[0] -# f.write(svc+".SaveRootDir = \"/hist/Savesets\";\n"); -# f.write(svc+".IsSaver = true;\n"); -# f.write(svc+".SaveInterval = -1;\n"); -# f.write(svc+".SaveonUpdate = false;\n"); -# f.write(svc+".SaveSetTaskName= \""+svc+"\";\n"); -# f.write(svc+".SaveInterval = -1;\n"); -# f.write(svc+".SaveonUpdate = false;\n"); -# f.write(svc+".SaveSetTaskName= \"AligWrk_"+altype+"\";\n"); -# f.write(svc+".ReceiveTimeout = 3;\n") -# # f.write(svc+".PauseOnEOR = true;\n") -# f.write(svc+".EoRTmoFactor = 15;\n") - f.write("\n") - - for s in cntsvc: - svc = s+"CountAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_"+s+"_00\";\n") - f.write(svc+".TaskPattern = \"<part>_HLT[a-z][0-9][0-9]_SubFarmAdder_(.*)\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_hlt[a-z][0-9][0-9]_"+s+"/Counter/\";\n") - f.write(svc+".AdderClass = \"Counter\";\n") - f.write(svc+".ReceiveTimeout = 12;\n") - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - if vnode: - if s in CounterDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA": - f.write(svc+".ReceiveTimeout = 0;\n") -# f.write(svc+".GotoPause = true;\n") - f.write("\n") - elif level == "3.1": #Top level saver - histsvc = [] - histsvc.append("Adder") -# tasklist.remove("MEPrx") - for s in tasklist: - hsvc = s#+"HistAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+hsvc+"HistAdder\"};\n") - histsvc.append(hsvc) - f.write("\n") - - for s in histsvc: - svc = s+"HistAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_Saverhlt01_"+s+"_00\";\n") - f.write(svc+".TaskPattern = \"MON_<part>_HLT02_PartAdder_0\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_hlt01_"+s+"_00/Histos/\";\n") - f.write(svc+".AdderClass = \"hists\";\n") - f.write(svc+".ReceiveTimeout = 12;\n") - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - f.write(svc+".SaveRootDir = \"/hist/Savesets\";\n"); - f.write(svc+".IsSaver = true;\n"); - f.write(svc+".SaveInterval = 900;\n"); - f.write(svc+".SaveonUpdate = false;\n"); - f.write(svc+".SaveSetTaskName= \""+s+"\";\n"); - if vnode: - if s in HistDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA" and s=="AligWrk": # overwrite certain options for the Alignment... -# f.write(svc+".DebugOn = true;\n") - act = "" - act=OnlineEnvBase.Activity - acts = act.split('|') - if len(acts) > 1: - altype = acts[1] - else: - altype = acts[0] - f.write(svc+".SaveInterval = -1;\n"); - f.write(svc+".SaveonUpdate = true;\n"); - f.write(svc+".SaveSetTaskName= \"AligWrk_"+altype+"\";\n"); - f.write(svc+".ReceiveTimeout = 3;\n") -# f.write(svc+".PauseOnEOR = true;\n") - f.write(svc+".EoRTmoFactor = 15;\n") -# f.write(svc+".DebugOn = true;\n") - f.write("\n") - elif level == "4": - histsvc = [] - cntsvc = [] -# histsvc.append("Adder") -# cntsvc.append("Busy") - for s in tasklist: - hsvc = s#+"HistAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+hsvc+"HistAdder\"};\n") - csvc = s#+"CountAdder" - f.write("ApplicationMgr.ExtSvc += {\"AdderSvc/"+csvc+"CountAdder\"};\n") - histsvc.append(hsvc) - cntsvc.append(csvc) - f.write("\n") - - for s in histsvc: - svc = s+"HistAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_X_"+s+"\";\n") - f.write(svc+".TaskPattern = \"<part>_HLT01_PartAdder_(.*)\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_hlt01_"+s+"/Histos/\";\n") - f.write(svc+".AdderClass = \"hists\";\n") - f.write(svc+".ReceiveTimeout = 12;\n") - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - if vnode: - if s in HistDebugSvcs: - f.write(svc+".DebugOn = true;\n") - f.write("\n") - - for s in cntsvc: - svc = s+"CountAdder" - f.write(svc+".PartitionName = @OnlineEnv.PartitionName;\n") - f.write(svc+".MyName = \"<part>_X_"+s+"\";\n") - f.write(svc+".TaskPattern = \"<part>_HLT01_PartAdder_(.*)\";\n") - f.write(svc+".ServicePattern = \"MON_<part>_hlt01_"+s+"/Counter/\";\n") - f.write(svc+".AdderClass = \"Counter\";\n") - f.write(svc+".ReceiveTimeout = 12;\n") - f.write(svc+".InDNS = "+InDns+";\n") - f.write(svc+".OutDNS = "+OutDns+";\n") - if vnode: - if s in CounterDebugSvcs: - f.write(svc+".DebugOn = true;\n") - if pname == "LHCbA": - f.write(svc+".ReceiveTimeout = 1000000;\n") - f.write("\n") - # Add UI options - ##f.write("//\n// RPC UI options for adders:\n//\n") - ##f.write("ApplicationMgr.ExtSvc += { \"Online::OnlineUISvc/UI\" };\n") - ##f.write("UI.When = \"initialize\";\n") - -tasklist = [] -vnode= VictimNode() -arch = OnlineEnvBase.HltArchitecture +import OnlineEnvBase +tasklist = [] +adderlist = [] +vnode = VictimNode() +## part = os.getenv("PARTITION",part) part = OnlineEnvBase.PartitionName -arch = os.getenv("ARCH",arch) +## arch = os.getenv("ARCHITECTURE",arch) +arch = OnlineEnvBase.WorkerArchitecture hostdns = False -if arch == "Calib": - hostdns = True -arch = "/group/online/dataflow/architectures/lbDataflowArch_"+arch+".xml" -level = sys.argv[1] +level = os.getenv("LEVEL","1") +print("Adder: Level: %s Partition: %s Architecture: %s"%(level, part, arch)) TaskListfromArch(arch, tasklist) -ofile = "" -if len(sys.argv) >= 3: - ofile = sys.argv[2] -if ofile == "": - ofile = "/tmp/AdderOptions.opts" -OptionsfromTasks(tasklist,level,ofile,part,hostdns) +AddersfromTasks(tasklist,level,part,hostdns,adderlist) +app = AdderApp(outputLevel=OnlineEnvBase.OutputLevel,partitionName=part,adders=adderlist) diff --git a/Online/FarmConfig/job/BU.sh b/Online/FarmConfig/job/BU.sh index 1402c8f01750b678833c790eabda03cbf07ef921..ed0c227b4e8fa783ee4c8d900f1636442f66b98d 100755 --- a/Online/FarmConfig/job/BU.sh +++ b/Online/FarmConfig/job/BU.sh @@ -12,7 +12,7 @@ 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.${CMTCONFIG}.vars; +. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64-centos7-gcc9-opt.vars; cd ${FARMCONFIGROOT}/job; # `dataflow_task Class1` -opts=../../EventBuilding/options/${BU_OPTIONS} ${AUTO_STARTUP} ${DEBUG_STARTUP}; diff --git a/Online/FarmConfig/job/EBNodeAdder.sh b/Online/FarmConfig/job/EBNodeAdder.sh new file mode 100644 index 0000000000000000000000000000000000000000..4633edc0e9b74e67b517dd3b18308db65a280ece --- /dev/null +++ b/Online/FarmConfig/job/EBNodeAdder.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# ========================================================================= +# +# Default script to start the event reader task on the HLT farm +# +# Author M.Frank +# Version: 1.0 +# Date: 20/05/2013 +# +# ========================================================================= +# +#export victimnodes="hltb0113(.*)" +cd /group/online/dataflow/cmtuser/OnlineRelease; +export ARCH=Markus_Dataflow; +export PYTHONPATH=${ONLINE_ENV_DIR}:${PYTHONPATH}; +#export AdderOptsFile=/tmp/${PARTITION_NAME}_AdderOpts.opts; +#export AdderStaticOpts=../options/NodeAdderStatic.opts +export LEVEL=1 + +exec -a $UTGID python `which gaudirun.py` --application=Online::OnlineApplication Online/FarmConfig/job/AddersFromArchitecture.py +#python ./Tasklist_from_architecture.py 1 ${AdderOptsFile}; +#export RTL_SLEEP_ON_FATAL=1 +#if test "${PARTITION_NAME}" = "LHCb"; then +# exec -a ${UTGID} ${Class1_task} -opts=../options/genAdder.opts; +# exec -a ${UTGID} ~beat/scripts/debug --command=~beat/AdderDebugScript --args ${Class1_task} -opts=../options/genAdder.opts; +#fi +#if test "${PARTITION_NAME}" = "LHCbA"; then +# exec -a ${UTGID} ${Class1_task} -opts=../options/genAdder.opts; +# exec -a ${UTGID} ~beat/scripts/debug --command=~beat/AdderDebugScript --args ${Class1_task} -opts=../options/genAdder.opts; +#else +# exec -a ${UTGID} ${Class1_task} -opts=../options/genAdder.opts; +#fi +#exec -a ${UTGID} ${Class0_task} -opt=../options/Daemon.opts -main=../options/genAdder.opts diff --git a/Online/FarmConfig/job/MFPGen.sh b/Online/FarmConfig/job/MFPGen.sh index 1149cf721705b875c9d417193ff335c625a248a0..dfe4b380f8296d2f031adf24f234488d3b7b48f6 100755 --- a/Online/FarmConfig/job/MFPGen.sh +++ b/Online/FarmConfig/job/MFPGen.sh @@ -9,7 +9,7 @@ # # ========================================================================= # -. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.${CMTCONFIG}.vars; +. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64-centos7-gcc9-opt.vars; cd ${FARMCONFIGROOT}/job; # `dataflow_task Class1` -opts=../../EventBuilding/options/${TASK_TYPE}.opts ${AUTO_STARTUP} ${DEBUG_STARTUP}; diff --git a/Online/FarmConfig/job/RU.sh b/Online/FarmConfig/job/RU.sh index 02a2301d9dfadcce62f8356c1a6e8f8f9aa9fcff..cf34325d8fcdb318871ca99bdcabbff867c3eeb4 100755 --- a/Online/FarmConfig/job/RU.sh +++ b/Online/FarmConfig/job/RU.sh @@ -9,6 +9,6 @@ # # ========================================================================= # -. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.${CMTCONFIG}.vars; +. /group/online/dataflow/EventBuilder/EventBuilderRelease/setup.x86_64-centos7-gcc9-opt.vars; cd ${EVENTBUILDINGROOT}/options; `dataflow_task Class1` -opts=EB_RU.opts ${AUTO_STARTUP} ${DEBUG_STARTUP} diff --git a/Online/FarmConfig/job/createEnvironment.sh b/Online/FarmConfig/job/createEnvironment.sh index f910ac14590af3fd515cfdf8d5f1a33be8a25af0..f8024ee798ffe61676738a9c0381eb7c38f204f8 100755 --- a/Online/FarmConfig/job/createEnvironment.sh +++ b/Online/FarmConfig/job/createEnvironment.sh @@ -43,6 +43,10 @@ while len(args): _p('export ARCH_FILE='+value) elif type == '-taskinfo': _p('export ARCH_FILE='+value) + elif type == '-architecture': + _p('export ARCHITECTURE='+value) + elif type == '-application': + _p('export APPLICATION='+value) elif type == '-count': _p('export NBOFSLAVES='+value) elif type == '-instances': diff --git a/Online/FarmConfig/options/EBMBM.opts b/Online/FarmConfig/options/EBMBM.opts index cd3a10d3145b030ff72332d80f3be86dee4e13e7..45a8530bf38d7456d2a068db9a6a43409a7065fa 100644 --- a/Online/FarmConfig/options/EBMBM.opts +++ b/Online/FarmConfig/options/EBMBM.opts @@ -1,9 +1,9 @@ #pragma print off #include "$INFO_OPTIONS" -#include "$MBM_SETUP_OPTIONS" +//#include "$MBM_SETUP_OPTIONS" #include "$FARMCONFIG_OPTIONS/Logging.opts" Manager.Setup = {"Dataflow_MBMServer/MEPManager"}; Manager.Services = {"Dataflow_UI/UI"}; -MEPManager.PartitionBuffers = @OnlineEnv.PartitionBuffers; +MEPManager.PartitionBuffers = true; MEPManager.PartitionName = @OnlineEnv.PartitionName; -MEPManager.InitFlags = "-s=1000000 -e=50 -u=20 -b=12 -t=1 -n=0 -f -i=Events_0 -c -s=1000000 -e=50 -u=20 -b=12 -t=1 -n=1 -f -i=Events_1 -c -s=500000 -e=50 -u=5 -b=12 -t=1 -f -i=Output -c"; +MEPManager.InitFlags = "-s=35000000 -e=150 -u=20 -b=12 -t=1 -n=0 -f -i=Events_0 -c -s=35000000 -e=150 -u=20 -b=12 -t=1 -n=1 -f -i=Events_1 -c -s=500000 -e=150 -u=5 -b=12 -t=1 -f -i=Output -c"; diff --git a/Online/Gaucho/CMakeLists.txt b/Online/Gaucho/CMakeLists.txt index 09519acfa0c13342486674cbcaace209c92e6d34..6d5787667d758883b472228c7a964e98a88cc226 100755 --- a/Online/Gaucho/CMakeLists.txt +++ b/Online/Gaucho/CMakeLists.txt @@ -5,11 +5,11 @@ gaudi_subdir(Gaucho v7r48) gaudi_depends_on_subdirs(GaudiKernel GaudiAlg - DAQ/MDF - Event/DAQEvent Online/dim Online/GauchoBase Online/OnlineBase + Online/Tell1Data + Online/PCIE40Data Online/Trending) find_package(ROOT) @@ -18,11 +18,11 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}) gaudi_add_library(GauchoLib src/*.cpp PUBLIC_HEADERS Gaucho - INCLUDE_DIRS ROOT + INCLUDE_DIRS ROOT LINK_LIBRARIES Boost dim OnlineBase GaudiKernel GauchoBase) gaudi_add_module(Gaucho src/components/*.cpp - INCLUDE_DIRS ROOT - LINK_LIBRARIES GaudiKernel dim GauchoBase GauchoLib GaudiAlgLib DAQEventLib) + INCLUDE_DIRS ROOT Tell1Data + LINK_LIBRARIES GaudiKernel dim GauchoBase GauchoLib GaudiAlgLib) target_compile_options(Gaucho PRIVATE -Wno-implicit-fallthrough) diff --git a/Online/Gaucho/Gaucho/IGauchoMonitorSvc.h b/Online/Gaucho/Gaucho/IGauchoMonitorSvc.h index 7db1c7c75677a02c3df2bce146a003720da2caa4..122b437b33644989cf77b7982f97bda811e7a82c 100644 --- a/Online/Gaucho/Gaucho/IGauchoMonitorSvc.h +++ b/Online/Gaucho/Gaucho/IGauchoMonitorSvc.h @@ -9,7 +9,6 @@ // Author : B.Jost // //========================================================================== -// $Id: IGauchoMonitorSvc.h,v 1.19 2010/01/20 16:06:03 evh Exp $ #ifndef KERNEL_IGAUCHOMONITORSVC_H #define KERNEL_IGAUCHOMONITORSVC_H 1 @@ -44,8 +43,7 @@ class IGauchoMonitorSvc: virtual public IMonitorSvc return IID_IGauchoMonitorSvc; } - virtual void updateSvc(const std::string& name, int runno, - const IInterface* owner = 0) = 0; + virtual StatusCode update(int runno) = 0; virtual void updateAll(bool endOfRun = false, const IInterface* owner = 0) = 0; virtual void updatePerSvc(unsigned long ref)=0; diff --git a/Online/Gaucho/src/components/EoEIncidentListener.cpp b/Online/Gaucho/src/components/EoEIncidentListener.cpp index e1fae336afa7be4f26b246bc423127e44651c5ab..f77fb248a0749e5727fb9eec338af60413fa726b 100644 --- a/Online/Gaucho/src/components/EoEIncidentListener.cpp +++ b/Online/Gaucho/src/components/EoEIncidentListener.cpp @@ -9,6 +9,7 @@ // Author : B.Jost // //========================================================================== +#if 0 /* * EoEIncidentListener.cpp * @@ -67,3 +68,4 @@ void EoEIncidentListener::handle(const Incident &i) // printf("-----------------EoE Handler Monitor System LockED\n"); } } +#endif diff --git a/Online/Gaucho/src/components/MonSvcTest.cpp b/Online/Gaucho/src/components/MonSvcTest.cpp index e0a8dda75b122e9065c921b58a12b024427e421f..1e499ead064eab7de6009882e38dc6db35d3d819 100644 --- a/Online/Gaucho/src/components/MonSvcTest.cpp +++ b/Online/Gaucho/src/components/MonSvcTest.cpp @@ -166,7 +166,7 @@ class MonSvcTest: virtual public Service, if (m_changeRun) { m_changeRun = false; - m_mons->updateSvc("this", runno, this); + m_mons->update(runno).ignore(); m_mons->resetHistos(this); runno++; m_mons->setRunNo(runno); diff --git a/Online/Gaucho/src/components/MonitorSvc.cpp b/Online/Gaucho/src/components/MonitorSvc.cpp index fca17848ad4fa353ae1e78de1a9f10ed2ec0df48..d5ed793cfe1874d8a3cddcff9fa6acc08e470597 100644 --- a/Online/Gaucho/src/components/MonitorSvc.cpp +++ b/Online/Gaucho/src/components/MonitorSvc.cpp @@ -13,20 +13,11 @@ #include "GaudiKernel/IIncidentSvc.h" #include "Gaucho/MyDimErrorHandler.h" -//#include "MonitorSvc.h" #include "GaudiKernel/IAlgorithm.h" #include "GaudiKernel/IAlgTool.h" #include "GaudiKernel/MsgStream.h" #include "GaudiKernel/DataObject.h" #include "GaudiKernel/IRegistry.h" -//#include "GaudiKernel/Service.h" -//#include "Gaucho/CntrMgr.h" -//#include "Gaucho/MonHist.h" -//#include "Gaucho/MonSys.h" -//#include "Gaucho/CounterSubSys.h" -//#include "Gaucho/HistSubSys.h" -//#include "Gaucho/MonCounter.h" -//#include "Gaucho/MonitorClass.h" #include "Gaucho/Utilities.h" #include "RTL/rtl.h" @@ -47,9 +38,6 @@ #include "Gaucho/MonitorInterface.h" #include "Gaucho/HistSubSys.h" -//#include "StatusService.h" -//template void HistSubSys::addEntry<Gaudi::Accumulators::Histogram<2u,Gaudi::Accumulators::atomicity::full,double>> -//(const std::string& name, const std::string &desc,const Gaudi::Accumulators::Histogram<2u,Gaudi::Accumulators::atomicity::full,double> &var); #include "Gaucho/MonitorInterface.h" using namespace std; @@ -89,7 +77,6 @@ MonitorSvc::MonitorSvc(const string& name, ISvcLocator* sl) { m_started = false; m_monsysrecover = 0; - m_MonIntf = 0; m_errh=0; /// Initialize ROOT and disable the SEGV signal handler ROOT::GetROOT(); @@ -121,53 +108,51 @@ MonitorSvc::MonitorSvc(const string& name, ISvcLocator* sl) // declareProperty("DimUpdateInterval", m_updateInterval = 20); declareProperty("DimUpdateInterval", m_updateInterval = 40); declareProperty("CounterUpdateInterval", m_CounterInterval =0); - declareProperty("ExpandCounterServices",m_expandCounterServices=0); - declareProperty("ExpandNameInfix",m_expandInfix=""); - declareProperty("PartitionName",m_partname="LHCb"); - declareProperty("ProcessName",m_ProcName=""); - declareProperty("ProgramName",m_ProgName=""); - declareProperty("DontResetCountersonRunChange",m_DontResetCountersonRunChange=false); - declareProperty("UseDStoreNames",m_useDStoreNames=false); - declareProperty("CounterClasses",m_CounterClasses); - declareProperty("HistogramClasses",m_HistogramClasses); - declareProperty("RunAware",m_runAware=false); + declareProperty("ExpandCounterServices", m_expandCounterServices=0); + declareProperty("ExpandNameInfix", m_expandInfix=""); + declareProperty("PartitionName", m_partname="LHCb"); + declareProperty("ProcessName", m_ProcName=""); + declareProperty("ProgramName", m_ProgName=""); + declareProperty("DontResetCountersonRunChange", m_DontResetCountersonRunChange=false); + declareProperty("UseDStoreNames", m_useDStoreNames=false); + declareProperty("CounterClasses", m_CounterClasses); + declareProperty("HistogramClasses", m_HistogramClasses); + declareProperty("RunAware", m_runAware=false); TH1D::SetDefaultSumw2(); TH2D::SetDefaultSumw2(); TProfile::SetDefaultSumw2(); + m_runno = 1; m_InfoMap.clear(); } -MonitorSvc::~MonitorSvc() -{ - deletePtr(m_MonIntf); +MonitorSvc::~MonitorSvc() { + m_MonIntf.reset(); } -StatusCode MonitorSvc::initialize() -{ -// m_StatusService = 0; - MsgStream msg(msgSvc(),"MonitorSvc"); + +StatusCode MonitorSvc::initialize() { StatusCode sc = Service::initialize(); if (m_ProcName == "") { m_ProcName = RTL::processName(); } if (m_expandCounterServices) { - StringReplace(m_expandInfix,"<part>", m_partname); - StringReplace(m_expandInfix,"<proc>", m_ProcName); - StringReplace(m_expandInfix,"<program>",m_ProgName); + StringReplace(m_expandInfix, "<part>", m_partname); + StringReplace(m_expandInfix, "<proc>", m_ProcName); + StringReplace(m_expandInfix, "<program>", m_ProgName); } if (m_CounterInterval == 0) m_CounterInterval = m_updateInterval; if ( 0 != m_disableMonRate) { - msg << MSG::DEBUG << "MonRate process is disabled." << endmsg; + debug() << "MonRate process is disabled." << endmsg; } sc = serviceLocator()->service("IncidentSvc",m_incidentSvc,true); if( !sc.isSuccess() ) { - msg << MSG::FATAL << "Service [IncidentSvc] not found" << endmsg; + fatal() << "Service [IncidentSvc] not found" << endmsg; return sc; } - m_incidentSvc->addListener(this,"APP_RUNNING"); - m_incidentSvc->addListener(this,"APP_STOPPED"); + m_incidentSvc->addListener(this, "APP_RUNNING"); + m_incidentSvc->addListener(this, "APP_STOPPED"); SubSysParams cpars; cpars.m_RatePrefix = "R_"; cpars.m_dontclear = m_DontResetCountersonRunChange; @@ -182,7 +167,7 @@ StatusCode MonitorSvc::initialize() hpars.m_updatePeriod = m_updateInterval; hpars.m_type = MONSUBSYS_Histogram; hpars.m_runAware = m_runAware; - m_MonIntf = new MonitorInterface(this->m_utgid,cpars,hpars); + m_MonIntf.reset(new MonitorInterface(this->m_utgid,cpars,hpars)); m_MonIntf->ApplyCouterClasses(m_CounterClasses); m_MonIntf->ApplyHistogramClasses(m_HistogramClasses); return sc; @@ -190,8 +175,7 @@ StatusCode MonitorSvc::initialize() /// Incident handler implemenentation: Inform that a new incident has occured void MonitorSvc::handle(const Incident& inc) { - MsgStream log(msgSvc(),name()); - log << MSG::INFO << "MonitorSvc: Got incident from:" << inc.source() << ": " << inc.type() << endmsg; + info() << "MonitorSvc: Got incident from:" << inc.source() << ": " << inc.type() << endmsg; if ( inc.type() == "APP_RUNNING" ) { i_start().ignore(); } @@ -219,28 +203,22 @@ void MonitorSvc::undeclareInfo( const string& name, const IInterface* owner) /** Undeclare monitoring information @param owner Owner identifier of the monitoring information */ -void MonitorSvc::undeclareAll( const IInterface* owner) -{ +void MonitorSvc::undeclareAll( const IInterface* owner) { string oname = owner ? infoOwnerName(owner) : ""; m_MonIntf->undeclareAll(oname); } -StatusCode MonitorSvc::start() -{ -// if (m_StatusService == 0)m_StatusService = new StatusService(this); +StatusCode MonitorSvc::start() { if (m_errh ==0) m_errh = new MyDimErrorHandler(); m_errh->start(); DimServer::addErrorHandler(m_errh); return Service::start(); } -StatusCode MonitorSvc::i_start() -{ -// CALLGRIND_START_INSTRUMENTATION - MsgStream msg(msgSvc(),"MonitorSvc"); +StatusCode MonitorSvc::i_start() { m_i_startState = true; - msg << MSG::DEBUG << "======== MonitorSvc start() called ============= " << endmsg; + debug() << "======== MonitorSvc start() called ============= " << endmsg; // setProperties(); // dis_set_debug_on(); m_MonIntf->start(); @@ -249,12 +227,12 @@ StatusCode MonitorSvc::i_start() return StatusCode::SUCCESS; } -StatusCode MonitorSvc::i_stop() -{ +StatusCode MonitorSvc::i_stop() { m_i_startState = false; m_MonIntf->stop(); return StatusCode::SUCCESS; } + void MonitorSvc::StopUpdate() { m_errh->stop(); @@ -262,14 +240,9 @@ void MonitorSvc::StopUpdate() StopSaving(); } - -StatusCode MonitorSvc::finalize() -{ - MsgStream msg(msgSvc(),"MonitorSvc"); - msg << MSG::DEBUG << "MonitorSvc Finalizer" << endmsg; - - if ( m_incidentSvc ) - { +StatusCode MonitorSvc::finalize() { + debug() << "MonitorSvc Finalizer" << endmsg; + if ( m_incidentSvc ) { m_incidentSvc->removeListener(this); m_incidentSvc->release(); m_incidentSvc = 0; @@ -281,9 +254,9 @@ StatusCode MonitorSvc::finalize() m_started = false; m_MonIntf->stop(); } - deletePtr(m_MonIntf); + m_MonIntf.reset(); dim_unlock(); - msg << MSG::DEBUG << "finalized successfully" << endmsg; + debug() << "finalized successfully" << endmsg; //printf("MonitorSvc: UNLocking DIM\n"); return Service::finalize(); @@ -294,78 +267,57 @@ void MonitorSvc::setRunNo(int runno) m_runno = runno; m_MonIntf->setRunNo(runno); } + template<class T> void MonitorSvc::i_declareCounter(const string& nam, const T& var, - const string& desc, const IInterface* owner) + const string& desc, const IInterface* owner) { - string fnam = nam; - if (owner != 0) - { - string oname = infoOwnerName(owner); - fnam = oname+"/"+nam; - } - ::lib_rtl_output(LIB_RTL_DEBUG,"MonitorSvc: i_declareCounter %s\n",nam.c_str()); + string fnam = owner ? infoOwnerName(owner)+'/'+nam : nam; + debug() << "MonitorSvc: i_declareCounter " << nam << endmsg; m_MonIntf->i_declareCounter(fnam,var,desc); } template<class T> void MonitorSvc::i_declarePair(const string& nam, const T& var1, const T& var2, const string& desc, const IInterface* owner) { - string fnam = nam; - if (owner != 0) - { - string oname = infoOwnerName(owner); - fnam = oname+"/"+nam; - } + string fnam = owner ? infoOwnerName(owner)+'/'+nam : nam; m_MonIntf->i_declarePair(fnam,var1,var2,desc); } + template <class T> void MonitorSvc::i_declareAtomic(const string& nam, const T & var, const string& desc, const IInterface* owner) { - string fnam = nam; - if (owner != 0) - { - string oname = infoOwnerName(owner); - fnam = oname+"/"+nam; - } - m_MonIntf->i_declareCounter(fnam,var,desc); + string fnam = owner ? infoOwnerName(owner)+'/'+nam : nam; + m_MonIntf->i_declareCounter(fnam,var,desc); } void MonitorSvc::i_unsupported(const string& nam, const type_info& typ, const IInterface* owner) { - MsgStream msg(msgSvc(),name()); string oname = infoOwnerName(owner); string typ_name = System::typeinfoName(typ); - msg << MSG::ERROR << "declareInfo(" << typ_name << ") not implemented " << oname << "/" << nam << endmsg; - return; + error() << "declareInfo(" << typ_name << ") not implemented " << oname << "/" << nam << endmsg; } -void MonitorSvc::declareInfo(const std::string& name, - const Entity &var, - const std::string& desc, const IInterface* owner) + +void MonitorSvc::declareInfo(const std::string& name, const Entity &var, + const std::string& desc, const IInterface* owner) { string oname = infoOwnerName(owner); string hnam; - if (m_disableMonObjectsForHistos == 0) - { - if (name.find(oname) == string::npos) - { + if (m_disableMonObjectsForHistos == 0) { + if (name.find(oname) == string::npos) { hnam = oname+"/"+name; } - else - { + else { hnam = name; } } auto j = var.toJSON(); std::string typ = j.at("type").get<std::string>(); - if (typ.find("histogram:") != typ.npos) - { + if (typ.find("histogram:") != typ.npos) { m_MonIntf->i_declareHistogram(hnam,var,desc); } - else if (typ.find("counter:") != string::npos) - { + else if (typ.find("counter:") != string::npos) { m_MonIntf->i_declareCounter(hnam,var,desc); } - return; } // #define _GDINFO(dim,at,ty) void MonitorSvc::declareInfo(const std::string& name,\ @@ -613,7 +565,6 @@ void MonitorSvc::declareInfo(const string& name, const string& format, const voi //printf("Declare Info called after start for Name %s\n",name.c_str()); } if (0 != m_disableDeclareInfoFormat) return; - MsgStream msg(msgSvc(),"MonitorSvc"); const std::string fnam = oname+"/"+name; std::string nname; nname = "R_"+oname+"/"+name; @@ -646,15 +597,13 @@ void MonitorSvc::declareInfo(const string& name, const string& format, const voi return; } } -// m_InfoMap.insert(pair<string,void*>(nname,m_RateMgr)); - return; } // void MonitorSvc::declareInfo(const string& name, const StatEntity& , const string& , const IInterface* owner) { - MsgStream msg(msgSvc(),"MonitorSvc"); - msg << MSG::WARNING << "=========================== DeclareInfo for StatEntity Not Supported anymore "<< name << " "<<infoOwnerName(owner)<<endmsg; + warning() << "=========================== DeclareInfo for StatEntity Not Supported anymore " + << name << " "<<infoOwnerName(owner)<<endmsg; } #if 0 { @@ -663,8 +612,7 @@ void MonitorSvc::declareInfo(const string& name, const StatEntity& , { // printf("Declare Info called after start for Name %s\n",name.c_str()); } - MsgStream msg(msgSvc(),"MonitorSvc"); - msg << MSG::DEBUG << "=========================== DeclareInfo for StatEntity "<< name << endmsg; + debug() << "=========================== DeclareInfo for StatEntity "<< name << endmsg; if (name.find("COUNTER_TO_RATE") != string::npos) { string newName = extract("COUNTER_TO_RATE", name); @@ -695,11 +643,11 @@ void MonitorSvc::declareInfo(const string& name, const StatEntity& , } else { - msg << MSG::DEBUG << "Counter "<< newName << " can not be declared because MonRate process is disabled." << endmsg; + debug() << "Counter "<< newName << " can not be declared because MonRate process is disabled." << endmsg; } return; } - ::lib_rtl_output(LIB_RTL_ERROR,"MonitorSvc: StatEntity monitoring not supported\n"); + error() << "MonitorSvc: StatEntity monitoring not supported" << endmsg; i_unsupported(name,typeid(var),owner); return; #if 0 @@ -721,101 +669,54 @@ void MonitorSvc::declareInfo(const string& name, const StatEntity& , void MonitorSvc::declareInfo(const string& nam, const AIDA::IBaseHistogram* var, const string& desc, const IInterface* owner) { - MsgStream msg(msgSvc(),name()); - string oname = infoOwnerName(owner); - // msg << MSG::INFO << "m_disableDeclareInfoHistos : " << m_disableDeclareInfoHistos << endmsg; - -// if (m_started) -// { -// msg << MSG::ERROR << "Declare Info (Histogram) called after start for Name " << -// nam <<"(" << oname << ")" << endmsg; -// } - if (0 != m_disableDeclareInfoHistos) - { - msg << MSG::DEBUG << "m_disableDeclareInfoHistos DISABLED " << endmsg; + if (0 != m_disableDeclareInfoHistos) { + debug() << "m_disableDeclareInfoHistos DISABLED " << endmsg; return; } -// MonBase *mhist = 0; - string hnam; - if (m_disableMonObjectsForHistos == 0) - { - if (m_useDStoreNames) - { + + string hnam = nam; + string oname = infoOwnerName(owner); + if (m_disableMonObjectsForHistos == 0) { + if (m_useDStoreNames) { AIDA::IBaseHistogram* h = (AIDA::IBaseHistogram*)var; DataObject* dObj = dynamic_cast<DataObject*>(h); IRegistry* reg = dObj->registry(); string path = reg->identifier(); // /stat/bla//bla/<histo-name> ::lib_rtl_output(LIB_RTL_INFO,"Data Store Path: %s , Hist Name: %s\n",path.c_str(),nam.c_str()); - if (nam.find(oname) == string::npos) - { - hnam = oname+"/"+nam; - } - else - { - hnam = nam; - } } - else - { - if (nam.find(oname) == string::npos) - { - hnam = oname+"/"+nam; - } - else - { - hnam = nam; - } + if ( nam.find(oname) == string::npos ) + hnam = oname+"/"+nam; + + if( 0 != dynamic_cast<const AIDA::IProfile1D* >(var) ) { + TProfile* h = Online::cast_histo<TProfile>(var); + m_MonIntf->i_declareHistogram(hnam,h,desc); + // m_HistSubSys->addEntry(hnam,desc,*h); + } + else if( 0 != dynamic_cast<const AIDA::IHistogram1D*>(var) ) { + TH1D* h = Online::cast_histo<TH1D>(var); + m_MonIntf->i_declareHistogram(hnam,h,desc); + } + else if( 0 != dynamic_cast<const AIDA::IHistogram2D*>(var) ) { + TH2D* h = Online::cast_histo<TH2D>(var); + m_MonIntf->i_declareHistogram(hnam,h,desc); + } + else if( 0 != dynamic_cast<const AIDA::IProfile2D*>(var) ) { + TProfile2D* h = Online::cast_histo<TProfile2D>(var); + m_MonIntf->i_declareHistogram(hnam,h,desc); + } + else { + error() << "Unknown histogram type ("<<typeid(var).name()<<"). Source " << nam << endmsg; } -// createHistSubSys(); - if( 0 != dynamic_cast<const AIDA::IProfile1D* >(var) ) - { - TProfile* h = Online::cast_histo<TProfile>(var); - m_MonIntf->i_declareHistogram(hnam,h,desc); -// m_HistSubSys->addEntry(hnam,desc,*h); - } - else if( 0 != dynamic_cast<const AIDA::IHistogram1D*>(var) ) - { - TH1D* h = Online::cast_histo<TH1D>(var); - m_MonIntf->i_declareHistogram(hnam,h,desc); - } - else if( 0 != dynamic_cast<const AIDA::IHistogram2D*>(var) ) - { - TH2D* h = Online::cast_histo<TH2D>(var); - m_MonIntf->i_declareHistogram(hnam,h,desc); - } - else if( 0 != dynamic_cast<const AIDA::IProfile2D*>(var) ) - { - TProfile2D* h = Online::cast_histo<TProfile2D>(var); - m_MonIntf->i_declareHistogram(hnam,h,desc); - } - else - { - msg << MSG::ERROR << "Unknown histogram type ("<<typeid(var).name()<<"). Source " << nam << endmsg; -// this->i_unsupported(nam,typeid(var),owner); return; } - -// m_InfoMap.insert(make_pair(hnam,m_HistSubSys)); -// m_HistSubSys->addObj(mhist); -// void *aaa = m_HistSubSys->findobj(hnam.c_str()); -// if (aaa == 0) -// { -// msg << MSG::ERROR << "Histogram" <<hnam << "added to SubSystem, but name not found in Map"<<endmsg; -// } - } - else - { -// delete mhist; - msg << MSG::ERROR << "MonitorSvc doesn't have support for declaring histograms/profiles without using MonObjects " << endmsg; - return; + else { + error() << "MonitorSvc doesn't have support for declaring histograms/profiles without using MonObjects " << endmsg; } } -//void MonitorSvc::declareMonRateComplement( int& runNumber, unsigned int& tck, int& cycleNumber, double& deltaT, double& offsetTimeFirstEvInRun, double& offsetTimeLastEvInCycle, double& offsetGpsTimeLastEvInCycle) void MonitorSvc::declareMonRateComplement( int& , unsigned int& , int& , double& , double& , double& , double& ) { - MsgStream msg(msgSvc(),"MonitorSvc"); - msg << MSG::WARNING << "declareMonRateComplement not supported anymore" << endmsg; + warning() << "declareMonRateComplement not supported anymore" << endmsg; } string MonitorSvc::extract(const string mascara, string value){ @@ -842,47 +743,35 @@ string MonitorSvc::infoOwnerName( const IInterface* owner ) } -void MonitorSvc::updateSvc( const string& , int runno, const IInterface* ) -{ - ::lib_rtl_output(LIB_RTL_INFO, "Monitor Service: Issuing EOR Update for Run %d\n",runno); +void MonitorSvc::updateSvc( const string& , int runno, const IInterface* ) { + info() << "Monitor Service: Issuing EOR Update for Run " << runno << endmsg; m_MonIntf->EORUpdate(runno); } -void MonitorSvc::updatePerSvc(unsigned long ref) -{ + +void MonitorSvc::updatePerSvc(unsigned long ref) { m_MonIntf->Update(ref); } + void MonitorSvc::resetHistos( const IInterface* ) { m_MonIntf->resetHistos(); } -void MonitorSvc::Lock(void) -{ +void MonitorSvc::Lock(void) { m_MonIntf->Lock(); } -void MonitorSvc::UnLock(void) -{ +void MonitorSvc::UnLock(void) { m_MonIntf->UnLock(); } -void MonitorSvc::StartSaving(string &dir, string &part,string &task, int period, DimService *sav) -{ +void MonitorSvc::StartSaving(string &dir, string &part,string &task, int period, DimService *sav) { m_MonIntf->StartSaving(dir,part,task,period,sav); } -void MonitorSvc::StopSaving() -{ +void MonitorSvc::StopSaving() { if (m_MonIntf!= 0) { m_MonIntf->StopSaving(); } } -//using HistT=Gaudi::Accumulators::Histogram<DIMS,A,T>; -//template <unsigned int DIMS=2, Gaudi::Accumulators::atomicity A=Gaudi::Accumulators::atomicity::full,typename T=double> void IGauchoMonitorSvc::declareInfo(const std::string& name, -// const Gaudi::Accumulators::Histogram<2, Gaudi::Accumulators::atomicity::full,double>* var, -// const std::string& desc, const IInterface* owner) ; - -//#define HistT Gaudi::Accumulators::Histogram<2, Gaudi::Accumulators::atomicity::full,double> -//void MonitorSvc::declareInfo<HistT>(const std::string& name, const HistT *var,const std::string& descc, const IInterface* owner); -//#undef HistT diff --git a/Online/Gaucho/src/components/MonitorSvc.h b/Online/Gaucho/src/components/MonitorSvc.h index 1b7813d592c04c485d69299924bcf45b4136dceb..4abb6338278bd433d30067ef91651bbb85c5bcca 100644 --- a/Online/Gaucho/src/components/MonitorSvc.h +++ b/Online/Gaucho/src/components/MonitorSvc.h @@ -23,12 +23,8 @@ #include <Gaudi/Accumulators.h> #include <Gaudi/MonitoringHub.h> #include "Gaucho/IGauchoMonitorSvc.h" -//#include "GaudiKernel/StatEntity.h" -//#include "GaudiKernel/IMonitorSvc.h" #include "GaudiKernel/IIncidentListener.h" #include "Gaucho/TaskSaveTimer.h" -//#include "GaudiCounters.h" -//#include "GaudiHistograms.h" // Forward declarations class ISvcLocator; class IIncidentSvc; @@ -75,7 +71,7 @@ class MonitorSvc: virtual public IGauchoMonitorSvc, MyDimErrorHandler *m_errh; MonitorSvc(const std::string& name, ISvcLocator* sl); virtual ~MonitorSvc(); - MonitorInterface *m_MonIntf; + //IInterface pure member functions StatusCode queryInterface(const InterfaceID& riid, void** ppvIF) override; // Service pure virtual member functions @@ -228,35 +224,28 @@ class MonitorSvc: virtual public IGauchoMonitorSvc, /** Get the names for all declared monitoring informations for a given owner. If the owner is NULL, then it returns for all owners */ - std::set<std::string> * getInfos(const IInterface* = 0) override - { + std::set<std::string> * getInfos(const IInterface* = 0) override { return 0; } - ; - void updateSvc(const std::string& name, int runno, const IInterface* owner) - override; + void updateSvc(const std::string& name, int runno, const IInterface* owner); void updatePerSvc(unsigned long ref) override; // void updateSvc( const std::string& name, bool runno , const IInterface* owner) {}; /** Update all monitoring information @param owner Owner identifier of the monitoring information */ - void updateAll(bool, const IInterface* = 0) override - { + void updateAll(bool, const IInterface* = 0) override { } - ; void resetHistos(const IInterface* owner = 0) override; void setRunNo(int runno) override; - StatusCode update(int id) override - { + StatusCode update(int id) override { updateSvc("", id, 0); return StatusCode::SUCCESS; } - ; - //void resetHistos(bool saveHistos); private: + std::unique_ptr<MonitorInterface> m_MonIntf; bool m_expandCounterServices; bool m_saveInter; bool m_runAware; @@ -287,9 +276,9 @@ class MonitorSvc: virtual public IGauchoMonitorSvc, public: void declareMonRateComplement(int& runNumber, - unsigned int& triggerConfigurationKey, int& cycleNumber, double& deltaT, - double& offsetTimeFirstEvInRun, double& offsetTimeLastEvInCycle, - double& offsetGpsTimeLastEvInCycle) override; + unsigned int& triggerConfigurationKey, int& cycleNumber, double& deltaT, + double& offsetTimeFirstEvInRun, double& offsetTimeLastEvInCycle, + double& offsetGpsTimeLastEvInCycle) override; int m_CounterInterval; int m_uniqueServiceNames; int m_disableMonRate; diff --git a/Online/Gaucho/src/components/UpdateAndReset.cpp b/Online/Gaucho/src/components/UpdateAndReset.cpp index cb1e9bdf292817ee560132947625177787df39da..67e1d97375b3690279ee485cd6a0019bfe10b49a 100644 --- a/Online/Gaucho/src/components/UpdateAndReset.cpp +++ b/Online/Gaucho/src/components/UpdateAndReset.cpp @@ -23,743 +23,397 @@ // // ==================================================================== +#include "UpdateAndReset.h" // Include files -#include "GaudiKernel/SmartDataPtr.h" -#include "GaudiKernel/MsgStream.h" -#include "GaudiKernel/LinkManager.h" -#include "GaudiKernel/IDataProviderSvc.h" -#include "GaudiKernel/ISvcLocator.h" -#include "GaudiKernel/SmartDataPtr.h" -#include "GaudiKernel/IRegistry.h" -#include "GaudiKernel/IHistogramSvc.h" -#include "GaudiKernel/IIncidentSvc.h" - -#include "AIDA/IHistogram.h" -#include "AIDA/IProfile1D.h" -#include "TFile.h" -#include "TH1.h" -#include "TProfile.h" -#include "TDirectory.h" -#include "TROOT.h" -#include "TSystem.h" +#include <GaudiKernel/SmartDataPtr.h> +#include <GaudiKernel/MsgStream.h> +#include <GaudiKernel/IDataProviderSvc.h> +#include <GaudiKernel/IDataManagerSvc.h> +#include <GaudiKernel/IRegistry.h> +#include <GaudiKernel/IHistogramSvc.h> +#include <GaudiKernel/IIncidentSvc.h> #include <GaudiUtils/Aida2ROOT.h> -#include "Gaucho/Misc.h" - -#include "GaudiKernel/ServiceLocatorHelper.h" -#include "GaudiKernel/IDataManagerSvc.h" - -#include "RTL/rtl.h" - -#include "Event/RawEvent.h" -#include "Event/RawBank.h" -#include "MDF/OnlineRunInfo.h" - -#include "UpdateAndReset.h" -#include "Gaucho/IGauchoMonitorSvc.h" -#include "RTL/rtl.h" +#include <Gaucho/Utilities.h> +#include <PCIE40Data/sodin.h> +#include <Tell1Data/RunInfo.h> +#include <Tell1Data/Tell1Bank.h> +#include <dim/dis.hxx> +#include <RTL/rtl.h> + +#include <AIDA/IHistogram.h> +#include <AIDA/IProfile1D.h> +#include <TFile.h> +#include <TH1.h> +#include <TProfile.h> +#include <TDirectory.h> +#include <TROOT.h> +#include <TSystem.h> + +#include <sstream> +using namespace Online; // Static Factory declaration DECLARE_COMPONENT(UpdateAndReset) +namespace { + static const std::string s_statusNoUpdated("NO_UPDATED"); + static const std::string s_statusProcessingUpdate("PROCESSINGUPDATE"); + static const std::string s_statusUpdated("UPDATED"); + + template <typename T> void save_histogram(T* profile, bool save, bool reset) { + if ( save ) { + TObject* hRoot = Gaudi::Utils::Aida2ROOT::aida2root(profile); + dyn_string *HistoFullName = Strsplit((char*) hRoot->GetName(), + (char*) "/"); + gDirectory->Cd("/"); + for (unsigned int i = 0; i < HistoFullName->size() - 1; i++) { + TKey *k = gDirectory->GetKey(HistoFullName->at(i).c_str()); + if (k == 0) { + gDirectory->mkdir(HistoFullName->at(i).c_str()); + } + gDirectory->Cd(HistoFullName->at(i).c_str()); + } + hRoot->Write(HistoFullName->at(HistoFullName->size() - 1).c_str()); + //should we reset at the root level? + //if (reset) hRoot->Reset(); + } + if (reset) { + // msg << MSG::DEBUG << "Resetting profile" << endmsg; + profile->reset(); + } + } +} + // Constructor //------------------------------------------------------------------------------ -UpdateAndReset::UpdateAndReset(const std::string& name, ISvcLocator* ploc) : - GaudiAlgorithm(name, ploc) +UpdateAndReset::UpdateAndReset(const std::string& name, ISvcLocator* ploc) + : Gaudi::Algorithm(name, ploc) { - declareProperty("disableMonRate", m_disableMonRate = 1); - declareProperty("desiredDeltaTCycle", m_desiredDeltaTCycle = 20); - declareProperty("disableReadOdin", m_disableReadOdin = 0); - declareProperty("disableChekInTimer", m_disableChekInTimer = 0); - declareProperty("disableChekInExecute", m_disableChekInExecute = 0); - declareProperty("disableUpdateData", m_disableUpdateData = 0); - declareProperty("disableResetHistos", m_disableResetHistos = 0); - - declareProperty("saveHistograms", m_saveHistograms = 0); - declareProperty("saveSetDir", m_saveSetDir = "/hist/Savesets"); - declareProperty("saverCycle", m_saverCycle = 900); - declareProperty("resetHistosAfterSave", m_resetHistosAfterSave = 0); - declareProperty("abortRetroEvents", m_abortRetroEvents = true); - declareProperty("publishSaveSetLocation", m_publishSavesetLoc = true); - declareProperty("teste", m_teste = 100000); - declareProperty("MyName", m_MyName = ""); //partition_TaskName - declareProperty("DoRunChangeInc", m_doRunChangeInc = false); - declareProperty("ResetonStart", m_ResetonStart = false); - declareProperty("ProcLimit", m_ProcLimit = 30); - - m_timerCycle = m_desiredDeltaTCycle - 1; - m_firstExecute = true; - m_cycleNumber = 0; - m_runNumber = 0; - gpstime = 0; - m_firstCycleNumber = 0; - m_timeStart = 0; - m_timeFirstEvInRun = 0; - m_offsetTimeFirstEvInRun = 0; - m_timeLastEvInCycle = 0; - m_offsetTimeLastEvInCycle = 0; - m_gpsTimeLastEvInCycle = 0; - m_offsetGpsTimeLastEvInCycle = 0; + declareProperty("desiredDeltaTCycle", m_desiredDeltaTCycle = 20); + declareProperty("disableReadOdin", m_disableReadOdin = 0); + + declareProperty("saveHistograms", m_saveHistograms = 0); + declareProperty("saveSetDir", m_saveSetDir = "/hist/Savesets"); + declareProperty("saverCycle", m_saverCycle = 900); + declareProperty("resetHistosAfterSave", m_resetHistosAfterSave = 0); + declareProperty("publishSaveSetLocation", m_publishSavesetLoc = true); + declareProperty("MyName", m_MyName = ""); //partition_TaskName + declareProperty("resetOnStart", m_resetOnStart = false); + + m_runNumber = 0; m_dimSvcSaveSetLoc = 0; - m_pGauchoMonitorSvc = 0; - EoEInc = 0; - m_incs = 0; - m_eorNumber = 0; - m_one = 1; + m_eorNumber = 0; + m_one = 1; } //------------------------------------------------------------------------------ StatusCode UpdateAndReset::initialize() { -//------------------------------------------------------------------------------ - MsgStream msg(msgSvc(), name()); - StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first - if (sc.isSuccess()) - msg << MSG::DEBUG << "GaudiAlgorithm Initialized" << endmsg; - else - { - msg << MSG::FATAL << "GaudiAlgorithm not Initialized" << endmsg; - return StatusCode::FAILURE; - } - serviceLocator()->service("IncidentSvc", m_incs, true).ignore(); - EoEInc = new EoEIncidentListener("", serviceLocator(), -1); - EoEInc->m_proclimit = m_ProcLimit; - m_stopdone = false; - //const std::string& utgid = RTL::processName(); return StatusCode::SUCCESS; } StatusCode UpdateAndReset::start() { - m_one = 1; + MsgStream msg(msgSvc(), name()); + std::string utgid = RTL::processName(); - MsgStream msg(msgSvc(), name()); - m_utgid = RTL::processName(); - StatusCode sc; - m_stopdone = false; - sc = StatusCode::SUCCESS; - /*if (m_pGauchoMonitorSvc== 0)*/sc = serviceLocator()->service("MonitorSvc", - m_pGauchoMonitorSvc, false); - if (sc.isSuccess()) - msg << MSG::DEBUG << "Found the IGauchoMonitorSvc interface" << endmsg; - else - { + m_one = 1; + m_gauchoMonitorSvc = monitorSvc(); + if ( !m_gauchoMonitorSvc ) { msg << MSG::FATAL << "Unable to locate the IGauchoMonitorSvc interface." << endmsg; return StatusCode::FAILURE; } - // to make the ODIN object. doesn't work. - //updMgrSvc(); - taskName = "unknownTask"; - partName = "unknownPartition"; - instancenumber = "1"; - if (m_MyName.empty()) - { - serviceParts = Strsplit((char*) m_utgid.c_str(), (char*) "_"); - if (3 == serviceParts->size()) - { - partName = serviceParts->at(0); - taskName = serviceParts->at(1); - instancenumber = serviceParts->at(2); - if (partName == "CALD0701") - { - partName = "LHCb"; - if (instancenumber == "1") - { - taskName = "CaloDAQCalib"; - } - else - { - taskName = "Calib" + taskName + "_" + instancenumber; - } - } + m_taskName = "unknownTask"; + m_partName = "unknownPartition"; + + std::unique_ptr<dyn_string> serviceParts; + if (m_MyName.empty()) { + serviceParts.reset(Strsplit(utgid.c_str(), "_")); + if (3 == serviceParts->size()) { + m_partName = serviceParts->at(0); + m_taskName = serviceParts->at(1); } - else if (4 == serviceParts->size()) - { - partName = serviceParts->at(0); - taskName = serviceParts->at(2); + else if (4 == serviceParts->size()) { + m_partName = serviceParts->at(0); + m_taskName = serviceParts->at(2); } } - else - { - serviceParts = Strsplit((char*) m_utgid.c_str(), (char*) "_"); - partName = serviceParts->at(0); - if (partName == "CALD0701") - { - partName = "LHCb"; - } - taskName = m_MyName; + else { + serviceParts.reset(Strsplit(utgid.c_str(), "_")); + m_partName = serviceParts->at(0); + m_taskName = m_MyName; } - m_infoFileStatus = - "SAVESETLOCATION/......................................................"; - infoName = partName + "/" + taskName + "/SAVESETLOCATION"; - if (m_saveHistograms) - { - if ((m_dimSvcSaveSetLoc == 0) && m_publishSavesetLoc) - { - m_dimSvcSaveSetLoc = new DimService(infoName.c_str(), - (char*) m_infoFileStatus.c_str()); + + m_infoFileStatus = "SAVESETLOCATION/......................................................"; + if (m_saveHistograms) { + if ((m_dimSvcSaveSetLoc == 0) && m_publishSavesetLoc) { + std::string infoName = m_partName + "/" + m_taskName + "/SAVESETLOCATION"; + m_dimSvcSaveSetLoc = new DimService(infoName.c_str(),(char*)m_infoFileStatus.c_str()); } } declareInfo("Tasks", m_one, "NumberOfTasks"); - sc = serviceLocator()->service("HistogramDataSvc", m_histogramSvc, true); - - if (sc.isFailure()) - msg << MSG::FATAL << "Unable to locate the HistogramDataService" << endmsg; - else - msg << MSG::DEBUG << "Found the HistogramDataService" << endmsg; - - if (0 == m_desiredDeltaTCycle) - { -// msg << MSG::WARNING << "Your algorithm is using the UpdateAndReset algrithm which update and reset data every desiredDeltaTCycle seconds. You didn't fill the desiredDeltaTCycle option in your options file, then we will consider 10 seconds as default." << endmsg; - m_desiredDeltaTCycle = 20; - } - - if (1 == m_saveHistograms) - { + if (1 == m_saveHistograms) { div_t divresult = div(m_saverCycle, m_desiredDeltaTCycle); - m_numCyclesToSave = divresult.quot; - if (0 == divresult.rem) - { + if (0 == divresult.rem) { } - else - { + else { m_saverCycle = divresult.quot * m_desiredDeltaTCycle; } } // The below part is for test - m_runNumber = 0; - m_deltaTRunTest = 8 * m_desiredDeltaTCycle; - - // m_runNumber = currentRunNumber().first.first; - m_triggerConfigurationKey = currentTCK(); -// m_cycleNumber = currentCycleNumber(m_timeStart).first; - m_timeFirstEvInRun = m_timeStart; - m_offsetTimeFirstEvInRun = offsetToBoundary(m_cycleNumber, m_timeFirstEvInRun, - true); - m_timeLastEvInCycle = m_timeStart; -// m_gpsTimeLastEvInCycle = gpsTime(); - m_runStatus = s_statusNoUpdated; - m_cycleStatus = s_statusNoUpdated; + m_runNumber = 0; + m_runStatus = s_statusNoUpdated; + m_cycleStatus = s_statusNoUpdated; - EoEInc->setMonitorSvc(m_pGauchoMonitorSvc); -#if 0 - if (0 == m_disableMonRate) - m_pGauchoMonitorSvc->declareMonRateComplement(m_runNumber, - m_triggerConfigurationKey, m_cycleNumber, m_deltaTCycle, - m_offsetTimeFirstEvInRun, m_offsetTimeLastEvInCycle, - m_gpsTimeLastEvInCycle); -#endif - if (this->m_saveHistograms != 0) - { - m_pGauchoMonitorSvc->StartSaving(this->m_saveSetDir, partName, taskName, + if (this->m_saveHistograms != 0) { + m_gauchoMonitorSvc->StartSaving(this->m_saveSetDir, m_partName, m_taskName, this->m_saverCycle, m_dimSvcSaveSetLoc); } - if (m_ResetonStart) - { - m_pGauchoMonitorSvc->resetHistos(this); + if (m_resetOnStart) { + m_gauchoMonitorSvc->resetHistos(this); } return StatusCode::SUCCESS; } + //------------------------------------------------------------------------------ -StatusCode UpdateAndReset::execute() +StatusCode UpdateAndReset::execute(EventContext const& /* ctxt */) const { -//------------------------------------------------------------------------------ - MsgStream msg(msgSvc(), name()); - - int runno; - unsigned int tck; - ulonglong gps; - EoEInc->m_startTime = time(0); - m_pGauchoMonitorSvc->Lock(); - this->EoEInc->m_executing = true; -// printf("+++++++++++++++++++++++++++++ UPDATE AND RESET Monitor System LockED\n"); - getEventChar(runno, tck, gps, m_L0EvtNr); - EoEInc->m_RunNr = runno; - EoEInc->m_EvtNr = m_L0EvtNr; - if (m_runNumber == 0) - { -// printf ("================================> FIRST EVENT ... Run number %d\n",runno); - m_runNumber = runno; - m_triggerConfigurationKey = tck; - m_pGauchoMonitorSvc->setRunNo(runno); - + UpdateAndReset* This = const_cast<UpdateAndReset*>(this); + if ( m_disableReadOdin ) { + return This->do_execute(m_runNumber); } - if (runno > m_runNumber) - { -// printf("+_+_+_+_+_+_+_+_+_+_+_++_+_+_ Different Run!!! \n"); - m_pGauchoMonitorSvc->UnLock(); - m_pGauchoMonitorSvc->updateSvc("this", m_runNumber, this); - m_pGauchoMonitorSvc->Lock(); - if (1 == m_saveHistograms) - { - //calling finalize - don't need to reset, they probably don't exist anymore - m_eorNumber = m_runNumber; -// m_pGauchoMonitorSvc->UnLock(); - manageTESHistos(false, true, true, true); -// m_pGauchoMonitorSvc->Lock(); + /// Otherwise normal execution: retrieve the run number from ODIN + const evt_data_t* event = m_rawData.get(); + int runno = 100; + if ( event ) { + for( const auto& b : *event ) { + const auto* hdr = b.first; + if ( hdr->type() == Tell1Bank::ODIN ) { + if ( hdr->version() < 7 ) { + const RunInfo* odin = (const RunInfo*)b.second; + runno = odin->run_number(); + } + else { + const pcie40::sodin_t* odin = (const pcie40::sodin_t*)b.second; + runno = odin->run_number(); + } + return This->do_execute(runno); + } } - m_triggerConfigurationKey = tck; - if (this->m_doRunChangeInc) - { - this->m_incs->fireIncident(Incident(name(), IncidentType::EndRun)); + MsgStream msg(msgSvc(), name()); + msg << MSG::DEBUG << "ODIN bank not found at location " << m_rawData << endmsg; + return StatusCode::FAILURE; + } + MsgStream msg(msgSvc(), name()); + msg << MSG::DEBUG << "rawEvent not found at location " << m_rawData << endmsg; + return StatusCode::FAILURE; +} + +StatusCode UpdateAndReset::do_execute(int runno) { + if (m_runNumber == 0) { + std::lock_guard<std::mutex> lock(m_mutex); + if (m_runNumber == 0) { + m_runNumber = runno; + m_gauchoMonitorSvc->setRunNo(runno); } - m_pGauchoMonitorSvc->resetHistos(this); - m_pGauchoMonitorSvc->setRunNo(runno); - m_runNumber = runno; } - else if (runno < m_runNumber) - { - if (m_abortRetroEvents) - { - m_incs->fireIncident(Incident(name(), IncidentType::AbortEvent)); - return StatusCode::SUCCESS; + if (runno > m_runNumber) { + std::lock_guard<std::mutex> lock(m_mutex); + if (runno > m_runNumber) { + m_gauchoMonitorSvc->update(m_runNumber).ignore(); + if ( m_saveHistograms > 0 ) { + m_eorNumber = m_runNumber; + manageTESHistos(false, true, true, true); + } + m_gauchoMonitorSvc->resetHistos(this); + m_gauchoMonitorSvc->setRunNo(runno); + m_runNumber = runno; } } - m_one = 1; - m_gpsTimeLastEvInCycle = (double) gps; -// printf("GPS Time %f\n",m_gpsTimeLastEvInCycle); -// m_pGauchoMonitorSvc->UnLock(); return StatusCode::SUCCESS; } //------------------------------------------------------------------------------ -StatusCode UpdateAndReset::stop() -{ -//------------------------------------------------------------------------------ +StatusCode UpdateAndReset::stop() { MsgStream msg(msgSvc(), name()); msg << MSG::DEBUG << "finalizing...." << endmsg; -// printf("======================UpdateAndReset STOP called\n"); - if (1 == m_saveHistograms) - { + if ( m_saveHistograms > 0 ) { m_eorNumber = m_runNumber; manageTESHistos(false, true, true, true); - if (0 != m_pGauchoMonitorSvc) - { - m_pGauchoMonitorSvc->StopSaving(); + if (m_gauchoMonitorSvc) { + m_gauchoMonitorSvc->StopSaving(); } } - else if (0 != m_pGauchoMonitorSvc) - { -// m_pGauchoMonitorSvc->StopUpdate(); -// printf("======================UpdateAndReset Updating EOR service \n"); -// this->m_pGauchoMonitorSvc->Lock(); - this->m_pGauchoMonitorSvc->updateSvc("this", m_runNumber, this); - if (!m_ResetonStart) - { - m_pGauchoMonitorSvc->resetHistos(0); + else if (m_gauchoMonitorSvc) { + m_gauchoMonitorSvc->update(m_runNumber).ignore(); + if (!m_resetOnStart) { + m_gauchoMonitorSvc->resetHistos(0); } -// this->m_pGauchoMonitorSvc->UnLock(); -// printf("======================UpdateAndReset Updating EOR DONE...... \n"); m_one = 0; - m_pGauchoMonitorSvc->release(); - m_pGauchoMonitorSvc = 0; + m_gauchoMonitorSvc.reset(); } - m_stopdone = true; return StatusCode::SUCCESS; } -StatusCode UpdateAndReset::restart() -{ - return StatusCode::SUCCESS; -} -StatusCode UpdateAndReset::finalize() -{ -//------------------------------------------------------------------------------ - MsgStream msg(msgSvc(), name()); - msg << MSG::DEBUG << "finalizing...." << endmsg; -// if (m_stopdone) -// { -// return StatusCode::SUCCESS; -// } -// else if ( 1 == m_saveHistograms ) -// { -// m_eorNumber=m_runNumber; -// manageTESHistos(false, false, true, true); -// } -// else if ( 0 != m_pGauchoMonitorSvc ) -// { -// this->m_pGauchoMonitorSvc->Lock(); -// this->m_pGauchoMonitorSvc->updateSvc( "this" , m_runNumber,this ); -// this->m_pGauchoMonitorSvc->UnLock(); -// m_pGauchoMonitorSvc->release(); -// m_pGauchoMonitorSvc = 0; -// } - if (m_dimSvcSaveSetLoc != 0) - { - delete m_dimSvcSaveSetLoc; - m_dimSvcSaveSetLoc = 0; - } - if (EoEInc != 0) - delete EoEInc; - return StatusCode::SUCCESS; -} - -//------------------------------------------------------------------------------ -//void UpdateAndReset::retrieveRunNumber(int runNumber, ulonglong gpsTime) { -////------------------------------------------------------------------------------ -// -// m_runNumber = runNumber; -// m_runStatus = s_statusNoUpdated; -// m_timeFirstEvInRun = gpsTime; -// m_offsetTimeFirstEvInRun = offsetToBoundary(currentCycleNumber(m_timeFirstEvInRun).first, m_timeFirstEvInRun, true); -//} - -//------------------------------------------------------------------------------ -// std::pair<int, bool> UpdateAndReset::currentRunNumber() { -void UpdateAndReset::getEventChar(int &runno, unsigned int &tck, ulonglong &gps, - long int &L0EvtNr) -//------------------------------------------------------------------------------ -{ - MsgStream msg(msgSvc(), name()); - - //msg << MSG::DEBUG<< "Reading ODIN Bank. " <<endmsg; - - if (exist<LHCb::RawEvent>(LHCb::RawEventLocation::Default)) - { - m_rawEvt = get<LHCb::RawEvent>(LHCb::RawEventLocation::Default); - LHCb::RawBank::BankType i = LHCb::RawBank::BankType(16); // 16 is Odin bank ID... - std::string bname = LHCb::RawBank::typeName(i); - std::string::size_type odinfound = bname.find("ODIN", 0); - - if (odinfound != std::string::npos) - { - auto b = m_rawEvt->banks(i); - if (b.size() > 0) - { - for (const auto* r : b) - { - const LHCb::OnlineRunInfo* ori = r->begin<LHCb::OnlineRunInfo>(); - tck = ori->TCK; - gps = ori->GPSTime; - runno = ori->Run; - L0EvtNr = ori->L0ID; - } - } - } - else - { - msg << MSG::DEBUG << "ODIN bank not found at location '" << rootInTES() - << LHCb::RawEventLocation::Default << endmsg; - ; - } - } - else - { - msg << MSG::DEBUG << "rawEvent not found at location '" << rootInTES() - << LHCb::RawEventLocation::Default << endmsg; - } -} -//------------------------------------------------------------------------------ -unsigned int UpdateAndReset::currentTCK() -{ //------------------------------------------------------------------------------ - MsgStream msg(msgSvc(), name()); - unsigned int triggerConfigurationKey = 0; - - //msg << MSG::DEBUG<< "Reading ODIN Bank. " <<endmsg; - - if (0 == m_disableReadOdin) - { - triggerConfigurationKey = tck; - } - else - { - } - return triggerConfigurationKey; +StatusCode UpdateAndReset::restart() { + return StatusCode::SUCCESS; } //------------------------------------------------------------------------------ -void UpdateAndReset::retrieveCycleNumber(int cycleNumber) -{ -//------------------------------------------------------------------------------ - // In order to avoid conflict, the cycle number is updated here and only here - m_cycleNumber = cycleNumber; - m_cycleStatus = s_statusNoUpdated; -} - -double UpdateAndReset::offsetToBoundary(int cycleNumber, ulonglong time, - bool inferior) -{ - if (inferior) - { - ulonglong timeIniCycle = ((ulonglong) cycleNumber) - * ((ulonglong) (m_desiredDeltaTCycle * 1000000)); - return ((double) (time - timeIniCycle)); - } - else - { - ulonglong timeEndCycle = ((ulonglong) (cycleNumber + 1)) - * ((ulonglong) (m_desiredDeltaTCycle * 1000000)); - return ((double) (time - timeEndCycle)); +StatusCode UpdateAndReset::finalize() { + if ( m_dimSvcSaveSetLoc != nullptr ) { + delete m_dimSvcSaveSetLoc; + m_dimSvcSaveSetLoc = nullptr; } - /* if (inferior) { - double timeIniCycle = cycleNumber*m_desiredDeltaTCycle*1000000; - return ((double)((double)time - timeIniCycle)); - } - else { - double timeEndCycle = (cycleNumber+1)*m_desiredDeltaTCycle*1000000; - return ((double)((double)time - timeEndCycle)); - }*/ -} - -bool UpdateAndReset::isSaveCycle(int m_cycleNumber) -{ - if (m_cycleNumber == m_firstCycleNumber) - return false; - div_t divresult = div(m_cycleNumber - m_firstCycleNumber, m_numCyclesToSave); - if (0 != divresult.rem) - return false; - return true; + return StatusCode::SUCCESS; } -void UpdateAndReset::manageTESHistos(bool list, bool reset, bool save, - bool isFromEndOfRun) +void UpdateAndReset::manageTESHistos(bool list, bool reset, bool save, bool isFromEndOfRun) { MsgStream msg(msgSvc(), name()); IRegistry* object = rootObject(); - int level = 0; + char timestr[64], year[5], month[3], day[3]; + time_t rawTime = time(NULL); + struct tm* timeInfo = localtime(&rawTime); std::vector<std::string> idList; + int level = 0; + TFile *f = 0; + msg << MSG::DEBUG << "managing histos list " << list << " reset " << reset << " save " << save << " endofrun " << isFromEndOfRun << endmsg; - TFile *f = 0; m_infoFileStatus = "......this is the file name were we will save histograms..........."; - char timestr[64]; - char year[5]; - char month[3]; - char day[3]; - time_t rawTime = time(NULL); - struct tm* timeInfo = localtime(&rawTime); ::strftime(timestr, sizeof(timestr), "%Y%m%dT%H%M%S", timeInfo); ::strftime(year, sizeof(year), "%Y", timeInfo); ::strftime(month, sizeof(month), "%m", timeInfo); ::strftime(day, sizeof(day), "%d", timeInfo); - if (save) - { - //std::string dirName = m_saveSetDir + "/" + year + "/" + partName + "/" + taskName; - //add the month and day to avoid too many files per year - std::string dirName = m_saveSetDir + "/" + year + "/" + partName + "/" - + taskName + "/" + month + "/" + day; + if ( save ) { + std::string dirName = m_saveSetDir + "/" + year + "/" + m_partName + "/" + + m_taskName + "/" + month + "/" + day; void *dir = gSystem->OpenDirectory(dirName.c_str()); - if ((dir == 0) && (save)) + if ( dir == nullptr ) { gSystem->mkdir(dirName.c_str(), true); } - std::string tmpfile = ""; - //add runnumber to saveset name - if (m_runNumber != 0) - { - std::string runNumberstr; - std::stringstream outstr; - if (isFromEndOfRun) - outstr << m_eorNumber; - else - outstr << m_runNumber; - runNumberstr = outstr.str(); - if (isFromEndOfRun) - tmpfile = dirName + "/" + taskName + "-" + runNumberstr + "-" + timestr - + "-EOR.root"; - else - tmpfile = dirName + "/" + taskName + "-" + runNumberstr + "-" + timestr - + ".root"; + std::string tmpfile = ""; + // add runnumber to saveset name + if (m_runNumber != 0) { + std::stringstream str; + str << dirName << "/" << m_taskName << "-" + << (isFromEndOfRun ? m_eorNumber : m_runNumber) << "-" << timestr + << (isFromEndOfRun ? "-EOR.root" : ".root"); + tmpfile = str.str(); } + else if ( isFromEndOfRun ) + tmpfile = dirName + "/" + m_taskName + "-0-" + timestr + "-EOR.root"; else - { - if (isFromEndOfRun) - tmpfile = dirName + "/" + taskName + "-0-" + timestr + "-EOR.root"; - else - tmpfile = dirName + "/" + taskName + "-0-" + timestr + ".root"; - } - // std::string tmpfile = dirName + "/" + taskName + "-" + timestr + ".root"; - // if (isFromEndOfRun) tmpfile = dirName + "/" + taskName + "-" + timestr + "-EOR.root"; + tmpfile = dirName + "/" + m_taskName + "-0-" + timestr + ".root"; + msg << MSG::DEBUG << "updating infofile status" << endmsg; m_infoFileStatus.replace(0, m_infoFileStatus.length(), tmpfile); - // msg << MSG::INFO << "We will save histograms in file " << m_infoFileStatus << endmsg; f = new TFile(m_infoFileStatus.c_str(), "create"); } - if (f != 0) - { - if (!f->IsZombie()) - { + if (f != 0) { + if (!f->IsZombie()) { histogramIdentifier(object, idList, reset, save, level, (TDirectory*) f); - if (save) - { + if (save) { f->Close(); delete f; f = 0; } - } - else - { + else { std::string errorTmpfile = "Error Saving Data => Zombie File..!!!!!"; m_infoFileStatus.replace(0, m_infoFileStatus.length(), errorTmpfile); msg << MSG::DEBUG << "error opening file " << m_infoFileStatus << ". Closing it." << endmsg; - if (f->IsOpen()) - { + if (f->IsOpen()) { f->Close(); } delete f; f = 0; } - if (m_publishSavesetLoc) - { - m_dimSvcSaveSetLoc->updateService((char*) m_infoFileStatus.c_str()); + if (m_publishSavesetLoc) { + m_dimSvcSaveSetLoc->updateService((char*)m_infoFileStatus.c_str()); } } - else - { - //f=0 because should also be able to reset without saving - histogramIdentifier(object, idList, reset, save, level, (TDirectory*) f); + else { // f=0 because should also be able to reset without saving + histogramIdentifier(object, idList, reset, save, level, nullptr); } - } -void UpdateAndReset::histogramIdentifier(IRegistry* object, - std::vector<std::string> &idList, bool reset, bool save, int &level, - TDirectory* rootdir) +void UpdateAndReset::histogramIdentifier(const IRegistry* object, + std::vector<std::string> &idList, + bool reset, bool save, int &level, + TDirectory* rootdir) { MsgStream msg(msgSvc(), name()); - std::vector<IRegistry*> leaves; - std::vector<IRegistry*>::const_iterator it; Bool_t dirstat = TH1::AddDirectoryStatus(); + TH1::AddDirectory(kFALSE); - try - { - // msg << MSG::INFO << "Looking for histos in object " << object->identifier() << ", level " << level << endmsg; - SmartIF<IDataManagerSvc> dataManagerSvc(m_histogramSvc); - if (!dataManagerSvc) - { - // msg << MSG::WARNING << " Unable to go to the transient store. " << endmsg; + try { + std::vector<IRegistry*> leaves; + SmartIF<IDataManagerSvc> dataManagerSvc(this->histoSvc()); + if( !dataManagerSvc ) { TH1::AddDirectory(dirstat); return; } - StatusCode sc = dataManagerSvc->objectLeaves(object, leaves); - if (sc.isFailure()) - { - // msg << MSG::WARNING << " No histograms found on the transient store." << endmsg; + if( sc.isFailure() ) { TH1::AddDirectory(dirstat); return; } - - for (it = leaves.begin(); it != leaves.end(); it++) - { - const std::string& id = (*it)->identifier(); - if (rootdir != 0) + for (const auto* l : leaves) { + const std::string& id = l->identifier(); + if( rootdir != 0 ) rootdir->cd(); - // msg << MSG::DEBUG << " Object found: " << id << endmsg; DataObject* dataObject; - sc = m_histogramSvc->retrieveObject(id, dataObject); - if (sc.isFailure()) - { - // msg << MSG::WARNING << "Could not retrieve object from TES " << endmsg; + sc = histoSvc()->retrieveObject(id, dataObject); + if( sc.isFailure() ) { continue; } - - IHistogram* histogram = dynamic_cast<AIDA::IHistogram*>(dataObject); - if (0 != histogram) - { - if (save) - { - TH1* hRoot = (TH1*) Gaudi::Utils::Aida2ROOT::aida2root(histogram); - dyn_string *HistoFullName = Strsplit((char*) hRoot->GetName(), - (char*) "/"); - gDirectory->Cd("/"); - for (unsigned int i = 0; i < HistoFullName->size() - 1; i++) - { - TKey *k; - k = gDirectory->GetKey(HistoFullName->at(i).c_str()); - if (k == 0) - { - gDirectory->mkdir(HistoFullName->at(i).c_str()); - } - gDirectory->Cd(HistoFullName->at(i).c_str()); - } - hRoot->Write(HistoFullName->at(HistoFullName->size() - 1).c_str()); - // msg << MSG::INFO << ", saving name=" << hRoot->GetName() << " directory=" - // << (hRoot->GetDirectory() ? hRoot->GetDirectory()->GetName() : "none") <<endmsg; - // should we reset on the root level? - // if (reset) hRoot->Reset(); - } - // msg << MSG::DEBUG << "Resetting histogram" << endmsg; - if (reset) - { - // msg << MSG::INFO << "Resetting histogram" << endmsg; - histogram->reset(); - } + if( IHistogram* histogram = dynamic_cast<AIDA::IHistogram*>(dataObject) ) { + save_histogram(histogram, save, reset); idList.push_back(id); continue; } - IProfile1D* profile = dynamic_cast<AIDA::IProfile1D*>(dataObject); - if (0 != profile) - { - if (save) - { - TProfile* hRoot = (TProfile*) Gaudi::Utils::Aida2ROOT::aida2root( - profile); - dyn_string *HistoFullName = Strsplit((char*) hRoot->GetName(), - (char*) "/"); - gDirectory->Cd("/"); - for (unsigned int i = 0; i < HistoFullName->size() - 1; i++) - { - TKey *k; - k = gDirectory->GetKey(HistoFullName->at(i).c_str()); - if (k == 0) - { - gDirectory->mkdir(HistoFullName->at(i).c_str()); - } - gDirectory->Cd(HistoFullName->at(i).c_str()); - } - hRoot->Write(HistoFullName->at(HistoFullName->size() - 1).c_str()); - //should we reset at the root level? - //if (reset) hRoot->Reset(); - } - if (reset) - { - // msg << MSG::DEBUG << "Resetting profile" << endmsg; - profile->reset(); - } + if( IProfile1D* profile = dynamic_cast<AIDA::IProfile1D*>(dataObject) ) { + save_histogram(profile, save, reset); idList.push_back(id); continue; } - // not an histogram: must be a directory: create corresponding TDirectory - dyn_string *rootDirs = Strsplit((char*) id.c_str(), (char*) "/"); + std::unique_ptr<dyn_string> rootDirs(Strsplit(id.c_str(), "/")); TDirectory* newdir = rootdir; - if (NULL != newdir) - { + if( nullptr != newdir ) { newdir = rootdir->mkdir(rootDirs->at(rootDirs->size() - 1).c_str()); newdir->cd(); } int newLevel = level + 1; if (newLevel >= 10) continue; - histogramIdentifier(*it, idList, reset, save, newLevel, newdir); + histogramIdentifier(l, idList, reset, save, newLevel, newdir); } } - catch (const std::exception &ex) - { - msg << MSG::WARNING << "histogramidentifier std::exception: " << ex.what() - << endmsg; + catch (const std::exception &ex) { + msg << MSG::WARNING << "histogramidentifier std::exception: " << ex.what() << endmsg; } TH1::AddDirectory(dirstat); } -IRegistry* UpdateAndReset::rootObject() -{ - MsgStream msg(msgSvc(), name()); - std::string path; - SmartDataPtr<DataObject> smartDataPtr(m_histogramSvc, path); - // msg << MSG::DEBUG << "root identifier : " << smartDataPtr->registry()->identifier() << endmsg; - return smartDataPtr->registry(); +IRegistry* UpdateAndReset::rootObject() { + DataObject* pObj {nullptr}; + if ( histoSvc()->retrieveObject(std::string(),pObj).isSuccess() ) + return pObj->registry(); + return nullptr; } diff --git a/Online/Gaucho/src/components/UpdateAndReset.h b/Online/Gaucho/src/components/UpdateAndReset.h index aaa21dff2f465546bdabdfcdd255e3c881dc61c2..88feceef444e8f90469f372045b719298039fa5c 100644 --- a/Online/Gaucho/src/components/UpdateAndReset.h +++ b/Online/Gaucho/src/components/UpdateAndReset.h @@ -13,128 +13,75 @@ #define GAUCHO_UPDATEANDRESET_H 1 // Include files -#include "GaudiAlg/GaudiAlgorithm.h" -#include "GaudiKernel/IRegistry.h" -#include "Gaudi/Property.h" -#include "Gaucho/IGauchoMonitorSvc.h" -//#include "GauchoTimer.h" -#include "dim/dis.hxx" -#include <map> -#include <sstream> -#include "Event/RawEvent.h" -#include "Gaucho/EoEIncidentListener.h" -#include "Gaucho/Utilities.h" - -static const std::string s_statusNoUpdated("NO_UPDATED"); -static const std::string s_statusProcessingUpdate("PROCESSINGUPDATE"); -static const std::string s_statusUpdated("UPDATED"); - -//class DimService; - -class UpdateAndReset : public GaudiAlgorithm{ -public: - /// Constructor of this form must be provided - UpdateAndReset(const std::string& name, ISvcLocator* pSvcLocator); - - StatusCode initialize() override; - StatusCode execute() override; - StatusCode finalize() override; - StatusCode testeExecute(); - StatusCode start() override; - StatusCode stop() override; - StatusCode restart() override; - - - - void retrieveRunNumber(int runNumber, ulonglong gpsTime); - void retrieveCycleNumber(int cycleNumber); - - std::pair<std::pair<int, ulonglong>, bool> currentRunNumber(); - std::pair<int, bool> currentCycleNumber(ulonglong currentTime); - unsigned int currentTCK(); - ulonglong gpsTime(); - IIncidentSvc *m_incs; - bool m_stopdone; - void verifyAndProcessRunChange(); - void verifyAndProcessCycleChange(bool isFromTimerHandler); - double offsetToBoundary(int cycleNumber, ulonglong time, bool inferior); - time_t m_ProcLimit; -private: - bool isSaveCycle(int m_cycleNumber); - void manageTESHistos(bool list, bool reset, bool save, bool isFromEndOfRun); - void histogramIdentifier(IRegistry* object, std::vector<std::string> &idList, bool reset, bool save, int &level, - TDirectory* rootdir); - IRegistry* rootObject(); - void getEventChar(int &runno, unsigned int &tck, ulonglong &gps,long int &EvtNr); -private: - EoEIncidentListener *EoEInc; - IGauchoMonitorSvc* m_pGauchoMonitorSvc; ///< Online Gaucho Monitoring Service - IHistogramSvc* m_histogramSvc; - LHCb::RawEvent* m_rawEvt; - std::vector<std::string> m_bankNames; - std::vector<LHCb::RawBank::BankType> m_bankTypes; - - int m_desiredDeltaTCycle;// integer because dimTimer can only accept seconds - - // MonRate information - int m_one; - int m_runNumber; - int m_eorNumber; - long int m_L0EvtNr; - unsigned int m_triggerConfigurationKey; - unsigned int tck; - ulonglong gpstime; - int m_cycleNumber; - int m_firstCycleNumber; - ulonglong m_timeStart; - ulonglong m_timeFirstEvInRun; - double m_offsetTimeFirstEvInRun; - ulonglong m_timeLastEvInCycle; - double m_offsetTimeLastEvInCycle; - double m_gpsTimeLastEvInCycle; - double m_offsetGpsTimeLastEvInCycle; - double m_deltaTCycle; - bool m_abortRetroEvents; - - // For Testing RunNumber generator - int m_deltaTRunTest; - int m_runNumberTest; - - int m_teste; - - bool m_firstExecute; - bool m_doRunChangeInc; - bool m_ResetonStart; - - std::string m_utgid; - dyn_string *serviceParts; - std::string taskName; - std::string partName; - std::string instancenumber; - std::string infoName; - - std::string m_cycleStatus; - std::string m_runStatus; - std::string m_infoFileStatus; - std::string m_MyName; - - int m_disableMonRate; - int m_disableReadOdin; - int m_disableChekInTimer; - int m_disableChekInExecute; - int m_disableUpdateData; - int m_disableResetHistos; - int m_saveHistograms; - std::string m_saveSetDir; - int m_saverCycle; - int m_timerCycle; - int m_numCyclesToSave; - int m_resetHistosAfterSave; - bool m_publishSavesetLoc; - DimService *m_dimSvcSaveSetLoc; - -}; - +#include <Gaudi/Algorithm.h> +#include <GaudiKernel/IRegistry.h> +#include <GaudiKernel/DataObjectHandle.h> +#include <Gaucho/IGauchoMonitorSvc.h> + +#include <mutex> + +class TDirectory; +class DimService; + +namespace Online { + class Tell1Bank; + + class UpdateAndReset : public Gaudi::Algorithm { + public: + /// Constructor of this form must be provided + UpdateAndReset(const std::string& name, ISvcLocator* pSvcLocator); + + StatusCode initialize() override; + StatusCode execute(EventContext const& ctxt) const override final; + StatusCode finalize() override; + StatusCode testeExecute(); + StatusCode start() override; + StatusCode stop() override; + StatusCode restart() override; + + StatusCode do_execute(int run_number); + + private: + void manageTESHistos(bool list, bool reset, bool save, bool isFromEndOfRun); + void histogramIdentifier(const IRegistry* object, + std::vector<std::string> &idList, + bool reset, bool save, int &level, + TDirectory* rootdir); + IRegistry* rootObject(); + + private: + SmartIF<IGauchoMonitorSvc> m_gauchoMonitorSvc; ///< Online Gaucho Monitoring Service + + typedef Tell1Bank BankHeader; + typedef std::vector<std::pair<const BankHeader*, const void*> > evt_data_t; + DataObjectReadHandle<evt_data_t> m_rawData{this,"RawData","Banks/RawData"}; + + DimService *m_dimSvcSaveSetLoc; + std::mutex m_mutex; + std::string m_taskName; + std::string m_partName; + std::string m_cycleStatus; + std::string m_runStatus; + std::string m_infoFileStatus; + + + // MonRate information + int m_one; + int m_runNumber; + int m_eorNumber; + + /// Properties: + std::string m_MyName; + std::string m_saveSetDir; + int m_desiredDeltaTCycle;// integer because dimTimer can only accept seconds + int m_disableReadOdin; + int m_saveHistograms; + int m_saverCycle; + int m_resetHistosAfterSave; + bool m_publishSavesetLoc; + bool m_resetOnStart; + }; +} #endif // GAUCHO_UPDATEANDRESET_H diff --git a/Online/GauchoAppl/CMakeLists.txt b/Online/GauchoAppl/CMakeLists.txt index 5b2effc125d58fa69548ffb9df6da89fdd6c3071..4a608750a1a835d75f8a38a372f50166f65f4227 100755 --- a/Online/GauchoAppl/CMakeLists.txt +++ b/Online/GauchoAppl/CMakeLists.txt @@ -5,6 +5,7 @@ gaudi_subdir(GauchoAppl v1r33) gaudi_depends_on_subdirs(GaudiKernel Online/Gaucho + Online/Tell1Data Online/GaudiOnline) find_package(ROOT COMPONENTS Core Cling Thread Minuit Gpad) diff --git a/Online/GauchoAppl/GauchoAppl/AddTimer.h b/Online/GauchoAppl/GauchoAppl/AddTimer.h index 7878eb39c6715c77fc1c03d65f9fd9060045517e..809aab1cfb3cc87c507c4cb8d3c21df5a4d30974 100644 --- a/Online/GauchoAppl/GauchoAppl/AddTimer.h +++ b/Online/GauchoAppl/GauchoAppl/AddTimer.h @@ -15,6 +15,7 @@ #include "Gaucho/GenTimer.h" #include "Gaucho/BRTL_Lock.h" class MonAdder; + class AddTimer : public GenTimer { MonAdder *m_owner; diff --git a/Online/GauchoAppl/GauchoAppl/COutService.h b/Online/GauchoAppl/GauchoAppl/COutService.h index ed1ece19fa85b173c27f59b221829953b0f2150e..237643e2287f57be0c0e80d1aa970800a2bfa797 100644 --- a/Online/GauchoAppl/GauchoAppl/COutService.h +++ b/Online/GauchoAppl/GauchoAppl/COutService.h @@ -18,42 +18,29 @@ #ifndef COUTSERVICE_H_ #define COUTSERVICE_H_ -#include <string> + #include <map> +#include <memory> +#include <string> #include <dim/dis.hxx> -//class DimService; class COutServiceBase { public: std::string m_nam; - COutServiceBase(const std::string nam) - { - m_nam = nam; - } + COutServiceBase(const std::string& nam) : m_nam(nam) { } + virtual ~COutServiceBase() = default; }; + template <typename T> class COutService : public COutServiceBase { public: T m_data; - DimService *m_serv; - COutService(std::string nam); -// { -// printf("New Output Service %s of type %s\n",nam.c_str(),typeid(T).name()); -// m_data = -1; -// m_serv = new DimService(m_nam.c_str(),m_data); -// } + std::unique_ptr<DimService> m_serv; + + COutService(const std::string& name); + virtual ~COutService() = default; void Update(T &dat); -// { -// printf("Update Service %s of type %s\n",m_nam.c_str(),typeid(T).name()); -// m_serv->updateService(dat); -// } - //COutService(std::string nam); - - ~COutService() - { - delete m_serv; - } }; typedef std::map<std::string,COutServiceBase*> COUTServiceMap; diff --git a/Online/GauchoAppl/GauchoAppl/ClassDescriptor.h b/Online/GauchoAppl/GauchoAppl/ClassDescriptor.h index b3b4cad06ca23dd5501768ae0edcc3592028feaf..ac88d65da347d4a6cb28fe6c951536f99f72aea8 100644 --- a/Online/GauchoAppl/GauchoAppl/ClassDescriptor.h +++ b/Online/GauchoAppl/GauchoAppl/ClassDescriptor.h @@ -67,7 +67,4 @@ class ClassMap : public std::map<std::string,ClassDescriptor*> } } }; - - - #endif /* ONLINE_GAUCHOAPPL_GAUCHOAPPL_CLASSDESCRIPTOR_H_ */ diff --git a/Online/GauchoAppl/GauchoAppl/HistAdder.h b/Online/GauchoAppl/GauchoAppl/HistAdder.h index 909f1f56eccc2ad3604b01566d75263eb41f6315..5dd6028b1a7be43b18af4dba9c8713277c1be682 100644 --- a/Online/GauchoAppl/GauchoAppl/HistAdder.h +++ b/Online/GauchoAppl/GauchoAppl/HistAdder.h @@ -11,21 +11,7 @@ //========================================================================== #ifndef HISTADDER_H #define HISTADDER_H -#include "Gaucho/MonTypes.h" -#include "Gaucho/MonInfo.h" -#include "Gaucho/ObjService.h" -#include <map> -#include <string> -#include "GauchoAppl/AddSerializer.h" #include "GauchoAppl/MonAdder.h" -#include "stdlib.h" -#include "stdio.h" - -class ObjService; -class MonServer; -class ObjRPC; -//class HistAdder; -class MyTProfile; class HistAdder : public MonAdder { @@ -33,9 +19,7 @@ public: void add(void *buffer, int siz, MonInfo *h) override; void addBuffer(void *buffer, int siz, MonInfo *h) override; void Update() override; - HistAdder(char *myName, char * serviceName/*, bool expand = false*/); + HistAdder(const char* myName, const char* serviceName); virtual ~HistAdder(); -// void TaskHandler(char*,int); -// void ServiceHandler(DimInfo *,char*,int); }; #endif diff --git a/Online/GauchoAppl/GauchoAppl/InfoHandlers.h b/Online/GauchoAppl/GauchoAppl/InfoHandlers.h index 9e7ddd027705718b3aa409d3819403a760453dd6..59f0b78d73f869917a1c5bea849e866184f4b6dd 100644 --- a/Online/GauchoAppl/GauchoAppl/InfoHandlers.h +++ b/Online/GauchoAppl/GauchoAppl/InfoHandlers.h @@ -20,7 +20,7 @@ #define INFOHANDLERS_H_ #include <map> #include <string> -#include "dim/dic.hxx" +#include <dim/dic.hxx> typedef std::map<std::string, DimInfo*> TaskMap; typedef std::pair<std::string,DimInfo*> TaskPair; diff --git a/Online/GauchoAppl/GauchoAppl/MonAdder.h b/Online/GauchoAppl/GauchoAppl/MonAdder.h index ce92fc3735a62ca5df2490fe41019f47c25f9866..be2989c71bb27ec14480b302d62f955a2835806d 100644 --- a/Online/GauchoAppl/GauchoAppl/MonAdder.h +++ b/Online/GauchoAppl/GauchoAppl/MonAdder.h @@ -12,32 +12,32 @@ #ifndef ONLINE_GAUCHO_MonAdder_H #define ONLINE_GAUCHO_MonAdder_H -#include "Gaucho/MonTypes.h" -#include "Gaucho/ObjService.h" +#include <Gaucho/MonTypes.h> +#include <Gaucho/ObjService.h> +#include <Gaucho/BRTL_Lock.h> +#include <Gaucho/MonInfo.h> +#include <Gaucho/Utilities.h> +#include <GauchoAppl/AddTimer.h> +#include <GauchoAppl/RunManager.h> + +#include <dim/dic.hxx> +#include <RTL/rtl.h> +#include <dim/dis.hxx> + #include <map> #include <string> #include <set> #include <memory> -#include <boost/regex.hpp> -#include "dim/dic.hxx" -#include "Gaucho/MonInfo.h" -#include "RTL/rtl.h" -#include "Gaucho/Utilities.h" -#include "GauchoAppl/AddTimer.h" -#include "Gaucho/BRTL_Lock.h" -#include "dim/dis.hxx" #include <vector> -#include "GauchoAppl/RunManager.h" +#include <boost/regex.hpp> #define ADD_HISTO 1 #define ADD_COUNTER 2 -//#include "CCPCSerializer.h" //char hist_prefix[]="_HIST_"; std::string getClassName(std::string &service); #define offsetinBounds(base,recl,offs) !((AddPtr(base,offs)>AddPtr(base,recl))||(AddPtr(base,offs)<base)||(offs<0)) -//using namespace std; -//typedef std::map<std::string, void*> MonMap; + class MonMap : public std::map<std::string, void*> { public: @@ -121,24 +121,7 @@ public: return m_buffer; } }; -//class OUTServiceDescr -//{ -//public: -// std::string m_serviceName; -// long long last_update; -// void *m_svc; -// void *m_buffer; -// int m_buffersize; -// OUTServiceDescr(char *name, void *srvc) -// { -// m_serviceName = std::string(name); -// m_svc = srvc;//new ObjService(m_serviceName.c_str(),(char*)"C",&empty,4,&m_buffer,&m_buffersize); -// } -// ~OUTServiceDescr() -// { -//// delete m_svc; -// } -//}; + typedef std::map<std::string, TaskSvcDescr*> TaskServiceMap; typedef std::pair<std::string, TaskSvcDescr*> TaskServicePair; typedef TaskServiceMap::iterator TaskServIter; @@ -147,40 +130,36 @@ typedef std::map<std::string, INServiceDescr*> INServiceMap; typedef std::pair<std::string, INServiceDescr*> INServicePair; typedef INServiceMap::iterator INServIter; -//typedef std::map<std::string, OUTServiceDescr*> OUTServiceMap; -//typedef std::pair<std::string, OUTServiceDescr*> OUTServicePair; -//typedef OUTServiceMap::iterator OUTServIter; - class TaskDescr { public: INServiceMap m_servicemap; - std::string m_TaskName; - TaskDescr(char *name) + std::string m_TaskName; + TaskDescr(const char *name) { m_TaskName = name; -// m_services.erase(); } }; typedef std::map<std::string, TaskDescr*> TskMap; typedef std::pair<std::string, INServiceDescr*> TskPair; typedef TskMap::iterator TskIter; + class TskServiceMap : public std::map<std::string,std::string> { - public: - void Dump(); + public: + void Dump(); }; namespace AIDA { class IHistogram1D; } class IGauchoMonitorSvc; - class TimeoutCmd; class AdderSvc; class DimServiceDns; class ClassDescriptor; class ClassMap; + class HistEntry { public: @@ -198,7 +177,7 @@ class TaskStruct class MonAdder { public: - ClassDescriptor *m_currentClass; + ClassDescriptor *m_currentClass; // std::vector<HistEntry*> m_HistActions; std::map<long long,std::vector<HistEntry*>*> m_HistQueueMap; std::map<std::string, TaskStruct*> m_TaskInventory; @@ -278,6 +257,7 @@ public: virtual void BasicAdd(void *buffer, int siz, MonInfo *h); virtual void addBuffer(void *buffer, int siz, MonInfo *h)=0; bool m_isSaver; + MonAdder(); virtual ~MonAdder(); void *Allocate(int siz); diff --git a/Online/GauchoAppl/GauchoAppl/RunManager.h b/Online/GauchoAppl/GauchoAppl/RunManager.h index 52289cdeb2f33bfa70a9a0e1218b002e17eb9062..c4c170c0a7b65b358341f4576439768b4a031427 100644 --- a/Online/GauchoAppl/GauchoAppl/RunManager.h +++ b/Online/GauchoAppl/GauchoAppl/RunManager.h @@ -18,13 +18,11 @@ #ifndef ONLINE_GAUCHOAPPL_GAUCHOAPPL_RUNMANAGER_H_ #define ONLINE_GAUCHOAPPL_GAUCHOAPPL_RUNMANAGER_H_ -#include "map" + +#include <map> + class ClassMap; -class RunDescr -{ - public: -}; class RunManager: public std::map<unsigned int,ClassMap*> { public: diff --git a/Online/GauchoAppl/src/AdderSvc.cpp b/Online/GauchoAppl/src/AdderSvc.cpp index b559c5ffdfb51dc668c1c37e8ac67e153cb11303..8bcfb7bf2ba69f8739592a8495f6230bf10897bd 100644 --- a/Online/GauchoAppl/src/AdderSvc.cpp +++ b/Online/GauchoAppl/src/AdderSvc.cpp @@ -157,7 +157,7 @@ StatusCode AdderSvc::initialize() if (m_dohisto) { m_arrhist = m_phistsvc->book(name()+"/arrivaltime","Adder Packet Arrival Time in seconds",100,0.0,50.0); - m_pMonitorSvc->declareInfo("ArrivalTimes",(const AIDA::IBaseHistogram*)m_arrhist,"",this); + m_pMonitorSvc->declareInfo("ArrivalTimes",/* (const AIDA::IBaseHistogram*)*/ m_arrhist,"",this); } return StatusCode::SUCCESS; } @@ -187,6 +187,7 @@ StatusCode AdderSvc::start() } m_AdderSys = &AdderSys::Instance(); m_AdderSys->setDebugOn(m_DebugOn); + MonInfo::ShutdowninProgress = false; // Nodeadders: // Source task names: // Reconstruction task structure: <Partition>_<Node>_RecBrunel_xx @@ -255,11 +256,11 @@ StatusCode AdderSvc::start() if (m_AdderClass == "hists") { - m_adder = new HistAdder((char*)myservicename.c_str(), (char*)"Data"); + m_adder = new HistAdder(myservicename.c_str(), "Data"); } else if (m_AdderClass == "counter") { - m_adder = new CounterAdder((char*)myservicename.c_str(), (char*)"Data"); + m_adder = new CounterAdder(myservicename.c_str(), "Data"); } m_adder->m_DebugOn = m_DebugOn; m_adder->m_Test = m_Test; @@ -397,6 +398,7 @@ StatusCode AdderSvc::finalize() // m_adder->m_histo = 0; // m_phistsvc->unregisterObject((AIDA::IBaseHistogram*)m_arrhist); } + MonInfo::ShutdowninProgress = true; m_arrhist = 0; if (m_adder != 0) { diff --git a/Online/GauchoAppl/src/COutService.cpp b/Online/GauchoAppl/src/COutService.cpp index 2ea0e2e07dec32d30cf806ca6bf14a0821a6705e..4fdaed36ad6afdc6fa0fda2b6f38616013dda744 100644 --- a/Online/GauchoAppl/src/COutService.cpp +++ b/Online/GauchoAppl/src/COutService.cpp @@ -17,29 +17,26 @@ */ #include <typeinfo> #include "GauchoAppl/COutService.h" -template <typename T> COutService<T>::COutService(std::string nam):COutServiceBase(nam) +template <typename T> COutService<T>::COutService(const std::string& nam):COutServiceBase(nam) { -// printf("New Standard Output Service %s of type %s\n",nam.c_str(),typeid(T).name()); m_data = -1; - m_serv = new DimService(m_nam.c_str(),m_data); + m_serv.reset(new DimService(m_nam.c_str(),m_data)); } + template <typename T> void COutService<T>::Update(T &dat) { -// printf("Update Service %s of type %s\n",m_nam.c_str(),typeid(T).name()); m_serv->updateService(dat); } -template <> COutService<double>::COutService(std::string nam) : COutServiceBase(nam) +template <> COutService<double>::COutService(const std::string& nam) : COutServiceBase(nam) { m_data = -1; -// printf("New SPECIAL Output Service %s of type double\n",nam.c_str()); - m_serv = new DimService(m_nam.c_str(),"F",0,0);//(float&)m_data); + m_serv.reset(new DimService(m_nam.c_str(),"F",0,0));//(float&)m_data); } -template <> COutService<long long>::COutService(std::string nam) : COutServiceBase(nam) +template <> COutService<long long>::COutService(const std::string& nam) : COutServiceBase(nam) { m_data = -1; -// printf("New SPECIAL Output Service %s of type long long\n", nam.c_str()); - m_serv = new DimService(m_nam.c_str(),"I",0,0); + m_serv.reset(new DimService(m_nam.c_str(),"I",0,0)); } template <> void COutService<double>::Update(double &d) diff --git a/Online/GauchoAppl/src/HistAdder.cpp b/Online/GauchoAppl/src/HistAdder.cpp index a6c8d0c742f806328c49623c77cad8d0f9f4c6a9..4433537c4bdfda17010459310c0381ca17bd5c74 100644 --- a/Online/GauchoAppl/src/HistAdder.cpp +++ b/Online/GauchoAppl/src/HistAdder.cpp @@ -45,7 +45,7 @@ extern "C" return 0; } } -HistAdder::HistAdder(char *myName, char *serviceName) +HistAdder::HistAdder(const char *myName, const char *serviceName) { m_serviceName = serviceName; // m_serviceName = std::string("/Histos/") + serviceName; diff --git a/Online/GauchoAppl/src/MonAdder.cpp b/Online/GauchoAppl/src/MonAdder.cpp index 217c01a1630e0c29ad057be239ba2eef945ce7f9..3b2f678b75cf63820d437d8b4a2f471373fbf6fc 100644 --- a/Online/GauchoAppl/src/MonAdder.cpp +++ b/Online/GauchoAppl/src/MonAdder.cpp @@ -510,7 +510,7 @@ void MonAdder::SynchronizeServices(std::string taskname, std::vector<std::string } if (!status) { - ::lib_rtl_output(LIB_RTL_ERROR,"SynchronizeServices: No Match Taskname = %s, expected task name = %s\n",taskname.c_str(),m_taskPattern.c_str()); + if (m_DebugOn) ::lib_rtl_output(LIB_RTL_ERROR,"SynchronizeServices: No Match Taskname = %s, expected task name = %s\n",taskname.c_str(),m_taskPattern.c_str()); return; } if (m_DebugOn) ::lib_rtl_output(LIB_RTL_ERROR,"Success In SynchronizeServices: Taskname = %s, expected task name = %s\n",taskname.c_str(),m_taskPattern.c_str()); diff --git a/Online/GauchoAppl/src/Test/CounterTest.cpp b/Online/GauchoAppl/src/Test/CounterTest.cpp index 905d74810e368707043c758531eca63fd95e61df..f50e0b82c8d5ddb12896abf54532e4e7a79b0c44 100644 --- a/Online/GauchoAppl/src/Test/CounterTest.cpp +++ b/Online/GauchoAppl/src/Test/CounterTest.cpp @@ -16,175 +16,160 @@ * Author: beat */ -#include "Gaucho/CounterTask.h" -#include "Gaucho/MonCounter.h" +#include <Gaucho/CounterTask.h> +#include <Gaucho/MonCounter.h> +#include <RTL/rtl.h> + +#include <iostream> +#include <iomanip> + +static void print_tasks(const std::set<std::string>& tasks) { + size_t i = 0; + for( const auto& t : tasks ) + ::printf("Task[%3ld] %s\n", ++i, t.c_str()); +} int main(int argc, char *argv[]) { // Taskname, DNS Node - CounterTask *h; - std::string task; - std::string dns; - printf ("Number of Arguments: %d\n",argc); - if (argc ==3) - { - task = std::string(argv[1]); - dns = std::string(argv[2]); - } - else if (argc ==2) - { - task = ""; - dns = argv[1]; + std::string dns, task; + int continuous = 0; + RTL::CLI cli(argc, argv, [] (){ + std::cout + << " Usage: CounterTest -arg [-arg] \n" + << " -d(ns)=<dns> DNS name to interrogate for services\n" + << " -t(ask)=<task-name> Supply task name for detailed counter printout\n" + << " -c(continuous)=<number> Continuous mode. Give seconds between updates." + << std::endl; + }); + cli.getopt("continuous", 1, continuous); + cli.getopt("task", 1, task); + cli.getopt("dns", 1, dns); + if ( dns.empty() ) { + std::cout << "Insufficient Number of arguments" << std::endl; + cli.call_help(); } - else - { - printf ("Insufficient Number of arguments\n"); - return 0; + if ( continuous < 1 ) { + continuous = 2; } - std::vector<std::string> tasks; - tasks.clear(); + + std::set<std::string> tasks; CounterTask::TaskList(dns,tasks); - for (unsigned int i=0;i<tasks.size();i++) - { - printf ("%s\n",tasks[i].c_str()); - } - h = new CounterTask(task,dns); - std::vector<std::string> hists; - hists.clear(); - int status = h->Directory(hists); - if (status == 1) - { - printf("Task does not exist...\n"); - return 1; - } - for (unsigned int i=0;i<hists.size();i++) - { - printf ("%s\n",hists[i].c_str()); - } - printf("Number of Counters for Task %s %d\n",task.c_str(),(int)hists.size()); - std::vector<std::string> hsts; - printf("Trying to retrieve the following Counters\n "); - for (unsigned int i=0;i<hists.size();i++) - { - hsts.push_back(hists[i]); - printf("%s\n",hsts[i].c_str()); + if ( task.empty() ) { + print_tasks(tasks); } - std::vector<CntrDescr*> objs; - h->Counters(hsts,objs); - printf ("Retrieved %d Counters\n", (int)objs.size()); - for (unsigned int i=0;i<objs.size();i++) - { - printf ("Counter %-32s at address %p data ",objs[i]->name.c_str(), (void*)objs[i]); - switch (objs[i]->type) - { + else { + auto h = std::make_unique<CounterTask>(task, dns); + std::vector<std::string> counters; + std::vector<std::string> hsts; + std::vector<CntrDescr*> objs; + + int status = h->Directory(counters); + if (status == 1) { + std::cout << "Task " << task << " does not exist..." << std::endl; + return 1; + } + std::cout << "Number of Counters for Task " << task << " " << counters.size() << std::endl; + std::cout << "Trying to retrieve the following Counters:" << std::endl; + for (size_t i=0;i<counters.size();i++) { + hsts.push_back(counters[i]); + std::cout << hsts[i] << std::endl; + } + std::cout << std::flush; + + Again: + objs.clear(); + h->Counters(hsts,objs); + std::cout << std::endl + << RTL::timestr() << " Retrieved " << objs.size() << " Counters " << std::endl; + for (size_t i=0; i<objs.size(); i++) { + char text[128]; + switch (objs[i]->type) { case C_INT: - { - printf ("(INT) %d\n",objs[i]->i_data); - break; - } + snprintf(text, sizeof(text), "(INT) %d",objs[i]->i_data); + break; case C_LONGLONG: case C_ATOMICINT: case C_ATOMICLONG: case C_GAUDIACCLONG: case C_GAUDIACCINT: - { - printf ("(LONGLONG) %ld\n",long(objs[i]->l_data)); - break; - - } + snprintf(text, sizeof(text), "(LONGLONG) %ld",long(objs[i]->l_data)); + break; case C_FLOAT: case C_ATOMICFLOAT: - { - printf ("(FLOAT) %f\n",objs[i]->f_data); - break; - } + snprintf(text, sizeof(text), "(FLOAT) %f",objs[i]->f_data); + break; case C_DOUBLE: case C_ATOMICDOUBLE: - { - printf ("(DOUBLE) %f\n",objs[i]->d_data); - break; - } + snprintf(text, sizeof(text), "(DOUBLE) %f",objs[i]->d_data); + break; case C_RATEDOUBLE: - { - printf ("(RATEDOUBLE) %f Hz\n",objs[i]->d_data); - break; - } + snprintf(text, sizeof(text), "(RATEDOUBLE) %f Hz",objs[i]->d_data); + break; case C_RATEFLOAT: - { - printf ("(RATEFLOAT) %f Hz\n",objs[i]->f_data); - break; - } + snprintf(text, sizeof(text), "(RATEFLOAT) %f Hz",objs[i]->f_data); + break; case C_INTSTAR: case C_UINTSTAR: - { - int *p = (int*)objs[i]->ptr; - int nel = objs[i]->nel; - for (int j=0;j<nel;j++) - { - printf("(INT*) index %d value %d\n",j,p[j]); - } - break; - } + for (int j=0, nel=objs[i]->nel, *p=(int*)objs[i]->ptr; j<nel; j++) { + snprintf(text, sizeof(text), "(INT*) index %d value %d",j,p[j]); + } + break; case C_LONGSTAR: case C_ULONGSTAR: - { - long *p = (long*)objs[i]->ptr; - int nel = objs[i]->nel; - for (int j=0;j<nel;j++) - { - printf("(LONG*) index %d value %li\n",j,p[j]); - } - break; - } + { + long *p = (long*)objs[i]->ptr; + int nel = objs[i]->nel; + for (int j=0;j<nel;j++) { + snprintf(text, sizeof(text), "(LONG*) index %d value %li",j,p[j]); + } + } + break; case C_FLOATSTAR: - { - float *p = (float*)objs[i]->ptr; - int nel = objs[i]->nel; - for (int j=0;j<nel;j++) - { - printf("(FLOAT*) index %d value %f\n",j,p[j]); - } - break; - } + { + float *p = (float*)objs[i]->ptr; + int nel = objs[i]->nel; + for (int j=0;j<nel;j++) { + snprintf(text, sizeof(text), "(FLOAT*) index %d value %f",j,p[j]); + } + } + break; case C_DOUBLESTAR: case C_RATEDOUBLESTAR: - { - double *pp = (double*)(objs[i]->ptr); - int nel = objs[i]->nel; - for (int j=0;j<nel;j++) - { - double p = pp[j]; - printf("(DOUBLE*) index %d value %f\n",j,p); - } - break; - } + { + double *pp = (double*)(objs[i]->ptr); + int nel = objs[i]->nel; + for (int j=0;j<nel;j++) { + double p = pp[j]; + snprintf(text, sizeof(text), "(DOUBLE*) index %d value %f",j,p); + } + } + break; case C_INTPAIR: - { - printf("(INT Pair) value %d %d\n",objs[i]->ip_data.first,objs[i]->ip_data.second); - break; - } + snprintf(text, sizeof(text), "(INT Pair) value %d %d",objs[i]->ip_data.first,objs[i]->ip_data.second); + break; case C_LONGPAIR: - { - printf("(LONG Pair) value %ld %ld\n",objs[i]->lp_data.first,objs[i]->lp_data.second); - break; - } + snprintf(text, sizeof(text), "(LONG Pair) value %ld %ld",objs[i]->lp_data.first,objs[i]->lp_data.second); + break; case C_GAUDIAVGACCl: - { - printf("(Gaudi Averging Counter <long>) value %ld %ld\n",objs[i]->lp_data.first,objs[i]->lp_data.second); - break; - } + snprintf(text, sizeof(text), "(Gaudi Averging Counter <long>) value %ld %ld",objs[i]->lp_data.first,objs[i]->lp_data.second); + break; case C_GAUDIAVGACCd: - { - printf("(Gaudi Averging Counter<double>) value %ld %f\n",objs[i]->avg_data.first,objs[i]->avg_data.second); - break; - } + snprintf(text, sizeof(text), "(Gaudi Averging Counter<double>) value %ld %f",objs[i]->avg_data.first,objs[i]->avg_data.second); + break; case C_GAUDIBINACC: - { - printf("(Gaudi Binary Counter) value %ld %ld\n",objs[i]->lp_data.first,objs[i]->lp_data.second); - break; - } + snprintf(text, sizeof(text), "(Gaudi Binary Counter) value %ld %ld",objs[i]->lp_data.first,objs[i]->lp_data.second); + break; default: - { - printf("Unknown Counter\n"); + snprintf(text, sizeof(text), "Unknown Counter"); + break; } + std::cout << "Counter " << std::left << std::setw(32) << objs[i]->name + << " at address " << (void*)objs[i] << " data " << text << std::endl; + std::cout << std::flush; + } + if ( continuous > 0 ) { + std::cout << "=========================================================================================" << std::endl; + ::lib_rtl_sleep(continuous*1000); + goto Again; } } return 0; diff --git a/Online/GauchoAppl/src/Test/HistTest.cpp b/Online/GauchoAppl/src/Test/HistTest.cpp index 31134fb8f5a6561cc7adb72c11da3fac7ddc1d2c..2b62642582fce17632383f4c8d386ddf1518893d 100644 --- a/Online/GauchoAppl/src/Test/HistTest.cpp +++ b/Online/GauchoAppl/src/Test/HistTest.cpp @@ -16,64 +16,94 @@ * Author: beat */ -#include "Gaucho/HistTask.h" -#include "TH1D.h" -#include "TH2D.h" -#include "TProfile.h" -#include "TBrowser.h" -#include "TApplication.h" -#include "TROOT.h" +#include <Gaucho/HistTask.h> +#include <RTL/rtl.h> +#include <TH1D.h> +#include <TH2D.h> +#include <TRint.h> +#include <TProfile.h> +#include <TBrowser.h> +#include <TDirectory.h> + +#include <iostream> +#include <iomanip> + +static void print_tasks(const std::set<std::string>& tasks) { + size_t i = 0; + for( const auto& t : tasks ) + ::printf("Task[%3ld] %s\n", ++i, t.c_str()); +} + int main(int argc, char *argv[]) // Taskname, DNS Node { + RTL::CLI cli(argc, argv, [] (){ + std::cout + << " Usage: HistTest -arg [-arg] \n" + << " -d(ns)=<dns> DNS name to interrogate for services\n" + << " -t(ask)=<task-name> Supply task name for detailed counter printout\n" + << " -s(how) Display the retrieved histograms." + << std::endl; + }); + std::string dns, task; + bool show = cli.getopt("show",1); + cli.getopt("task", 1, task); + cli.getopt("dns", 1, dns); + if ( dns.empty() ) { + std::cout << "Insufficient Number of arguments" << std::endl; + cli.call_help(); + } + TH1D::SetDefaultSumw2(); TH2D::SetDefaultSumw2(); TProfile::SetDefaultSumw2(); - HistTask *h; - std::string task; - std::string dns; - task = std::string(argv[1]); - dns = std::string(argv[2]); - std::vector<std::string> tasks; - tasks.clear(); - HistTask::TaskList(dns,tasks); - for (unsigned int i=0;i<tasks.size();i++) - { - printf ("%s\n",tasks[i].c_str()); - } - h = new HistTask(task,dns); - std::vector<std::string> hists; - hists.clear(); - int status = h->Directory(hists); - if (status == 1) - { - printf("Task does not exist...\n"); - return 1; - } - for (unsigned int i=0;i<hists.size();i++) - { - printf ("%s\n",hists[i].c_str()); - } - printf("Number of Histograms for Task %s %d\n",task.c_str(),(int)hists.size()); - std::vector<std::string> hsts; - printf("Trying to retrieve the following histograms\n "); - for (unsigned int i=0;i<(hists.size()>hists.size()?3:hists.size());i++) - { - hsts.push_back(hists[i]); - printf("%s\n",hsts[i].c_str()); + + if ( task.empty() ) { + std::set<std::string> tasks; + HistTask::TaskList(dns,tasks); + print_tasks(tasks); } - std::vector<TObject*> robjs; - h->Histos(hsts,robjs); - printf ("Retrieved %d Histograms\n", (int)robjs.size()); - for (unsigned int i=0;i<robjs.size();i++) - { - gDirectory->Add(robjs[i]); - printf ("Histogram %s at address %llx\n",hsts[i].c_str(), (long long unsigned int)robjs[i]); + else { + auto h = std::make_unique<HistTask>(task, dns); + std::vector<std::string> hists; + hists.clear(); + int status = h->Directory(hists); + if (status == 1) { + printf("Task does not exist...\n"); + return 1; + } + for (std::size_t i=0; i < hists.size(); i++) + std::cout << hists[i] << std::endl; + + std::cout << "Number of Histograms for Task " << task << ": " << hists.size() << std::endl; + + std::vector<std::string> hsts; + std::cout << "Trying to retrieve the histograms" << std::endl; + for (std::size_t i=0; i < hists.size(); i++) + hsts.push_back(hists[i]); + + std::vector<TObject*> robjs; + h->Histos(hsts,robjs); + std::cout << "Retrieved " << robjs.size() << " Histograms" << std::endl; + for (std::size_t i=0; i < robjs.size(); i++) { + std::cout << "Histogram [" << i << "]: " << hsts[i] + << " at address " << (void*)robjs[i]; + std::cout << std::endl; + } + if ( show ) { + char cmd[256]; + TRint theApp("App", &argc, argv); + ::lib_rtl_sleep(100); + ::snprintf(cmd,sizeof(cmd), + "std::vector<TH1*>& gHistos = *(std::vector<TH1*>*)%p;", + (void*)&robjs); + gInterpreter->ProcessLine(cmd); + std::cout << std::endl + << "***** Use the ROOT interpreter variable " << std::endl + << "***** 'std::vector<TH1*>& gHistos'" << std::endl + << "***** to access and draw histograms!" << std::endl; + new TBrowser(); + theApp.Run(); + } } -// new TApplication(); - TApplication theApp("App", &argc, argv); - new TBrowser(); - theApp.Run(); - char ch[255]; - scanf("%s\n",ch); return 0; } diff --git a/Online/GauchoAppl/src/Test/RPCTest.cpp b/Online/GauchoAppl/src/Test/RPCTest.cpp index 654a6080455b1f7dba23a7819ea7f9e4938303bd..8e0b346c25d642ca22ad09e573e4e8f0643ed50d 100644 --- a/Online/GauchoAppl/src/Test/RPCTest.cpp +++ b/Online/GauchoAppl/src/Test/RPCTest.cpp @@ -20,65 +20,58 @@ #include "TH2D.h" #include "TTimer.h" #include "Gaucho/HistSerDes.h" -class MyTTimer : public TTimer -{ - -public: - RPCCommRead *rrd; - int rdlen; - RPCRec *rec; - MyTTimer(RPCRec* r, RPCCommRead *rdc, int rlen) : TTimer(5000,true) - { - rec = r; - rrd = rdc; - rdlen = rlen; - } - Bool_t Notify() override +namespace { + class MyTTimer : public TTimer { - printf("Timer Fired\n"); - rec->setData(rrd,rdlen); - Start(5000,true); - return true; + public: + RPCRec *rec {nullptr}; + RPCCommRead *rrd {nullptr}; + int rdlen {0}; + MyTTimer(RPCRec* r, RPCCommRead *rdc, int rlen) + : TTimer(5000,true), rec(r), rrd(rdc), rdlen(rlen) + { + } + Bool_t Notify() override + { + ::printf("Timer Fired\n"); + rec->setData(rrd,rdlen); + Start(5000,true); + return true; + }; }; -}; -TCanvas *canv; -std::vector <std::string*> hnames; -static TObject *o=0; -extern "C" -{ - void DirCB(NAMEVEC *nam) - { - NAMEVEC::iterator i; - hnames.clear(); - for (i=nam->begin();i!=nam->end();i++) + TCanvas *canv; + std::vector <std::string*> hnames; + static TObject *o=0; + void DirCB(RPCRec::NAMEVEC &nam) + { + hnames.clear(); + for (auto i=nam.begin();i!=nam.end();i++) { - hnames.push_back(new std::string(*i)); + hnames.push_back(new std::string(*i)); } -// printf("Total Number of Histograms: %d\n",n_hist); - } - void DatCB(PTRMAP *hists) - { -// MonHist h; - PTRMAP::iterator i; - for (i=hists->begin();i!=hists->end();i++) + // printf("Total Number of Histograms: %d\n",n_hist); + } + void DatCB(RPCRec::PTRMAP &hists) + { + for (auto i=hists.begin();i!=hists.end();i++) { -// printf("Looping over Histos...\n"); - DimBuffBase *hist = (DimBuffBase *)i->second; - if (o) delete o; - o = (TObject*)HistSerDes::de_serialize(hist); - o->Draw(); + // printf("Looping over Histos...\n"); + DimBuffBase *hist = (DimBuffBase *)i->second; + if (o) delete o; + o = (TObject*)HistSerDes::de_serialize(hist); + o->Draw(); } - canv->Update(); - } + canv->Update(); + } } int main(int argc, char *argv[]) { // int rpcCBValue = 0; char *nam; - if (argc<=1) + if ( argc <= 1 ) { nam = (char*)"plus16_MON_Adder_MON_Moore_0/Histos/Data/Command"; } @@ -89,27 +82,21 @@ int main(int argc, char *argv[]) RPCRec rpcCB(nam, 1000); rpcCB.declareDirCB(&DirCB); rpcCB.declareDatCB(&DatCB); - //RPCRec rpcCB("ALPC15_HIST_shit_0/HistCommand", 1000); + RPCComm *rda = new RPCComm; -// void *req; - hnames.clear(); - RPCComm *rda; - RPCCommRead *rrd; - rda = new RPCComm; rda->c = RPCCReadAll; TH1D::SetDefaultSumw2(); TH2D::SetDefaultSumw2(); TProfile::SetDefaultSumw2(); - int dat; - dat = RPCCDirectory; + int dat = RPCCDirectory; rpcCB.setData(dat); while (hnames.size() == 0) { - sleep(1); + ::sleep(1); } for (int i=0;i<(int)hnames.size();i++) { - printf("%d %s\n",i,hnames[i]->c_str()); + ::printf("%d %s\n",i,hnames[i]->c_str()); } TApplication *app=new TApplication("Shit",&argc,argv); canv = gROOT->MakeDefCanvas(); @@ -117,10 +104,10 @@ int main(int argc, char *argv[]) canv->Show(); canv->Draw(); int rdlen = sizeof(RPCCommRead)+strlen(hnames[1023]->c_str()); - rrd = (RPCCommRead*)malloc(rdlen); - memset(rrd,0,rdlen); - strcpy(&rrd->which,hnames[1023]->c_str()); - printf("asking for histogram %s\n",hnames[1023]->c_str()); + RPCCommRead *rrd = (RPCCommRead*)malloc(rdlen); + ::memset(rrd,0,rdlen); + ::strcpy(&rrd->which,hnames[1023]->c_str()); + ::printf("asking for histogram %s\n",hnames[1023]->c_str()); rrd->c = RPCCRead; MyTTimer *timr = new MyTTimer(&rpcCB, rrd,rdlen); timr->TurnOn(); diff --git a/Online/GauchoAppl/src/components/PubSvc.h b/Online/GauchoAppl/src/components/PubSvc.h index 30c7cb0bf6032dc36169999e61c13a32ba319bad..fbf8f7efbd898391fca12e6c21482914630c9b2c 100644 --- a/Online/GauchoAppl/src/components/PubSvc.h +++ b/Online/GauchoAppl/src/components/PubSvc.h @@ -27,6 +27,8 @@ class IIncidentSvc; class IGauchoMonitorSvc; class IHistogramSvc; class ISimpleTrendWriter; + + class PubSvc : public Service, virtual public IIncidentListener { public: diff --git a/Online/GauchoBase/Gaucho/CounterTask.h b/Online/GauchoBase/Gaucho/CounterTask.h index 742826f95ed55427ba2fe453a322015078292da3..633db5eb79bf199b35182ea8f5f50355cf838378 100644 --- a/Online/GauchoBase/Gaucho/CounterTask.h +++ b/Online/GauchoBase/Gaucho/CounterTask.h @@ -18,14 +18,16 @@ #ifndef COUNTERTASK_H_ #define COUNTERTASK_H_ +#include <Gaucho/RPCRec.h> +#include <boost/regex.hpp> +#include <dim/dic.hxx> + #include <vector> #include <string> -#include <boost/regex.hpp> -#include "dim/dic.hxx" -#include "Gaucho/RPCRec.h" + class CntrDescr; -class CounterTask -{ + +class CounterTask { protected: std::string m_DNS; std::string m_task; @@ -39,7 +41,7 @@ public: int Counters(std::vector<std::string> &Ctrs); int Counters(std::vector<std::string> &CounterNames,std::vector<CntrDescr*> &Cntrs); int Counters(std::vector<std::string> &CounterNames,std::map<std::string,CntrDescr*> &Cntrs); - static int TaskList(std::string dns,std::vector<std::string> &); + template <typename CONT> static int TaskList(std::string dns, CONT &); }; #endif /* COUNTERTASK_H_ */ diff --git a/Online/GauchoBase/Gaucho/HistTask.h b/Online/GauchoBase/Gaucho/HistTask.h index 71749b954ab351e793bc552b8e81b714b685f4e4..5e2725fdd7852a6d70294e175e4c60a0aa2d36f2 100644 --- a/Online/GauchoBase/Gaucho/HistTask.h +++ b/Online/GauchoBase/Gaucho/HistTask.h @@ -21,12 +21,12 @@ #include <vector> #include <string> #include <boost/regex.hpp> -#include "dim/dic.hxx" -#include "Gaucho/RPCRec.h" +#include <Gaucho/RPCRec.h> class TObject; -class HistTask -{ + + +class HistTask { protected: std::string m_DNS; std::string m_task; @@ -40,7 +40,7 @@ public: int Directory(std::vector<std::string> &hists); int Histos(std::vector<std::string> &hists,std::vector<TObject*> &histos); int Histos(std::vector<std::string> &hists,std::map<std::string,TObject*> &histos); - static int TaskList(std::string dns,std::vector<std::string> &); + template <typename CONT> static int TaskList(std::string dns, CONT &); }; #endif /* HISTTASK_H_ */ diff --git a/Online/GauchoBase/Gaucho/MonInfo.h b/Online/GauchoBase/Gaucho/MonInfo.h index 99275cc480bb5e43738c8db14ab9090e453308f9..3971c50686cfbbb630ba4556ddc03e70dfc71d35 100644 --- a/Online/GauchoBase/Gaucho/MonInfo.h +++ b/Online/GauchoBase/Gaucho/MonInfo.h @@ -21,6 +21,7 @@ class MonInfo : public DIMTYPE void (*AdderFn)(void*,void*,int, MonInfo *); void *adderobj; public: + static bool ShutdowninProgress; std::string m_TargetService; virtual ~MonInfo(){} MonInfo(char *target, int period); diff --git a/Online/GauchoBase/Gaucho/RPCRec.h b/Online/GauchoBase/Gaucho/RPCRec.h index 04e92b15dda902f4fe35cf247a6541c09db8315f..38e70e8dbc81b40b1f388688418a0585fe2033e5 100644 --- a/Online/GauchoBase/Gaucho/RPCRec.h +++ b/Online/GauchoBase/Gaucho/RPCRec.h @@ -17,27 +17,29 @@ #include <string> #include <vector> #include <map> -typedef std::vector<char*> NAMEVEC; -typedef std::vector<std::string*> STRVEC; -typedef std::map<char*,void*> PTRMAP; + class RPCRec : public DimRpcInfo { -private: + public: + typedef std::vector<char*> NAMEVEC; + typedef std::vector<std::string> STRVEC; + typedef std::map<char*,void*> PTRMAP; + private: bool m_synch; RPCCommType m_reply; -public: - NAMEVEC *names; - PTRMAP *hists; + public: + NAMEVEC names; + PTRMAP hists; void rpcInfoHandler() override; - RPCRec(char *name, int timeout,bool synch=false); // : DimRpcInfo(name, timeout, -1) + RPCRec(const char *name, int timeout,bool synch=false); // : DimRpcInfo(name, timeout, -1) virtual ~RPCRec(); - void (*DirCB)(NAMEVEC*); - void (*DatCB)(PTRMAP*); - void declareDirCB(void CBfn(NAMEVEC*)){DirCB = CBfn;return;}; - void declareDatCB(void CBfn(PTRMAP*)){DatCB = CBfn;return;}; + void (*DirCB)(NAMEVEC&); + void (*DatCB)(PTRMAP&); + void declareDirCB(void CBfn(NAMEVEC&)){DirCB = CBfn;return;}; + void declareDatCB(void CBfn(PTRMAP&)){DatCB = CBfn;return;}; int analyseReply(); - int analyseReply(NAMEVEC *); - int analyseReply(PTRMAP *); - int analyseReply(STRVEC *); + int analyseReply(NAMEVEC &); + int analyseReply(PTRMAP &); + int analyseReply(STRVEC &); }; #endif diff --git a/Online/GauchoBase/Gaucho/Utilities.h b/Online/GauchoBase/Gaucho/Utilities.h index 2925db815ef6756a52f16b44465b901e812451e8..60f2d8e42a6acaac10d9ccc45b3912a64e6f3909 100644 --- a/Online/GauchoBase/Gaucho/Utilities.h +++ b/Online/GauchoBase/Gaucho/Utilities.h @@ -82,8 +82,6 @@ namespace } -dyn_string *Strsplit(char *s, char *del); -dyn_string *Strsplit(const char *s, char *del); dyn_string *Strsplit(char *s, const char *del); dyn_string *Strsplit(const char *s, const char *del); void StringReplace(std::string &in, const char *patt, std::string &repl); diff --git a/Online/GauchoBase/src/CounterSubSys.cpp b/Online/GauchoBase/src/CounterSubSys.cpp index a118ca863458d6fa0f5cb2c2821bbec906a97c9a..a13d1ee6d7f88acb28039f0c567ff951240c91ad 100644 --- a/Online/GauchoBase/src/CounterSubSys.cpp +++ b/Online/GauchoBase/src/CounterSubSys.cpp @@ -23,15 +23,13 @@ typedef ObjMap::iterator SysIter; CounterSubSys::CounterSubSys(SubSysParams &p): MonSubSys(p), m_updatePeriod(p.m_updatePeriod), m_RatePrefix(p.m_RatePrefix), - m_expandInfix(p.m_expandInfix), m_expandnames(p.m_expandnames) { - ::lib_rtl_output(LIB_RTL_INFO,"CounterSubSys Constructor\n"); + m_expandInfix(p.m_expandInfix), m_expandnames(p.m_expandnames) +{ m_type = MONSUBSYS_Counter; - char pid[255]; - sprintf(pid,"MON_SUBSYS_%0X_%0lX",lib_rtl_pid(),(unsigned long)this); m_dontclear = false; } -CounterSubSys::~CounterSubSys() -{ + +CounterSubSys::~CounterSubSys() { Lock(); if (m_expandnames) { diff --git a/Online/GauchoBase/src/CounterTask.cpp b/Online/GauchoBase/src/CounterTask.cpp index c18fe3ff71925f64c2b8b5aefd370b959e847c6f..be672582285104c917ee51e315ab57af804cb3ee 100644 --- a/Online/GauchoBase/src/CounterTask.cpp +++ b/Online/GauchoBase/src/CounterTask.cpp @@ -16,40 +16,26 @@ * Author: beat */ -#include "Gaucho/CounterTask.h" -#include "Gaucho/Utilities.h" -#include "Gaucho/MonCounter.h" -//HistTask::HistTask(const std::string &task,const std::string &dns) -//: m_DNS(dns),m_task(task) -//{ -// char *srvs=0; -// if (m_DNS == "") -// { -// m_DNS = std::string(getenv("DIM_DNS_NODE")); -// } -// DimClient::setDnsNode(m_DNS.c_str()); -// m_taskexp = boost::regex(("(.*)"+m_task+"(.*)").c_str(),boost::regex_constants::icase); -// DimCurrentInfo *dns_info=new DimCurrentInfo((char*)"DIS_DNS/SERVER_LIST", (char*)"DEAD"); -// srvs = dns_info->getString(); -//// std::string dimServers(srvs); -// dyn_string *svcs = Strsplit(srvs,(char*)"|"); -// unsigned int i; -// m_service = ""; -// m_RPC = 0; -// for (i=0;i<svcs->size();i++) -// { -// int status = boost::regex_search(svcs->at(i),m_taskexp); -// if (status) -// { -// m_service = std::string("MON_")+svcs->at(i).substr(0,svcs->at(i).find("@"))+std::string("/Histos/HistCommand"); -// m_RPC = new RPCRec((char*)m_service.c_str(),3,true); -// } -// } -//} +#include <Gaucho/CounterTask.h> +#include <Gaucho/MonCounter.h> +#include <Gaucho/Utilities.h> + +#include <unordered_set> +#include <vector> +#include <list> +#include <set> + +namespace { + void __insert(std::vector<std::string>& c, const std::string& v) { c.push_back(v); } + void __insert(std::list<std::string>& c, const std::string& v) { c.push_back(v); } + void __insert(std::set<std::string>& c, const std::string& v) { c.insert(v); } + void __insert(std::unordered_set<std::string>& c, const std::string& v) { c.insert(v); } +} + CounterTask::CounterTask(const std::string &task,const std::string &dns) : m_DNS(dns),m_task(task),m_RPC(0) { - if (m_DNS == "") + if ( m_DNS.empty() ) { m_DNS = std::string(getenv("DIM_DNS_NODE")); } @@ -62,28 +48,22 @@ CounterTask::CounterTask(const std::string &task,const std::string &dns) m_RPC = new RPCRec((char*)m_service.c_str(),3,true); } } -int CounterTask::Directory(std::vector<std::string> &Counters) + +int CounterTask::Directory(std::vector<std::string> &counters) { - int status; if (m_RPC == 0) return 1; int dat = RPCCDirectory; m_RPC->setData(dat); - status = m_RPC->analyseReply(); - unsigned int i; - for (i=0;i<m_RPC->names->size();i++) - { - Counters.push_back(std::string(m_RPC->names->at(i))); - } - return status; + return m_RPC->analyseReply(counters); } + int CounterTask::Counters(std::vector<std::string> &CounterNames,std::vector<CntrDescr*> &Cntrs) { int status; if (m_RPC == 0) return 1; RPCCommRead *rrd; int rdlen = sizeof(RPCCommRead); - unsigned int i; - for (i=0;i<CounterNames.size();i++) + for (size_t i=0; i<CounterNames.size(); i++ ) { rdlen += strlen(CounterNames[i].c_str())+1; } @@ -91,8 +71,7 @@ int CounterTask::Counters(std::vector<std::string> &CounterNames,std::vector<Cnt memset(rrd,0,rdlen); rrd->c = RPCCRead; char *dst = &rrd->which; - for (i=0;i<CounterNames.size();i++) - { + for (size_t i=0; i<CounterNames.size(); i++ ) { int clen; clen = strlen(CounterNames[i].c_str()); memcpy(dst,CounterNames[i].c_str(),clen); @@ -102,24 +81,21 @@ int CounterTask::Counters(std::vector<std::string> &CounterNames,std::vector<Cnt } m_RPC->setData((void*)rrd,rdlen); status = m_RPC->analyseReply(); - if (status == 0) - { - PTRMAP::iterator k; - for (k=m_RPC->hists->begin() ;k!=m_RPC->hists->end();k++) - { + if (status == 0) { + for (auto k=m_RPC->hists.begin() ;k!=m_RPC->hists.end();k++) { CntrDescr *o = (CntrDescr*)CounterSerDes::de_serialize(k->second); Cntrs.push_back(o); } } return status; } + int CounterTask::Counters(std::vector<std::string> &Ctrs) { int status; RPCCommRead *rrd; int rdlen = sizeof(RPCCommRead); - unsigned int i; - for (i=0;i<Ctrs.size();i++) + for (size_t i=0;i<Ctrs.size();i++) { rdlen += strlen(Ctrs[i].c_str())+1; } @@ -127,10 +103,9 @@ int CounterTask::Counters(std::vector<std::string> &Ctrs) memset(rrd,0,rdlen); rrd->c = RPCCRead; char *dst = &rrd->which; - for (i=0;i<Ctrs.size();i++) + for (size_t i=0;i<Ctrs.size();i++) { - int clen; - clen = strlen(Ctrs[i].c_str()); + int clen = strlen(Ctrs[i].c_str()); memcpy(dst,Ctrs[i].c_str(),clen); dst += clen; *dst = '\n'; @@ -143,13 +118,9 @@ int CounterTask::Counters(std::vector<std::string> &Ctrs) int CounterTask::Counters(std::vector<std::string> &CounterNames,std::map<std::string,CntrDescr*> &Cntrs) { - int status; - status = Counters(CounterNames); - if (status == 0) - { - PTRMAP::iterator k; - for (k=m_RPC->hists->begin() ;k!=m_RPC->hists->end();k++) - { + int status = Counters(CounterNames); + if (status == 0) { + for (auto k=m_RPC->hists.begin() ;k!=m_RPC->hists.end();k++) { CntrDescr *o = (CntrDescr*)CounterSerDes::de_serialize(k->second); Cntrs.insert(std::pair<std::string,CntrDescr*>(k->first,o)); } @@ -157,25 +128,27 @@ int CounterTask::Counters(std::vector<std::string> &CounterNames,std::map<std::s return status; } -int CounterTask::TaskList(std::string dns, std::vector<std::string> &tasklist) +template <typename CONT> +int CounterTask::TaskList(std::string dns, CONT &tasklist) { - if (dns == "") - { + if ( dns.empty() ) { dns = std::string(getenv("DIM_DNS_NODE")); } DimClient::setDnsNode(dns.c_str()); DimBrowser b; - int nservcs = b.getServices("MON_*/Counter/*/Data*"); - int i; - for (i=0;i<nservcs;i++) - { + int nservcs = b.getServices("MON_*/Counter/Data"); + for( int i=0; i<nservcs; i++ ) { char *svcn, *fmt; int stat = b.getNextService(svcn,fmt); - if (stat != 0) - { + if (stat != 0) { std::string svc = std::string(svcn); - tasklist.push_back(svc.substr(strlen("MON_"),svc.find("/Counter")-strlen("MON_"))); + __insert(tasklist, svc.substr(strlen("MON_"),svc.find("/Counter")-strlen("MON_"))); } } 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); diff --git a/Online/GauchoBase/src/HistTask.cpp b/Online/GauchoBase/src/HistTask.cpp index fce815cf9bd74fd63915a3f59c5cef10db5f4337..4cfcd837db257ddae197d69d044536930e11d38b 100644 --- a/Online/GauchoBase/src/HistTask.cpp +++ b/Online/GauchoBase/src/HistTask.cpp @@ -9,44 +9,24 @@ // Author : B.Jost // //========================================================================== -/* - * HistTask.cpp - * - * Created on: Jan 31, 2011 - * Author: beat - */ +#include <Gaucho/HistTask.h> +#include <Gaucho/Utilities.h> +#include <Gaucho/MonHist.h> +#include <Gaucho/HistSerDes.h> +#include <dim/dic.hxx> + +#include <unordered_set> +#include <vector> +#include <list> +#include <set> + +namespace { + void __insert(std::vector<std::string>& c, const std::string& v) { c.push_back(v); } + void __insert(std::list<std::string>& c, const std::string& v) { c.push_back(v); } + void __insert(std::set<std::string>& c, const std::string& v) { c.insert(v); } + void __insert(std::unordered_set<std::string>& c, const std::string& v) { c.insert(v); } +} -#include "Gaucho/HistTask.h" -#include "Gaucho/Utilities.h" -#include "Gaucho/MonHist.h" -#include "Gaucho/HistSerDes.h" -//HistTask::HistTask(const std::string &task,const std::string &dns) -//: m_DNS(dns),m_task(task) -//{ -// char *srvs=0; -// if (m_DNS == "") -// { -// m_DNS = std::string(getenv("DIM_DNS_NODE")); -// } -// DimClient::setDnsNode(m_DNS.c_str()); -// m_taskexp = boost::regex(("(.*)"+m_task+"(.*)").c_str(),boost::regex_constants::icase); -// DimCurrentInfo *dns_info=new DimCurrentInfo((char*)"DIS_DNS/SERVER_LIST", (char*)"DEAD"); -// srvs = dns_info->getString(); -//// std::string dimServers(srvs); -// dyn_string *svcs = Strsplit(srvs,(char*)"|"); -// unsigned int i; -// m_service = ""; -// m_RPC = 0; -// for (i=0;i<svcs->size();i++) -// { -// int status = boost::regex_search(svcs->at(i),m_taskexp); -// if (status) -// { -// m_service = std::string("MON_")+svcs->at(i).substr(0,svcs->at(i).find("@"))+std::string("/Histos/HistCommand"); -// m_RPC = new RPCRec((char*)m_service.c_str(),3,true); -// } -// } -//} HistTask::~HistTask() { deletePtr(m_RPC); @@ -54,7 +34,7 @@ HistTask::~HistTask() HistTask::HistTask(const std::string &task,const std::string &dns, int tmo) : m_DNS(dns),m_task(task),m_RPC(0) { - if (m_DNS == "") + if ( m_DNS.empty() ) { m_DNS = std::string(getenv("DIM_DNS_NODE")); } @@ -75,14 +55,13 @@ int HistTask::Directory(std::vector<std::string> &hists) m_RPC->setData(dat); status = m_RPC->analyseReply(); unsigned int i; - for (i=0;i<m_RPC->names->size();i++) - { - hists.push_back(std::string(m_RPC->names->at(i))); + for (i=0;i<m_RPC->names.size();i++) { + hists.push_back(std::string(m_RPC->names.at(i))); } return status; } -int HistTask::Histos(std::vector<std::string> &hists,std::vector<TObject*> &histos) -{ + +int HistTask::Histos(std::vector<std::string> &hists,std::vector<TObject*> &histos) { int status; if (m_RPC == 0) return 1; RPCCommRead *rrd; @@ -109,8 +88,7 @@ int HistTask::Histos(std::vector<std::string> &hists,std::vector<TObject*> &hist status = m_RPC->analyseReply(); if (status == 0) { - PTRMAP::iterator k; - for (k=m_RPC->hists->begin() ;k!=m_RPC->hists->end();k++) + for (auto k=m_RPC->hists.begin() ;k!=m_RPC->hists.end();k++) { TObject *o = (TObject*)HistSerDes::de_serialize(k->second); histos.push_back(o); @@ -152,8 +130,7 @@ int HistTask::Histos(std::vector<std::string> &hists,std::map<std::string,TObjec status = Histos(hists); if (status == 0) { - PTRMAP::iterator k; - for (k=m_RPC->hists->begin() ;k!=m_RPC->hists->end();k++) + for (auto k=m_RPC->hists.begin() ;k!=m_RPC->hists.end();k++) { TObject *o = (TObject*)HistSerDes::de_serialize(k->second); histos.insert(std::pair<std::string,TObject*>(k->first,o)); @@ -162,25 +139,27 @@ int HistTask::Histos(std::vector<std::string> &hists,std::map<std::string,TObjec return status; } -int HistTask::TaskList(std::string dns, std::vector<std::string> &tasklist) +template <typename CONT> +int HistTask::TaskList(std::string dns, CONT &tasklist) { - if (dns == "") - { - dns = std::string(getenv("DIM_DNS_NODE")); + if ( dns.empty() ) { + dns = std::string(::getenv("DIM_DNS_NODE")); } DimClient::setDnsNode(dns.c_str()); DimBrowser b; - int nservcs = b.getServices("MON_*/Histos/Data",5); - int i; - for (i=0;i<nservcs;i++) - { + int nservcs = b.getServices("MON_*/Histos/Data"); + for( int i=0; i<nservcs; i++ ) { char *svcn, *fmt; int stat = b.getNextService(svcn,fmt); - if (stat != 0) - { - std::string svc = std::string(svcn); - tasklist.push_back(svc.substr(strlen("MON_"),svc.find("/Histos")-strlen("MON_"))); + if (stat != 0) { + std::string svc = svcn; + __insert(tasklist, svc.substr(strlen("MON_"),svc.find("/Histos")-strlen("MON_"))); } } 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); diff --git a/Online/GauchoBase/src/MonInfo.cpp b/Online/GauchoBase/src/MonInfo.cpp index 3b1ffe669208fd92c6a9fffae9c74059fef24cc7..aa8484996344c8034f7ed4805adb0ce7fa74bd04 100644 --- a/Online/GauchoBase/src/MonInfo.cpp +++ b/Online/GauchoBase/src/MonInfo.cpp @@ -14,6 +14,7 @@ #include "stdio.h" #include "RTL/rtl.h" static int empty =-1; +bool MonInfo::ShutdowninProgress = false; #define AddPtr(ptr,offs) (void*)((char*)ptr +offs) MonInfo::MonInfo(char *targetservice, int period=0): DIMTYPE(targetservice,period, &empty,4) { @@ -46,6 +47,7 @@ void MonInfo::infoHandler() return; } // ::lib_rtl_output(LIB_RTL_INFO,"New Input from %s size %d\n",this->itsName,siz); + if (ShutdowninProgress) return; if (AdderFn != 0) { unsigned char* buff = new unsigned char[siz]; diff --git a/Online/GauchoBase/src/MonitorInterface.cpp b/Online/GauchoBase/src/MonitorInterface.cpp index a90c8ed521725e4bb4acf7952fb98a56293e217d..e57abd9c807aafb7d250634b89cd2688445495e0 100644 --- a/Online/GauchoBase/src/MonitorInterface.cpp +++ b/Online/GauchoBase/src/MonitorInterface.cpp @@ -192,8 +192,7 @@ int MonitorInterface::start() return 1; } -int MonitorInterface::stop() -{ +int MonitorInterface::stop() { if (m_MonSys) { m_MonSys->stop(); @@ -202,28 +201,26 @@ int MonitorInterface::stop() } -void MonitorInterface::createCounterSubSys(SubSysParams& pars) -{ +void MonitorInterface::createCounterSubSys(SubSysParams& pars) { if (m_CntrSubSys == 0) { - ::lib_rtl_output(LIB_RTL_INFO,"MonitorInterface createCounterSubSys \n"); + ::lib_rtl_output(LIB_RTL_DEBUG,"MonitorInterface createCounterSubSys \n"); pars.m_type = MONSUBSYS_Counter; m_CntrSubSys = new CounterSubSys(pars); // m_CntrSubSys->m_type = MONSUBSYS_Counter; m_MonSys->addSubSys(m_CntrSubSys); } } -void MonitorInterface::createHistSubSys(SubSysParams& pars) -{ - if (m_HistSubSys == 0) - { + +void MonitorInterface::createHistSubSys(SubSysParams& pars) { + if (m_HistSubSys == 0) { pars.m_type = MONSUBSYS_Histogram; m_HistSubSys = new HistSubSys(pars); m_MonSys->addSubSys(m_HistSubSys); } } -void MonitorInterface::ApplyCouterClasses( - std::vector<std::string> &m_CounterClasses) + +void MonitorInterface::ApplyCouterClasses(std::vector<std::string> &m_CounterClasses) { if (m_CounterClasses.size() > 0) { @@ -232,8 +229,8 @@ void MonitorInterface::ApplyCouterClasses( MakeClassList(clist, m_CounterClasses); for (auto i = clist.begin(); i != clist.end(); i++) { - (*i)->setType((int)MONSUBSYS_Counter); - (*i)->configure((int)MONSUBSYS_Counter); + (*i)->setType(MONSUBSYS_Counter); + (*i)->configure(MONSUBSYS_Counter); (*i)->m_runAware = m_CntrPars.m_runAware; m_CntrSubSys->AddClass(*i); } diff --git a/Online/GauchoBase/src/RPCRec.cpp b/Online/GauchoBase/src/RPCRec.cpp index 736efd1c340ebdce8900c6364a5f89da19ecf6ec..1e025443d90434016f95721c822e3d4fd514fde9 100644 --- a/Online/GauchoBase/src/RPCRec.cpp +++ b/Online/GauchoBase/src/RPCRec.cpp @@ -30,12 +30,12 @@ int RPCRec::analyseReply() m_reply = RPCCIllegal; if (rep->status == -1) { -// printf ("Timeout...\n"); + // printf ("Timeout...\n"); return 1; } if (rep->status == -2) { -// printf ("RPC Error...\n"); + // printf ("RPC Error...\n"); return 2; } m_reply = rep->comm; @@ -53,7 +53,7 @@ int RPCRec::analyseReply() valend = (void*)((char *)valin+siz); // printf("Received answer of size %d\n",siz); DimHistbuff1 *p1; - hists->clear(); + hists.clear(); p1 = (DimHistbuff1*)(AddPtr(valin,sizeof(RPCReply))); while (p1<valend) { @@ -68,7 +68,7 @@ int RPCRec::analyseReply() namoff = p1->nameoff;//sizeof(DimHistbuff2); } nam = (char*)AddPtr(p1,namoff); - hists->insert(std::pair<char*,void*> (nam,p1)); + hists.insert(std::pair<char*,void*> (nam,p1)); // printf ("Type %d record Length %d dimension %d hdrlength %d\n title %s\n", // p1->type,p1->reclen,p1->dim,p1->dataoff,(char*)((char*)p1+titoff)); if (p1->reclen<= 0) break; @@ -82,13 +82,13 @@ int RPCRec::analyseReply() void *p1 = (AddPtr(valin,sizeof(RPCReply))); int recl; int cumul=sizeof(RPCReply); - names->clear(); + names.clear(); while (p1<valend) { int titoff; titoff = 4; char *tptr = (char*)AddPtr(p1,titoff); - names->push_back(tptr); + names.push_back(tptr); // printf ("Type %d name %s\n",*(int*)p1,tptr); recl = 4+strlen(tptr)+1; cumul += recl; @@ -101,36 +101,33 @@ int RPCRec::analyseReply() // cout << "Callback RPC Received : " << valin << endl; return 0; } -int RPCRec::analyseReply(NAMEVEC *v) +int RPCRec::analyseReply(NAMEVEC& v) { int stat = analyseReply(); if (stat == 0) { - *v = *names; + v = names; } return stat; } -int RPCRec::analyseReply(PTRMAP *p) +int RPCRec::analyseReply(PTRMAP& p) { int stat = analyseReply(); if (stat == 0) { - *p = *hists; + p = hists; } return stat; } -int RPCRec::analyseReply(STRVEC *v) +int RPCRec::analyseReply(STRVEC& v) { - NAMEVEC::iterator i; int stat = analyseReply(); + v.clear(); if (stat == 0) { - v->clear(); - for (i=names->begin();i!=names->end();i++) - { - v->push_back(new std::string(*i)); - } + for (auto i=names.begin();i!=names.end();i++) + v.push_back(*i); } return stat; // printf("Total Number of Histograms: %d\n",n_hist); @@ -171,18 +168,12 @@ void RPCRec::rpcInfoHandler() return; } -RPCRec::RPCRec(char *name, int timeout, bool synch) : DimRpcInfo(name, timeout, -1) +RPCRec::RPCRec(const char *name, int timeout, bool synch) : DimRpcInfo(name, timeout, -1) { DirCB = 0; DatCB = 0; - names = new NAMEVEC; - names->clear(); - hists = new PTRMAP; - hists->clear(); m_synch = synch; } RPCRec::~RPCRec() { - deletePtr(names); - deletePtr(hists); } diff --git a/Online/GauchoBase/src/Utilities.cpp b/Online/GauchoBase/src/Utilities.cpp index 945a96e51f8d8c367937186de16fdb98d25d7357..acb9fe19a054290f3b3f198bc66f4c280457f4a3 100644 --- a/Online/GauchoBase/src/Utilities.cpp +++ b/Online/GauchoBase/src/Utilities.cpp @@ -30,17 +30,9 @@ extern "C" } dyn_string *Strsplit(const char *s, const char *del) { - return Strsplit((char*)s, (char*)del); -} -dyn_string *Strsplit(const char *s, char *del) -{ - return Strsplit((char*)s,del); + return Strsplit((char*)s, del); } dyn_string *Strsplit(char *s, const char *del) -{ - return Strsplit(s,(char*)del); -} -dyn_string *Strsplit(char *s, char *del) { char *pch; pch = strtok(s,del); diff --git a/Online/GaudiOnline/GaudiOnline/Configuration.h b/Online/GaudiOnline/GaudiOnline/Configuration.h index 00e12b0c3e43dab1ca410d194a5f56ca64d7553e..e136cf79b1bb4e3d2ac9b82cb461cafe19e95371 100644 --- a/Online/GaudiOnline/GaudiOnline/Configuration.h +++ b/Online/GaudiOnline/GaudiOnline/Configuration.h @@ -48,6 +48,8 @@ namespace Online { public: /// Property: Debug flag bool debug; + /// Property: Flag to dump options in the application constructor + bool dump_options; /// Property: Automatic startup flag bool autoStart; /// Property: Automatic stop flag diff --git a/Online/GaudiOnline/GaudiOnline/OnlineApplication.h b/Online/GaudiOnline/GaudiOnline/OnlineApplication.h index e0fcc1093ce75f1d4b8127c268d6c3276e7cd4d5..5f70809da23f7769b2c8ebe54777d2eaa6bd86c5 100644 --- a/Online/GaudiOnline/GaudiOnline/OnlineApplication.h +++ b/Online/GaudiOnline/GaudiOnline/OnlineApplication.h @@ -118,6 +118,11 @@ namespace Online { /// Handle to the incident service SmartIF<IIncidentSvc> m_incidentSvc; + protected: + + /// Dump all job options + void dumpOptions( const Gaudi::Application::Options& options ) const; + public: /// Declare FSM state diff --git a/Online/GaudiOnline/components/InputAlg.cpp b/Online/GaudiOnline/components/InputAlg.cpp index ee1d827132bb413ed349069bbb074a7573ccc468..536fd210d9932b92ea7a78e8cee281c11201fbbe 100644 --- a/Online/GaudiOnline/components/InputAlg.cpp +++ b/Online/GaudiOnline/components/InputAlg.cpp @@ -15,6 +15,8 @@ /// Framework include files #include "InputAlg.h" +#include <PCIE40Data/sodin.h> +#include <Tell1Data/RunInfo.h> // C/C++ include files #include <stdexcept> @@ -68,12 +70,19 @@ StatusCode Online::InputAlg::initialize() { if ( !m_io ) { return StatusCode::FAILURE; } + IDataProviderSvc* svc = eventSvc(); std::string tool_type = "Online__RawEventRegister"; m_evtTool = IRawEventCreator::Factory::create(tool_type, svc); if ( !m_evtTool.get() ) { m_logger->except("Failed to access RawEvent creation tool!"); } +#if 0 + auto mon = service<IMonitorSvc>("MonitorSvc",true); + if ( !mon.get() ) { + m_logger->except("Failed to access Monitor service!"); + } +#endif return EventProcessor::initialize(); } @@ -86,12 +95,15 @@ StatusCode Online::InputAlg::finalize() { /// Start the algorithm StatusCode Online::InputAlg::start() { + /// Handle to monitor service + m_monitor = monitorSvc(); return StatusCode::SUCCESS; } /// Stop the algorithm StatusCode Online::InputAlg::stop() { m_halt = 0; + m_monitor.reset(); return StatusCode::SUCCESS; } @@ -100,7 +112,7 @@ StatusCode Online::InputAlg::process(EventContext const& /* ctxt */) const { using namespace event_traits; typedef std::vector<void*> lb_banks_t; - EventAccess::event_t e(m_io->pop()); + evt_desc_t e(m_io->pop()); if ( e.second ) { try { StatusCode sc; @@ -108,6 +120,21 @@ StatusCode Online::InputAlg::process(EventContext const& /* ctxt */) const { bool make_raw_evt = m_makeRawEvt.value(); bool expand_tae = m_expandTAE.value(); bool save_guard = declare_banks || make_raw_evt || expand_tae; + + /// We have to update the run number in the monitoring service + /// Otherwise the adding does not work properly. + const auto [header, data] = this->get_odin_bank(e); + if ( m_monitor && header ) { + if ( header->version() < 7 ) { + //const auto* odin = (const RunInfo*)data; + //m_monitor->update(odin->run_number()).ignore(); + } + else { + //const auto* odin = (const pcie40::sodin_t*)data; + //m_monitor->update(odin->run_number()).ignore(); + } + } + /// Now declare the event data if requested: if ( declare_banks || make_raw_evt ) { evt_data_t event = this->create_event_data(e, 0); /// Invoke here the conversion to raw events @@ -121,6 +148,7 @@ StatusCode Online::InputAlg::process(EventContext const& /* ctxt */) const { m_rawData.put(move(event)); } } + /// Expand TAE data if requested and present if ( expand_tae && (declare_banks || make_raw_evt) ) { auto [half_window, central] = this->check_tae(e); if ( central && half_window > 0 ) { diff --git a/Online/GaudiOnline/components/InputAlg.h b/Online/GaudiOnline/components/InputAlg.h index cf10a3403ab5656a5a66b18b11c818eb6008d67d..f5a6c3e9ea0863a98396130b6f01989e963769d9 100644 --- a/Online/GaudiOnline/components/InputAlg.h +++ b/Online/GaudiOnline/components/InputAlg.h @@ -17,6 +17,7 @@ /// Framework include files #include <GaudiOnline/IRawEventCreator.h> +#include <GaudiKernel/IUpdateable.h> #include "EventProcessor.h" #include "IOService.h" @@ -34,7 +35,6 @@ namespace Online { protected: typedef std::vector<const RawBank40*> daq_error_t; - typedef EventProcessor::evt_data_t evt_data_t; Gaudi::Property<bool> m_declareData{this, "DeclareData", true, "Declare or drop data"}; Gaudi::Property<bool> m_declareErrs{this, "DeclareErrors",false, "Declare error data"}; @@ -52,6 +52,8 @@ namespace Online { /// Reference to the I/O service SmartIF<IOService> m_io; + /// Reference to the I/O service + SmartIF<IUpdateableIF> m_monitor; /// Reference to RawEvent tool std::unique_ptr<IRawEventCreator> m_evtTool; diff --git a/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py b/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py index 315807d43273a08430225f5229b61651ed8db4d9..8bf867bc825bd3a8542c9abe2e8bbd5eae30fa16 100644 --- a/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py +++ b/Online/GaudiOnline/python/GaudiOnline/OnlineApplication.py @@ -19,10 +19,13 @@ if 'UTGID' in os.environ: else: utgid = 'P%06d'%(os.getpid(),) +MessageSvc = Configurables.MessageSvc +MonitorSvc = Configurables.MonitorSvc FlowManager = Configurables.Online__FlowManager Configuration = Configurables.Online__Configuration InputAlg = Configurables.Online__InputAlg OutputAlg = Configurables.Online__OutputAlg +UpdateAndReset = Configurables.Online__UpdateAndReset NumaControl = Configurables.Online__NumaControlSvc TransitionSleepSvc = Configurables.Online__TransitionSleepSvc UISvc = Configurables.Online__OutputAlg @@ -95,7 +98,7 @@ class Application(object): self.app.AppName = '' self.app.OutputLevel = self.outputLevel self.config = Configuration('Application') - self.messageSvc = Configurables.MessageSvc('MessageSvc') + self.messageSvc = MessageSvc('MessageSvc') self.messageSvc.Format = '% F%8W%L%T %25W%L%S %0W%M' self.messageSvc.OutputLevel = self.outputLevel config = self.config @@ -131,9 +134,9 @@ class Application(object): def log(self, level, fmt, *args): log(level, fmt, *args) - def setup_event_input(self, TAE=None): + def setup_event_input(self): log(MSG_INFO,'Setup event input for REGULAR processing') - input = Configurables.Online__InputAlg('EventInput') + input = InputAlg('EventInput') input.DeclareData = True input.DeclareEvent = True input.DeclareErrors = False @@ -143,12 +146,18 @@ class Application(object): def setup_monitoring(self, type='MonitorSvc'): config = self.config config.monitorType = type - mon = Configurables.MonitorSvc(config.monitorType) + mon = Configurables.MonitorSvc('MonitorSvc') mon.PartitionName = self.partitionName mon.ExpandNameInfix = '<proc>/' mon.ExpandCounterServices = True mon.UniqueServiceNames = True + self.app.ExtSvc.insert(0, mon) self.monSvc = mon + update = Configurables.Online__UpdateAndReset('UpdateAndReset') + update.resetOnStart = False; + update.saverCycle = 900 + update.saveHistograms = 0 + self.updateAndReset = update; def setup_algorithms(self,*args,**kwd): return self @@ -228,7 +237,7 @@ class Application(object): self.broker = DataBroker() self.broker.OutputLevel = self.outputLevel self.app.EventLoop = flowmgr - self.app.ExtSvc = [self.whiteboard] + self.app.ExtSvc.append(self.whiteboard) return self def setup_events(self): @@ -238,7 +247,7 @@ class Application(object): self.broker = DataBroker() self.broker.OutputLevel = self.outputLevel self.app.EventLoop = self.flowmgr - self.app.ExtSvc = [self.whiteboard] + self.app.ExtSvc.append(self.whiteboard) return self def setup_mbm_output(self, type, partitionBuffers=True, buffer='Output'): diff --git a/Online/GaudiOnline/python/GaudiOnline/Passthrough.py b/Online/GaudiOnline/python/GaudiOnline/Passthrough.py index cfdf7e4b1b05c5a2fdf62c756603c3865b77555f..d6a1fd9bbd364db47778acf854938331bae3b2b8 100644 --- a/Online/GaudiOnline/python/GaudiOnline/Passthrough.py +++ b/Online/GaudiOnline/python/GaudiOnline/Passthrough.py @@ -28,7 +28,11 @@ class Passthrough(Application): sequence = Gaudi.GaudiSequencer('Output') sequence.Members = [passThrough] if writer: sequence.Members.append(writer) - self.app.TopAlg = [input, sequence] + self.app.TopAlg = [] + self.app.TopAlg.append(input) + if hasattr(self,'updateAndReset'): + self.app.TopAlg.append(self.updateAndReset) + self.app.TopAlg.append(sequence) self.sequence = sequence self.broker.DataProducers = self.app.TopAlg return self diff --git a/Online/GaudiOnline/src/Configuration.cpp b/Online/GaudiOnline/src/Configuration.cpp index 04013ed73e25a4728a3c5080b42516f389f5b5ca..765aa1513475b928e3724f21ec53c193eed3e7dd 100644 --- a/Online/GaudiOnline/src/Configuration.cpp +++ b/Online/GaudiOnline/src/Configuration.cpp @@ -36,6 +36,7 @@ Configuration::Configuration(std::string nam, ISvcLocator* svcloc) : Service(nam, svcloc) { declareProperty("debug", debug = false); + declareProperty("dump_options", dump_options = false); declareProperty("classType", clazz = 1); declareProperty("numaNode", numaNode = -1); declareProperty("autoStart", autoStart = false); diff --git a/Online/GaudiOnline/src/OnlineApplication.cpp b/Online/GaudiOnline/src/OnlineApplication.cpp index 4c11365f4ffe16fa7dc068056d5d4a313f63dde1..d9d42f95b047fb3b1debc34ef2eebf620dfb4983 100644 --- a/Online/GaudiOnline/src/OnlineApplication.cpp +++ b/Online/GaudiOnline/src/OnlineApplication.cpp @@ -167,7 +167,6 @@ namespace { opt = options.erase( opt ); } } - using namespace Online; } @@ -228,6 +227,9 @@ OnlineApplication::OnlineApplication(Options opts) m_monitor.pid = ::lib_rtl_pid(); m_monitor.partitionID = -1; m_monitor.pad = 0; + if ( m_config->dump_options ) { + dumpOptions(opts); + } connectDIM(); } @@ -240,6 +242,12 @@ OnlineApplication::~OnlineApplication() { s_dimtask_instance = 0; } +/// Dump all job options +void OnlineApplication::dumpOptions( const Gaudi::Application::Options& options ) const { + for( const auto& opt : options ) + m_logger->always("%-40s = %s", opt.first.c_str(), opt.second.c_str()); +} + /// Print overload void OnlineApplication::output(int level, const char* s) { return m_logger->output(level, s); @@ -457,7 +465,15 @@ int OnlineApplication::startupDone() { connectDIM(0); } if ( m_config->clazz == 0 ) { - StatusCode sc = app->initialize(); + StatusCode sc; +#if 0 + sc = app->configure(); + if ( !sc.isSuccess() ) { + m_logger->error("Failed (Gaudi) configure the Class 0 application."); + return ONLINE_ERROR; + } +#endif + sc = app->initialize(); if ( !sc.isSuccess() ) { m_logger->error("Failed to (Gaudi) initialize the Class 0 application."); declareState(ST_ERROR); @@ -498,7 +514,15 @@ int OnlineApplication::startupDone() { int OnlineApplication::configureApplication() { SmartIF<ISvcLocator> sloc = app.as<ISvcLocator>(); if ( m_config->clazz == 1 ) { - StatusCode sc = app->initialize(); + StatusCode sc; +#if 0 + sc = app->configure(); + if ( !sc.isSuccess() ) { + m_logger->error("Failed to configure Gaudi."); + return ONLINE_ERROR; + } +#endif + sc = app->initialize(); if ( !sc.isSuccess() ) { m_logger->error("Failed to initialize Gaudi."); return ONLINE_ERROR; @@ -517,6 +541,7 @@ int OnlineApplication::finalizeApplication() { m_incidentSvc.reset(); if ( m_config->clazz == 1 ) { app->finalize().ignore(); + app->terminate().ignore(); } return ONLINE_OK; } @@ -544,7 +569,15 @@ int OnlineApplication::startApplication() { } } else if ( m_config->clazz == 2 ) { - StatusCode sc = app->initialize(); + StatusCode sc; +#if 0 + sc = app->configure(); + if ( !sc.isSuccess() ) { + m_logger->error("Failed to configure Gaudi."); + return ONLINE_ERROR; + } +#endif + sc = app->initialize(); if ( !sc.isSuccess() ) { m_logger->error("Failed to (Gaudi) initialize the Class 2 application."); return ONLINE_ERROR; diff --git a/Online/GaudiOnlineTests/CMakeLists.txt b/Online/GaudiOnlineTests/CMakeLists.txt index fdc760bcba744b2954d3b2c0d6ba8c31a322465a..9e08135b8f40cbf928f502bebddf24dc6f71aa41 100644 --- a/Online/GaudiOnlineTests/CMakeLists.txt +++ b/Online/GaudiOnlineTests/CMakeLists.txt @@ -23,6 +23,7 @@ gaudi_depends_on_subdirs(GaudiAud Online/OnlineBase Online/OnlineKernel Online/RawBankSizes + Online/Tell1Data Online/GaudiOnline GaudiExamples) @@ -35,7 +36,7 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}) gaudi_add_library(GaudiOnlineTests src/*.cpp INCLUDE_DIRS Boost NO_PUBLIC_HEADERS - LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt OnlineBase OnlineKernel dim) + LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt dim OnlineBase OnlineKernel Tell1Data) target_compile_options(GaudiOnlineTests PRIVATE -Wno-address-of-packed-member) gaudi_add_module(GaudiOnlineTestsComp components/*.cpp diff --git a/Online/GaudiOnlineTests/src/TestProcess.cpp b/Online/GaudiOnlineTests/src/TestProcess.cpp index d2136b84454f2b38dced96edd013e5fba267ee1c..226a7296c690db8fcd16801aa9e89ee361a6572b 100644 --- a/Online/GaudiOnlineTests/src/TestProcess.cpp +++ b/Online/GaudiOnlineTests/src/TestProcess.cpp @@ -13,7 +13,7 @@ // Author : Markus Frank //========================================================================== // Include files -#include "RTL/ProcessGroup.h" +#include <RTL/ProcessGroup.h> #include <cmath> #include <ctime> diff --git a/Online/GaudiOnlineTests/src/TestRawFile.cpp b/Online/GaudiOnlineTests/src/TestRawFile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..39d37242c7a6cd63c5d40d27b5ecdc5fa0408d12 --- /dev/null +++ b/Online/GaudiOnlineTests/src/TestRawFile.cpp @@ -0,0 +1,47 @@ +//========================================================================== +// LHCb Online software suite +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see OnlineSys/LICENSE. +// +// Author : M.Frank +// +//========================================================================== +#include <RTL/rtl.h> +#include <Tell1Data/RawFile.h> + +extern "C" int test_rawfile_mkdir(int argc, char** argv) { + RTL::CLI cli(argc, argv, [] { + }); + std::string dir; + cli.getopt("directory",1,dir); + if ( dir.empty() ) cli.call_help(); + + int ret = Online::RawFile::mkdir(dir.c_str(), 0777, false); + if ( ret ) { + ::lib_rtl_output(LIB_RTL_ALWAYS,"FAILED to create directory: %s [%s]", + dir.c_str(), RTL::errorString(errno).c_str()); + cli.call_help(); + } + ::lib_rtl_output(LIB_RTL_ALWAYS,"Created directory: %s",dir.c_str()); + return 0; +} + +extern "C" int test_rawfile_rmdir(int argc, char** argv) { + RTL::CLI cli(argc, argv, [] { + }); + std::string dir; + cli.getopt("directory",1,dir); + if ( dir.empty() ) cli.call_help(); + + int ret = Online::RawFile::rmdir(dir.c_str(), true, false); + if ( ret ) { + ::lib_rtl_output(LIB_RTL_ALWAYS,"FAILED to remove directory: %s [%s]", + dir.c_str(), RTL::errorString(errno).c_str()); + cli.call_help(); + } + ::lib_rtl_output(LIB_RTL_ALWAYS,"Removed directory: %s",dir.c_str()); + return 0; +} diff --git a/Online/HTTP/HTTP/Asio.h b/Online/HTTP/HTTP/Asio.h index 76a354ef0dca26683377b08871c9573ed24948af..747fd2e4fcd50cd808bf6fffb06c7444bfac710b 100644 --- a/Online/HTTP/HTTP/Asio.h +++ b/Online/HTTP/HTTP/Asio.h @@ -40,5 +40,16 @@ namespace boost { } } +/// Namespace for the http server and client apps +namespace http { + /// Forward declarations + class HttpReply; + + /// Convert the reply into a vector of buffers. The buffers do not own the + /// underlying memory blocks, therefore the reply object must remain valid and + /// not be changed until the write operation has completed. + std::vector<boost::asio::const_buffer> to_buffers(const HttpReply& rep); +} // End namespace http + #endif // HTTP_HTTP_ASIO_H diff --git a/Online/HTTP/HTTP/HttpReply.h b/Online/HTTP/HTTP/HttpReply.h index 42c18f58d703c75942ee0232d23dc6987069f891..6190d137fb37233febffbe00562a1bc653f49d17 100644 --- a/Online/HTTP/HTTP/HttpReply.h +++ b/Online/HTTP/HTTP/HttpReply.h @@ -32,11 +32,11 @@ // Framework include files #include <HTTP/HttpHeader.h> -#include <HTTP/Asio.h> // C/C++ include files #include <vector> #include <chrono> +#include <memory> /// Namespace for the http server and client apps namespace http { @@ -177,10 +177,5 @@ namespace http { std::string to_string(const HttpReply& status); std::vector<unsigned char> to_vector(HttpReply::status_type status); - - /// Convert the reply into a vector of buffers. The buffers do not own the - /// underlying memory blocks, therefore the reply object must remain valid and - /// not be changed until the write operation has completed. - std::vector<boost::asio::const_buffer> to_buffers(const HttpReply& rep); } // End namespace http #endif // HTTP_HTTP_HTTPREPLY_H diff --git a/Online/HTTP/HTTP/HttpRequest.h b/Online/HTTP/HTTP/HttpRequest.h index 60ca66c61dbd154563bf87435ba86f00f6e1f02f..20832c5c932296a676f554d6c543118d7538af12 100644 --- a/Online/HTTP/HTTP/HttpRequest.h +++ b/Online/HTTP/HTTP/HttpRequest.h @@ -32,9 +32,7 @@ // Framework include files #include <HTTP/HttpHeader.h> - -// Boost inlcude files -#include <boost/asio.hpp> +#include <HTTP/Asio.h> // C/C++ include files #include <vector> diff --git a/Online/HTTP/HTTP/HttpServer.h b/Online/HTTP/HTTP/HttpServer.h index b54383d2d0c9a7bceef5cdf6c5cd785009188d85..d65f95f13ab6385783d534334148f270b0a550ec 100644 --- a/Online/HTTP/HTTP/HttpServer.h +++ b/Online/HTTP/HTTP/HttpServer.h @@ -34,6 +34,7 @@ #include <HTTP/HttpHeader.h> #include <HTTP/HttpRequest.h> #include <HTTP/HttpReply.h> +#include <HTTP/Asio.h> // C/C++ include files #include <set> @@ -43,7 +44,6 @@ #include <thread> // Boost inlcude files -#include <boost/asio.hpp> #include <boost/noncopyable.hpp> /// Namespace for the http server and client apps diff --git a/Online/HTTP/src/HttpReply.cpp b/Online/HTTP/src/HttpReply.cpp index 855acbc8a78c4bbda1d25ae4ac5b3ad44d5384da..23c9958c7d52876855ab978538a5e62dbde436be 100644 --- a/Online/HTTP/src/HttpReply.cpp +++ b/Online/HTTP/src/HttpReply.cpp @@ -30,6 +30,7 @@ // Framework include files #include "HTTP/HttpReply.h" +#include "HTTP/Asio.h" // C/C++ include files #include <iostream> diff --git a/Online/HTTP/src/HttpServer.cpp b/Online/HTTP/src/HttpServer.cpp index 4c2343411e1f5760e2288f2408f954ec9da8042e..983eba0c09ab69af0279bd92bf24d7cce609d593 100644 --- a/Online/HTTP/src/HttpServer.cpp +++ b/Online/HTTP/src/HttpServer.cpp @@ -30,6 +30,7 @@ // Framework include files #include <HTTP/HttpServer.h> +#include <HTTP/Asio.h> #include <RTL/rtl.h> // C/C++ include files diff --git a/Online/OnlineBase/OnlineBase/LOG/FifoLog.inl.h b/Online/OnlineBase/OnlineBase/LOG/FifoLog.inl.h index 6ff7e037e2d22655462b77224114502a5f3eab28..a5759be994fef79220148acb5a1a776bc75653fb 100644 --- a/Online/OnlineBase/OnlineBase/LOG/FifoLog.inl.h +++ b/Online/OnlineBase/OnlineBase/LOG/FifoLog.inl.h @@ -253,6 +253,7 @@ namespace fifolog { }; } +#include <system_error> #include <stdexcept> #include <iostream> #include <sstream> @@ -277,11 +278,8 @@ std::string logger_imp::utgid; namespace fifolog { /// Translate errno into error string - inline const char* cerror(int err) { - static char text[1024]; - text[0] = 0; - ::strerror_r(err, text, sizeof(text)); - return text; + inline const std::string cerror(int err) { + return std::make_error_code(std::errc(err)).message(); } template <typename FUNC_TYPE> inline FUNC_TYPE get_sym(const char* name) { @@ -421,13 +419,13 @@ void logger_imp::init(const std::string& f, const std::string& u, const std::str // check if fifo is writable if( ::access(fifo.c_str(),W_OK) == -1) { // write access to fifo OK ::snprintf(text,sizeof(text),"+++ Failed to access output: %s [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); throw std::runtime_error(text); } // get fifo information if( ::stat(fifo.c_str(),&statBuf) == -1) { // fifo information got ::snprintf(text,sizeof(text),"+++ Output: Canno stat device %s! [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); throw std::runtime_error(text); } // check if fifo is a FIFO @@ -439,7 +437,7 @@ void logger_imp::init(const std::string& f, const std::string& u, const std::str this->fifo_fd = ::open(fifo.c_str(), O_RDWR|O_NONBLOCK|O_APPEND); if( this->fifo_fd == -1 ) { /* fifo open() failed */ ::snprintf(text,sizeof(text),"+++ Failed to open output: %s! [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); throw std::runtime_error(text); } // Now we are sure that another process has the FIFO open for reading. @@ -448,14 +446,14 @@ void logger_imp::init(const std::string& f, const std::string& u, const std::str if ( status < 0 ) { ::close(this->fifo_fd); ::snprintf(text,sizeof(text),"+++ Cannot fcntl fifo path %s. [%s]", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); throw std::runtime_error(text); } status &= ~O_NONBLOCK; /* unset O_NONBLOCK bit */ if ( ::fcntl(this->fifo_fd, F_SETFL,status) == -1 ) { ::close(this->fifo_fd); ::snprintf(text,sizeof(text),"+++ Cannot set O_NONBLOCK bit of fifo %s. [%s]", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); throw std::runtime_error(text); } } @@ -587,7 +585,7 @@ void fifolog::LibCLogger::init(const std::string& f, const std::string& u, const int ret = ::dup2(this->fifo_fd, fd); if ( ret == -1 ) { ::snprintf(text,sizeof(text),"+++ Failed to dup stdout for fifo: %s. [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); ::close(this->fifo_fd); throw std::runtime_error(text); } @@ -595,7 +593,7 @@ void fifolog::LibCLogger::init(const std::string& f, const std::string& u, const ret = ::dup2(this->fifo_fd, fd); if ( ret == -1 ) { ::snprintf(text,sizeof(text),"+++ Failed to dup stderr for fifo: %s. [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); ::close(this->fifo_fd); throw std::runtime_error(text); } @@ -631,7 +629,7 @@ void fifolog::PollLogger::init(const std::string& f, const std::string& u, const ret = ::pipe(this->std_fd); if ( ret != 0 ) { ::snprintf(text,sizeof(text),"+++ Failed to create stdout pipe for fifo: %s. [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); ::close(this->fifo_fd); this->fifo_fd = -1; throw std::runtime_error(text); @@ -640,7 +638,7 @@ void fifolog::PollLogger::init(const std::string& f, const std::string& u, const ret = ::dup2(this->std_fd[1],fd); if ( ret == -1 ) { ::snprintf(text,sizeof(text),"+++ Failed to dup stdout for fifo: %s. [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); ::close(this->fifo_fd); this->fifo_fd = -1; throw std::runtime_error(text); @@ -649,7 +647,7 @@ void fifolog::PollLogger::init(const std::string& f, const std::string& u, const ret = ::dup2(this->std_fd[1],fd); if ( ret == -1 ) { ::snprintf(text,sizeof(text),"+++ Failed to dup stderr for fifo: %s. [%s]\n", - fifo.c_str(), cerror(errno)); + fifo.c_str(), cerror(errno).c_str()); ::close(this->fifo_fd); this->fifo_fd = -1; throw std::runtime_error(text); @@ -664,7 +662,7 @@ void fifolog::PollLogger::init(const std::string& f, const std::string& u, const ret = ::epoll_ctl(this->epoll_fd, EPOLL_CTL_ADD, this->std_fd[0], &ev); if ( ret != 0 ) { ::snprintf(text,sizeof(text),"+++ Failed to add FD %d to epoll structure for fifo: %s. [%s]\n", - this->std_fd[0], fifo.c_str(), cerror(errno)); + this->std_fd[0], fifo.c_str(), cerror(errno).c_str()); ::close(this->epoll_fd); ::close(this->fifo_fd); throw std::runtime_error(text); @@ -775,7 +773,7 @@ extern "C" int fifolog_set_fifo(const char* fifo) { return 1; } ::fprintf(stderr,"Failed to set output fifo: %s [%s] logger %s initialized.\n", - fifo ? fifo : "???", ::strerror(errno), log.get() ? "already" : "NOT"); + fifo ? fifo : "???", fifolog::cerror(errno).c_str(), log.get() ? "already" : "NOT"); errno = ENOENT; return 0; } @@ -974,3 +972,5 @@ __asm__ (".global __vfprintf_chk; .type __vfprintf_chk,@function; __vfprintf_ch __asm__ (".global __printf_chk; .type __printf_chk,@function; __printf_chk = local__printf_chk"); __asm__ (".global __fprintf_chk; .type __fprintf_chk,@function; __fprintf_chk = local__fprintf_chk"); __asm__ (".global __vfprintf_chk; .type __vfprintf_chk,@function; __vfprintf_chk = local__vfprintf_chk"); + +#undef LOGGER_VA_LIST diff --git a/Online/OnlineBase/OnlineBase/NET/TransferTest.h b/Online/OnlineBase/OnlineBase/NET/TransferTest.h index 0ba4719356f5cf5d79ce6200103fb165a864daea..673e2a4b2c4803924e78d6c49aa13ddbfcacf120 100755 --- a/Online/OnlineBase/OnlineBase/NET/TransferTest.h +++ b/Online/OnlineBase/OnlineBase/NET/TransferTest.h @@ -18,6 +18,7 @@ #include <cstring> #include <cerrno> #include <string> +#include <system_error> // Framework includes #include "RTL/rtl.h" @@ -159,8 +160,10 @@ extern "C" int TRANSFERTEST(send) (int argc, char **argv) { ::gettimeofday(&start,0); for (int i=0, mx=loop; mx > 0; --mx, ++i) { int sc = net_send(cl.m_net, wmessage, length, to, 1); - if (sc != NET_SUCCESS) - ::printf("Client::send Failed: Error=%d errno=%d [%s]\n",sc,errno,::strerror(errno)); + if (sc != NET_SUCCESS) { + std::string err = std::make_error_code(std::errc(errno)).message(); + ::printf("Client::send Failed: Error=%d errno=%d [%s]\n",sc,errno,err.c_str()); + } num_bytes += length; if ( ((i+1) % print_freq) == 0 ) { struct timeval now; diff --git a/Online/OnlineBase/OnlineBase/RTL/rtl.h b/Online/OnlineBase/OnlineBase/RTL/rtl.h index 048e218e099c0bb6b83f1c01a48c13314bfddb2f..ec5131864e67230597e8e4f1d8e165e9f477db62 100755 --- a/Online/OnlineBase/OnlineBase/RTL/rtl.h +++ b/Online/OnlineBase/OnlineBase/RTL/rtl.h @@ -376,8 +376,10 @@ namespace RTL { const std::string& nodeNameShort(); /// Access data interface name const std::string& dataInterfaceName(); - /// Access current time string + /// Access current local time string std::string timestr(time_t tp=0, __CXX_CONST char* fmt = "%b %d %H:%M:%S "); + /// Access current GMT time string + std::string gmtimestr(time_t tp=0, __CXX_CONST char* fmt = "%b %d %H:%M:%S "); /// Independent version of strerror std::string errorString(); diff --git a/Online/OnlineBase/src/ASIO/TanInterface.cpp b/Online/OnlineBase/src/ASIO/TanInterface.cpp index 7c11a5b8990e1040e767a86bbd4d9256c9064951..0ecf96b165a36edddbe624c9a966d8a8d7014b95 100755 --- a/Online/OnlineBase/src/ASIO/TanInterface.cpp +++ b/Online/OnlineBase/src/ASIO/TanInterface.cpp @@ -23,6 +23,7 @@ #include <mutex> #include <string> #include <stdexcept> +#include <system_error> using namespace BoostAsio; @@ -111,7 +112,8 @@ TanInterface::TanInterface() : m_conOut(0), m_conIn(0) { m_pcHostName[sizeof (m_pcHostName)-1] = 0; h = hostByName(m_pcHostName); if ( h == 0 ) { - throw std::runtime_error(std::string("Tan(ASIO):")+::strerror(errno)); + std::string err = std::make_error_code(std::errc(errno)).message(); + throw std::runtime_error("Tan(ASIO):"+err); } dot = strchr(m_pcHostName,'.'); // Do not truncate host names in internet format like 192.168.xxx.yyy diff --git a/Online/OnlineBase/src/ASIO/Transfer.cpp b/Online/OnlineBase/src/ASIO/Transfer.cpp index fcb744c3bb29614af2d976c006b32b16b6ad26e4..b080b3d814fba9779f531fbd02983f3b2c0a3d5c 100755 --- a/Online/OnlineBase/src/ASIO/Transfer.cpp +++ b/Online/OnlineBase/src/ASIO/Transfer.cpp @@ -139,7 +139,7 @@ namespace TRANSFER_NS { virtual ~NetConnection() { //::lib_rtl_output(LIB_RTL_DEBUG,"Transfer(ASIO): Remove connection %p [%s]\n", this, name.c_str()); if ( entry ) net->handle_close(entry); - entry = 0; + entry = nullptr; } /// Handle completion of a asynchonous unlocked read/write operation. void handle_read(const error_t& error, size_t bytes_transferred) override { @@ -346,12 +346,15 @@ namespace { //---------------------------------------------------------------------------------- NetErrorCode netentry_t::close() { asio::error_code ec; - TransferConnection::socket_t& chan = connection->socket(); - connection->entry = 0; - if ( chan.is_open() ) { - chan.set_option(asio::socket_base::linger(true,0)); - chan.shutdown(TransferConnection::socket_t::shutdown_both,ec); - chan.close(ec); + if ( this->connection ) { + TransferConnection::socket_t& chan = this->connection->socket(); + this->connection->entry = nullptr; + if ( chan.is_open() ) { + chan.set_option(asio::socket_base::linger(true,0), ec); + chan.shutdown(TransferConnection::socket_t::shutdown_both, ec); + chan.close(ec); + } + this->connection = nullptr; } return NET_SUCCESS; } @@ -410,7 +413,10 @@ NET::~NET() { for (netdb_t::iterator i=m_db.begin(); i!=m_db.end();++i) { netentry_t* e = (*i).second; (*i).second = 0; - delete e; + if ( e ) { + e->close(); + delete e; + } } m_db.clear(); } @@ -532,12 +538,14 @@ NetErrorCode NET::remove(netentry_t *e) { void NET::setSockOpts(TransferConnection::socket_t& chan) { if ( chan.is_open() ) { #ifdef HAVE_ASIO_IPC - //chan.set_option(asio::socket_base::send_buffer_size(SEND_BUFFER_SIZE)); + //asio::error_code ec; + //chan.set_option(asio::socket_base::send_buffer_size(SEND_BUFFER_SIZE), ec); #else - chan.set_option(asio::socket_base::reuse_address(true)); - chan.set_option(asio::socket_base::linger(true,0)); - //chan.set_option(asio::socket_base::receive_buffer_size(RECV_BUFFER_SIZE)); - //chan.set_option(asio::socket_base::send_buffer_size(SEND_BUFFER_SIZE)); + asio::error_code ec; + chan.set_option(asio::socket_base::reuse_address(true), ec); + chan.set_option(asio::socket_base::linger(true,0), ec); + //chan.set_option(asio::socket_base::receive_buffer_size(RECV_BUFFER_SIZE), ec); + //chan.set_option(asio::socket_base::send_buffer_size(SEND_BUFFER_SIZE), ec); #endif } } diff --git a/Online/OnlineBase/src/MBM/mbm_extract.cpp b/Online/OnlineBase/src/MBM/mbm_extract.cpp index 2007ff943d55b9513e56a7666d23a815cd9b5cc9..7e7c50a42589e64ba1dd6ce488263cd1810a7b73 100644 --- a/Online/OnlineBase/src/MBM/mbm_extract.cpp +++ b/Online/OnlineBase/src/MBM/mbm_extract.cpp @@ -18,6 +18,7 @@ // C/C++ include files #include <cerrno> #include <cstring> +#include <system_error> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -89,14 +90,16 @@ extern "C" int mbm_extract(int argc,char **argv) { int fid = ::open(output.c_str(), O_WRONLY|O_CREAT|O_LARGEFILE|O_TRUNC, S_IRWXG|S_IRWXU); if ( fid == -1 ) { int err = errno; + std::string error = std::make_error_code(std::errc(err)).message(); ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Failed to open output file: %s", output.c_str()); - ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error[%d]: %s", err, ::strerror(err)); + ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error[%d]: %s", err, error.c_str()); ::exit(err); } BMID bmid = ::mbm_include(buffer.c_str(),name.c_str(),partID,comm_type,BM_INC_READ); if ( bmid == MBM_INV_DESC ) { + std::string error = std::make_error_code(std::errc(errno)).message(); ::lib_rtl_output(LIB_RTL_ALWAYS," Failed to include in MBM buffer %s [%s].", - buffer.c_str(), strerror(errno)); + buffer.c_str(), error.c_str()); ::exit(errno); } int event_type = EVENT_TYPE_EVENT; @@ -143,7 +146,8 @@ extern "C" int mbm_extract(int argc,char **argv) { break; ::mbm_free_event(bmid); if ( errno != 0 ) { - ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error writing: %s", ::strerror(errno)); + std::string error = std::make_error_code(std::errc(errno)).message(); + ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error writing: %s", error.c_str()); break; } if ( tr_number+1 == count ) { @@ -153,16 +157,19 @@ extern "C" int mbm_extract(int argc,char **argv) { ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Wrote buffer %ld", tr_number); } else { - ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error mbm_wait_event: %s", ::strerror(errno)); + std::string error = std::make_error_code(std::errc(errno)).message(); + ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error mbm_wait_event: %s", error.c_str()); } } else { - ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error mbm_get_event_a: %s", ::strerror(errno)); + std::string error = std::make_error_code(std::errc(errno)).message(); + ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error mbm_get_event_a: %s", error.c_str()); } } if ( tr_number < count ) { + std::string error = std::make_error_code(std::errc(errno)).message(); ::lib_rtl_output(LIB_RTL_ALWAYS,"+++ Error writing: %s %ld %ld", - ::strerror(errno), tr_number, count); + error.c_str(), tr_number, count); } ::mbm_exclude(bmid); ::close(fid); diff --git a/Online/OnlineBase/src/MBM/mbmlib_server.cpp b/Online/OnlineBase/src/MBM/mbmlib_server.cpp index 85a75e1a3075603dfaad18e4f67dcc072b63b759..0095c7813a77fd7e47be96c82edf192f0746f854 100755 --- a/Online/OnlineBase/src/MBM/mbmlib_server.cpp +++ b/Online/OnlineBase/src/MBM/mbmlib_server.cpp @@ -46,7 +46,7 @@ static inline int mbm_error_code() { static inline int mbm_error(const char* fn, int line) { int e = errno; - ::lib_rtl_output(LIB_RTL_ERROR,"MBM inconsistency in '%s' Line:%d errno:%d\n", + ::lib_rtl_output(LIB_RTL_ERROR,"MBM inconsistency in '%s' Line:%d errno:%d", fn, line, e, RTL::errorString(e).c_str()); return MBM_ERROR; } @@ -275,7 +275,7 @@ int mbmsrv_init_comm(ServerBMID bmid) { ::lib_rtl_delete_named_section(comm_mod); int status = ::lib_rtl_create_section(comm_mod,len,&bm->comm_add); if (!lib_rtl_is_success(status)) { - ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Error mapping SHM communiction section for MBM buffer %s\n", + ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Error mapping SHM communiction section for MBM buffer %s", bm->bm_name); return MBM_ERROR; } @@ -346,8 +346,8 @@ int _mbmsrv_map_buff_section(BufferMemory* bm) { const char* bm_name = bm->bm_name; ::snprintf(text,sizeof(text),"bm_buff_%s",bm_name); int status = ::lib_rtl_map_section(text,0,&bm->buff_add); - if (!lib_rtl_is_success(status)) { - ::lib_rtl_output(LIB_RTL_OS,"++bm_serevr++ Error mapping buffer section for MBM buffer %s\n",bm_name); + if ( !lib_rtl_is_success(status) ) { + ::lib_rtl_output(LIB_RTL_OS,"++bm_serevr++ Error mapping buffer section for MBM buffer %s", bm_name); return MBM_ERROR; } bm->buffer_add = (char*)bm->buff_add->address; @@ -361,8 +361,8 @@ int _mbmsrv_map_ctrl_section(BufferMemory* bm) { const char* bm_name = bm->bm_name; ::snprintf(text,sizeof(text),"bm_ctrl_%s",bm_name); int status = ::lib_rtl_map_section(text,0,&bm->gbl_add); - if (!lib_rtl_is_success(status)) { - ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Error mapping control section for MBM buffer %s\n",bm_name); + if ( !lib_rtl_is_success(status) ) { + ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Error mapping control section for MBM buffer %s", bm_name); return MBM_ERROR; } bm->gbl = (char*)bm->gbl_add->address; @@ -551,10 +551,10 @@ USER* _mbmsrv_ualloc(ServerBMID bm) { /// Delete user from the wait_event queue void _mbmsrv_del_wev (ServerBMID bm, USER* u) { if ( u->state != S_wevent ) { - ::lib_rtl_output(LIB_RTL_ERROR,"INCONSISTENCY: Delete user from WEV queue without state S_wevent\n"); + ::lib_rtl_output(LIB_RTL_ERROR,"INCONSISTENCY: Delete user from WEV queue without state S_wevent"); } if ( u->wenext.next == 0 && u->wenext.prev != 0 ) { - ::lib_rtl_output(LIB_RTL_ERROR,"INCONSISTENCY: Remove user from WEV queue without valid QUE entry\n"); + ::lib_rtl_output(LIB_RTL_ERROR,"INCONSISTENCY: Remove user from WEV queue without valid QUE entry"); } if ( ::remqent(&u->wenext) ) --bm->ctrl->wait_event_count; @@ -563,7 +563,7 @@ void _mbmsrv_del_wev (ServerBMID bm, USER* u) { /// Delete user from the wait_space queue void _mbmsrv_del_wsp (ServerBMID bm, USER* u) { if (u->state != S_wspace) { - _mbm_printf("INCONSISTENCY: Delete user from WSP queue without state S_wspace\n"); + _mbm_printf("INCONSISTENCY: Delete user from WSP queue without state S_wspace"); } if ( ::remqent(&u->wsnext) ) --bm->ctrl->wait_space_count; @@ -1132,7 +1132,7 @@ int mbmsrv_include (ServerBMID bmid, void* connection, MSG& msg) { USER* u = _mbmsrv_ualloc(bm); // find free user slot if (u == 0) { - ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Failed to allocate user slot of %s for %s.\n", + ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Failed to allocate user slot of %s for %s.", bm_name,name); return mbmsrv_send_include_error(bm,msg,MBM_NO_FREE_US); // Typical use case: Too many users } @@ -1274,7 +1274,7 @@ int mbmsrv_get_event(ServerBMID bm, MSG& msg) { USER* u = CHECKED_CONSUMER(msg.user); if ( u->state == S_wevent ) { ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ Too many calls to " - "mbm_get_event '%s'\n", u->name); + "mbm_get_event '%s'", u->name); return MBM_NO_REPLY; } _mbmsrv_rel_event(bm, u); @@ -1613,7 +1613,7 @@ void _mbmsrv_check_wev (ServerBMID bm, EVENT* e) { // Something is really odd here. // The BM internal structure looks corrupted.... ::lib_rtl_output(LIB_RTL_ERROR, - "++bm_server++ structures of '%s' look corrupted. Something ugly happened!\n", + "++bm_server++ structures of '%s' look corrupted. Something ugly happened!", bm->bm_name); return; } @@ -1716,7 +1716,7 @@ int _mbmsrv_connect(ServerBMID bm) { #ifndef MBM_HAVE_STD_MUTEX /// Create table lock if ( !lib_rtl_is_success(::lib_rtl_create_lock(0, &bm->lockid)) ) { - ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Failed create server lock for buffer %s.\n", + ::lib_rtl_output(LIB_RTL_OS,"++bm_server++ Failed create server lock for buffer %s.", bm->bm_name); _mbmsrv_close_connections(bm); return MBM_ERROR; @@ -1909,10 +1909,10 @@ static int _mbmsrv_client_watch(void* param) { return 0x1; } catch(const std::exception& e) { - ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ MBM server thread exited with exception: %s\n",e.what()); + ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ MBM server thread exited with exception: %s",e.what()); } catch(...) { - ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ MBM server thread exited with UNKNOWN exception.\n"); + ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ MBM server thread exited with UNKNOWN exception."); } return 0x0; } @@ -1941,10 +1941,10 @@ static int mbmsrv_thread_routine(void* param) { return bm->communication.dispatch(id); } catch(const std::exception& e) { - ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ Thread exited with exception: %s\n",e.what()); + ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ Thread exited with exception: %s",e.what()); } catch(...) { - ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ Thread exited with UNKNOWN exception.\n"); + ::lib_rtl_output(LIB_RTL_ERROR,"++bm_server++ Thread exited with UNKNOWN exception."); } return 0; } diff --git a/Online/OnlineBase/src/RTL/FmcLogDevice.cpp b/Online/OnlineBase/src/RTL/FmcLogDevice.cpp index a7bfc1a45998cc22b61c39a463cc2658525a1ce7..1f4ad161f5db24617b81e8a07155195a6b58ec16 100644 --- a/Online/OnlineBase/src/RTL/FmcLogDevice.cpp +++ b/Online/OnlineBase/src/RTL/FmcLogDevice.cpp @@ -18,6 +18,8 @@ #include <climits> #include <cstring> #include <stdexcept> +#include <system_error> + #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> @@ -28,6 +30,13 @@ using namespace std; using namespace RTL; +namespace { + /// Translate errno into error string + inline const string cerror(int err) { + return make_error_code(errc(err)).message(); + } +} + /// Default constructor FmcLogDevice::FmcLogDevice() : Logger::LogDevice() { fifoFD = NO_FIFO; @@ -115,28 +124,28 @@ int FmcLogDevice::open(const char* path) const { if( ::access(fifo,W_OK) == -1 ) { /* access denied */ if( errno == ENOENT ) { this->except("FmcLogDevice", "Fifo path %s not writable [%s].", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); } this->except("FmcLogDevice", "Fifo path %s not writable. Check permissions.", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); return NO_FIFO; } if ( ::stat(fifo,&statBuf) == -1 ) { /* get fifo info */ this->except("FmcLogDevice", "Cannot stat fifo path %s. [%s]", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); } if( !S_ISFIFO(statBuf.st_mode) ) { /* check if fifo is a FIFO */ this->except("FmcLogDevice", "Fifo path %s is not a FIFO device. [%s]", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); } /* open error log */ fd = ::open(fifo,(allowDrop ? O_WRONLY : O_RDWR)|O_NONBLOCK|O_APPEND); if ( fd == NO_FIFO ) { if ( errno == ENXIO ) this->except("FmcLogDevice", "Fifo path %s not owned by any process. [%s]", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); this->except("FmcLogDevice", "Failed to open fifo:%s [%s]", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); } /*-------------------------------------------------------------------------*/ if ( allowDrop ) { @@ -147,13 +156,13 @@ int FmcLogDevice::open(const char* path) const { if(status<0) { ::close(fd); this->except("FmcLogDevice", "Cannot fcntl fifo path %s. [%s]", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); } status &= ~O_NONBLOCK; /* unset O_NONBLOCK bit */ if ( ::fcntl(fd, F_SETFL,status) == -1 ) { ::close(fd); this->except("FmcLogDevice", "Cannot set O_NONBLOCK bit of fifo %s. [%s]", - fifo, ::strerror(errno)); + fifo, cerror(errno).c_str()); } } return fd; diff --git a/Online/OnlineBase/src/RTL/Logger.cpp b/Online/OnlineBase/src/RTL/Logger.cpp index 99d40ed0c38fa58e541ecac7c20992e764302746..80cb159df43b2e94ceaf72ac5ecd89305ffdb278 100644 --- a/Online/OnlineBase/src/RTL/Logger.cpp +++ b/Online/OnlineBase/src/RTL/Logger.cpp @@ -29,7 +29,7 @@ using namespace RTL; namespace { - std::shared_ptr<Logger::LogDevice> s__dev; + shared_ptr<Logger::LogDevice> s__dev; /// Helper function to steer printing bool may_print(const Logger* c, int level) { @@ -41,12 +41,12 @@ namespace { } /// Default constructor -Logger::LogDevice::LogDevice() : device_lock(new std::mutex()) { +Logger::LogDevice::LogDevice() : device_lock(new mutex()) { char pathName[PATH_MAX] = ""; int len = ::readlink("/proc/self/exe",pathName,sizeof(pathName)-1); if ( len == -1 ) { - this->except("LogDevice", - "Output: readlink(): %s.",::strerror(errno)); + string err = make_error_code(errc(errno)).message(); + this->except("LogDevice", "Output: readlink(): %s.",err.c_str()); } pathName[len]='\0'; executable = ::basename(pathName); @@ -93,15 +93,17 @@ void Logger::LogDevice::set_io_buffering(size_t mode) { } /// Set stdout to line - buffered mode if ( 0 != ::setvbuf(stdout, nullptr, buff_mode, buff_size) ) { + string err = make_error_code(errc(errno)).message(); this->except("LogDevice", "Output: Failed to set stdout to line buffered mode: %s.", - ::strerror(errno)); + err.c_str()); } /// Set stderr to line - buffered mode if ( 0 != ::setvbuf(stderr, nullptr, buff_mode, buff_size) ) { + string err = make_error_code(errc(errno)).message(); this->except("LogDevice", "Output: Failed to set stderr to line buffered mode: %s.", - ::strerror(errno)); + err.c_str()); } } @@ -244,7 +246,7 @@ size_t Logger::LogDevice::printmsg(int severity, const char* source, const char* ++len; } { - lock_guard<std::mutex> lock(*device_lock); + lock_guard<mutex> lock(*device_lock); return ::write(STDOUT_FILENO, text, len); } } @@ -271,7 +273,7 @@ size_t Logger::LogDevice::printout(int severity, const char* source, const char* void Logger::LogDevice::exceptmsg(const char* source, const char* msg) const { char header[2048]; formatHeader(header, sizeof(header), LIB_RTL_ERROR, source); { - lock_guard<std::mutex> lock(*device_lock); + lock_guard<mutex> lock(*device_lock); ::fprintf(stdout, "%s %s\n", header, msg); ::fflush(stdout); } diff --git a/Online/OnlineBase/src/RTL/rtl.cpp b/Online/OnlineBase/src/RTL/rtl.cpp index 085c5205602b21bcb803a2a9d372d6c92ff599c8..d71b0f004f5b96041ffd8030f1e4675587645b07 100755 --- a/Online/OnlineBase/src/RTL/rtl.cpp +++ b/Online/OnlineBase/src/RTL/rtl.cpp @@ -18,6 +18,7 @@ #include <cstring> #include <climits> #include <iostream> +#include <system_error> #include <fcntl.h> using namespace std; @@ -83,9 +84,9 @@ namespace RTL { #include <signal.h> #define ERROR_SUCCESS 0 std::string RTL::errorString(int status) { - char buff[1024]; - ::strerror_r(status, buff, sizeof(buff)); - return buff; + if ( status != 0 ) + return std::make_error_code(std::errc(status)).message(); + return "success"; } #define INSTALL_SIGNAL(x,y) install(x , #x , y); @@ -307,7 +308,7 @@ extern "C" void lib_rtl_signal_log(int value) { } std::string RTL::errorString() { - return errorString(lib_rtl_get_error()); + return errorString(errno); } RTL::ExitHandler::ExitHandler() { @@ -420,41 +421,42 @@ extern "C" int lib_rtl_pid() { int lib_rtl_signal_message(int action, const char* fmt, ...) { int status = 1; - char buff[2048]; - va_list args; - va_start( args, fmt ); if ( fmt ) { int err; + va_list args; + char buff[2048]; + + va_start( args, fmt ); + ::vsnprintf(buff, sizeof(buff), fmt, args); + buff[sizeof(buff)-1] = 0; + va_end(args); + switch(action) { case LIB_RTL_ERRNO: err = errno; if ( err != 0 ) { string errstr = RTL::errorString(err); - ::lib_rtl_output(LIB_RTL_ERROR,"RTL: %8d : %s\n",err, errstr.c_str()); - ::vsnprintf(buff, sizeof(buff), fmt, args); - ::lib_rtl_output(LIB_RTL_ERROR," %s\n",buff); + ::lib_rtl_output(LIB_RTL_ERROR, "RTL:%4d : %s", err, errstr.c_str()); + ::lib_rtl_output(LIB_RTL_ERROR, " %s", buff); status = 0; } break; case LIB_RTL_DEFAULT: - ::vsnprintf(buff, sizeof(buff), fmt, args); - ::lib_rtl_output(LIB_RTL_ERROR,"RTL: %s\n",buff); + ::lib_rtl_output(LIB_RTL_ERROR, "RTL: %s", buff); status = 0; break; case LIB_RTL_OS: default: - err = lib_rtl_get_error(); + err = ::lib_rtl_get_error(); if ( err != ERROR_SUCCESS ) { string errstr = RTL::errorString(err); - ::lib_rtl_output(LIB_RTL_ERROR,"RTL: %8d : %s\n",err, errstr.c_str()); - ::vsnprintf(buff, sizeof(buff), fmt, args); - ::lib_rtl_output(LIB_RTL_ERROR," %s\n",buff); + ::lib_rtl_output(LIB_RTL_ERROR, "RTL:%4d : %s", err, errstr.c_str()); + ::lib_rtl_output(LIB_RTL_ERROR, " %s",buff); status = 0; } break; } } - va_end(args); return status; } @@ -575,8 +577,9 @@ extern "C" size_t lib_rtl_log(int level, const char* format, va_list& args) { case LIB_RTL_ERRNO: case LIB_RTL_OS: if ( errno != 0 ) { - int err = errno; - ::lib_rtl_output(LIB_RTL_ERROR,"RTL: %8d : %s\n",err, RTL::errorString(err).c_str()); + int status = errno; + string err = RTL::errorString(status); + ::lib_rtl_output(LIB_RTL_ERROR, "RTL:%4d [%s]", status, err.c_str()); errno = 0; } level = LIB_RTL_ERROR; @@ -593,6 +596,7 @@ extern "C" size_t lib_rtl_log(int level, const char* format, va_list& args) { } else { result = ::vfprintf(stdout, format, args); + ::fputc('\n', stdout); ::fflush(stdout); } } @@ -784,12 +788,13 @@ extern "C" const char* lib_rtl_gmtimestr(const char* fmt, const time_t* tp) { } extern "C" const char* lib_rtl_gmtimestr_r(char* timestr, size_t timestrLen, const char* fmt, const time_t* tp) { + struct tm ti; time_t t; if ( 0 == tp ) { tp = &t; ::time(&t); } - struct tm *now = ::gmtime(tp); + struct tm *now = ::gmtime_r(tp,&ti); ::strftime(timestr,timestrLen,fmt,now); timestr[timestrLen-1] = 0; return timestr; @@ -838,7 +843,7 @@ namespace RTL { return s_nodeNameShort; } - /// Access current time string + /// Access current local time string string timestr(time_t tp, const char* fmt) { struct tm ti; char str[256]; @@ -849,6 +854,16 @@ namespace RTL { return str; } + /// Access current GMT time string + string gmtimestr(time_t tp, const char* fmt) { + struct tm ti; + char str[256]; + if ( 0 == tp ) tp = ::time(nullptr); + struct tm *now = ::gmtime_r(&tp, &ti); + ::strftime(str,sizeof(str),fmt,now); + str[sizeof(str)-1] = 0; + return str; + } std::string fileFromLink(const std::string& link) { char filePath[PATH_MAX]; diff --git a/Online/OnlineBase/src/RTL/rtl_events.cpp b/Online/OnlineBase/src/RTL/rtl_events.cpp index aa298ef5100912cb8ac9826b9ef735478fd4fde7..e7659493d276fc83ee2b506bb96d068dbe26d25d 100755 --- a/Online/OnlineBase/src/RTL/rtl_events.cpp +++ b/Online/OnlineBase/src/RTL/rtl_events.cpp @@ -45,7 +45,7 @@ extern "C" int lib_rtl_event_exithandler() { lib_rtl_event_map_t m = allEventFlags(); lib_rtl_event_map_t::iterator i = m.begin(); for( ; i != m.end(); ++i ) { - // ::lib_rtl_output(LIB_RTL_ALWAYS,"Deleting event flag:%s\n",(*i).first.c_str()); + // ::lib_rtl_output(LIB_RTL_ALWAYS,"Deleting event flag:%s",(*i).first.c_str()); ::lib_rtl_delete_event((*i).second); } delete s_evtMap.release(); @@ -145,7 +145,7 @@ int lib_rtl_delete_event(lib_rtl_event_t handle) { lib_rtl_event_map_t& m = allEventFlags(); lib_rtl_event_map_t::iterator i = m.find(h->name); if ( i != m.end() ) { - // ::lib_rtl_output(LIB_RTL_ALWAYS,"Deleting event: %s\n",(*i).first.c_str()); + // ::lib_rtl_output(LIB_RTL_ALWAYS,"Deleting event: %s",(*i).first.c_str()); m.erase(i); } } @@ -290,8 +290,8 @@ int lib_rtl_wait_for_event_a(lib_rtl_event_t flag, lib_rtl_thread_routine_t acti } static void help_set_event() { - ::lib_rtl_output(LIB_RTL_ALWAYS,"rtl_set_event -opt [-opt] \n"); - ::lib_rtl_output(LIB_RTL_ALWAYS," -n=<name> Event flag name \n"); + ::lib_rtl_output(LIB_RTL_ALWAYS,"rtl_set_event -opt [-opt] "); + ::lib_rtl_output(LIB_RTL_ALWAYS," -n=<name> Event flag name "); } extern "C" int rtl_set_event(int argc, char** argv) { lib_rtl_event_t flag; diff --git a/Online/OnlineBase/src/RTL/rtl_sys.cpp b/Online/OnlineBase/src/RTL/rtl_sys.cpp index 3467fbccefcf545c8490b057f4cefd27d21b1553..b116e65f9ddebc4143251d03c597490cad28876a 100755 --- a/Online/OnlineBase/src/RTL/rtl_sys.cpp +++ b/Online/OnlineBase/src/RTL/rtl_sys.cpp @@ -101,7 +101,7 @@ int SysFile::read(char* buf, size_t siz) const { FileDescriptor fd(::open(m_name.c_str(),O_RDONLY)); if( fd.get() < 0 ) { string err = "Failed to open "+m_name+" "; - throw runtime_error(err+::strerror(errno)); + throw runtime_error(err+RTL::errorString(errno)); } size_t tmp = 0; while ( tmp < siz ) { @@ -123,7 +123,7 @@ int SysFile::read(char* buf, size_t siz) const { } if ( tmp != siz ) { string err = "Read of system file "+m_name+" failed:"; - err += ::strerror(errno); + err += RTL::errorString(errno); throw runtime_error(err); } return tmp; @@ -134,7 +134,7 @@ int SysFile::write(char* buf, size_t siz, int flags) const { FileDescriptor fd(::open(m_name.c_str(),O_WRONLY|O_CREAT|O_TRUNC,flags)); if( fd.get() < 0 ) { string err = "Failed to open "+m_name+" "; - throw runtime_error(err+::strerror(errno)); + throw runtime_error(err+RTL::errorString(errno)); } size_t tmp = 0; while ( tmp < siz ) { @@ -156,7 +156,7 @@ int SysFile::write(char* buf, size_t siz, int flags) const { } if ( tmp != siz ) { string err = "Write of system file "+m_name+" failed:"; - err += ::strerror(errno); + err += RTL::errorString(errno); throw runtime_error(err); } return tmp; diff --git a/Online/OnlineBase/src/TAN/NameServer.cpp b/Online/OnlineBase/src/TAN/NameServer.cpp index 92c9293bf7715f8201871db9c7385024fed3fcad..d90406884524c3254d8b82c6e3000cd6ac3363a9 100755 --- a/Online/OnlineBase/src/TAN/NameServer.cpp +++ b/Online/OnlineBase/src/TAN/NameServer.cpp @@ -522,7 +522,6 @@ int TcpNameService::handleReceiveRequest ( EventHandler* handler ) { } } } - //lib_rtl_output(LIB_RTL_DEBUG,"handleReceiveRequest> Close receive on %d %s\n",chan, strerror(status)); hand->_Delete(); return status; } diff --git a/Online/OnlineBase/src/TAN/tan_alloc_tst.cpp b/Online/OnlineBase/src/TAN/tan_alloc_tst.cpp index c0208ef24a5e8e66745e4723f65459ace676c628..bc533859344cd34f451e18e1bcd45d7b6d813fe4 100755 --- a/Online/OnlineBase/src/TAN/tan_alloc_tst.cpp +++ b/Online/OnlineBase/src/TAN/tan_alloc_tst.cpp @@ -73,10 +73,10 @@ extern "C" int rtl_tan_alloc_test ( int argc, char* argv[] ) { alloc++; if ( status == TAN_SS_SUCCESS ) { if ( !quiet ) ::printf("allocatePort: %s Port:%04X status:%d [%s]\n", - buff+host_len, ports[i], status, ::strerror(errno)); + buff+host_len, ports[i], status, RTL::errorString(errno).c_str()); } else { - ::printf("FAILED: allocatePort(%s): %d [%s]\n", buff, status, ::strerror(errno)); + ::printf("FAILED: allocatePort(%s): %d [%s]\n", buff, status, RTL::errorString(errno).c_str()); } int aliases = (num_alias < 0) ? i : num_alias; for ( int j = 0; do_alias && j < aliases; j++ ) { @@ -86,7 +86,7 @@ extern "C" int rtl_tan_alloc_test ( int argc, char* argv[] ) { alias++; if ( !quiet || status != TAN_SS_SUCCESS ) { ::printf(" declareAlias: %s status:%d %08X errno:%d [%s]\n", - buff+host_len, status, status, errno, ::strerror(errno)); + buff+host_len, status, status, errno, RTL::errorString(errno).c_str()); } } @@ -104,10 +104,10 @@ extern "C" int rtl_tan_alloc_test ( int argc, char* argv[] ) { ++inquire; if ( status == TAN_SS_SUCCESS ) { if ( !quiet ) ::printf(" address_by_name: %s Port:%04X status:%d [%s]\n", - buff+host_len, addr.sin_port, status, ::strerror(errno)); + buff+host_len, addr.sin_port, status, RTL::errorString(errno).c_str()); } else { - ::printf(" FAILED: address_by_name(%s): %d [%s]\n", buff+host_len, status, ::strerror(errno)); + ::printf(" FAILED: address_by_name(%s): %d [%s]\n", buff+host_len, status, RTL::errorString(errno).c_str()); } int aliases = (num_alias < 0) ? i : num_alias; for ( int j = 0; do_alias && j < aliases; j++ ) { @@ -117,11 +117,11 @@ extern "C" int rtl_tan_alloc_test ( int argc, char* argv[] ) { ++inquire; if ( status == TAN_SS_SUCCESS ) { if ( !quiet ) ::printf(" address_by_name: %s Port:%04X status:%d [%s]\n", - buff+host_len, addr.sin_port, status, ::strerror(errno)); + buff+host_len, addr.sin_port, status, RTL::errorString(errno).c_str()); } else { ::printf(" FAILED: address_by_name(%s): %d [%s]\n", - buff+host_len, status, ::strerror(errno)); + buff+host_len, status, RTL::errorString(errno).c_str()); } } } @@ -132,7 +132,7 @@ extern "C" int rtl_tan_alloc_test ( int argc, char* argv[] ) { status = ::tan_remove_alias(buff); if ( status != TAN_SS_SUCCESS ) { ::printf(" FAILED: tan_remove_alias(%s): %d [%s]\n", - host_name.c_str()+host_len, status, ::strerror(errno)); + host_name.c_str()+host_len, status, RTL::errorString(errno).c_str()); } } } @@ -143,7 +143,8 @@ extern "C" int rtl_tan_alloc_test ( int argc, char* argv[] ) { status = ::tan_deallocate_port_number ( buff ); dealloc++; if ( !quiet || status != TAN_SS_SUCCESS ) { - ::printf("deallocatePort(%s) Port:%04X status:%d [%s]\n", buff+host_len, ports[i], status, strerror(errno)); + ::printf("deallocatePort(%s) Port:%04X status:%d [%s]\n", + buff+host_len, ports[i], status, RTL::errorString(errno).c_str()); } if ( dealloc%50 == 0 ) { ::printf("->%-4ld sec<- Allocations:%-6d Aliases:%-8d Inquire:%-6d Deallocations:%-6d\n", diff --git a/Online/OnlineBase/src/TAN/tan_inquire_tst.cpp b/Online/OnlineBase/src/TAN/tan_inquire_tst.cpp index e5efaa0a139924cab12cba1f5e064529303fe004..d1d367b1fee5f51589e5ba51e88b714f19c1a519 100755 --- a/Online/OnlineBase/src/TAN/tan_inquire_tst.cpp +++ b/Online/OnlineBase/src/TAN/tan_inquire_tst.cpp @@ -13,7 +13,7 @@ #ifdef _VMS #define lib_signal(x) lib$signal(x) #else -#define lib_signal(x) {printf("%s\n",strerror(x)); } +#define lib_signal(x) {printf("%s\n",RTL::errorString(x).c_str()); } #endif static void help() { printf("Usage : inquire -opt <opts>\n"); diff --git a/Online/PCIE40Data/PCIE40Data/pcie40.h b/Online/PCIE40Data/PCIE40Data/pcie40.h index 7b9f74ddc57ca0f4839531bae91df0e187715dd4..261a6c1fc4b77221bff8283a718efcfb74a53e06 100644 --- a/Online/PCIE40Data/PCIE40Data/pcie40.h +++ b/Online/PCIE40Data/PCIE40Data/pcie40.h @@ -19,6 +19,7 @@ // C/C++ include files #include <stdexcept> +#include <cstdint> #include <cstring> #include "PCIE40Data/Pack.h" @@ -171,13 +172,17 @@ namespace Online { /// Check basic quantities for validity bool is_valid() const; /// Pointer to the Types array - const unsigned char *types() const; + const uint8_t *types() const; /// Pointer to the array of bank payload sizes - const unsigned short *sizes() const; + const uint16_t *sizes() const; /// Pointer to the start of the data of the banks const frontend_data_t *data() const; /// Access the next fragment in the list const multi_fragment_t* next() const; + /// Get data by proper type + template <typename T> T* as(); + /// Get data by proper type (const) + template <typename T> const T* as() const; }; /// Class describing the MEP header (see EDMS 2100937 for details) @@ -310,25 +315,25 @@ namespace Online { public: /// Access collection Offset according to source ID - static std::size_t collection_offset_source_id(unsigned short src_id); + static std::size_t collection_offset_source_id(uint16_t src_id); /// Access collection Offset according to source ID and bank type - static std::pair<bool,std::size_t> collection_offset(unsigned short src_id, unsigned char type); + static std::pair<bool,std::size_t> collection_offset(uint16_t src_id, uint8_t type); /// Get bank data of a given source and type - std::pair<std::size_t, const bank_t*> get(unsigned short src_id, unsigned char type) const; + std::pair<std::size_t, const bank_t*> get(uint16_t src_id, uint8_t type) const; /// Total number of bank collections availible std::size_t num_bank_collections() const; /// Access to the bank collection indexed by subdetector - const bank_collection_t* bank_collection(std::size_t i) const; + const bank_collection_t* bank_collection(std::size_t i) const; /// Total memory size of the event block in bytes - std::size_t total_length() const; + std::size_t total_length() const; /// Copy event data to target buffer - void* copy_data(void* pointer) const; + void* copy_data(void* pointer) const; /// Check TAE flags - bool is_tae() const; + bool is_tae() const; /// Check TAE central flag - bool is_tae_central() const; + bool is_tae_central() const; /// Access half window size - uint8_t tae_half_window() const; + uint8_t tae_half_window() const; }; /// Collection of mep events as they arrive from the event builder @@ -361,21 +366,21 @@ namespace Online { public: /// Check if event entries are present - bool empty() const { return length == 0; } + bool empty() const { return length == 0; } /// Number of encapsulated event in the collection - std::size_t size() const { return length; } + std::size_t size() const { return length; } /// Number of encapsulated event in the collection - std::size_t num_events() const { return length; } + std::size_t num_events() const { return length; } /// Capacity of the event block - std::size_t max_events() const { return capacity; } + std::size_t max_events() const { return capacity; } /// Access to the MEP header structure - const mep_header_t* mep_header() const { return mep; } + const mep_header_t* mep_header() const { return mep; } /// Event iteration: iteration start - const event_t* begin() const; + const event_t* begin() const; /// Event iteration: end marker - const event_t* end() const; + const event_t* end() const; /// Event iteration: access the next event - const event_t* next(const event_t* e) const; + const event_t* next(const event_t* e) const; /// Direct access to an event by index const event_t* at(std::size_t which) const; /// Direct access to an event by index @@ -391,7 +396,7 @@ namespace Online { * \date 25/10/2019 */ namespace params { - typedef unsigned short detsource_t; + typedef uint16_t detsource_t; static constexpr std::size_t INVALID_BANK_TYPE = ~0x0UL; @@ -404,15 +409,15 @@ namespace Online { static constexpr detsource_t sourceid_Muon = 13; static constexpr detsource_t sourceid_Rich = 4; - static constexpr detsource_t sourceid_TOP5 = (unsigned short)(0xFFFF<<11); - static constexpr detsource_t sourceid_top5_ODIN = (unsigned short)((sourceid_ODIN<<11)&sourceid_TOP5); - static constexpr detsource_t sourceid_top5_VP = (unsigned short)((sourceid_VP<<11)&sourceid_TOP5); - static constexpr detsource_t sourceid_top5_UT = (unsigned short)((sourceid_UT<<11)&sourceid_TOP5); - static constexpr detsource_t sourceid_top5_FT = (unsigned short)((sourceid_FT<<11)&sourceid_TOP5); - static constexpr detsource_t sourceid_top5_Ecal = (unsigned short)((sourceid_Ecal<<11)&sourceid_TOP5); - static constexpr detsource_t sourceid_top5_Hcal = (unsigned short)((sourceid_Hcal<<11)&sourceid_TOP5); - static constexpr detsource_t sourceid_top5_Muon = (unsigned short)((sourceid_Muon<<11)&sourceid_TOP5); - static constexpr detsource_t sourceid_top5_Rich = (unsigned short)((sourceid_Rich<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_TOP5 = (uint16_t)(0xFFFF<<11); + static constexpr detsource_t sourceid_top5_ODIN = (uint16_t)((sourceid_ODIN<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_top5_VP = (uint16_t)((sourceid_VP<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_top5_UT = (uint16_t)((sourceid_UT<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_top5_FT = (uint16_t)((sourceid_FT<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_top5_Ecal = (uint16_t)((sourceid_Ecal<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_top5_Hcal = (uint16_t)((sourceid_Hcal<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_top5_Muon = (uint16_t)((sourceid_Muon<<11)&sourceid_TOP5); + static constexpr detsource_t sourceid_top5_Rich = (uint16_t)((sourceid_Rich<<11)&sourceid_TOP5); static constexpr std::size_t maxTell40ODIN = 1; // True counts static constexpr std::size_t maxTell40VP = 215; // 208 @@ -516,35 +521,44 @@ namespace Online { /// Internal helper to access the data inline std::size_t multi_fragment_t::data_offset() const { return sizeof(header) - + sizeof(unsigned char) * round_up(header.packing, header_t::types_alignment) - + sizeof(unsigned short) * round_up(header.packing, 1<<header.alignment); + + sizeof(uint8_t) * round_up(this->header.packing, header_t::types_alignment) + + sizeof(uint16_t) * round_up(this->header.packing, 1<<this->header.alignment); } /// pointer to the Types array - inline const unsigned char *multi_fragment_t::types() const { - return add_ptr<unsigned char>(this, sizeof(multi_fragment_t)); + inline const uint8_t *multi_fragment_t::types() const { + return add_ptr<uint8_t>(this, sizeof(multi_fragment_t)); } /// Pointer to the array of bank payload sizes - inline const unsigned short *multi_fragment_t::sizes() const { - return add_ptr<unsigned short>(this, sizeof(multi_fragment_t) + round_up(header.packing, header_t::types_alignment)); + inline const uint16_t *multi_fragment_t::sizes() const { + return add_ptr<uint16_t>(this, sizeof(multi_fragment_t) + round_up(this->header.packing, header_t::types_alignment)); } /// Pointer to the start of the data of the Banks inline const frontend_data_t* multi_fragment_t::data() const { - return add_ptr<frontend_data_t>(this, data_offset()); + return add_ptr<frontend_data_t>(this, this->data_offset()); } /// Access the next fragment in the list inline const multi_fragment_t *multi_fragment_t::next() const { - return add_ptr<const multi_fragment_t>(this, data_offset() + round_up(header.size,4)); + return add_ptr<const multi_fragment_t>(this, this->data_offset() + round_up(this->header.size,4)); + } + + /// Get data by proper type + template <typename T> inline T* multi_fragment_t::as() { + return (T*)this->data(); + } + /// Get data by proper type (const) + template <typename T> inline const T* multi_fragment_t::as() const { + return (T*)this->data(); } /// Check basic quantities for validity inline bool mep_header_t::is_valid() const { - const int* siz = (const int*)this; - return (magic == MagicPattern) && (num_source > 0) - && (siz[0] != siz[1]) && (siz[0] != siz[2]); + struct evheader_t { uint32_t s0, s1, s2; }; + const evheader_t* h = reinterpret_cast<const evheader_t*>(this); + return (this->magic == MagicPattern) && (this->num_source > 0) && (h->s0 != h->s1) && (h->s0 != h->s2); } /// Access the table of offsets in the MEP header @@ -555,18 +569,18 @@ namespace Online { /// Offset of individual MFPs inline uint32_t mep_header_t::fragment_offset(std::size_t which) const { - const uint32_t* offsetN = fragment_offsets(); + const uint32_t* offsetN = this->fragment_offsets(); return offsetN[which]*sizeof(uint32_t); } /// Access to individual MFPs inline const multi_fragment_t* mep_header_t::multi_fragment(std::size_t which) const { - return add_ptr<multi_fragment_t>(this, fragment_offset(which)); + return add_ptr<multi_fragment_t>(this, this->fragment_offset(which)); } /// Support iterations: Jump to next MEP inline const mep_header_t* mep_header_t::next() const { - return add_ptr<mep_header_t>(this, size*sizeof(uint32_t)); + return add_ptr<mep_header_t>(this, this->size*sizeof(uint32_t)); } /// Bank iteration: start of regular banks @@ -576,17 +590,17 @@ namespace Online { /// Bank iteration: start of special banks inline const bank_t* bank_collection_t::special_begin() const { - return add_ptr<bank_t>(this->banks,sizeof(bank_t) * (capacity-specials)); + return add_ptr<bank_t>(this->banks,sizeof(bank_t) * (this->capacity - this->specials)); } /// Bank iteration: end marker of special banks inline const bank_t* bank_collection_t::special_end() const { - return add_ptr<bank_t>(this->banks,sizeof(bank_t) * capacity); + return add_ptr<bank_t>(this->banks,sizeof(bank_t) * this->capacity); } /// Bank iteration: end marker of regular banks inline const bank_t* bank_collection_t::end() const { - return add_ptr<bank_t>(this->banks,sizeof(bank_t) * length); + return add_ptr<bank_t>(this->banks,sizeof(bank_t) * this->length); } /// Bank iteration: access next element of the iteration @@ -616,7 +630,7 @@ namespace Online { /// Copy data to target buffer inline void* bank_collection_t::copy_data(void* ptr) const { - unsigned char* p = (unsigned char*)ptr; + uint8_t* p = (uint8_t*)ptr; std::size_t len = bank_t::hdrSize(); for( const auto* b=this->begin(); b != this->end(); b=this->next(b) ) { ::memcpy(p, b, len); @@ -648,7 +662,7 @@ namespace Online { } /// Access collection Offset according to source ID - inline std::size_t event_t::collection_offset_source_id(unsigned short src_id) { + inline std::size_t event_t::collection_offset_source_id(uint16_t src_id) { switch(src_id) { case params::sourceid_top5_ODIN: return params::collectionOffsetODIN; case params::sourceid_top5_VP: return params::collectionOffsetVP; @@ -663,7 +677,7 @@ namespace Online { } /// Access collection Offset according to source ID and bank type - inline std::pair<bool,std::size_t> event_t::collection_offset(unsigned short src_id, unsigned char type) { + inline std::pair<bool,std::size_t> event_t::collection_offset(uint16_t src_id, uint8_t type) { std::size_t offset = event_t::collection_offset_source_id(src_id¶ms::sourceid_TOP5); switch ( type ) { case bank_t::ODIN: @@ -698,9 +712,9 @@ namespace Online { } /// Get bank data of a given source and type - inline std::pair<std::size_t, const bank_t*> event_t::get(unsigned short src_id, unsigned char type) const { + inline std::pair<std::size_t, const bank_t*> event_t::get(uint16_t src_id, uint8_t type) const { auto ret = event_t::collection_offset(src_id, type); - const auto* c = add_ptr<bank_collection_t>(banks,ret.second); + const auto* c = add_ptr<bank_collection_t>(this->banks,ret.second); if ( ret.first ) { return std::make_pair(c->length,c->banks); } @@ -734,12 +748,12 @@ namespace Online { /// Event iteration: iteration start inline const event_t* event_collection_t::begin() const { - return events; + return this->events; } /// Event iteration: end marker inline const event_t* event_collection_t::end() const { - return add_ptr<event_t>(events,params::eventRecordLength*length); + return add_ptr<event_t>(this->events,params::eventRecordLength*this->length); } /// Event iteration: access the next event @@ -749,12 +763,12 @@ namespace Online { /// Direct access to an event by index inline const event_t* event_collection_t::operator[](std::size_t i) const { - return add_ptr<event_t>(events,params::eventRecordLength*i); + return add_ptr<event_t>(this->events,params::eventRecordLength*i); } /// Direct access to an event by index inline const event_t* event_collection_t::at(std::size_t i) const { - return add_ptr<event_t>(events,params::eventRecordLength*i); + return add_ptr<event_t>(this->events,params::eventRecordLength*i); } /// Total memory size of the event block in bytes diff --git a/Online/PCIE40Data/PCIE40Data/sodin.h b/Online/PCIE40Data/PCIE40Data/sodin.h index a6bdee4e6e845721c1284b13898de64c6d08cedb..a5f51d18202887667763abaeb99b731ad72b2a80 100644 --- a/Online/PCIE40Data/PCIE40Data/sodin.h +++ b/Online/PCIE40Data/PCIE40Data/sodin.h @@ -13,6 +13,7 @@ // C/C++ include files #include <ctime> +#include <cstdint> // Framework include files. Note: pack.h must come last! #include "PCIE40Data/Pack.h" diff --git a/Online/PCIE40Data/main/pcie40_decode_file.cpp b/Online/PCIE40Data/main/pcie40_decode_file.cpp index 9ef4010d8d0957babc470526513f53469d66c972..e2c7874a3641fe3d82cb47878a279f5443e84724 100644 --- a/Online/PCIE40Data/main/pcie40_decode_file.cpp +++ b/Online/PCIE40Data/main/pcie40_decode_file.cpp @@ -11,6 +11,7 @@ // Created on: Apr 8, 2019 //========================================================================== #include <PCIE40Data/pcie40decoder.h> +#include <system_error> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> @@ -51,7 +52,8 @@ int main(int argc, char *argv[]) { ::close(fd); if ( mep_start == (pcie40::mep_header_t*)MAP_FAILED ) { - ::printf("+++ FAILED mapping mep file %s [%s]\n", argv[1], ::strerror(errno)); + std::string err = std::make_error_code(std::errc(errno)).message(); + ::printf("+++ FAILED mapping mep file %s [%s]\n", argv[1], err.c_str()); ::exit(errno); } diff --git a/Online/PyDIM/src/dimcppmodule.cpp b/Online/PyDIM/src/dimcppmodule.cpp index fe1748ef522ddafcb2d2bc3b399b1708aae24825..f2b016e9d5912ddcb35fa47130247f1062dc96f8 100755 --- a/Online/PyDIM/src/dimcppmodule.cpp +++ b/Online/PyDIM/src/dimcppmodule.cpp @@ -18,16 +18,17 @@ * *************************************************************************/ #define DIMCPP_MODULE -extern "C" { -#include "Python.h" -#include "structmember.h" -} #include <dim/dis.hxx> #include <dim/dic.hxx> #include <cctype> #include <cstdlib> #include <cstdio> +#define PY_SSIZE_T_CLEAN +extern "C" { +#include "Python.h" +#include "structmember.h" +} #include "pydim_utils.cpp" diff --git a/Online/PyDIM/src/dimmodule.cpp b/Online/PyDIM/src/dimmodule.cpp index 380dc60baa1663742e4f079c9ac61b89e6952a49..9788d7ecf8da6f0a74ae63755704f6f97bdd01ef 100755 --- a/Online/PyDIM/src/dimmodule.cpp +++ b/Online/PyDIM/src/dimmodule.cpp @@ -33,6 +33,8 @@ #ifdef _XOPEN_SOURCE #undef _XOPEN_SOURCE #endif + +#define PY_SSIZE_T_CLEAN extern "C" { #include <Python.h> } @@ -124,12 +126,12 @@ dim_dis_start_serving (PyObject* /* self */, PyObject *args) { * @param server_name The name under which the server is going to be * registered in the DIM DNS. If not specified the hostname is used. */ - char *name = NULL; + char *name = nullptr; int ret; if (!PyArg_ParseTuple(args, "|s", &name)) { PyErr_SetString(PyExc_RuntimeError, "Invalid server name."); - return NULL; + return nullptr; } if (name) { ::strncpy(server_name, name, HOST_NAME_MAX); @@ -165,12 +167,12 @@ dim_dis_set_dns_node(PyObject* /* self */, PyObject* args) { * @param dns_node_name The name of the DNS server * @return DIM return code (1 for success) */ - char* name = NULL; + char* name = nullptr; int ret; if ( !PyArg_ParseTuple(args, "s", &name) ) { PyErr_SetString(PyExc_RuntimeError, "Invalid DNS name"); - return NULL; + return nullptr; } ret = dis_set_dns_node(name); @@ -186,7 +188,7 @@ dim_dis_get_dns_node(PyObject* /* self */, PyObject* /* args */) { char names[256]; if ( !dis_get_dns_node(names) ) { PyErr_SetString(PyExc_RuntimeError, "Failed to get DNS node name"); - return NULL; + return nullptr; } return Py_BuildValue("s", names); } @@ -206,7 +208,7 @@ dim_dis_set_dns_port(PyObject* /* self */, PyObject* args) { if (!PyArg_ParseTuple(args, "I", &port)) { PyErr_SetString(PyExc_TypeError, "Argument 'port' must be a pozitive integer"); - return NULL; + return nullptr; } ret = dis_set_dns_port(port); @@ -312,12 +314,10 @@ dim_dis_add_exit_handler(PyObject* self, PyObject* args) { */ PyObject *temp; - if (!PyArg_ParseTuple(args, "O:set_callback", &temp) || - !PyCallable_Check(temp)) - { - PyErr_SetString(PyExc_TypeError, "Expected a callable Python object"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O:set_callback", &temp) || !PyCallable_Check(temp)) { + PyErr_SetString(PyExc_TypeError, "Expected a callable Python object"); + return nullptr; + } Py_XINCREF(temp); Py_XINCREF(self); @@ -340,12 +340,10 @@ dim_dis_add_error_handler(PyObject* self, PyObject* args) { */ PyObject *temp; - if (!PyArg_ParseTuple(args, "O:set_callback", &temp) || - !PyCallable_Check(temp)) - { - PyErr_SetString(PyExc_TypeError, "Expected a callable Python object"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O:set_callback", &temp) || !PyCallable_Check(temp)) { + PyErr_SetString(PyExc_TypeError, "Expected a callable Python object"); + return nullptr; + } /* Add a reference to new callback */ Py_XINCREF(temp); Py_XINCREF(self); @@ -366,12 +364,9 @@ dim_dis_add_client_exit_handler(PyObject* self, PyObject* args) { * @param callback A callable Python object. */ PyObject *temp; - - if (!PyArg_ParseTuple(args, "O:set_callback", &temp) || - !PyCallable_Check(temp)) - { + if (!PyArg_ParseTuple(args, "O:set_callback", &temp) || !PyCallable_Check(temp)) { PyErr_SetString(PyExc_TypeError, "Expected a callable Python object"); - return NULL; + return nullptr; } /* Add a reference to new callback */ Py_XINCREF(temp); @@ -392,20 +387,20 @@ dim_dis_selective_update_service(PyObject* /* self */, PyObject* args) { /** * Calls int dis_selective_update_service (int service_id, int** client_ids) */ - int* client_ids=NULL, res; + int* client_ids=nullptr, res; PyObject* listOrTuple; int service_id; if (!PyArg_ParseTuple(args, "iO;list or tuple", &service_id, &listOrTuple)) { PyErr_SetString(PyExc_TypeError, "Invalid arguments: expected and integer and a list/tuple of integers"); - return NULL; + return nullptr; } if (!listOrTuple2Int(listOrTuple, &client_ids)) { PyErr_SetString(PyExc_TypeError, "Second argument must a list/tuple of integers" ); - return NULL; + return nullptr; } res = dis_selective_update_service(service_id, client_ids); @@ -422,20 +417,17 @@ dim_dis_set_quality(PyObject* /* self */, PyObject* args) { */ unsigned int service_id; int quality; - if (!PyArg_ParseTuple(args, "Ii", &service_id, &quality)) { PyErr_SetString(PyExc_TypeError, "Invalid arguments: expected an unsigned integer and an integer"); - return NULL; + return nullptr; } dis_set_quality(service_id, quality); Py_RETURN_NONE; } - -static PyObject* -dim_dis_set_timestamp(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_set_timestamp(PyObject* /* self */, PyObject* args) { /** * Calls void dis_set_timestamp(unsigned int service_id, * int secs, @@ -450,16 +442,14 @@ dim_dis_set_timestamp(PyObject* /* self */, PyObject* args) { if (!PyArg_ParseTuple(args, "Iii", &service_id, &secs, &milisecs)) { PyErr_SetString(PyExc_TypeError, "Invalid arguments: expected an unsigned integer and two integers"); - return NULL; + return nullptr; } dis_set_timestamp(service_id, secs, milisecs); Py_RETURN_NONE; } - -static PyObject* -dim_dis_remove_service(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_remove_service(PyObject* /* self */, PyObject* args) { /** * Call int dis_remove_service (unsigned int service_id) * @param service_id @@ -468,7 +458,7 @@ dim_dis_remove_service(PyObject* /* self */, PyObject* args) { if ( !PyArg_ParseTuple(args, "I", &service_id) ) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected an unsigned integer"); - return NULL; + return nullptr; } ServiceIDMap::iterator it = serviceID2Callback.find(service_id); if ( it != serviceID2Callback.end() ) { @@ -485,8 +475,7 @@ dim_dis_remove_service(PyObject* /* self */, PyObject* args) { } -static PyObject* -dim_dis_get_next_cmnd(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_get_next_cmnd(PyObject* /* self */, PyObject* args) { /** * Calls int dis_get_next_cmnd (long* tag, int* buffer, int* size) * @@ -499,54 +488,48 @@ dim_dis_get_next_cmnd(PyObject* /* self */, PyObject* args) { * * @param size The maximum size of the data received by the command */ - int res=0, *buffer, size; - long tag=0; - PyObject* tmp; + int res = 0, *buffer, dim_size = 0; + Py_ssize_t size; + long tag = 0; + PyObject* tmp; if ( !PyArg_ParseTuple(args, "I", &size) ) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected an unsigned integer"); - return NULL; + return nullptr; } buffer = (int*)malloc(size*sizeof(int)); - res = dis_get_next_cmnd(&tag, buffer, &size); + res = ::dis_get_next_cmnd(&tag, buffer, &dim_size); + size = dim_size; tmp = Py_BuildValue("(iis#)", res, tag, buffer, size); free(buffer); return tmp; } - -static PyObject* -dim_dis_get_client(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_get_client(PyObject* /* self */, PyObject* args) { /** * Calls: int dis_get_client (char* name) */ char* name; int res; - if ( !PyArg_ParseTuple(args, "s", &name) ) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected an string"); - return NULL; + return nullptr; } - res = dis_get_client(name); + res = ::dis_get_client(name); return Py_BuildValue("i", res); } - -static PyObject* -dim_dis_get_conn_id(PyObject* /* self */, PyObject* /* args */) { +static PyObject* dim_dis_get_conn_id(PyObject* /* self */, PyObject* /* args */) { /** * Calls: int dis_get_conn_id() */ - int res; - res = dis_get_conn_id(); + int res = dis_get_conn_id(); return Py_BuildValue("i", res); } - -static PyObject* -dim_dis_get_timeout(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_get_timeout(PyObject* /* self */, PyObject* args) { /** * Calls: int dis_get_timeout (unsigned int service_id, int client_id) * @param service_id The service_id returned by dis_add_service or by @@ -560,64 +543,50 @@ dim_dis_get_timeout(PyObject* /* self */, PyObject* args) { if ( !PyArg_ParseTuple(args, "Ii", &service_id, &client_id) ) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected an unsigned int and an int"); - return NULL; + return nullptr; } - res = dis_get_timeout(service_id, client_id); + res = ::dis_get_timeout(service_id, client_id); return Py_BuildValue("i", res); } - -static PyObject* -dim_dis_get_client_services(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_get_client_services(PyObject* /* self */, PyObject* args) { /** * Calls: char* dis_get_client_services (int conn_id) * * @param conn_id The connection ID to a client. */ - char* res=NULL; int conn_id; - if ( !PyArg_ParseTuple(args, "i", &conn_id) ) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected an int"); - return NULL; + return nullptr; } - res = dis_get_client_services(conn_id); - + char* res = ::dis_get_client_services(conn_id); return Py_BuildValue("s", res); } - -static PyObject* -dim_dis_set_client_exit_handler(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_set_client_exit_handler(PyObject* /* self */, PyObject* args) { /** * Calls: void dis_set_client_exit_handler (int conn_id, int tag) */ int conn_id, tag; - if ( !PyArg_ParseTuple(args, "ii", &conn_id, &tag) ) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected two ints"); - return NULL; + return nullptr; } - dis_set_client_exit_handler(conn_id, tag); - + ::dis_set_client_exit_handler(conn_id, tag); Py_RETURN_NONE; } - -static PyObject* -dim_dis_get_error_services(PyObject* /* self */, PyObject* /* args */) { +static PyObject* dim_dis_get_error_services(PyObject* /* self */, PyObject* /* args */) { /** * Calls: char* dis_get_error_services (int conn_id) */ - char* res=NULL; - res = dis_get_error_services(); + char* res = dis_get_error_services(); return Py_BuildValue("s", res); } - -static PyObject* -dim_dis_add_cmnd(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dis_add_cmnd(PyObject* /* self */, PyObject* args) { /* @param name * @param description * @param py_function @@ -639,22 +608,21 @@ dim_dis_add_cmnd(PyObject* /* self */, PyObject* args) { * for the callback. The address will become a string long * tag - will be passed back to the Python callback */ - unsigned int res=0; - char *name = NULL, *format = NULL; - PyObject *tag = NULL; - int sizeFormat, sizeName; - PyObject *pyFunc; + unsigned int res=0; + char *name = nullptr, *format = nullptr; + PyObject *tag = nullptr; + PyObject *pyFunc; + Py_ssize_t sizeFormat, sizeName; CmndCallback *callback, *oldCallback; string s; - if (!PyArg_ParseTuple(args, "s#s#O|O", - &name, &sizeName, &format, &sizeFormat, &pyFunc, &tag) + if (!PyArg_ParseTuple(args, "s#s#O|O", &name, &sizeName, &format, &sizeFormat, &pyFunc, &tag) || !PyCallable_Check(pyFunc) ) { PyErr_SetString(PyExc_TypeError, "Invalid arguments: expected two strings, " "a callable object and an integer"); - return NULL; + return nullptr; } Py_INCREF(pyFunc); debug("Adding command name %s, format %s function %p and tag %p", name, format, (void*)pyFunc, (void*)tag); @@ -737,7 +705,7 @@ serviceProxy(void *tagp, void **buf, int *size, int * /*first_time*/) { svc->bufferSize = 0; if (svc->buffer) { free(svc->buffer); - svc->buffer = NULL; + svc->buffer = nullptr; } } else if (svc->isUpdated && svc->buffer) { /* nothing much to do there, we have everything already */ @@ -768,42 +736,42 @@ dim_dis_add_service(PyObject* /* self */, PyObject* args) { * @param tag */ - int name_size, format_size, service_id=0; + Py_ssize_t name_size, format_size; + unsigned int service_id=0; char *name, *format; long pyTag; PyObject *pyFunc; ServiceCallback *svc; - if (!PyArg_ParseTuple(args, "s#s#Ol", &name, - &name_size, - &format, - &format_size, + if (!PyArg_ParseTuple(args, "s#s#Ol", + &name, &name_size, + &format, &format_size, &pyFunc, &pyTag) || !PyCallable_Check(pyFunc)) { PyErr_SetString(PyExc_TypeError, "Invalid arguments: expected two strings, a callable object and a long."); - return NULL; + return nullptr; } Py_INCREF(pyFunc); - svc = (ServiceCallback*)malloc(sizeof(ServiceCallback)); - svc->name = (char*)malloc(sizeof(char)*(name_size+1)); + svc = (ServiceCallback*)malloc(sizeof(ServiceCallback)); + svc->name = (char*)malloc(sizeof(char)*(name_size+1)); svc->format = (char*)malloc(sizeof(char)*(format_size+1)); if (!svc || !svc->name || !svc->format) goto noMem; - strncpy(svc->name, name, sizeof(char)*(name_size)); + ::strncpy(svc->name, name, sizeof(char)*name_size); svc->name[sizeof(char)*(name_size)] = 0; - strncpy(svc->format, format, sizeof(char)*(format_size)); - svc->format[sizeof(char)*(format_size)] = 0; + ::strncpy(svc->format, format, sizeof(char)*format_size); + svc->format[sizeof(char)*format_size] = 0; svc->pyTag = pyTag; svc->pyFunc = pyFunc; - svc->buffer = NULL; + svc->buffer = nullptr; svc->bufferSize = 0; service_id = dis_add_service(name, format, - NULL, + nullptr, 0, serviceProxy, (long)svc); @@ -813,7 +781,7 @@ dim_dis_add_service(PyObject* /* self */, PyObject* args) { ::free(svc->format); ::free(svc); PyErr_SetString(PyExc_RuntimeError, "Could not create DIM service"); - return NULL; + return nullptr; } serviceID2Callback[service_id] = svc; debug("Service %s added successfully with pointer %ld", svc->name, (long)svc); @@ -821,7 +789,7 @@ dim_dis_add_service(PyObject* /* self */, PyObject* args) { noMem: PyErr_SetString(PyExc_MemoryError, "Could not allocate memory"); - return NULL; + return nullptr; } @@ -831,27 +799,27 @@ dim_dis_update_service(PyObject* /* self */, PyObject* args) { * Calls: int dis_update_service (int service_id) */ int service_id, res; - PyObject *svc_args=NULL, *arg; + PyObject *svc_args=nullptr, *arg; PyGILState_STATE gstate; if ( !PyArg_ParseTuple(args, "i|O", &service_id, &svc_args) ){ //if ( !PyArg_ParseTuple(args, "i", &service_id) ){ PyErr_SetString(PyExc_TypeError, "Argument error: incorect service ID"); - return NULL; + return nullptr; } ServiceCallbackPtr svc = serviceID2Callback[service_id]; if (!svc){ // Service was not found, already deleted? PyErr_SetString(PyExc_RuntimeError, "Service ID doesn't match any service"); - return NULL; + return nullptr; } if (!svc_args) { if (!svc->pyFunc) { PyErr_SetString(PyExc_TypeError, "No arguments and no callback function was given"); - return NULL; + return nullptr; } gstate = PyGILState_Ensure(); arg = Py_BuildValue("(i)", svc->pyTag); @@ -862,12 +830,12 @@ dim_dis_update_service(PyObject* /* self */, PyObject* args) { PyGILState_Release(gstate); if (!svc_args) { /* there was an exception raised when calling the python function - * returning NULL implies the exception will be propageted + * returning nullptr implies the exception will be propageted * back to the interpretor */ print("Error in calling python function %p", (void*)svc->pyFunc); PyErr_Print(); - return NULL; + return nullptr; } } /* NOTE: it might not be optimal to allocate a buffer each time */ @@ -880,7 +848,7 @@ dim_dis_update_service(PyObject* /* self */, PyObject* args) { { PyErr_SetString(PyExc_TypeError, "Arguments do not match initial service format"); - return NULL; + return nullptr; } Py_DECREF(svc_args); svc->isUpdated = 1; @@ -942,12 +910,12 @@ dim_dic_set_dns_node(PyObject* /* self */, PyObject* args) { * @param dns_name The name of the new DNS. * @return ret_code The DIM return code (1 for success). */ - char* name = NULL; + char* name = nullptr; int i; if ( !PyArg_ParseTuple(args, "s", &name) ) { PyErr_SetString(PyExc_TypeError, "Invalid DIM DNS name"); - return NULL; + return nullptr; } i = dic_set_dns_node(name); @@ -965,7 +933,7 @@ dim_dic_get_dns_node(PyObject* /* self */, PyObject* /* args */) { if ( !dic_get_dns_node(names) ) { PyErr_SetString(PyExc_TypeError, "Could not get DIM DNS node name."); - return NULL; + return nullptr; } return Py_BuildValue("s", names); @@ -986,7 +954,7 @@ dim_dic_set_dns_port(PyObject* /* self */, PyObject* args) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected a pozitive integer" ); - return NULL; + return nullptr; } i = dic_set_dns_port(port); @@ -1049,7 +1017,7 @@ dim_dic_get_quality(PyObject* /* self */, PyObject* args) { if (!PyArg_ParseTuple(args, "I", &service_id) ) { PyErr_SetString(PyExc_TypeError, "Invalid argument: expected an unsigned integer"); - return NULL; + return nullptr; } res = dic_get_quality(service_id); @@ -1070,9 +1038,8 @@ dim_dic_get_timestamp(PyObject* /* self */, PyObject* args) { int secs, milisecs=0; if (!PyArg_ParseTuple(args, "Iii", &service_id)) { - PyErr_SetString(PyExc_TypeError, - "service id should be an unsigned integer"); - return NULL; + PyErr_SetString(PyExc_TypeError, "service id should be an unsigned integer"); + return nullptr; } dic_get_timestamp(service_id, &secs, &milisecs); @@ -1088,12 +1055,11 @@ dim_dic_get_format(PyObject* /* self */, PyObject* args) { * @return format A string containing the format description. */ unsigned int service_id; - char* format=NULL; + char* format=nullptr; if (! PyArg_ParseTuple(args, "I", &service_id) ) { - PyErr_SetString(PyExc_TypeError, - "Service id should be an unsigned integer"); - return NULL; + PyErr_SetString(PyExc_TypeError, "Service id should be an unsigned integer"); + return nullptr; } format = dic_get_format(service_id); @@ -1111,9 +1077,8 @@ dim_dic_release_service(PyObject* /* self */, PyObject* args) { if (!PyArg_ParseTuple(args, "I", &service_id)) { debug("Invalid service id specified"); - PyErr_SetString(PyExc_TypeError, - "Service id should be an unsigned integer"); - return NULL; + PyErr_SetString(PyExc_TypeError, "Service id should be an unsigned integer"); + return nullptr; } /* ::printf("PyDIM: Releasing service: %d\n",service_id); */ InfoSvcMap::iterator it=_dic_info_service_id2Callback.find(service_id); @@ -1162,14 +1127,14 @@ dim_dic_info_service(PyObject* /* self */, PyObject* args) { int service_type=MONITORED; int timeout=0; int tag=0; - int format_size; - int name_size; + Py_ssize_t format_size; + Py_ssize_t name_size; unsigned int service_id; - PyObject* pyFunc=NULL, *default_value=NULL ; + PyObject* pyFunc=nullptr, *default_value=nullptr ; _dic_info_service_callback *svc; if (!PyArg_ParseTuple(args, "s#s#O|iiiO", - &name, &name_size, + &name, &name_size, &format, &format_size, &pyFunc, &service_type, @@ -1231,13 +1196,13 @@ dim_dic_info_service(PyObject* /* self */, PyObject* args) { " int tag ,"\ " PyObject* default_value" ); - return NULL; + return nullptr; /* memory problems */ no_memory: PyErr_SetString(PyExc_MemoryError, "Could not allocate memory"); Py_DECREF(pyFunc); - return NULL; + return nullptr; /* invalid service registration */ dealocate: @@ -1264,9 +1229,7 @@ dim_dic_info_service_stamped(PyObject* self, PyObject* args){ return dim_dic_info_service(self, args); } - -static PyObject* -dim_dic_get_server(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dic_get_server(PyObject* /* self */, PyObject* args) { /** * Proxy function for: * dic_get_server(char* name) @@ -1279,16 +1242,14 @@ dim_dic_get_server(PyObject* /* self */, PyObject* args) { if ( !PyArg_ParseTuple(args, "s", &srv_name) ) { PyErr_SetString(PyExc_TypeError, "Invalid parameters. Expected argument:string service_name"); - return NULL; + return nullptr; } service_id = dic_get_server(srv_name); return Py_BuildValue("i", service_id); } - -static PyObject* -dim_dic_get_conn_id(PyObject* /* self */, PyObject* /* args */) { +static PyObject* dim_dic_get_conn_id(PyObject* /* self */, PyObject* /* args */) { /** * Proxy function for: * dic_get_conn_id(char* name) @@ -1300,9 +1261,7 @@ dim_dic_get_conn_id(PyObject* /* self */, PyObject* /* args */) { return Py_BuildValue("i", service_id); } - -static PyObject* -dim_dic_get_server_services(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dic_get_server_services(PyObject* /* self */, PyObject* args) { /** * Proxy function for: * dic_get_server_services(int conn_id) @@ -1310,13 +1269,13 @@ dim_dic_get_server_services(PyObject* /* self */, PyObject* args) { * @return services_list A Python list of services. */ int conn_id; - char* srv_names=NULL; + char* srv_names=nullptr; PyObject* ret; if (!PyArg_ParseTuple(args, "i", &conn_id)) { PyErr_SetString(PyExc_TypeError, "Invalid parameters. Expected argument:int conn_id"); - return NULL; + return nullptr; } srv_names = dic_get_server_services(conn_id); ret = stringList_to_tuple(srv_names); @@ -1324,9 +1283,7 @@ dim_dic_get_server_services(PyObject* /* self */, PyObject* args) { return ret; } - -static PyObject* -dim_dic_get_error_services(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dic_get_error_services(PyObject* /* self */, PyObject* args) { /** It is meant to be called inside the error handler to determine * what service originated the error. * @@ -1335,15 +1292,13 @@ dim_dic_get_error_services(PyObject* /* self */, PyObject* args) { * * @return service_list a python list of services in error. */ - char* srv_names=NULL; + char* srv_names=nullptr; srv_names = dic_get_error_services(); stringList_to_tuple(srv_names); return args; } - -static PyObject* -dim_dic_add_error_handler(PyObject* self, PyObject* args) { +static PyObject* dim_dic_add_error_handler(PyObject* self, PyObject* args) { /** * @param python callback (callable object) * It is a stub function for calling: @@ -1357,7 +1312,7 @@ dim_dic_add_error_handler(PyObject* self, PyObject* args) { { PyErr_SetString(PyExc_TypeError, "Invalid parameters. Expected argument: callable object "); - return NULL; + return nullptr; } Py_XINCREF(pyFunc); Py_XINCREF(self); @@ -1372,8 +1327,7 @@ dim_dic_add_error_handler(PyObject* self, PyObject* args) { Py_RETURN_NONE; } -static PyObject* -dim_dic_cmnd_service(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dic_cmnd_service(PyObject* /* self */, PyObject* args) { /** * @param service_name (string), * @param command_data (tuple or list), @@ -1405,7 +1359,7 @@ dim_dic_cmnd_service(PyObject* /* self */, PyObject* args) { PyErr_SetString(PyExc_TypeError, "Invalid parameters. Expected: string service_name (string), "\ "update_data (tuple or list), format (DIM format string)"); - return NULL; + return nullptr; error: PyErr_SetString(PyExc_RuntimeError, @@ -1413,13 +1367,12 @@ dim_dic_cmnd_service(PyObject* /* self */, PyObject* args) { "Please check that the order/number "\ "of the argument maches the provided command format."); free(buffer); - return NULL; + return nullptr; } -static PyObject* -dim_dic_cmnd_callback(PyObject* /* self */, PyObject* args) { +static PyObject* dim_dic_cmnd_callback(PyObject* /* self */, PyObject* args) { /** * @param service_name (string), * @param command_data (tuple or list), @@ -1482,18 +1435,18 @@ dim_dic_cmnd_callback(PyObject* /* self */, PyObject* args) { " function_callback (a Python callable object) \n"\ " int tag" ); - return NULL; + return nullptr; error: PyErr_SetString(PyExc_RuntimeError, "Could not serialise provided arguments to a DIM buffer.\n"\ "Please check that the order/number "\ "of the argument maches the provided command format."); - return NULL; + return nullptr; memory_error: PyErr_SetString(PyExc_MemoryError, "Could not allocate memory"); - return NULL; + return nullptr; } @@ -1572,8 +1525,8 @@ void _dic_info_service_dummy (void* tag, void* buffer, int* size) { * that dim_buf_to_tuple creates Python object so the lock must be held. */ - PyObject* funargs = NULL, *res; - PyObject* args = NULL; + PyObject* funargs = nullptr, *res; + PyObject* args = nullptr; _dic_info_service_callback* svc; PyGILState_STATE gstate; @@ -1615,7 +1568,7 @@ void _dic_info_service_dummy (void* tag, void* buffer, int* size) { if (funargs) { res = PyObject_CallObject(svc->pyFunc, funargs); if (!res){ - if (PyErr_Occurred() != NULL) { + if (PyErr_Occurred() != nullptr) { print("Error when calling object %s", svc->name); PyErr_Print(); } else { @@ -1857,7 +1810,7 @@ static PyMethodDef DimMethods[] = { METH_VARARGS , "Adds an error handler to this client." }, - {NULL, NULL, 0, NULL} /* Sentinel */ + {nullptr, nullptr, 0, nullptr} /* Sentinel */ }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef dim_module = { diff --git a/Online/PyDIM/src/pydim_utils.cpp b/Online/PyDIM/src/pydim_utils.cpp index 81abc3a2c4e1927d8cfacce5c8672ff88d8a1d6d..6663194f2d77e3161d92f8fb39ed28d76ddce9fe 100755 --- a/Online/PyDIM/src/pydim_utils.cpp +++ b/Online/PyDIM/src/pydim_utils.cpp @@ -272,7 +272,7 @@ static int verify_dim_format(const char *format) #endif - static int +static int next_element(const char *schema, unsigned int *p, int *type, int *mult) { /** \brief Incrementally parses a DIM format and returns the next element diff --git a/Online/ROLogger/kafka/KafkaProducer.cpp b/Online/ROLogger/kafka/KafkaProducer.cpp index e352dd1d20faa7c307bbd53968fedb8e40efe939..376adcbf5b3a20d740ef4479c78837dd2789e48a 100644 --- a/Online/ROLogger/kafka/KafkaProducer.cpp +++ b/Online/ROLogger/kafka/KafkaProducer.cpp @@ -405,10 +405,11 @@ void KafkaProducer::handle_payload(const char* /* topic */, ::lib_rtl_output(LIB_RTL_ERROR,"+++ Kafka producer error: No such partition: %6d", partition); } else if ( err == RD_KAFKA_RESP_ERR__QUEUE_FULL ) { - ::lib_rtl_output(LIB_RTL_ERROR,"+++ Kafka producer error: %s (backpressure)", rd_kafka_err2str(err)); + // + // ::lib_rtl_output(LIB_RTL_ERROR,"+++ Kafka producer error: %s (backpressure)", rd_kafka_err2str(err)); } else { - ::lib_rtl_output(LIB_RTL_ERROR,"+++ Kafka producer error: %s %s", rd_kafka_err2str(err)); + ::lib_rtl_output(LIB_RTL_ERROR,"+++ Kafka producer error: %s", rd_kafka_err2str(err)); } } } diff --git a/Online/RawBankSizes/CMakeLists.txt b/Online/RawBankSizes/CMakeLists.txt index bbf4aacc280b6fbbe1f01b543a0a053985890357..ba2b61373a640d8ed8dd176069cb93ac30f5c3b6 100644 --- a/Online/RawBankSizes/CMakeLists.txt +++ b/Online/RawBankSizes/CMakeLists.txt @@ -13,31 +13,24 @@ gaudi_subdir(RawBankSizes v2r22) gaudi_depends_on_subdirs(GaudiKernel - GaudiAlg - GaudiOnline Event/DAQEvent - Kernel/LHCbKernel Online/Tell1Data + Online/GaudiOnline Online/OnlineHistDB) find_package(AIDA) find_package(Boost) -find_package(GSL) -find_path(CPP_GSL_INCLUDE_DIR NAMES gsl/span) -if(NOT CPP_GSL_INCLUDE_DIR) - message(FATAL "required headers from C++ GSL missing") -endif() - include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) # Only for testing: # gau di_depends_on_subdirs(GaudiSvc Online/OnlineKernel Online/Gaucho Online/GaudiOnline) -gaudi_add_module(RawBankSizes RawBankSizes.cpp Structure.cpp SPDMult.cpp DupEvs.cpp EventSize.cpp RawEventRegister.cpp - INCLUDE_DIRS GaudiOnline ${CPP_GSL_INCLUDE_DIR} - LINK_LIBRARIES GaudiAlgLib DAQEventLib) +gaudi_add_module(RawBankSizes RawBankSizes.cpp Structure.cpp EventSize.cpp RawEventRegister.cpp + INCLUDE_DIRS Boost AIDA GaudiOnline + LINK_LIBRARIES Tell1Data DAQEventLib) gaudi_add_executable(MakePages MakePages.cpp LINK_LIBRARIES OnlineHistDB) +gaudi_add_executable(ParseHistParams ParseHistParams.cpp Structure.cpp LINK_LIBRARIES GaudiKernel) if(GAUDI_USE_EXE_SUFFIX) set(exe_suff .exe) diff --git a/Online/RawBankSizes/RawBankSizes/BankDescr.h b/Online/RawBankSizes/RawBankSizes/BankDescr.h index ae161981fe88571d11bae4e748f6f3653115c525..9b02f36ce64d0bfb2666fb30aae2877c2101fa65 100644 --- a/Online/RawBankSizes/RawBankSizes/BankDescr.h +++ b/Online/RawBankSizes/RawBankSizes/BankDescr.h @@ -1,7 +1,9 @@ #ifdef RAWSIZE_BANKDESCR_H #else #define RAWSIZE_BANKDESCR_H -namespace LHCb + + +namespace Online { #define HISTPERHIST 3 std::string titqual[HISTPERHIST]={" (all Triggers)"," (HLTAccept)"," (noBias)"}; @@ -24,9 +26,9 @@ std::string namqual[HISTPERHIST]={"(all)","(HLTAccept)","(HLT-Pass)"}; double xmin,xmax,binw; int nbin; int nentries; - IHistogram1D *h[HISTPERHIST]; + AIDA::IHistogram1D *h[HISTPERHIST]; std::string h_name[HISTPERHIST]; - IProfile1D *p[HISTPERHIST]; + AIDA::IProfile1D *p[HISTPERHIST]; std::string p_name[HISTPERHIST]; bool noprofile; bool nohist; @@ -37,7 +39,7 @@ std::string namqual[HISTPERHIST]={"(all)","(HLTAccept)","(HLT-Pass)"}; sum=0; isError = false; } - void init(std::string &nam, bool noprof) + void init(const std::string& nam, bool noprof) { int i; name = nam; @@ -54,76 +56,76 @@ std::string namqual[HISTPERHIST]={"(all)","(HLTAccept)","(HLT-Pass)"}; noprofile = noprof; switch (bn) { - case LHCb::RawBank::ITError: + case Tell1Bank::ITError: { isError = true; - rootbankidx=LHCb::RawBank::IT; + rootbankidx=Tell1Bank::IT; break; } - case LHCb::RawBank::TTError: + case Tell1Bank::TTError: { isError = true; - rootbankidx=LHCb::RawBank::TT; + rootbankidx=Tell1Bank::TT; break; } - case LHCb::RawBank::VeloError: + case Tell1Bank::VeloError: { isError = true; - rootbankidx=LHCb::RawBank::Velo; + rootbankidx=Tell1Bank::Velo; break; } - case LHCb::RawBank::OTError: + case Tell1Bank::OTError: { isError = true; - rootbankidx=LHCb::RawBank::OT; + rootbankidx=Tell1Bank::OT; break; } - case LHCb::RawBank::EcalPackedError: + case Tell1Bank::EcalPackedError: { isError = true; - rootbankidx=LHCb::RawBank::EcalPacked; + rootbankidx=Tell1Bank::EcalPacked; break; } - case LHCb::RawBank::HcalPackedError: + case Tell1Bank::HcalPackedError: { isError = true; - rootbankidx=LHCb::RawBank::HcalPacked; + rootbankidx=Tell1Bank::HcalPacked; break; } - case LHCb::RawBank::PrsPackedError: + case Tell1Bank::PrsPackedError: { isError = true; - rootbankidx=LHCb::RawBank::PrsPacked; + rootbankidx=Tell1Bank::PrsPacked; break; } - case LHCb::RawBank::L0CaloError: + case Tell1Bank::L0CaloError: { isError = true; - rootbankidx=LHCb::RawBank::L0Calo; + rootbankidx=Tell1Bank::L0Calo; break; } - case LHCb::RawBank::L0MuonError: + case Tell1Bank::L0MuonError: { isError = true; - rootbankidx=LHCb::RawBank::L0Muon; + rootbankidx=Tell1Bank::L0Muon; break; } - case LHCb::RawBank::MuonError: + case Tell1Bank::MuonError: { isError = true; - rootbankidx=LHCb::RawBank::Muon; + rootbankidx=Tell1Bank::Muon; break; } - case LHCb::RawBank::L0DUError: + case Tell1Bank::L0DUError: { isError = true; - rootbankidx=LHCb::RawBank::L0DU; + rootbankidx=Tell1Bank::L0DU; break; } - case LHCb::RawBank::L0PUError: + case Tell1Bank::L0PUError: { isError = true; - rootbankidx=LHCb::RawBank::L0PU; + rootbankidx=Tell1Bank::L0PU; break; } default: @@ -133,7 +135,7 @@ std::string namqual[HISTPERHIST]={"(all)","(HLTAccept)","(HLT-Pass)"}; break; } } - name=LHCb::RawBank::typeName( (LHCb::RawBank::BankType) bn ); + name = Tell1Printout::bankType( Tell1Bank::BankType(bn) ); int i; for (i=0;i<HISTPERHIST;i++) { diff --git a/Online/RawBankSizes/RawBankSizes/DupEvs.h b/Online/RawBankSizes/RawBankSizes/DupEvs.h deleted file mode 100755 index 84ad3f8f9c8bb901e283a05345f89b53997f8d59..0000000000000000000000000000000000000000 --- a/Online/RawBankSizes/RawBankSizes/DupEvs.h +++ /dev/null @@ -1,40 +0,0 @@ -// $Id: RawBankSizes.h,v 1.7 2010-09-25 21:31:08 frankb Exp $ -#ifndef COMPONENT_DUPEVS_H -#define COMPONENT_DUPEVS_H 1 - -// Include files -// from system -#include "math.h" -#include <map> -#include <set> -// from Gaudi -#include "GaudiAlg/GaudiAlgorithm.h" -// from LHCb -#include "Event/RawEvent.h" -#include "Tell1Data/MEP.h" - -namespace LHCb -{ - - class DupEvs : public GaudiAlgorithm - { - public: - /// Standard constructor - DupEvs( const std::string& name, ISvcLocator* pSvcLocator ); - LHCb::RawEvent* m_rawEvt; - long m_dupEvsOBX; - long m_dupEvsL0ID; - long m_Nev; - std::map<unsigned long long,std::set<long long int>> m_EventIDs; - std::map<unsigned long long,std::vector<Online::RunInfo>> m_OBxDups; - std::set<long long int> m_EventL0ID; - virtual ~DupEvs( ); ///< Destructor - StatusCode initialize() override; ///< Algorithm initialization - StatusCode execute () override; ///< Algorithm execution - StatusCode finalize () override; ///< Algorithm finalization - - protected: - - }; -} -#endif // COMPONENT_DUPEVS_H diff --git a/Online/RawBankSizes/RawBankSizes/MEPSizeMonitor.h b/Online/RawBankSizes/RawBankSizes/MEPSizeMonitor.h deleted file mode 100755 index 55f41ad4b4556caf21dfaabbe4c5923be532ab43..0000000000000000000000000000000000000000 --- a/Online/RawBankSizes/RawBankSizes/MEPSizeMonitor.h +++ /dev/null @@ -1,81 +0,0 @@ -// $Id: MEPSizeMonitor.h,v 1.7 2010-09-25 21:31:08 frankb Exp $ -#ifndef COMPONENT_MEPSizeMonitor_H -#define COMPONENT_MEPSizeMonitor_H 1 - -// Include files -// from system -#include "math.h" -#include <map> -// from Gaudi -#include "Structure.h" -#include "GaudiAlg/GaudiHistoAlg.h" -// from LHCb -#include "AIDA/IHistogram1D.h" -#include "AIDA/IProfile1D.h" -#include "GaudiKernel/IHistogramSvc.h" -#include "Event/RawEvent.h" -#include "BankDescr.h" - -namespace LHCb -{ - typedef std::map<std::string,BankDescr*> detbmap; - typedef detbmap::iterator detbmiter; - typedef std::pair<detbmiter, bool> detbinsrtp; - typedef std::map<std::string,HParam::HistParams*> dethmap; - typedef dethmap::iterator dethmiter; - typedef std::pair<dethmiter, bool> dethinsrtp; -} -namespace LHCb -{ - - class MEPSizeMonitor : public GaudiHistoAlg - { - public: - /// Standard constructor - MEPSizeMonitor( const std::string& name, ISvcLocator* pSvcLocator ); - - virtual ~MEPSizeMonitor( ); ///< Destructor - - StatusCode initialize() override; ///< Algorithm initialization - StatusCode execute () override; ///< Algorithm execution - StatusCode finalize () override; ///< Algorithm finalization - - protected: - - private: - std::vector<std::string> m_DetectorNames; - LHCb::RawEvent* m_rawEvt; - - std::vector<std::string> m_bankNames; - - LHCb::detbmap m_detectors; - LHCb::dethmap m_dethparams; - - std::vector<Tell1Bank::BankType> m_bankTypes; - std::map<std::string,IHistogram1D *> m_dethist; - std::map<int,double > m_detsums; - std::map<std::string,int> m_max; - int m_def; - int m_bin; - bool m_prof; - bool m_firstevent; - LHCb::BankDescr Banks[Tell1Bank::LastType]; - LHCb::BankDescr totsize; - HParam::HistParams m_hparams[Tell1Bank::LastType]; - - HParam::HistParams m_totevpar; - HParam::HistParams m_HLTratiopar; - - dethmap dethparams; - - - IHistogram1D *h_totev[HISTPERHIST]; - IProfile1D *p_banks[HISTPERHIST]; - IHistogram1D *h_HLTratio[HISTPERHIST]; - //IProfile1D *p_HLTratio[HISTPERHIST]; - int n_ev; - bool first_few; - int m_nRMS; - }; -} -#endif // COMPONENT_MEPSizeMonitor_H diff --git a/Online/RawBankSizes/RawBankSizes/RawBankSizes.h b/Online/RawBankSizes/RawBankSizes/RawBankSizes.h index 719389a65c2706a64af2ef45524623910b129a81..c5bb30399b749f7736a0c316af86f15649c48383 100755 --- a/Online/RawBankSizes/RawBankSizes/RawBankSizes.h +++ b/Online/RawBankSizes/RawBankSizes/RawBankSizes.h @@ -1,82 +1,88 @@ -// $Id: RawBankSizes.h,v 1.7 2010-09-25 21:31:08 frankb Exp $ +//========================================================================== +// 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 COMPONENT_RawBankSizes_H #define COMPONENT_RawBankSizes_H 1 -// Include files -// from system -#include "math.h" +// Include files from system +#include <math.h> #include <map> -// from Gaudi + +#include <Tell1Data/Tell1Bank.h> +#include <Tell1Data/Tell1Decoder.h> +#include <AIDA/IProfile1D.h> +#include <AIDA/IHistogram1D.h> #include "Structure.h" -#include "GaudiAlg/GaudiHistoAlg.h" -// from LHCb -#include "AIDA/IHistogram1D.h" -#include "AIDA/IProfile1D.h" -#include "GaudiKernel/IHistogramSvc.h" -#include "Tell1Data/MEP.h" -#include "Event/RawEvent.h" #include "BankDescr.h" -namespace LHCb -{ - typedef std::map<std::string,BankDescr*> detbmap; - typedef detbmap::iterator detbmiter; - typedef std::pair<detbmiter, bool> detbinsrtp; - typedef std::map<std::string,HParam::HistParams*> dethmap; - typedef dethmap::iterator dethmiter; - typedef std::pair<dethmiter, bool> dethinsrtp; -} -namespace LHCb -{ +// from Gaudi +#include <Gaudi/Algorithm.h> +#include <GaudiKernel/IHistogramSvc.h> +#include <GaudiKernel/DataObjectHandle.h> - class RawBankSizes : public GaudiHistoAlg - { +namespace Online { + + class RawBankSizes : public Gaudi::Algorithm { + typedef std::map<std::string,BankDescr*> detbmap; + typedef detbmap::iterator detbmiter; + typedef std::pair<detbmiter, bool> detbinsrtp; + typedef std::map<std::string,HParam::HistParams*> dethmap; + typedef dethmap::iterator dethmiter; + typedef std::pair<dethmiter, bool> dethinsrtp; public: /// Standard constructor - RawBankSizes( const std::string& name, ISvcLocator* pSvcLocator ); + RawBankSizes(const std::string& name, ISvcLocator* pSvcLocator); - virtual ~RawBankSizes( ); ///< Destructor + virtual ~RawBankSizes(); - StatusCode initialize() override; ///< Algorithm initialization - StatusCode execute () override; ///< Algorithm execution - StatusCode finalize () override; ///< Algorithm finalization + /// Algorithm initialization + StatusCode initialize() override; + /// Algorithm execution + StatusCode execute (const EventContext& context) const override final; + /// Algorithm finalization + StatusCode finalize () override; protected: + + typedef Tell1Bank BankHeader; + typedef std::vector<std::pair<const BankHeader*, const void*> > evt_data_t; - private: - std::vector<std::string> m_DetectorNames; - LHCb::RawEvent* m_rawEvt; - - std::vector<std::string> m_bankNames; - - LHCb::detbmap m_detectors; - LHCb::dethmap m_dethparams; - - std::vector<RawBank::BankType> m_bankTypes; - std::map<std::string,IHistogram1D *> m_dethist; - std::map<int,double > m_detsums; - std::map<std::string,int> m_max; - int m_def; - int m_bin; - bool m_prof; - bool m_firstevent; - LHCb::BankDescr Banks[RawBank::LastType]; - LHCb::BankDescr totsize; - HParam::HistParams m_hparams[RawBank::LastType]; + StatusCode fill_histos(const evt_data_t& data, int runno); - HParam::HistParams m_totevpar; - HParam::HistParams m_HLTratiopar; + DataObjectReadHandle<evt_data_t> m_rawData{this,"RawData","Banks/RawData"}; + std::mutex m_mutex; - dethmap dethparams; + std::vector<std::string> m_detectorNames; + std::vector<std::string> m_bankNames; + detbmap m_detectors; + dethmap m_dethparams; + std::vector<Tell1Bank::BankType> m_bankTypes; + std::map<std::string,IHistogram1D*> m_dethist; + std::map<int,double > m_detsums; + std::map<std::string,int> m_max; + int m_def; + int m_bin; + bool m_prof; + bool m_dumpOptions; + BankDescr Banks[Tell1Bank::LastType]; + BankDescr m_totsize; + HParam::HistParams m_hparams[Tell1Bank::LastType]; + HParam::HistParams m_totevpar; + HParam::HistParams m_HLTratiopar; - IHistogram1D *h_totev[HISTPERHIST]; - IProfile1D *p_banks[HISTPERHIST]; - IHistogram1D *h_HLTratio[HISTPERHIST]; - //IProfile1D *p_HLTratio[HISTPERHIST]; - int n_ev; - bool first_few; - int m_nRMS; + IHistogram1D *h_totev[HISTPERHIST]; + IProfile1D *p_banks[HISTPERHIST]; + IHistogram1D *h_HLTratio[HISTPERHIST]; }; } #endif // COMPONENT_RawBankSizes_H diff --git a/Online/RawBankSizes/RawBankSizes/SPDMult.h b/Online/RawBankSizes/RawBankSizes/SPDMult.h deleted file mode 100755 index a854d9917512eea9557eb49c2649c0c40724d995..0000000000000000000000000000000000000000 --- a/Online/RawBankSizes/RawBankSizes/SPDMult.h +++ /dev/null @@ -1,36 +0,0 @@ -// $Id: RawBankSizes.h,v 1.7 2010-09-25 21:31:08 frankb Exp $ -#ifndef COMPONENT_SPDMULT_H -#define COMPONENT_SPDMULT_H 1 - -// Include files -// from system -#include "math.h" -#include <map> -// from Gaudi -#include "GaudiAlg/GaudiHistoAlg.h" -// from LHCb -#include "AIDA/IHistogram1D.h" -#include "AIDA/IProfile1D.h" -#include "GaudiKernel/IHistogramSvc.h" -#include "Event/RawEvent.h" - -namespace LHCb -{ - - class SPDMult : public GaudiHistoAlg - { - public: - /// Standard constructor - SPDMult( const std::string& name, ISvcLocator* pSvcLocator ); - LHCb::RawEvent* m_rawEvt; - - virtual ~SPDMult( ); ///< Destructor - IHistogram1D *m_SPDMultHist; - StatusCode initialize() override; ///< Algorithm initialization - StatusCode execute () override; ///< Algorithm execution - StatusCode finalize () override; ///< Algorithm finalization - protected: - - }; -} -#endif // COMPONENT_SPDMULT_H diff --git a/Online/RawBankSizes/RawBankSizes/Structure.h b/Online/RawBankSizes/RawBankSizes/Structure.h index d16754dea2609b645d57da1c947968a7659e3204..1384fbe65d423e17474db559273794579180c241 100644 --- a/Online/RawBankSizes/RawBankSizes/Structure.h +++ b/Online/RawBankSizes/RawBankSizes/Structure.h @@ -1,4 +1,3 @@ -// $Id: Structure.h,v 1.1 2010-02-15 16:00:32 jost Exp $ #ifndef BEAT_STRUCTURE_H #define BEAT_STRUCTURE_H 1 @@ -6,46 +5,25 @@ #include "GaudiKernel/StatusCode.h" #include <string> -namespace HParam -{ - class HistParams - { - public: - int n_bin; - float xmin; - float xmax; - int s_min; - int s_max; - std::string det; - - HistParams() - { - n_bin = -2; - xmin = 0.0; - xmax = 0.0; - s_min = 0; - s_max = -2; - det = "Unknown"; - }; - }; +namespace HParam { + class HistParams { + public: + int n_bin {-2}; + float xmin {0e0}; + float xmax {0e0}; + int s_min {0}; + int s_max {-2}; + std::string det {"Unknown"}; + HistParams() = default; + }; } // ============================================================================ -namespace Gaudi -{ - namespace Utils - { - std::ostream& toStream - ( const HParam::HistParams& , std::ostream& ) ; +namespace Gaudi { + namespace Utils { + std::ostream& toStream (const HParam::HistParams& o, std::ostream& os); } -} - -// ============================================================================ -namespace Gaudi -{ - namespace Parsers - { - StatusCode parse ( HParam::HistParams& o , - const std::string& input ) ; + namespace Parsers { + StatusCode parse(HParam::HistParams& o, const std::string& input); } } // ============================================================================ diff --git a/Online/RawBankSizes/options/RawSizeMon.py b/Online/RawBankSizes/options/RawSizeMon.py new file mode 100644 index 0000000000000000000000000000000000000000..23ef3555df63b701ed34e6085eb5ec7d34bbb3ec --- /dev/null +++ b/Online/RawBankSizes/options/RawSizeMon.py @@ -0,0 +1,190 @@ +""" + Online Raw bank size monitoring application configuration + + @author M.Frank +""" +__version__ = "1.0" +__author__ = "Markus Frank <Markus.Frank@cern.ch>" + +import os +import sys +import Configurables +import Gaudi.Configuration as Gaudi +import OnlineEnvBase as OnlineEnv + +import GaudiOnline +from Configurables import Online__FlowManager as FlowManager + + +class RawSizeMon(GaudiOnline.Application): + def __init__(self, outputLevel, partitionName, partitionID, classType): + GaudiOnline.Application.__init__(self, + outputLevel=outputLevel, + partitionName=partitionName, + partitionID=partitionID, + classType=classType) + + def setup_algorithms(self): + import Gaudi.Configuration as Gaudi + import Configurables + input = self.setup_event_input() + self.input = input + self.config.debug = False + self.config.dump_options = False + monitor = Configurables.Online__RawBankSizes('RawBankSizes') + monitor.RawData = '/Event/Banks/RawData' + monitor.Bins = 100 + monitor.DumpOptions = False + monitor.D_L0 = (100,0.0,4000.0,0,-1,"L0") + monitor.D_PRS = (100,0.0,6000.0,0,-1,"PRS") + monitor.D_ECal = (100,4000.0,11000.0,0,-1,"ECal") + monitor.D_HCal = (100,0.0,3000.0,0,-1,"HCal") + monitor.D_Velo = (100,0.0,22000.0,0,-1,"Velo") + monitor.D_RICH = (100,0.0,22000.0,0,-1,"RICH") + monitor.D_IT = (100,0.0,16000.0,0,-1,"IT") + monitor.D_TT = (100,0.0,16000.0,0,-1,"TT") + monitor.D_OT = (100,0.0,24000.0,0,-1,"OT") + monitor.D_Muon = (100,0.0,6000.0,0,-1,"Muon") + monitor.D_HLT = (1000,0.0,100000.0,0,-1,"HLT") + monitor.D_Online = (100,0.0,400.0,0,-1,"Online") + monitor.D_LHCb = (100,0.0,20000.0,0,-1,"LHCb") + monitor.D_Unknown = (100,0.0,20000.0,0,-1,"Unknown") + monitor.D_TDET = (100,0.0,20000.0,0,-1,"TDET") + + monitor.D_UT = (100,0.0,20000.0,0,-1,"UT") + monitor.D_FT = (100,0.0,20000.0,0,-1,"FT") + monitor.D_Calo = (100,0.0,20000.0,0,-1,"Calo") + + monitor.DAQ = (5,0.0,100.0,0,-1,"Online") + monitor.DstAddress = (100,0.0,10000.0,0,128,"LHCb") + monitor.DstBank = (100,0.0,10000.0,0,128,"LHCb") + monitor.DstData = (100,0.0,10000.0,0,128,"LHCb") + monitor.EcalE = (100,0.0,10000.0,0,128,"ECal") + monitor.EcalPacked = (100,3000.0,11000.0,0,26,"ECal") + monitor.EcalPackedError = (100,0.0,10000.0,0,128,"ECal") + monitor.EcalTrig = (100,0.0,10000.0,0,128,"ECal") + monitor.FTCluster = (100,0.0,10000.0,0,1024,"FT") + monitor.FTGeneric = (100,0.0,10000.0,0,1024,"FT") + monitor.FTSpecial = (100,0.0,10000.0,0,1024,"FT") + monitor.FTNZS = (100,0.0,10000.0,0,1024,"FT") + monitor.FTCalibration = (100,0.0,10000.0,0,1024,"FT") + + monitor.FileID = (100,0.0,10000.0,0,128,"LHCb") + monitor.GaudiHeader = (100,0.0,10000.0,0,128,"LHCb") + monitor.GaudiSerialize = (100,0.0,10000.0,0,128,"LHCb") + monitor.HC = (100,0.0,10000.0,0,1024,"Unknown") + monitor.HCError = (100,0.0,10000.0,0,1024,"Unknown") + monitor.HLTRatio = (100,0.0,1.0,0,-1,"LHCb") + monitor.HcalE = (100,0.0,10000.0,0,128,"HCal") + monitor.HcalPacked = (100,1000.0,3000.0,0,10,"HCal") + monitor.HcalPackedError = (100,0.0,10000.0,0,128,"HCal") + monitor.HcalTrig = (100,0.0,10000.0,0,128,"HCal") + monitor.HltDecReports = (100,0.0,1000.0,0,-1,"HLT") + monitor.HltLumiSummary = (5,0.0,100.0,0,-1,"HLT") + monitor.HltRoutingBits = (10,0.0,100.0,0,-1,"HLT") + monitor.HltSelReports = (500,0.0,100000.0,0,5,"HLT") + monitor.HltTrackReports = (100,0.0,10000.0,0,1024,"Unknown") + monitor.HltVertexReports = (50,0.0,200.0,0,-1,"HLT") + monitor.IT = (100,0.0,12000.0,0,80,"IT") + monitor.ITError = (50,0.0,600.0,0,128,"IT") + monitor.ITFull = (50,0.0,10000.0,0,128,"IT") + monitor.ITPedestal = (100,0.0,10000.0,0,128,"IT") + monitor.ITProcFull = (100,0.0,10000.0,0,128,"IT") + monitor.L0Calo = (50,0.0,1000.0,0,5,"L0") + monitor.L0CaloError = (100,0.0,10000.0,0,128,"L0") + monitor.L0CaloFull = (100,0.0,10000.0,0,128,"L0") + monitor.L0DU = (5,100.0,200.0,0,-1,"L0") + monitor.L0DUError = (100,0.0,10000.0,0,-1,"L0") + monitor.L0Muon = (5,0.0,100.0,0,10,"L0") + monitor.L0MuonCtrlAll = (100,0.0,10000.0,0,128,"L0") + monitor.L0MuonError = (100,0.0,10000.0,0,128,"L0") + monitor.L0MuonProcCand = (10,0.0,1000.0,0,10,"L0") + monitor.L0MuonProcData = (70,0.0,1400.0,0,128,"L0") + monitor.L0MuonRaw = (100,0.0,10000.0,0,128,"L0") + monitor.L0PU = (25,200.0,400.0,0,-1,"L0") + monitor.L0PUError = (100,0.0,10000.0,0,-1,"L0") + monitor.L0PUFull = (10,3000.0,4000.0,0,-1,"L0") + monitor.Muon = (100,0.0,5000.0,0,20,"Muon") + monitor.MuonError = (100,0.0,10000.0,0,128,"Muon") + monitor.MuonFull = (100,0.0,10000.0,0,128,"Muon") + monitor.MuonSpecial = (100,0.0,10000.0,0,128,"Muon") + monitor.ODIN = (5,0.0,100.0,0,20,"Online") + monitor.OT = (100,0.0,36000.0,200,900,"OT") + monitor.OTError = (100,0.0,10000.0,0,128,"OT") + monitor.OTRaw = (100,0.0,10000.0,200,900,"OT") + monitor.PrsE = (100,0.0,10000.0,0,128,"PRS") + monitor.PrsPacked = (100,0.0,6000.0,0,10,"PRS") + monitor.PrsPackedError = (100,0.0,10000.0,0,128,"PRS") + monitor.PrsTrig = (100,0.0,10000.0,0,128,"PRS") + monitor.Rich = (150,0.0,22000.0,0,32,"RICH") + monitor.RichError = (150,0.0,22000.0,0,32,"RICH") + monitor.RichCommissioning = (150,0.0,22000.0,0,32,"RICH") + monitor.TAEHeader = (100,0.0,10000.0,0,128,"Online") + monitor.TT = (200,0.0,16000.0,0,128,"TT") + monitor.TTError = (100,0.0,10000.0,0,128,"TT") + monitor.TTFull = (10,3000.0,4000.0,0,128,"TT") + monitor.TTPedestal = (100,0.0,10000.0,0,128,"TT") + monitor.TTProcFull = (100,0.0,10000.0,0,128,"TT") + monitor.TestDet = (100,0.0,10000.0,0,128,"TDET") + monitor.TotEv = (500,0.0,500000.0,0,-1,"LHCb") + monitor.UT = (100,0.0,10000.0,0,1024,"Unknown") + monitor.UTError = (100,0.0,10000.0,0,1024,"Unknown") + monitor.UTFull = (100,0.0,10000.0,0,1024,"Unknown") + monitor.UTPedestal = (100,0.0,10000.0,0,1024,"Unknown") + monitor.VL = (100,0.0,10000.0,0,1024,"Unknown") + monitor.VP = (100,0.0,10000.0,0,1024,"Unknown") + monitor.VPRetinaCluster = (100,0.0,10000.0,0,1024,"Unknown") + monitor.Velo = (200,0.0,22000.0,0,128,"Velo") + monitor.VeloError = (50,0.0,500.0,0,128,"Velo") + monitor.VeloFull = (500,0.0,500000.0,0,128,"Velo") + monitor.VeloPedestal = (100,0.0,10000.0,0,128,"Velo") + monitor.VeloProcFull = (100,0.0,10000.0,0,128,"Velo") + monitor.Calo = (100,0.0,10000.0,0,1024,"Calo") + monitor.CaloError = (100,0.0,10000.0,0,1024,"Calo") + + self.app.TopAlg = [] + input = self.setup_event_input() + self.app.TopAlg.append(input) + self.app.TopAlg.append(monitor) + if hasattr(self,'updateAndReset'): + self.app.TopAlg.append(self.updateAndReset) + self.broker.DataProducers = self.app.TopAlg + return self + + +application = RawSizeMon(outputLevel=OnlineEnv.OutputLevel, + partitionName=OnlineEnv.PartitionName, + partitionID=OnlineEnv.PartitionID, + classType=GaudiOnline.Class1) +# +application.setup_fifolog() +application.setup_monitoring() # Must be one of the first statements! +application.setup_mbm_access('Events', True) +application.setup_hive(FlowManager("EventLoop"), 40) +application.monSvc.ProgramName = 'RawBankSizes' +application.monSvc.UseDStoreNames = True +application.monSvc.DimUpdateInterval = 1 +application.updateAndReset.saveHistograms = 1 +application.updateAndReset.saverCycle = 90 +application.updateAndReset.saveSetDir = "/group/online/dataflow/cmtuser/Savesets" + + +application.setup_algorithms() + +application.config.burstPrintCount = 30000 +application.config.MBM_numConnections = 1 +application.config.MBM_numEventThreads = 1 +# Mode slection:: synch: 0 async_queued: 1 sync_queued: 2 +application.config.execMode = 1 +application.config.numEventThreads = 1 +# +application.config.execMode = 0 +application.config.numEventThreads = 1 +# +application.config.MBM_requests = [ + 'EvType=2;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=ONE;Frequency=PERC;Perc=100.0', + 'EvType=1;TriggerMask=0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF;VetoMask=0,0,0,0;MaskType=ANY;UserType=ONE;Frequency=PERC;Perc=100.0' +] +# +print('Setup complete....') + diff --git a/Online/RawBankSizes/scripts/RawSizeMon.sh b/Online/RawBankSizes/scripts/RawSizeMon.sh new file mode 100755 index 0000000000000000000000000000000000000000..a109247a0522394af41cfd7f42aea781fd4073ff --- /dev/null +++ b/Online/RawBankSizes/scripts/RawSizeMon.sh @@ -0,0 +1,32 @@ +#!/bin/bash +export UTGID=${UTGID} +if test -n "${LOGFIFO}"; then + export LOGFIFO=${LOGFIFO}; +fi; +if test -z "${LOGFIFO}" -a -e /dev/shm/logs.dev; then + export LOGFIFO=/dev/shm/logs.dev; +fi; +if [ -r /etc/sysconfig/dim ]; then + . /etc/sysconfig/dim; + if test "`echo $DIM_DNS_NODE | cut -b 1-5`" = "fmc01"; then + DIM_DNS_NODE=`hostname -s`; + fi; + export DIM_DNS_NODE; +fi; +# +export CMTCONFIG=x86_64_v2-centos7-gcc10-opt; +export CMTCONFIG=x86_64_v2-centos7-gcc10-do0; +# +. /group/online/dataflow/cmtuser/OnlineRelease/setup.${CMTCONFIG}.vars; +. ${FARMCONFIGROOT}/job/createEnvironment.sh $*; +# +export GEN_OPTIONS=/group/online/dataflow/options/${PARTITION}/MONITORING; +# +export ONLINETASKS=/group/online/dataflow/templates; +export INFO_OPTIONS=/group/online/dataflow/options/${PARTITION}/MONITORING/OnlineEnv.opts; +export PREAMBLE_OPTS=${FARMCONFIGROOT}/options/Empty.opts; +export PYTHONPATH=${GEN_OPTIONS}:${PYTHONPATH} +# +# +echo exec -a ${UTGID} genPython.exe `which gaudirun.py` ${RAWBANKSIZESROOT}/options/RawSizeMon.py --application=OnlineEvents; +exec -a ${UTGID} genPython.exe `which gaudirun.py` ${RAWBANKSIZESROOT}/options/RawSizeMon.py --application=OnlineEvents; diff --git a/Online/RawBankSizes/scripts/RawSizeONLMon.run2.sh b/Online/RawBankSizes/scripts/RawSizeONLMon.run2.sh new file mode 100644 index 0000000000000000000000000000000000000000..f8fdc885d7f6dd6f88b6ff57a8550d4a1e33de5e --- /dev/null +++ b/Online/RawBankSizes/scripts/RawSizeONLMon.run2.sh @@ -0,0 +1,17 @@ +#!/bin/bash +export UTGID +cd /home/beat/cmtuser/Online_v4r11/Online/RawBankSizes/cmt +. ./pathsetup_32.sh + +TASKCLASS=-tasktype=LHCb::${2}Task +TASKTYPE=${3} +DYNAMIC_OPTS=/group/online/dataflow/options +OPTIONS=${DYNAMIC_OPTS}/${PARTITION}/${1} +export ONLINETASKS=/group/online/dataflow/templates +export PREAMBLE_OPTS=$ONLINETASKS/options/Preamble.opts +export DATAINTERFACE=`python -c "import socket;print socket.gethostbyname(socket.gethostname().split('.')[0]+'-d1')"` +export TAN_PORT=YES +export TAN_NODE=${DATAINTERFACE} +export gaudi_exe="$GAUDIONLINEROOT/$CMTCONFIG/Gaudi.exe libGaudiOnline.so OnlineTask -msgsvc=LHCb::FmcMessageSvc " +export DIM_DNS_NODE=${4} +$gaudi_exe ${TASKCLASS} -opt=${OPTIONS} -main=$ONLINETASKS/options/Main.opts diff --git a/Online/RawBankSizes/scripts/RawSizeONLMon.sh b/Online/RawBankSizes/scripts/RawSizeONLMon.sh old mode 100755 new mode 100644 index f8fdc885d7f6dd6f88b6ff57a8550d4a1e33de5e..a109247a0522394af41cfd7f42aea781fd4073ff --- a/Online/RawBankSizes/scripts/RawSizeONLMon.sh +++ b/Online/RawBankSizes/scripts/RawSizeONLMon.sh @@ -1,17 +1,32 @@ #!/bin/bash -export UTGID -cd /home/beat/cmtuser/Online_v4r11/Online/RawBankSizes/cmt -. ./pathsetup_32.sh - -TASKCLASS=-tasktype=LHCb::${2}Task -TASKTYPE=${3} -DYNAMIC_OPTS=/group/online/dataflow/options -OPTIONS=${DYNAMIC_OPTS}/${PARTITION}/${1} -export ONLINETASKS=/group/online/dataflow/templates -export PREAMBLE_OPTS=$ONLINETASKS/options/Preamble.opts -export DATAINTERFACE=`python -c "import socket;print socket.gethostbyname(socket.gethostname().split('.')[0]+'-d1')"` -export TAN_PORT=YES -export TAN_NODE=${DATAINTERFACE} -export gaudi_exe="$GAUDIONLINEROOT/$CMTCONFIG/Gaudi.exe libGaudiOnline.so OnlineTask -msgsvc=LHCb::FmcMessageSvc " -export DIM_DNS_NODE=${4} -$gaudi_exe ${TASKCLASS} -opt=${OPTIONS} -main=$ONLINETASKS/options/Main.opts +export UTGID=${UTGID} +if test -n "${LOGFIFO}"; then + export LOGFIFO=${LOGFIFO}; +fi; +if test -z "${LOGFIFO}" -a -e /dev/shm/logs.dev; then + export LOGFIFO=/dev/shm/logs.dev; +fi; +if [ -r /etc/sysconfig/dim ]; then + . /etc/sysconfig/dim; + if test "`echo $DIM_DNS_NODE | cut -b 1-5`" = "fmc01"; then + DIM_DNS_NODE=`hostname -s`; + fi; + export DIM_DNS_NODE; +fi; +# +export CMTCONFIG=x86_64_v2-centos7-gcc10-opt; +export CMTCONFIG=x86_64_v2-centos7-gcc10-do0; +# +. /group/online/dataflow/cmtuser/OnlineRelease/setup.${CMTCONFIG}.vars; +. ${FARMCONFIGROOT}/job/createEnvironment.sh $*; +# +export GEN_OPTIONS=/group/online/dataflow/options/${PARTITION}/MONITORING; +# +export ONLINETASKS=/group/online/dataflow/templates; +export INFO_OPTIONS=/group/online/dataflow/options/${PARTITION}/MONITORING/OnlineEnv.opts; +export PREAMBLE_OPTS=${FARMCONFIGROOT}/options/Empty.opts; +export PYTHONPATH=${GEN_OPTIONS}:${PYTHONPATH} +# +# +echo exec -a ${UTGID} genPython.exe `which gaudirun.py` ${RAWBANKSIZESROOT}/options/RawSizeMon.py --application=OnlineEvents; +exec -a ${UTGID} genPython.exe `which gaudirun.py` ${RAWBANKSIZESROOT}/options/RawSizeMon.py --application=OnlineEvents; diff --git a/Online/RawBankSizes/src/DupEvs.cpp b/Online/RawBankSizes/src/DupEvs.cpp deleted file mode 100644 index 2570a958629073d5bfc45ff4419f718a89774d52..0000000000000000000000000000000000000000 --- a/Online/RawBankSizes/src/DupEvs.cpp +++ /dev/null @@ -1,175 +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. -// -//-------------------------------------------------------------------------- -// -// Package : GaudiOnline -// -// Author : Markus Frank -//========================================================================== - -// Include files - -// from Gaudi -#include <RawBankSizes/DupEvs.h> -#include <vector> -#include <map> -#include <string> -#include <utility> -#include <string.h> - -// Declaration of the Algorithm Factory -DECLARE_COMPONENT( LHCb::DupEvs ) - -using namespace LHCb; -using namespace Online; - -//============================================================================= -// Standard constructor, initializes variables -//============================================================================= -DupEvs::DupEvs( const std::string& name,ISvcLocator* pSvcLocator) - : GaudiAlgorithm ( name , pSvcLocator ) -{ - m_rawEvt = 0; - m_dupEvsOBX = 0; - m_dupEvsL0ID=0; - m_Nev = 0; -} -//============================================================================= -// Destructor -//============================================================================= -DupEvs::~DupEvs() -{ -} - -StatusCode DupEvs::initialize() -{ - StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first - if ( sc.isFailure() ) return sc; // error printed already by GaudiHistoAlg - m_EventIDs.clear(); - m_EventL0ID.clear(); - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg; - return StatusCode::SUCCESS; -} -static inline unsigned long long SwapLong(unsigned long long d) -{ - unsigned long w1,w2; - w1 = d & 0xffffffff; - w2 = d>>32; - unsigned long long r=0; - r = (w1<<32) +w2; - return r; -} -//============================================================================= -// Main execution -//============================================================================= -StatusCode DupEvs::execute() -{ - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg; - - // get RawEvent - if( exist<LHCb::RawEvent>( LHCb::RawEventLocation::Default ) ) - { - m_rawEvt= get<LHCb::RawEvent>( LHCb::RawEventLocation::Default ); - } - else - { - Warning( "rawEvent not found at location '" + rootInTES() + LHCb::RawEventLocation::Default ).ignore(); - return StatusCode::SUCCESS; - } - auto daq_banks= m_rawEvt->banks(LHCb::RawBank::ODIN); - if (daq_banks.size()>1) - { - fatal()<<"Duplicate ODIN Banks Total Size: "<< daq_banks.size()<<endmsg; - } - for(const auto* b : daq_banks) - { - RunInfo *od = (RunInfo*) b->data(); - unsigned long long uevid = 0; -#if 0 - unsigned int *l0id; - unsigned int tmp; - l0id = (unsigned int *)&od->L0ID; - tmp = l0id[1]; - l0id[1] = l0id[0]; - l0id[0] = tmp; - long long int L0ID = od->L0ID;//*((long long int *)l0id); -#endif - long long int L0ID = SwapLong(od->L0ID); - //long long int GPSTime=SwapLong(od->GPSTime); - uevid = od->Orbit; - uevid = uevid<<16; - uevid += od->bunchID; - m_Nev++; - if (m_EventL0ID.find(L0ID) == m_EventL0ID.end()) - { - m_EventL0ID.insert(L0ID); - } - else - { - m_dupEvsL0ID++; - error()<<"Event in File "<<m_Nev<<" L0 ID duplicate"<<L0ID<< " ("<<L0ID<<")"<< endmsg; - } - if (m_EventIDs.find(uevid) == m_EventIDs.end()) - { - std::set<long long int> s; - s.insert(L0ID); - m_EventIDs.insert(std::make_pair(uevid,s)); - } - else - { - m_EventIDs[uevid].insert(L0ID); - if (m_OBxDups.find(uevid) == m_OBxDups.end()) - { - std::vector<RunInfo> s; - RunInfo o = *od; -// memcpy((void*)&o,(const void*)od,sizeof(OnlineRunInfo)); - s.push_back(o); - m_OBxDups.insert(std::make_pair(uevid,s)); - } - else - { - RunInfo o = *od; -// memcpy(&o,od,sizeof(OnlineRunInfo)); - m_OBxDups[uevid].push_back(o); - } -// error()<<"Event in File "<<m_Nev<<" Orbit/BXID duplicate " <<od->Orbit <<" BXID "<< od->bunchID <<" L0 ID "<<L0ID<<" ("<<L0ID<<")"<< endmsg; - m_dupEvsOBX++; - } - break; - } - - return StatusCode::SUCCESS; -} - - -//============================================================================= -// Finalize -//============================================================================= -StatusCode DupEvs::finalize() -{ - error()<<"Total Number of duplicate O/BX Events: " << m_dupEvsOBX <<" out of "<<m_Nev<<" Events"<<endmsg; - error()<<"Total Number of duplicate L0ID Events: " << m_dupEvsL0ID <<" out of "<<m_Nev<<" Events"<<endmsg; - error()<< "Duplicate inventory" <<endmsg; - for (auto i=m_OBxDups.begin();i!= m_OBxDups.end();i++) - { - unsigned long long uevid; - uevid = i->first; - unsigned int orb = uevid>>16; - unsigned int bxid = uevid & 0xFFFF; - error()<<"Orbit: "<<orb<<" BXID:"<<bxid<<endmsg; - for (auto j=i->second.begin();j!=i->second.end();j++) - { - long long int gps= j->GPSTime; - error()<<" L0Event ID: "<<j->L0ID<<" GPS Time: "<<SwapLong(gps)<<endmsg; - } - } - return GaudiAlgorithm::finalize(); // must be called after all other actions -} - -//============================================================================= diff --git a/Online/RawBankSizes/src/EventSize.cpp b/Online/RawBankSizes/src/EventSize.cpp index 2dd2fb4c9d59bbaf7427b77e10fced8fc3300198..d52cc2b933a8c2932517d772d38e3b2d45832500 100644 --- a/Online/RawBankSizes/src/EventSize.cpp +++ b/Online/RawBankSizes/src/EventSize.cpp @@ -14,12 +14,12 @@ //========================================================================== // Framework include files -#include "GaudiKernel/Algorithm.h" -#include "GaudiKernel/MsgStream.h" -#include "Event/RawEvent.h" -#include "Tell1Data/Tell1Decoder.h" -#include "GaudiKernel/IHistogramSvc.h" -#include "AIDA/IHistogram1D.h" +#include <Gaudi/Algorithm.h> +#include <GaudiKernel/MsgStream.h> +#include <GaudiKernel/IHistogramSvc.h> +#include <GaudiKernel/DataObjectHandle.h> +#include <Tell1Data/Tell1Bank.h> +#include <AIDA/IHistogram1D.h> /* * Online namespace declaration @@ -28,39 +28,23 @@ namespace Online { /**@class EventSize EventSize.cpp * - * Check the ODIN bank in each event for consistency + * Accumulate the total event size and fill a histogram * * @author: M.Frank * @version: 1.0 */ - class GAUDI_API EventSize: public Algorithm { + class GAUDI_API EventSize: public Gaudi::Algorithm { private: - /// Property: Raw bank location - std::string m_bankLocation; - std::string m_histPath {"EventSize/TotalSize"}; + typedef Tell1Bank BankHeader; + typedef std::vector<std::pair<const BankHeader*, const void*> > evt_data_t; + DataObjectReadHandle<evt_data_t> m_rawData{this,"RawData","Banks/RawData"}; + Gaudi::Property<std::string> m_histPath{this,"HistogramPath", "EventSize/TotalSize","Place of histogram"}; AIDA::IHistogram1D* m_eveLen = 0; public: /// Standard Algorithm Constructor(s) - EventSize(const std::string& nam, ISvcLocator* svc) - : Algorithm(nam,svc) - { - declareProperty("BankLocation", m_bankLocation=LHCb::RawEventLocation::Default); - declareProperty("HistogramPath",m_histPath); - } - - /// Default Destructor - virtual ~EventSize( ) {} - - /// Determine length of the sequential buffer from RawEvent object - size_t rawEventLength(const LHCb::RawEvent* evt) - { - size_t len = 0; - for(size_t i=LHCb::RawBank::L0Calo; i<LHCb::RawBank::LastType; ++i) - len += rawEventLengthBanks(evt->banks(LHCb::RawBank::BankType(i))); - return len; - } + using Algorithm::Algorithm; /// Algorithm overload: Initialize the algorithm StatusCode initialize() override { @@ -83,25 +67,23 @@ namespace Online { } /// Algorithm overload: Event execution routine - StatusCode execute() override { - DataObject* pDO = 0; - StatusCode sc = eventSvc()->retrieveObject(m_bankLocation,pDO); - if ( !sc.isSuccess() ) { - MsgStream err(msgSvc(),name()); - err << MSG::ERROR << "No RawEvent object found!" << endmsg; - return StatusCode::SUCCESS; // We want to continue! - } - if ( m_eveLen ) { - LHCb::RawEvent* evt = (LHCb::RawEvent*)pDO; - size_t length = rawEventLength(evt); - m_eveLen->fill(double(length), 1.0); - } - else { + StatusCode execute(const EventContext& /* context */ ) const override final { + if ( !m_eveLen ) { MsgStream err(msgSvc(),name()); err << MSG::ERROR << "Where the hack did my histogram go?" << endmsg; return StatusCode::FAILURE; } - return StatusCode::SUCCESS; + const evt_data_t* event = m_rawData.get(); + if ( event ) { + std::size_t total_length = 0; + for( const auto& b : *event ) + total_length += b.first->totalSize(); + m_eveLen->fill(double(total_length), 1.0); + return StatusCode::SUCCESS; + } + MsgStream err(msgSvc(),name()); + err << MSG::ERROR << "No raw data object found at " << m_rawData << endmsg; + return StatusCode::SUCCESS; // We want to continue! } }; } diff --git a/Online/RawBankSizes/src/MEPSizeMonitor.cpp b/Online/RawBankSizes/src/MEPSizeMonitor.cpp deleted file mode 100644 index d922b45f19ce9572f746e070aaa2c82f5fb4e843..0000000000000000000000000000000000000000 --- a/Online/RawBankSizes/src/MEPSizeMonitor.cpp +++ /dev/null @@ -1,533 +0,0 @@ -// $Id: MEPSizeMonitor.cpp,v 1.18 2010-09-25 21:31:08 frankb Exp $ -// Include files - -// from Gaudi -#include <vector> -#include <map> -#include <string> -#include <utility> -#include "RawBankSizes/MEPSizeMonitor.h" -#include "MDF/OnlineRunInfo.h" -#include "MDF/MDFHeader.h" -//#include "Event/ODIN.h" - -// local - -//----------------------------------------------------------------------------- -// Implementation file for class : MEPSizeMonitor -// -// 2008-03-27 : Olivier Deschamps -//----------------------------------------------------------------------------- - -// Declaration of the Algorithm Factory -DECLARE_COMPONENT( LHCb::MEPSizeMonitor ) - -using namespace LHCb; - -//============================================================================= -// Standard constructor, initializes variables -//============================================================================= -MEPSizeMonitor::MEPSizeMonitor( const std::string& name, - ISvcLocator* pSvcLocator) - : GaudiHistoAlg ( name , pSvcLocator ) -{ -// memset(m_hparams,0,sizeof(m_hparams)); - m_DetectorNames.push_back("L0"); - m_DetectorNames.push_back("PRS"); - m_DetectorNames.push_back("ECal"); - m_DetectorNames.push_back("HCal"); - m_DetectorNames.push_back("Velo"); - m_DetectorNames.push_back("RICH"); - m_DetectorNames.push_back("IT"); - m_DetectorNames.push_back("TT"); - m_DetectorNames.push_back("OT"); - m_DetectorNames.push_back("Muon"); - m_DetectorNames.push_back("HLT"); - m_DetectorNames.push_back("Online"); - m_DetectorNames.push_back("LHCb"); - m_DetectorNames.push_back("TDET"); - m_DetectorNames.push_back("Unknown"); - - declareProperty( "bankNames" , m_bankNames ); - declareProperty( "MaxSizeMap" , m_max); - declareProperty( "MaxSizeDef" , m_def=500); - declareProperty( "Bins" , m_bin=100); - declareProperty( "Profile" , m_prof=true); - declareProperty( "number_ofRMS" , m_nRMS=5); - - // default bank types list == all banks ! - for(int i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { - std::string bname = LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i ); - m_bankNames.push_back( bname ); - declareProperty(bname,m_hparams[i]/*,"(0,0.0,0.0,0,-2)"*/); - } - declareProperty("TotEv",m_totevpar/*,"(0,0.0,0.0,0,-2)"*/); - declareProperty("HLTRatio",m_HLTratiopar/*,"(0,0.0,0.0,0,-2)"*/); - std::vector<std::string>::iterator detiter = m_DetectorNames.begin(); - for (detiter= m_DetectorNames.begin();detiter != m_DetectorNames.end();detiter++) - { - std::string d = *detiter; - BankDescr *b = new BankDescr(); - b->init(d,true); - HParam::HistParams *p = new HParam::HistParams(); - declareProperty("D_"+d,*p); - m_detectors.insert(std::pair<std::string,BankDescr*>(d,b)); - m_dethparams.insert(std::pair<std::string,HParam::HistParams*>(d,p)); - } - m_firstevent = true; - first_few = true; - n_ev = 0; - std::string s="Total"; - totsize.init(s,false); -} -//============================================================================= -// Destructor -//============================================================================= -MEPSizeMonitor::~MEPSizeMonitor() -{ -} - -//============================================================================= -// Initialization -//============================================================================= -// StatusCode MEPSizeMonitor::initialize() -// { -// int i; -// StatusCode sc = GaudiHistoAlg::initialize(); // must be executed first -// if ( sc.isFailure() ) return sc; // error printed already by GaudiHistoAlg -// -// if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg; -// -// // Banks = new BankDescr[(int) LHCb::RawBank::LastType]; -// -// // convert bankNames to bankTypes -// for(std::vector<std::string>::iterator it = m_bankNames.begin();it!=m_bankNames.end();it++) -// { -// bool found = false; -// for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) -// { -// std::string bname = LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i ); -// if( bname == *it) -// { -// found = true; -// m_bankTypes.push_back( (LHCb::RawBank::BankType) i ); -// } -// } -// if( !found) warning() << "Requested bank '" << *it << "' is not a valid name" << endmsg; -// } -// -// for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) -// { -// // printf("%s %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i).c_str(), -// // m_hparams[i].det.c_str()); -// Banks[i].init(i,(m_hparams[i].s_max < 0)); -// if (m_hparams[i].n_bin == -2) -// { -// printf("WARNING: No Histogram Options for Bank %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i -// ).c_str()); -// } -// Banks[i].nohist = (m_hparams[i].n_bin <= 0); -// } -// for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) -// { -// int idx; -// idx = i; -// if (Banks[i].isError) -// { -// idx = Banks[i].rootbankidx; -// } -// if (!Banks[i].nohist) -// { -// double binw = (m_hparams[i].xmax - m_hparams[i].xmin)/m_hparams[i].n_bin; -// Banks[i].xmin = m_hparams[i].xmin; -// Banks[i].xmax = m_hparams[i].xmax; -// Banks[i].binw = binw; -// if (((int)binw % 4) != 0) -// { -// printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),binw); -// } -// Banks[i].nbin = m_hparams[i].n_bin; -// -// Banks[i].h[0] = histoSvc()->book( Banks[i].h_name[0],Banks[i].name+" Size in Bytes (all Triggers)",m_hparams[i].n_bin+2, -// m_hparams[i].xmin-binw,m_hparams[i].xmax+binw); -// declareInfo(Banks[i].h_name[0], Banks[i].h[0],Banks[i].name+" Size in Bytes (all Triggers)"); -// Banks[i].h[1] = histoSvc()->book( Banks[i].h_name[1],Banks[i].name+" Size in Bytes (nonLumi)",m_hparams[i].n_bin+2, -// m_hparams[i].xmin-binw,m_hparams[i].xmax+binw); -// declareInfo(Banks[i].h_name[1], Banks[i].h[1],Banks[i].name+" Size in Bytes (nonLumi)"); -// } -// else -// { -// printf("INFO: No Histogram booked for Bank %s\n",Banks[i].name.c_str()); -// } -// if (!Banks[i].noprofile) -// { -// Banks[i].p[0] = histoSvc()->bookProf( Banks[i].p_name[0],Banks[i].name+" Size vs. SourceID (all Triggers)", -// m_hparams[idx].s_max-m_hparams[idx].s_min+1, -// (float)m_hparams[idx].s_min,(float)m_hparams[idx].s_max); -// declareInfo(Banks[i].p_name[0], Banks[i].p[0],Banks[i].name+" Size vs. SourceID (all Triggers)"); -// Banks[i].p[1] = histoSvc()->bookProf( Banks[i].p_name[1],Banks[i].name+" Size vs. SourceID (nonLumi)", -// m_hparams[idx].s_max-m_hparams[idx].s_min+1, -// (float)m_hparams[idx].s_min,(float)m_hparams[idx].s_max); -// declareInfo(Banks[i].p_name[1], Banks[i].p[1],Banks[i].name+" Size vs. SourceID (nonLumi)"); -// } -// else -// { -// printf("INFO: No Profile booked for Bank %s\n",Banks[i].name.c_str()); -// } -// } -// totsize.xmin = m_totevpar.xmin; -// totsize.xmax = m_totevpar.xmax; -// totsize.nbin = m_totevpar.n_bin; -// totsize.binw = (totsize.xmax-totsize.xmin)/totsize.nbin; -// if (((int)totsize.binw % 4) != 0) -// { -// printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),totsize.binw); -// } -// h_totev[0] = histoSvc()->book( "TotSize(all)","Total Event Size in Bytes (all Triggers)",m_totevpar.n_bin+2, -// m_totevpar.xmin-totsize.binw,m_totevpar.xmax+totsize.binw); -// declareInfo("TotSize(all)", h_totev[0],"Total Event Size in Bytes (all Triggers)"); -// h_totev[1] = histoSvc()->book( "TotSize(nonLumi)","Total Event Size in Bytes (NonLumi)",m_totevpar.n_bin+2, -// m_totevpar.xmin-totsize.binw,m_totevpar.xmax+totsize.binw); -// declareInfo("TotSize(nonLumi)", h_totev[1],"Total Event Size in Bytes (nonLumi)"); -// p_banks[0] = histoSvc()->bookProf( "Banksp(all)","Bank Size vs. Bank Number (all Triggers)", -// LHCb::RawBank::LastType+1, -1.0, (float)LHCb::RawBank::LastType); -// declareInfo("Banksp(all)",p_banks[0],"Bank Size vs. Bank Number (all Triggers)"); -// p_banks[1] = histoSvc()->bookProf( "Banksp(nonLumi)","Bank Size vs. Bank Number (nonLumi)", -// LHCb::RawBank::LastType+1, -1.0, (float)LHCb::RawBank::LastType); -// declareInfo("Banksp(nonLumi)",p_banks[1],"Bank Size vs. Bank Number (nonLumi)"); -// for (dethmiter j=m_dethparams.begin();j!=m_dethparams.end();j++) -// { -// detbmiter bd = m_detectors.find(j->first); -// bd->second->xmin = j->second->xmin; -// bd->second->xmax = j->second->xmax; -// bd->second->nbin = j->second->n_bin; -// bd->second->binw = (j->second->xmax-j->second->xmin)/j->second->n_bin; -// if (((int)bd->second->binw % 4) != 0) -// { -// printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),bd->second->binw); -// } -// bd->second->h[0] = histoSvc()->book("Total_"+j->first+"(all)","Total Size for "+j->first+" in Bytes (all Triggers)", -// j->second->n_bin+2, j->second->xmin-bd->second->binw,j->second->xmax+bd->second->binw); -// declareInfo("Total_"+j->first+"(all)", bd->second->h[0],"Total Size for "+j->first+" in Bytes (all Triggers)"); -// bd->second->h[1] = histoSvc()->book("Total_"+j->first+"(noLumi)","Total Size for "+j->first+" in Bytes (nonLumi)", -// j->second->n_bin+2, j->second->xmin-bd->second->binw,j->second->xmax+bd->second->binw); -// declareInfo("Total_"+j->first+"(noLumi)", bd->second->h[1],"Total Size for "+j->first+" in Bytes (nonLumi)"); -// } -// m_firstevent = true; -// n_ev = 0; -// return StatusCode::SUCCESS; -// } - -StatusCode MEPSizeMonitor::initialize() -{ - int i; - int hindx; - - StatusCode sc = GaudiHistoAlg::initialize(); // must be executed first - if ( sc.isFailure() ) return sc; // error printed already by GaudiHistoAlg - - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg; - -// Banks = new BankDescr[(int) LHCb::RawBank::LastType]; - - // convert bankNames to bankTypes - for(std::vector<std::string>::iterator it = m_bankNames.begin();it!=m_bankNames.end();it++) - { - bool found = false; - for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { - std::string bname = LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i ); - if( bname == *it) - { - found = true; - m_bankTypes.push_back( (LHCb::RawBank::BankType) i ); - } - } - if( !found) warning() << "Requested bank '" << *it << "' is not a valid name" << endmsg; - } - - for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { -// printf("%s %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i).c_str(), -// m_hparams[i].det.c_str()); - Banks[i].init(i,(m_hparams[i].s_max < 0)); - if (m_hparams[i].n_bin == -2) - { - printf("WARNING: No Histogram Options for Bank %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i - ).c_str()); - } - Banks[i].nohist = (m_hparams[i].n_bin <= 0); - } - for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { - int idx; - idx = i; - if (Banks[i].isError) - { - idx = Banks[i].rootbankidx; - } - if (!Banks[i].nohist) - { - double binw = (m_hparams[i].xmax - m_hparams[i].xmin)/m_hparams[i].n_bin; - Banks[i].xmin = m_hparams[i].xmin; - Banks[i].xmax = m_hparams[i].xmax; - Banks[i].binw = binw; - if (((int)binw % 4) != 0) - { - printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),binw); - } - Banks[i].nbin = m_hparams[i].n_bin; - for (hindx = 0; hindx < HISTPERHIST;hindx++) - { - Banks[i].h[hindx] = histoSvc()->book( Banks[i].h_name[hindx],Banks[i].name+" Size in Bytes"+titqual[hindx],m_hparams[i].n_bin, - m_hparams[i].xmin,m_hparams[i].xmax); - declareInfo(Banks[i].h_name[hindx], Banks[i].h[hindx],Banks[i].name+" Size in Bytes"+titqual[hindx]); - } - } - else - { - printf("INFO: No Histogram booked for Bank %s\n",Banks[i].name.c_str()); - } - if (!Banks[i].noprofile) - { - for (hindx=0;hindx<HISTPERHIST;hindx++) - { - Banks[i].p[hindx] = histoSvc()->bookProf( Banks[i].p_name[hindx],Banks[i].name+" Size vs. SourceID"+titqual[hindx], - m_hparams[idx].s_max-m_hparams[idx].s_min+1, - (float)m_hparams[idx].s_min,(float)m_hparams[idx].s_max); - declareInfo(Banks[i].p_name[hindx], Banks[i].p[hindx],Banks[i].name+" Size vs. SourceID"+titqual[hindx]); - } - } - else - { - printf("INFO: No Profile booked for Bank %s\n",Banks[i].name.c_str()); - } - } - totsize.xmin = m_totevpar.xmin; - totsize.xmax = m_totevpar.xmax; - totsize.nbin = m_totevpar.n_bin; - totsize.binw = (totsize.xmax-totsize.xmin)/totsize.nbin; - if (((int)totsize.binw % 4) != 0) - { - // Beat: This is wrong and was Banks[i], which clearly accesses bad memory! - printf("Binwidth for %s not a multiple of 4. %f\n",Banks[0].name.c_str(),totsize.binw); - } - for (hindx=0;hindx<HISTPERHIST;hindx++) - { - h_totev[hindx] = histoSvc()->book( "TotSize"+namqual[hindx],"Total Event Size in Bytes"+titqual[hindx],m_totevpar.n_bin, - m_totevpar.xmin,m_totevpar.xmax); - declareInfo("TotSize"+namqual[hindx], h_totev[hindx],"Total Event Size in Bytes"+titqual[hindx]); - h_HLTratio[hindx] = histoSvc()->book( "HLTRatio"+namqual[hindx],"Ratio HLT Total Size"+titqual[hindx],m_HLTratiopar.n_bin, - m_HLTratiopar.xmin,m_HLTratiopar.xmax); - declareInfo("HLTRatio"+namqual[hindx], h_HLTratio[hindx],"Ratio HLT Total Size"+titqual[hindx]); - p_banks[hindx] = histoSvc()->bookProf("Banksp"+namqual[hindx],"Bank Size vs. Bank Number"+titqual[hindx], - LHCb::RawBank::LastType+1, -1.0, (float)LHCb::RawBank::LastType); - declareInfo("Banksp"+namqual[hindx],p_banks[hindx],"Bank Size vs. Bank Number"+titqual[hindx]); - } - for (dethmiter j=m_dethparams.begin();j!=m_dethparams.end();j++) - { - detbmiter bd = m_detectors.find(j->first); - bd->second->xmin = j->second->xmin; - bd->second->xmax = j->second->xmax; - bd->second->nbin = j->second->n_bin; - bd->second->binw = (j->second->xmax-j->second->xmin)/j->second->n_bin; - if (((int)bd->second->binw % 4) != 0) - { - // Beat: This is wrong and was Banks[i], which clearly accesses bad memory! - printf("Binwidth for %s not a multiple of 4. %f\n",Banks[0].name.c_str(),bd->second->binw); - } - for (hindx=0;hindx<HISTPERHIST;hindx++) - { - bd->second->h[hindx] = histoSvc()->book("Total_"+j->first+namqual[hindx],"Total Size for "+j->first+" in Bytes"+titqual[hindx], - j->second->n_bin, j->second->xmin,j->second->xmax); - declareInfo("Total_"+j->first+namqual[hindx], bd->second->h[hindx],"Total Size for "+j->first+" in Bytes"+titqual[hindx]); - } - } - m_firstevent = true; - n_ev = 0; - return StatusCode::SUCCESS; -} - - -//============================================================================= -// Main execution -//============================================================================= -StatusCode MEPSizeMonitor::execute() -{ -// int bsize[LHCb::RawBank::LastType]; - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg; - - // get RawEvent - if( exist<LHCb::RawEvent>( LHCb::RawEventLocation::Default ) ) - { - m_rawEvt= get<LHCb::RawEvent>( LHCb::RawEventLocation::Default ); - } - else - { - Warning( "rawEvent not found at location '" + rootInTES() + LHCb::RawEventLocation::Default ).ignore(); - return StatusCode::SUCCESS; - } - n_ev++; - int tots; - tots = 0; - int bnkid=0; - bool nolumi=false; - for (detbmiter j=m_detectors.begin();j!=m_detectors.end();j++) - { - j->second->sum = 0.0; - } - - for(std::vector<LHCb::RawBank::BankType>::const_iterator it = m_bankTypes.begin();it!=m_bankTypes.end();it++) - { - -// std::string bname = LHCb::RawBank::typeName( *it ); - Banks[*it].siz = 0.0; - } - const std::vector<LHCb::RawBank*>& daq_banks= m_rawEvt->banks(RawBank::DAQ); - nolumi = true; - for(std::vector<LHCb::RawBank*>::const_iterator ib = daq_banks.begin();ib!=daq_banks.end();ib++) - { - RawBank *b = *ib; - if (b->version() == DAQ_STATUS_BANK) - { - MDFHeader *h = b->begin<MDFHeader>(); - const unsigned int *trMask=h->subHeader().H1->triggerMask(); -// printf("Trigger Mask %0x %0x %0x %0x\n",trMask[0],trMask[1],trMask[2],trMask[3]); - if ((trMask[1] & 0x10000) != 0) - { - nolumi = false; - } - break; - } - } - - for(std::vector<LHCb::RawBank::BankType>::const_iterator it = m_bankTypes.begin();it!=m_bankTypes.end();it++) - { - const std::vector<LHCb::RawBank*>* banks= &m_rawEvt->banks( *it ); - for(std::vector<LHCb::RawBank*>::const_iterator ib = banks->begin();ib!=banks->end();ib++) - { - bnkid = (*ib)->type(); - int id; - id = bnkid; - tots += (*ib)->size(); - Banks[id].siz += (*ib)->size(); - if (!Banks[id].noprofile) - { - Banks[id].p[0]->fill( (double) (*ib)->sourceID() , (double) (*ib)->size()); - if (nolumi) - { - Banks[id].p[1]->fill( (double) (*ib)->sourceID() , (double) (*ib)->size()); - } - else - { - Banks[id].p[2]->fill( (double) (*ib)->sourceID() , (double) (*ib)->size()); - } - } - } - - if (Banks[*it].siz > 0.0) - { - double x = Banks[*it].siz; - if (!Banks[*it].nohist) - { -/* - if (x <Banks[*it].xmin) - { - x = Banks[*it].xmin-Banks[*it].binw/2.0; - } - else if(x > Banks[*it].xmax) - { - x = Banks[*it].xmax+Banks[*it].binw/2.0; - } -*/ - Banks[*it].h[0]->fill(x); - if (nolumi) - { - Banks[*it].h[1]->fill(x); - } - else - { - Banks[*it].h[2]->fill(x); - } - } - p_banks[0]->fill((double)(*it),Banks[*it].siz); - if (nolumi) - { - p_banks[1]->fill((double)(*it),Banks[*it].siz); - } - else - { - p_banks[2]->fill((double)(*it),Banks[*it].siz); - } - - } - } - for(std::vector<LHCb::RawBank::BankType>::const_iterator it = m_bankTypes.begin();it!=m_bankTypes.end();it++) - { - std::string d = m_hparams[*it].det; - detbmiter j = m_detectors.find(d); - j->second->sum += Banks[*it].siz; - } - for (detbmiter j=m_detectors.begin();j!=m_detectors.end();j++) - { - double x = j->second->sum; - if (x>0) - { -/* - if (j->second->sum < j->second->xmin) - { - x = j->second->xmin+j->second->binw/2.0; - } - else if(j->second->sum > j->second->xmax) - { - x = j->second->xmax-j->second->binw/2.0; - } -*/ - j->second->h[0]->fill(x); - if (nolumi) - { - j->second->h[1]->fill(x); - } - else - { - j->second->h[2]->fill(x); - } - } - } - - - double total = tots; - if (total >0) - { - detbmiter j = m_detectors.find("HLT"); - double rat = j->second->sum/total; - h_totev[0]->fill(total); - h_HLTratio[0]->fill(rat); - if (nolumi) - { - h_totev[1]->fill(total); - h_HLTratio[1]->fill(rat); - } - else - { - h_totev[2]->fill(total); - h_HLTratio[2]->fill(rat); - } - } - return StatusCode::SUCCESS; -} - - -//============================================================================= -// Finalize -//============================================================================= -StatusCode MEPSizeMonitor::finalize() -{ - printf("Number of Events Seen %d\n",n_ev); - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg; - - return GaudiHistoAlg::finalize(); // must be called after all other actions -} - -//============================================================================= diff --git a/Online/RawBankSizes/src/MakePages.cpp b/Online/RawBankSizes/src/MakePages.cpp index eccc19fd8e7a1c7da2419e57a5a71a59021bb537..e5dfc8a2c9a25d4b42737f71cc10048aa9430bdf 100644 --- a/Online/RawBankSizes/src/MakePages.cpp +++ b/Online/RawBankSizes/src/MakePages.cpp @@ -13,8 +13,8 @@ #include <cstdio> typedef std::map<std::string,std::vector<OnlineHistogram*> > bankmap; -int main() -{ + +int main() { std::set<std::string> banknams; bankmap profiles,histos; std::string password="HISTEGGIA194"; diff --git a/Online/RawBankSizes/src/ParseHistParams.cpp b/Online/RawBankSizes/src/ParseHistParams.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c47c44f8097c17403b8c08c10915562e39b96d8f --- /dev/null +++ b/Online/RawBankSizes/src/ParseHistParams.cpp @@ -0,0 +1,21 @@ +#include "RawBankSizes/Structure.h" +#include <iostream> +#include <string> + +static void test(const std::string& input) { + HParam::HistParams result; + auto ret = Gaudi::Parsers::parse(result, input); + std::cout << "Tried to parse: " << input << std::endl; + std::cout << ret.getCode() << " --> "; + Gaudi::Utils::toStream(result,std::cout); + std::cout << std::endl; +} + +int main(int, char**) { + test("(50, 0.0, 1000.0, 0, 5, 'L0')"); + test("(50, 0.0, 1000.0, 0, 5, \"L0\")"); + test("(50,0.0,1000.0,0,5,\"L0\")"); + test("(50,0.0,1000.0,0,5,'L0')"); + + return 0; +} diff --git a/Online/RawBankSizes/src/RawBankSizes.cpp b/Online/RawBankSizes/src/RawBankSizes.cpp index 71dd10e41eb013f77b795c76ce42d2eb4bb6555d..c63ec9c2f563d2c10e89c94a2162d5c88c573e2f 100644 --- a/Online/RawBankSizes/src/RawBankSizes.cpp +++ b/Online/RawBankSizes/src/RawBankSizes.cpp @@ -16,15 +16,12 @@ // Include files // from Gaudi -#include <vector> -#include <map> -#include <string> #include <utility> +#include "PCIE40Data/sodin.h" #include "Tell1Data/EventHeader.h" #include "RawBankSizes/RawBankSizes.h" // local - //----------------------------------------------------------------------------- // Implementation file for class : RawBankSizes // @@ -32,53 +29,56 @@ //----------------------------------------------------------------------------- // Declaration of the Algorithm Factory -DECLARE_COMPONENT( LHCb::RawBankSizes ) +DECLARE_COMPONENT( Online::RawBankSizes ) -using namespace LHCb; +using namespace Online; //============================================================================= // Standard constructor, initializes variables //============================================================================= RawBankSizes::RawBankSizes( const std::string& name, ISvcLocator* pSvcLocator) - : GaudiHistoAlg ( name , pSvcLocator ) + : Algorithm( name , pSvcLocator ) { -// memset(m_hparams,0,sizeof(m_hparams)); - m_DetectorNames.push_back("L0"); - m_DetectorNames.push_back("PRS"); - m_DetectorNames.push_back("ECal"); - m_DetectorNames.push_back("HCal"); - m_DetectorNames.push_back("Velo"); - m_DetectorNames.push_back("RICH"); - m_DetectorNames.push_back("IT"); - m_DetectorNames.push_back("TT"); - m_DetectorNames.push_back("OT"); - m_DetectorNames.push_back("Muon"); - m_DetectorNames.push_back("HLT"); - m_DetectorNames.push_back("Online"); - m_DetectorNames.push_back("LHCb"); - m_DetectorNames.push_back("TDET"); - m_DetectorNames.push_back("Unknown"); + m_detectorNames.push_back("L0"); + m_detectorNames.push_back("PRS"); + m_detectorNames.push_back("ECal"); + m_detectorNames.push_back("HCal"); + m_detectorNames.push_back("Calo"); + m_detectorNames.push_back("Velo"); + m_detectorNames.push_back("RICH"); + m_detectorNames.push_back("UT"); + m_detectorNames.push_back("FT"); + m_detectorNames.push_back("IT"); + m_detectorNames.push_back("TT"); + m_detectorNames.push_back("OT"); + m_detectorNames.push_back("Muon"); + m_detectorNames.push_back("HLT"); + m_detectorNames.push_back("Online"); + m_detectorNames.push_back("LHCb"); + m_detectorNames.push_back("TDET"); + m_detectorNames.push_back("Unknown"); - declareProperty( "bankNames" , m_bankNames ); + declareProperty( "bankNames" , m_bankNames); + declareProperty( "DumpOptions" , m_dumpOptions = false); declareProperty( "MaxSizeMap" , m_max); - declareProperty( "MaxSizeDef" , m_def=500); - declareProperty( "Bins" , m_bin=100); - declareProperty( "Profile" , m_prof=true); - declareProperty( "number_ofRMS" , m_nRMS=5); + declareProperty( "MaxSizeDef" , m_def = 500); + declareProperty( "Bins" , m_bin = 100); + declareProperty( "Profile" , m_prof = true); // default bank types list == all banks ! - for(int i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { - std::string bname = LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i ); - m_bankNames.push_back( bname ); - declareProperty(bname,m_hparams[i]/*,"(0,0.0,0.0,0,-2)"*/); + for(int i = 0 ; i != (int) Tell1Bank::LastType; i++) { + std::string bname = Tell1Printout::bankType(Tell1Bank::BankType(i)); + if ( bname != "UNKNOWN" ) { + m_bankNames.push_back( bname ); + declareProperty(bname,m_hparams[i]/*,"(0,0.0,0.0,0,-2)"*/); + continue; + } + ::printf("Warning: RawBankSizes: Unknown bank type: %d\n",i); } declareProperty("TotEv",m_totevpar/*,"(0,0.0,0.0,0,-2)"*/); declareProperty("HLTRatio",m_HLTratiopar/*,"(0,0.0,0.0,0,-2)"*/); - for (auto detiter= m_DetectorNames.begin();detiter != m_DetectorNames.end();detiter++) - { - std::string d = *detiter; + for (const auto& d : m_detectorNames ) { BankDescr *b = new BankDescr(); b->init(d,true); HParam::HistParams *p = new HParam::HistParams(); @@ -86,11 +86,7 @@ RawBankSizes::RawBankSizes( const std::string& name, m_detectors.insert(std::pair<std::string,BankDescr*>(d,b)); m_dethparams.insert(std::pair<std::string,HParam::HistParams*>(d,p)); } - m_firstevent = true; - first_few = true; - n_ev = 0; - std::string s="Total"; - totsize.init(s,false); + m_totsize.init("Total",false); } //============================================================================= // Destructor @@ -108,440 +104,235 @@ RawBankSizes::~RawBankSizes() //============================================================================= // Initialization //============================================================================= -// StatusCode RawBankSizes::initialize() -// { -// int i; -// StatusCode sc = GaudiHistoAlg::initialize(); // must be executed first -// if ( sc.isFailure() ) return sc; // error printed already by GaudiHistoAlg -// -// if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg; -// -// // Banks = new BankDescr[(int) LHCb::RawBank::LastType]; -// -// // convert bankNames to bankTypes -// for(std::vector<std::string>::iterator it = m_bankNames.begin();it!=m_bankNames.end();it++) -// { -// bool found = false; -// for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) -// { -// std::string bname = LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i ); -// if( bname == *it) -// { -// found = true; -// m_bankTypes.push_back( (LHCb::RawBank::BankType) i ); -// } -// } -// if( !found) warning() << "Requested bank '" << *it << "' is not a valid name" << endmsg; -// } -// -// for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) -// { -// // printf("%s %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i).c_str(), -// // m_hparams[i].det.c_str()); -// Banks[i].init(i,(m_hparams[i].s_max < 0)); -// if (m_hparams[i].n_bin == -2) -// { -// printf("WARNING: No Histogram Options for Bank %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i -// ).c_str()); -// } -// Banks[i].nohist = (m_hparams[i].n_bin <= 0); -// } -// for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) -// { -// int idx; -// idx = i; -// if (Banks[i].isError) -// { -// idx = Banks[i].rootbankidx; -// } -// if (!Banks[i].nohist) -// { -// double binw = (m_hparams[i].xmax - m_hparams[i].xmin)/m_hparams[i].n_bin; -// Banks[i].xmin = m_hparams[i].xmin; -// Banks[i].xmax = m_hparams[i].xmax; -// Banks[i].binw = binw; -// if (((int)binw % 4) != 0) -// { -// printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),binw); -// } -// Banks[i].nbin = m_hparams[i].n_bin; -// -// Banks[i].h[0] = histoSvc()->book( Banks[i].h_name[0],Banks[i].name+" Size in Bytes (all Triggers)",m_hparams[i].n_bin+2, -// m_hparams[i].xmin-binw,m_hparams[i].xmax+binw); -// declareInfo(Banks[i].h_name[0], Banks[i].h[0],Banks[i].name+" Size in Bytes (all Triggers)"); -// Banks[i].h[1] = histoSvc()->book( Banks[i].h_name[1],Banks[i].name+" Size in Bytes (nonLumi)",m_hparams[i].n_bin+2, -// m_hparams[i].xmin-binw,m_hparams[i].xmax+binw); -// declareInfo(Banks[i].h_name[1], Banks[i].h[1],Banks[i].name+" Size in Bytes (nonLumi)"); -// } -// else -// { -// printf("INFO: No Histogram booked for Bank %s\n",Banks[i].name.c_str()); -// } -// if (!Banks[i].noprofile) -// { -// Banks[i].p[0] = histoSvc()->bookProf( Banks[i].p_name[0],Banks[i].name+" Size vs. SourceID (all Triggers)", -// m_hparams[idx].s_max-m_hparams[idx].s_min+1, -// (float)m_hparams[idx].s_min,(float)m_hparams[idx].s_max); -// declareInfo(Banks[i].p_name[0], Banks[i].p[0],Banks[i].name+" Size vs. SourceID (all Triggers)"); -// Banks[i].p[1] = histoSvc()->bookProf( Banks[i].p_name[1],Banks[i].name+" Size vs. SourceID (nonLumi)", -// m_hparams[idx].s_max-m_hparams[idx].s_min+1, -// (float)m_hparams[idx].s_min,(float)m_hparams[idx].s_max); -// declareInfo(Banks[i].p_name[1], Banks[i].p[1],Banks[i].name+" Size vs. SourceID (nonLumi)"); -// } -// else -// { -// printf("INFO: No Profile booked for Bank %s\n",Banks[i].name.c_str()); -// } -// } -// totsize.xmin = m_totevpar.xmin; -// totsize.xmax = m_totevpar.xmax; -// totsize.nbin = m_totevpar.n_bin; -// totsize.binw = (totsize.xmax-totsize.xmin)/totsize.nbin; -// if (((int)totsize.binw % 4) != 0) -// { -// printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),totsize.binw); -// } -// h_totev[0] = histoSvc()->book( "TotSize(all)","Total Event Size in Bytes (all Triggers)",m_totevpar.n_bin+2, -// m_totevpar.xmin-totsize.binw,m_totevpar.xmax+totsize.binw); -// declareInfo("TotSize(all)", h_totev[0],"Total Event Size in Bytes (all Triggers)"); -// h_totev[1] = histoSvc()->book( "TotSize(nonLumi)","Total Event Size in Bytes (NonLumi)",m_totevpar.n_bin+2, -// m_totevpar.xmin-totsize.binw,m_totevpar.xmax+totsize.binw); -// declareInfo("TotSize(nonLumi)", h_totev[1],"Total Event Size in Bytes (nonLumi)"); -// p_banks[0] = histoSvc()->bookProf( "Banksp(all)","Bank Size vs. Bank Number (all Triggers)", -// LHCb::RawBank::LastType+1, -1.0, (float)LHCb::RawBank::LastType); -// declareInfo("Banksp(all)",p_banks[0],"Bank Size vs. Bank Number (all Triggers)"); -// p_banks[1] = histoSvc()->bookProf( "Banksp(nonLumi)","Bank Size vs. Bank Number (nonLumi)", -// LHCb::RawBank::LastType+1, -1.0, (float)LHCb::RawBank::LastType); -// declareInfo("Banksp(nonLumi)",p_banks[1],"Bank Size vs. Bank Number (nonLumi)"); -// for (dethmiter j=m_dethparams.begin();j!=m_dethparams.end();j++) -// { -// detbmiter bd = m_detectors.find(j->first); -// bd->second->xmin = j->second->xmin; -// bd->second->xmax = j->second->xmax; -// bd->second->nbin = j->second->n_bin; -// bd->second->binw = (j->second->xmax-j->second->xmin)/j->second->n_bin; -// if (((int)bd->second->binw % 4) != 0) -// { -// printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),bd->second->binw); -// } -// bd->second->h[0] = histoSvc()->book("Total_"+j->first+"(all)","Total Size for "+j->first+" in Bytes (all Triggers)", -// j->second->n_bin+2, j->second->xmin-bd->second->binw,j->second->xmax+bd->second->binw); -// declareInfo("Total_"+j->first+"(all)", bd->second->h[0],"Total Size for "+j->first+" in Bytes (all Triggers)"); -// bd->second->h[1] = histoSvc()->book("Total_"+j->first+"(noLumi)","Total Size for "+j->first+" in Bytes (nonLumi)", -// j->second->n_bin+2, j->second->xmin-bd->second->binw,j->second->xmax+bd->second->binw); -// declareInfo("Total_"+j->first+"(noLumi)", bd->second->h[1],"Total Size for "+j->first+" in Bytes (nonLumi)"); -// } -// m_firstevent = true; -// n_ev = 0; -// return StatusCode::SUCCESS; -// } - -StatusCode RawBankSizes::initialize() -{ - int i; - int hindx; - - StatusCode sc = GaudiHistoAlg::initialize(); // must be executed first - if ( sc.isFailure() ) return sc; // error printed already by GaudiHistoAlg - - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg; - -// Banks = new BankDescr[(int) LHCb::RawBank::LastType]; - +StatusCode RawBankSizes::initialize() { + auto& opt_svc = serviceLocator()->getOptsSvc(); + std::string prefix = name()+"."; + if ( m_dumpOptions ) { + const auto& props = getProperties(); + for(const auto* p : props) { + std::string val = p->toString(); + always() << prefix << p->name() << " = " << val + << " [" << System::typeinfoName(*p->type_info()) << "] " + << opt_svc.get(prefix+p->name()) + << endmsg; + } + } // convert bankNames to bankTypes - for(std::vector<std::string>::iterator it = m_bankNames.begin();it!=m_bankNames.end();it++) - { + for( const auto& bn : m_bankNames ) { bool found = false; - for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { - std::string bname = LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i ); - if( bname == *it) - { + for( int i = 0 ; i != (int)Tell1Bank::LastType; i++ ) { + std::string bname = Tell1Printout::bankType(Tell1Bank::BankType(i)); + if( bname == bn) { + m_bankTypes.push_back(Tell1Bank::BankType(i)); found = true; - m_bankTypes.push_back( (LHCb::RawBank::BankType) i ); + break; } } - if( !found) warning() << "Requested bank '" << *it << "' is not a valid name" << endmsg; + if( !found) warning() << "Requested bank '" << bn << "' is not a valid name" << endmsg; } - - for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { -// printf("%s %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i).c_str(), -// m_hparams[i].det.c_str()); - Banks[i].init(i,(m_hparams[i].s_max < 0)); - if (m_hparams[i].n_bin == -2) - { - printf("WARNING: No Histogram Options for Bank %s\n",LHCb::RawBank::typeName( (LHCb::RawBank::BankType) i - ).c_str()); - } - Banks[i].nohist = (m_hparams[i].n_bin <= 0); - } - for(i = 0 ; i != (int) LHCb::RawBank::LastType; i++) - { - int idx; - idx = i; - if (Banks[i].isError) - { + for( int i = 0 ; i != Tell1Bank::LastType; i++) { + Banks[i].init(i,(m_hparams[i].s_max < 0)); + if (m_hparams[i].n_bin == -2) { + std::string bt = Tell1Printout::bankType(Tell1Bank::BankType(i)); + warning() << "No Histogram Options for Bank " << bt << endmsg; + } + Banks[i].nohist = (m_hparams[i].n_bin <= 0); + } + for(int i = 0 ; i != (int) Tell1Bank::LastType; i++) { + int idx = i; + if (Banks[i].isError) { idx = Banks[i].rootbankidx; } - if (!Banks[i].nohist) - { - double binw = (m_hparams[i].xmax - m_hparams[i].xmin)/m_hparams[i].n_bin; - Banks[i].xmin = m_hparams[i].xmin; - Banks[i].xmax = m_hparams[i].xmax; - Banks[i].binw = binw; - if (((int)binw % 4) != 0) - { - printf("Binwidth for %s not a multiple of 4. %f\n",Banks[i].name.c_str(),binw); - } - Banks[i].nbin = m_hparams[i].n_bin; - for (hindx = 0; hindx < HISTPERHIST;hindx++) - { - Banks[i].h[hindx] = histoSvc()->book( Banks[i].h_name[hindx],Banks[i].name+" Size in Bytes"+titqual[hindx],m_hparams[i].n_bin, - m_hparams[i].xmin,m_hparams[i].xmax); - declareInfo(Banks[i].h_name[hindx], Banks[i].h[hindx],Banks[i].name+" Size in Bytes"+titqual[hindx]); - } + if (!Banks[i].nohist) { + double binw = (m_hparams[i].xmax - m_hparams[i].xmin)/m_hparams[i].n_bin; + Banks[i].xmin = m_hparams[i].xmin; + Banks[i].xmax = m_hparams[i].xmax; + Banks[i].binw = binw; + if (((int)binw % 4) != 0) { + info() << "Binwidth for " << Banks[i].name << " not a multiple of 4. " << binw << endmsg; + } + Banks[i].nbin = m_hparams[i].n_bin; + for (int hindx = 0; hindx < HISTPERHIST;hindx++) { + Banks[i].h[hindx] = histoSvc()->book( Banks[i].h_name[hindx], + Banks[i].name+" Size in Bytes"+titqual[hindx],m_hparams[i].n_bin, + m_hparams[i].xmin,m_hparams[i].xmax); + declareInfo(Banks[i].h_name[hindx], Banks[i].h[hindx],Banks[i].name+" Size in Bytes"+titqual[hindx]); + } } - else - { - printf("INFO: No Histogram booked for Bank %s\n",Banks[i].name.c_str()); + else { + info() << "No Histogram booked for Bank " << Banks[i].name << endmsg; } - if (!Banks[i].noprofile) - { - for (hindx=0;hindx<HISTPERHIST;hindx++) - { - Banks[i].p[hindx] = histoSvc()->bookProf( Banks[i].p_name[hindx],Banks[i].name+" Size vs. SourceID"+titqual[hindx], - m_hparams[idx].s_max-m_hparams[idx].s_min+1, - (float)m_hparams[idx].s_min,(float)m_hparams[idx].s_max); - declareInfo(Banks[i].p_name[hindx], Banks[i].p[hindx],Banks[i].name+" Size vs. SourceID"+titqual[hindx]); + if (!Banks[i].noprofile) { + for (int hindx=0; hindx<HISTPERHIST; hindx++) { + Banks[i].p[hindx] = histoSvc()->bookProf( Banks[i].p_name[hindx],Banks[i].name+" Size vs. SourceID"+titqual[hindx], + m_hparams[idx].s_max-m_hparams[idx].s_min+1, + (float)m_hparams[idx].s_min,(float)m_hparams[idx].s_max); + declareInfo(Banks[i].p_name[hindx], Banks[i].p[hindx],Banks[i].name+" Size vs. SourceID"+titqual[hindx]); } } - else + else { + info() << "No Profile booked for Bank " << Banks[i].name << endmsg; + } + } + m_totsize.xmin = m_totevpar.xmin; + m_totsize.xmax = m_totevpar.xmax; + m_totsize.nbin = m_totevpar.n_bin; + m_totsize.binw = (m_totsize.xmax-m_totsize.xmin)/m_totsize.nbin; + if (((int)m_totsize.binw % 4) != 0) { - printf("INFO: No Profile booked for Bank %s\n",Banks[i].name.c_str()); + // Beat: This is wrong and was Banks[i], which clearly accesses bad memory! + printf("Binwidth for %s not a multiple of 4. %f\n",Banks[0].name.c_str(),m_totsize.binw); } - } - totsize.xmin = m_totevpar.xmin; - totsize.xmax = m_totevpar.xmax; - totsize.nbin = m_totevpar.n_bin; - totsize.binw = (totsize.xmax-totsize.xmin)/totsize.nbin; - if (((int)totsize.binw % 4) != 0) - { - // Beat: This is wrong and was Banks[i], which clearly accesses bad memory! - printf("Binwidth for %s not a multiple of 4. %f\n",Banks[0].name.c_str(),totsize.binw); - } - for (hindx=0;hindx<HISTPERHIST;hindx++) - { - h_totev[hindx] = histoSvc()->book( "TotSize"+namqual[hindx],"Total Event Size in Bytes"+titqual[hindx],m_totevpar.n_bin, - m_totevpar.xmin,m_totevpar.xmax); - declareInfo("TotSize"+namqual[hindx], h_totev[hindx],"Total Event Size in Bytes"+titqual[hindx]); - h_HLTratio[hindx] = histoSvc()->book( "HLTRatio"+namqual[hindx],"Ratio HLT Total Size"+titqual[hindx],m_HLTratiopar.n_bin, - m_HLTratiopar.xmin,m_HLTratiopar.xmax); - declareInfo("HLTRatio"+namqual[hindx], h_HLTratio[hindx],"Ratio HLT Total Size"+titqual[hindx]); - p_banks[hindx] = histoSvc()->bookProf("Banksp"+namqual[hindx],"Bank Size vs. Bank Number"+titqual[hindx], - LHCb::RawBank::LastType+1, -1.0, (float)LHCb::RawBank::LastType); - declareInfo("Banksp"+namqual[hindx],p_banks[hindx],"Bank Size vs. Bank Number"+titqual[hindx]); - } - for (dethmiter j=m_dethparams.begin();j!=m_dethparams.end();j++) - { - detbmiter bd = m_detectors.find(j->first); - bd->second->xmin = j->second->xmin; - bd->second->xmax = j->second->xmax; - bd->second->nbin = j->second->n_bin; - bd->second->binw = (j->second->xmax-j->second->xmin)/j->second->n_bin; - if (((int)bd->second->binw % 4) != 0) - { - // Beat: This is wrong and was Banks[i], which clearly accesses bad memory! - printf("Binwidth for %s not a multiple of 4. %f\n",Banks[0].name.c_str(),bd->second->binw); - } - for (hindx=0;hindx<HISTPERHIST;hindx++) - { - bd->second->h[hindx] = histoSvc()->book("Total_"+j->first+namqual[hindx],"Total Size for "+j->first+" in Bytes"+titqual[hindx], - j->second->n_bin, j->second->xmin,j->second->xmax); - declareInfo("Total_"+j->first+namqual[hindx], bd->second->h[hindx],"Total Size for "+j->first+" in Bytes"+titqual[hindx]); - } - } - m_firstevent = true; - n_ev = 0; + for(int hindx = 0; hindx<HISTPERHIST; hindx++ ) { + h_totev[hindx] = histoSvc()->book("TotSize"+namqual[hindx], + "Total Event Size in Bytes"+titqual[hindx], + m_totevpar.n_bin, m_totevpar.xmin,m_totevpar.xmax); + declareInfo("TotSize"+namqual[hindx], + h_totev[hindx], + "Total Event Size in Bytes"+titqual[hindx]); + + h_HLTratio[hindx] = histoSvc()->book( "HLTRatio"+namqual[hindx],"Ratio HLT Total Size"+titqual[hindx],m_HLTratiopar.n_bin, + m_HLTratiopar.xmin,m_HLTratiopar.xmax); + declareInfo("HLTRatio"+namqual[hindx], h_HLTratio[hindx],"Ratio HLT Total Size"+titqual[hindx]); + p_banks[hindx] = histoSvc()->bookProf("Banksp"+namqual[hindx],"Bank Size vs. Bank Number"+titqual[hindx], + Tell1Bank::LastType+1, -1.0, (float)Tell1Bank::LastType); + declareInfo("Banksp"+namqual[hindx],p_banks[hindx],"Bank Size vs. Bank Number"+titqual[hindx]); + } + for (const auto& j : m_dethparams ) { + detbmiter bd = m_detectors.find(j.first); + bd->second->xmin = j.second->xmin; + bd->second->xmax = j.second->xmax; + bd->second->nbin = j.second->n_bin; + bd->second->binw = (j.second->xmax-j.second->xmin)/j.second->n_bin; + if (((int)bd->second->binw % 4) != 0) { + // Beat: This is wrong and was Banks[i], which clearly accesses bad memory! + info() << "Binwidth for " << Banks[0].name << " not a multiple of 4. " << bd->second->binw << endmsg; + } + for (int hindx=0; hindx<HISTPERHIST; hindx++) { + bd->second->h[hindx] = histoSvc()->book("Total_"+j.first+namqual[hindx], + "Total Size for "+j.first+" in Bytes"+titqual[hindx], + j.second->n_bin, j.second->xmin,j.second->xmax); + declareInfo("Total_"+j.first+namqual[hindx], + bd->second->h[hindx], + "Total Size for "+j.first+" in Bytes"+titqual[hindx]); + } + } return StatusCode::SUCCESS; } +//============================================================================= +// Finalization +//============================================================================= +StatusCode RawBankSizes::finalize() { + return StatusCode::SUCCESS; +} //============================================================================= // Main execution //============================================================================= -StatusCode RawBankSizes::execute() -{ -// int bsize[LHCb::RawBank::LastType]; - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg; - - // get RawEvent - if( exist<LHCb::RawEvent>( LHCb::RawEventLocation::Default ) ) - { - m_rawEvt= get<LHCb::RawEvent>( LHCb::RawEventLocation::Default ); - } - else - { - Warning( "rawEvent not found at location '" + rootInTES() + LHCb::RawEventLocation::Default ).ignore(); +StatusCode RawBankSizes::execute(const EventContext& /* context */) const { + const evt_data_t* event = m_rawData.get(); + int runno = 100; + if ( !event ) { + MsgStream msg(msgSvc(), name()); + msg << MSG::WARNING << "rawEvent not found at location '" << m_rawData << endmsg; return StatusCode::SUCCESS; } - n_ev++; - int tots; - tots = 0; - int bnkid=0; - bool nolumi=false; - for (detbmiter j=m_detectors.begin();j!=m_detectors.end();j++) - { - j->second->sum = 0.0; + for( const auto& b : *event ) { + const auto* hdr = b.first; + if ( hdr->type() == Tell1Bank::ODIN ) { + auto* This = const_cast<RawBankSizes*>(this); + if ( hdr->version() < 7 ) { + const RunInfo* odin = (const RunInfo*)b.second; + runno = odin->run_number(); + } + else { + const pcie40::sodin_t* odin = (const pcie40::sodin_t*)b.second; + runno = odin->run_number(); + } + return This->fill_histos(*event, runno); + } } + /// No ODIN Bank. Contrinue execution + return StatusCode::SUCCESS; +} - for(auto it = m_bankTypes.begin(); it!=m_bankTypes.end(); it++) - { - Banks[*it].siz = 0.0; - } - auto daq_banks = m_rawEvt->banks(RawBank::DAQ); - nolumi = true; - for(const auto* b : daq_banks) - { - if (b->version() == DAQ_STATUS_BANK) - { +StatusCode RawBankSizes::fill_histos(const evt_data_t& data, int /* runno */) { + size_t tot_sum = 0; + bool nolumi = true; + std::lock_guard<std::mutex> lock(m_mutex); + + for( const auto& j : m_detectors ) + j.second->sum = 0.0; + + for( const auto& type : m_bankTypes ) + Banks[type].siz = 0.0; + + for( const auto& dsc : data ) { + const auto* b = dsc.first; +#if 0 + if (b->version() == DAQ_STATUS_BANK) { auto *h = (Online::EventHeader*)b->begin<Online::EventHeader>(); auto trMask = h->subHeader().H1->triggerMask(); // printf("Trigger Mask %0x %0x %0x %0x\n",trMask[0],trMask[1],trMask[2],trMask[3]); - if ((trMask[1] & 0x10000) != 0) - { + if ((trMask[1] & 0x10000) != 0) { nolumi = false; } break; } - } - - for(auto typ : m_bankTypes ) - { - auto banks= m_rawEvt->banks( typ ); - for(auto* ib : banks) - { - bnkid = ib->type(); - int id; - id = bnkid; - tots += ib->size(); - Banks[id].siz += ib->size(); - if (!Banks[id].noprofile) - { - Banks[id].p[0]->fill( (double) ib->sourceID() , (double) ib->size()); - if (nolumi) - { - Banks[id].p[1]->fill( (double) ib->sourceID() , (double) ib->size()); - } - else - { - Banks[id].p[2]->fill( (double) ib->sourceID() , (double) ib->size()); - } +#endif + if ( b->type() == Tell1Bank::HltRoutingBits ) { + const auto* trMask = (const unsigned int*)dsc.second; + if ( (trMask[1] & 0x10000) != 0 ) { + nolumi = false; } + break; } + } + for( const auto& dsc : data ) { + const BankHeader* b = dsc.first; + int id = b->type(); + tot_sum += b->size(); + Banks[id].siz += b->size(); + if ( !Banks[id].noprofile ) { + Banks[id].p[0]->fill((double)b->sourceID(), (double)b->size()); + Banks[id].p[nolumi ? 1 : 2]->fill((double)b->sourceID(), (double)b->size()); + } + } - if (Banks[typ].siz > 0.0) - { + for( auto typ : m_bankTypes ) { + if ( Banks[typ].siz > 0.0 ) { double x = Banks[typ].siz; - if (!Banks[typ].nohist) - { -/* - if (x <Banks[typ].xmin) - { - x = Banks[typ].xmin-Banks[typ].binw/2.0; - } - else if(x > Banks[typ].xmax) - { - x = Banks[typ].xmax+Banks[typ].binw/2.0; - } -*/ + if ( !Banks[typ].nohist ) { Banks[typ].h[0]->fill(x); - if (nolumi) - { - Banks[typ].h[1]->fill(x); - } - else - { - Banks[typ].h[2]->fill(x); - } + Banks[typ].h[nolumi ? 1 : 2]->fill(x); } p_banks[0]->fill((double)(typ),Banks[typ].siz); - if (nolumi) - { - p_banks[1]->fill((double)(typ),Banks[typ].siz); - } - else - { - p_banks[2]->fill((double)(typ),Banks[typ].siz); - } - + p_banks[nolumi ? 1 : 2]->fill((double)(typ),Banks[typ].siz); } } - for(auto typ : m_bankTypes ) - { - std::string d = m_hparams[typ].det; + + for(auto typ : m_bankTypes ) { + const std::string& d = m_hparams[typ].det; detbmiter j = m_detectors.find(d); j->second->sum += Banks[typ].siz; } - for (detbmiter j=m_detectors.begin();j!=m_detectors.end();j++) - { + for (detbmiter j=m_detectors.begin();j!=m_detectors.end();j++) { double x = j->second->sum; - if (x>0) - { -/* - if (j->second->sum < j->second->xmin) - { - x = j->second->xmin+j->second->binw/2.0; - } - else if(j->second->sum > j->second->xmax) - { - x = j->second->xmax-j->second->binw/2.0; - } -*/ + if ( x > 0 ) { j->second->h[0]->fill(x); - if (nolumi) - { - j->second->h[1]->fill(x); - } - else - { - j->second->h[2]->fill(x); - } + j->second->h[nolumi ? 1 : 2]->fill(x); } } - - double total = tots; - if (total >0) - { - detbmiter j = m_detectors.find("HLT"); - double rat = j->second->sum/total; + double total = tot_sum; + if ( total > 0 ) { + detbmiter j = m_detectors.find("HLT"); + double rat = j->second->sum/total; h_totev[0]->fill(total); h_HLTratio[0]->fill(rat); - if (nolumi) - { - h_totev[1]->fill(total); - h_HLTratio[1]->fill(rat); - } - else - { - h_totev[2]->fill(total); - h_HLTratio[2]->fill(rat); - } + h_totev[nolumi ? 1 : 2]->fill(total); + h_HLTratio[nolumi ? 1 : 2]->fill(rat); } return StatusCode::SUCCESS; } - - -//============================================================================= -// Finalize -//============================================================================= -StatusCode RawBankSizes::finalize() -{ - printf("Number of Events Seen %d\n",n_ev); - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg; - - return GaudiHistoAlg::finalize(); // must be called after all other actions -} - -//============================================================================= diff --git a/Online/RawBankSizes/src/SPDMult.cpp b/Online/RawBankSizes/src/SPDMult.cpp deleted file mode 100644 index 9d12927aab5573032e70ec644b394151acf76c43..0000000000000000000000000000000000000000 --- a/Online/RawBankSizes/src/SPDMult.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// $Id: RawBankSizes.cpp,v 1.18 2010-09-25 21:31:08 frankb Exp $ -// Include files - -// from Gaudi -#include <vector> -#include <map> -#include <string> -#include <utility> -#include "RawBankSizes/SPDMult.h" -#include "MDF/OnlineRunInfo.h" -#include "MDF/MDFHeader.h" -//#include "Event/ODIN.h" - -// local - -//----------------------------------------------------------------------------- -// Implementation file for class : RawBankSizes -// -// 2008-03-27 : Olivier Deschamps -//----------------------------------------------------------------------------- - -// Declaration of the Algorithm Factory -DECLARE_COMPONENT( LHCb::SPDMult ) - -using namespace LHCb; - -//============================================================================= -// Standard constructor, initializes variables -//============================================================================= -SPDMult::SPDMult( const std::string& name, - ISvcLocator* pSvcLocator) - : GaudiHistoAlg ( name , pSvcLocator ) -{ - m_SPDMultHist = 0; - m_rawEvt = 0; -} -//============================================================================= -// Destructor -//============================================================================= -SPDMult::~SPDMult() -{ -} - -StatusCode SPDMult::initialize() -{ - StatusCode sc = GaudiHistoAlg::initialize(); // must be executed first - if ( sc.isFailure() ) return sc; // error printed already by GaudiHistoAlg - - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg; - m_SPDMultHist = histoSvc()->book( "SPDMultiplicity","SPD Multiplicity Distribution",1000, - 0.0,20000.0); - declareInfo(name()+"/SPDMulti", m_SPDMultHist,"SPD Multiplicity Spectrum"); - return StatusCode::SUCCESS; -} - -//============================================================================= -// Main execution -//============================================================================= -StatusCode SPDMult::execute() -{ -// int bsize[LHCb::RawBank::LastType]; - if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg; - - // get RawEvent - if( exist<LHCb::RawEvent>( LHCb::RawEventLocation::Default ) ) - { - m_rawEvt= get<LHCb::RawEvent>( LHCb::RawEventLocation::Default ); - } - else - { - Warning( "rawEvent not found at location '" + rootInTES() + LHCb::RawEventLocation::Default ).ignore(); - return StatusCode::SUCCESS; - } - double spdm; - - auto daq_banks= m_rawEvt->banks(RawBank::L0DU); - for(const auto* b : daq_banks) - { - const unsigned int *h = b->data(); - unsigned int w14 = h[15]; - int spdmult = (w14>>14) & 0x3fff; - spdm = double(spdmult); - m_SPDMultHist->fill(spdm); - break; - } - - return StatusCode::SUCCESS; -} - - -//============================================================================= -// Finalize -//============================================================================= -StatusCode SPDMult::finalize() -{ - return GaudiHistoAlg::finalize(); // must be called after all other actions -} - -//============================================================================= diff --git a/Online/RawBankSizes/src/Structure.cpp b/Online/RawBankSizes/src/Structure.cpp index 87febedda31ff1700e827502af56f047f6e3872c..3c34886cd321d06559e9958b879de8e6e83553a5 100644 --- a/Online/RawBankSizes/src/Structure.cpp +++ b/Online/RawBankSizes/src/Structure.cpp @@ -22,29 +22,23 @@ // stream it! // ============================================================================ -std::ostream& Gaudi::Utils::toStream -( const HParam::HistParams& o , - std::ostream& s ) -{ +std::ostream& Gaudi::Utils::toStream(const HParam::HistParams& o, std::ostream& s) { return s << "( " << o.n_bin << " , " << o.xmin << " , " << o.xmax << " , " - << o.s_min << " , " - << o.s_max << " , " - << "\"detector\"" //o.det + << o.s_min << " , " + << o.s_max << " , " + << '"' << o.det << '"' << " )" ; } // ============================================================================ -namespace Gaudi -{ +namespace Gaudi { // ========================================================================== - namespace Parsers - { + namespace Parsers { // ======================================================================== template< typename Iterator, typename Skipper> - class BeatGrammar: - public qi::grammar<Iterator, HParam::HistParams(), Skipper> + class BeatGrammar : public qi::grammar<Iterator, HParam::HistParams(), Skipper> { public: // ====================================================================== @@ -59,58 +53,51 @@ namespace Gaudi struct Operations { // Some magic: template <typename A, typename B = boost::fusion::unused_type, - typename C = boost::fusion::unused_type, - typename D = boost::fusion::unused_type> + typename C = boost::fusion::unused_type, + typename D = boost::fusion::unused_type> struct result { typedef void type; }; // Actions: // -------------------------------------------------------------------- - void operator()(HParam::HistParams& val, const int bin, - tag_bin) const { - val.n_bin = bin; + void operator()(HParam::HistParams& val, const int bin, tag_bin) const { + val.n_bin = bin; } - void operator()(HParam::HistParams& val, const float x, - tag_min) const { - val.xmin = x; + void operator()(HParam::HistParams& val, const float x, tag_min) const { + val.xmin = x; } - void operator()(HParam::HistParams& val, const float x, - tag_max) const { - val.xmax = x; + void operator()(HParam::HistParams& val, const float x, tag_max) const { + val.xmax = x; } - void operator()(HParam::HistParams& val, const int smin, - tag_smin) const { - val.s_min = smin; + void operator()(HParam::HistParams& val, const int smin, tag_smin) const { + val.s_min = smin; } - void operator()(HParam::HistParams& val, const int smax, - tag_smax) const { - val.s_max = smax; + void operator()(HParam::HistParams& val, const int smax, tag_smax) const { + val.s_max = smax; } - void operator()(HParam::HistParams& val, - const std::string& d) const { - val.det = d; + void operator()(HParam::HistParams& val, const std::string& d) const { + val.det = d; } }; public: - BeatGrammar() : BeatGrammar::base_type(para) - { - para = qi::lit('[') - >> qi::int_[op(qi::_val, qi::_1, tag_bin())] - >> ',' - >> qi::float_[op(qi::_val, qi::_1, tag_min())] - >> ',' - >> qi::float_[op(qi::_val, qi::_1, tag_max())] - >> ',' - >> qi::int_[op(qi::_val, qi::_1, tag_smin())] - >> ',' - >> qi::int_[op(qi::_val, qi::_1, tag_smax())] - >> ',' - >> det [op(qi::_val, qi::_1)] - >> ']' ; + BeatGrammar() : BeatGrammar::base_type(para) { + para = qi::lit('(') + >> qi::int_[op(qi::_val, qi::_1, tag_bin())] + >> ',' + >> qi::float_[op(qi::_val, qi::_1, tag_min())] + >> ',' + >> qi::float_[op(qi::_val, qi::_1, tag_max())] + >> ',' + >> qi::int_[op(qi::_val, qi::_1, tag_smin())] + >> ',' + >> qi::int_[op(qi::_val, qi::_1, tag_smax())] + >> ',' + >> det [op(qi::_val, qi::_1)] + >> ')' ; } qi::rule<Iterator, HParam::HistParams(), Skipper> para; StringGrammar<Iterator, Skipper> det; @@ -125,9 +112,7 @@ namespace Gaudi // ============================================================================ // parse it! // ============================================================================ -StatusCode Gaudi::Parsers::parse -( HParam::HistParams& result , - const std::string& input ) +StatusCode Gaudi::Parsers::parse(HParam::HistParams& result, const std::string& input) { return parse_(result, input); } diff --git a/Online/SmiController/scripts/runTask.sh b/Online/SmiController/scripts/runTask.sh index e903e78ec4f3abc3f6339d68bafe285341808713..6a8629f02a973983e98781f2be7b975952003d28 100755 --- a/Online/SmiController/scripts/runTask.sh +++ b/Online/SmiController/scripts/runTask.sh @@ -27,8 +27,7 @@ fi; export CMTCONFIG=x86_64_v2-centos7-gcc10-opt; export CMTCONFIG=x86_64_v2-centos7-gcc10-do0; # -#. /group/online/dataflow/cmtuser/OnlineRelease/setup.${CMTCONFIG}.vars; -. /home/frankm/upgrade_sw/ONLINE_v7r9/setup.${CMTCONFIG}.vars; +. /group/online/dataflow/cmtuser/OnlineRelease/setup.${CMTCONFIG}.vars; . ${FARMCONFIGROOT}/job/createEnvironment.sh $*; # export GEN_OPTIONS=/group/online/dataflow/options/${PARTITION}/MONITORING; diff --git a/Online/SmiController/src/SmiController.cpp b/Online/SmiController/src/SmiController.cpp index 6952f83395518e9dd0076d3740b51fd605557b22..62811678820f009c9c65d7261cb63956afd65b03 100644 --- a/Online/SmiController/src/SmiController.cpp +++ b/Online/SmiController/src/SmiController.cpp @@ -161,6 +161,13 @@ void SmiController::NodeProxy::invoke_transition(const std::string& cmd) { controller->m_state = ""; controller->declare_state(tmp); } + else if ( cmd == "error" ) { + auto& log = controller->logger(); + controller->set_target_state(State::ERROR); + controller->declare_state(controller->target_state()); + log.warning("User requested transition to ERROR: %s [%s]", + cmd.c_str(), controller->state().c_str()); + } else { auto& log = controller->logger(); log.error("NodeProxy: Unknown transition request: %s",cmd.c_str()); @@ -1125,9 +1132,9 @@ void SmiController::check_for_completion() { //============================================================================== /// Invoke single transition request on SMI machinery -SmiErrCond SmiController::invoke_transition(const string& cmd) { - if ( !cmd.empty() ) { - string command = RTL::str_upper(cmd); +SmiErrCond SmiController::invoke_transition(const string& command) { + if ( !command.empty() ) { + string cmd = RTL::str_lower(command); if ( cmd == Transition::LOAD ) { IocSensor::instance().send(this, CONTROLLER_LOAD_TASKS, this); return SMI_CONTROLLER_SUCCESS; @@ -1161,8 +1168,17 @@ SmiErrCond SmiController::invoke_transition(const string& cmd) { set_target_state(State::UNKNOWN); IocSensor::instance().send(this, TaskProxy::TASK_LIMBO, this); } - else + else if ( cmd == "error" ) { + set_target_state(State::ERROR); + declare_state(m_target_state); + m_log->warning("User requested transition to ERROR: %s [%s]", + cmd.c_str(), m_state.c_str()); + m_self->setState(m_state.c_str()); + return SMI_CONTROLLER_SUCCESS; + } + else { m_log->warning("Unknown transition: '%s'",cmd.c_str()); + } declare_state(m_target_state); IocSensor::instance().send(this, CONTROLLER_SETSTATE, nullptr); return SMI_CONTROLLER_SUCCESS; @@ -1319,7 +1335,7 @@ void SmiController::run() { env.emplace_back(environ[i]); } env.emplace_back(nullptr); - ::execvpe("gentest.exe",(char**)args, (char**)&env[0]); + ::execvpe("genRunner.exe",(char**)args, (char**)&env[0]); m_log->error("Failed to execvp to smiSM! [%s]", ::strerror(errno)); ::exit(errno); } diff --git a/Online/SmiController/src/SmiTaskConfiguration.cpp b/Online/SmiController/src/SmiTaskConfiguration.cpp index c685f31c8825ea7a72bcc7712d1b73b590a575e8..81eada00624c2fe64e70295629084c891d93f1c4 100644 --- a/Online/SmiController/src/SmiTaskConfiguration.cpp +++ b/Online/SmiController/src/SmiTaskConfiguration.cpp @@ -98,18 +98,19 @@ std::map<std::string,SmiTask*> SmiTaskConfiguration::taskList(int bind_cpu, int Tasklist::Task* t = *i; long instances = t->instances; string arguments = t->arguments(), fmc_start = t->fmcStartParams(), utgid=t->utgid; - fmc_start = RTL::str_replace(fmc_start, "${NODE}", node); - fmc_start = RTL::str_replace(fmc_start, "${PARTITION}", m_partition); - fmc_start = RTL::str_replace(fmc_start, "${RUNINFO}", m_runinfo); - fmc_start = RTL::str_replace(fmc_start, "${NAME}", t->name); - arguments = RTL::str_replace(arguments, "${NODE}", node); - arguments = RTL::str_replace(arguments, "${PARTITION}", m_partition); - arguments = RTL::str_replace(arguments, "${RUNINFO}", m_runinfo); - arguments = RTL::str_replace(arguments, "${NAME}", t->name); - utgid = RTL::str_replace(utgid, "${NODE}", node); - utgid = RTL::str_replace(utgid, "${PARTITION}", m_partition); - utgid = RTL::str_replace(utgid, "${RUNINFO}", m_runinfo); - utgid = RTL::str_replace(utgid, "${NAME}", t->name); + fmc_start = RTL::str_replace(fmc_start, "${NODE}", node); + fmc_start = RTL::str_replace(fmc_start, "${PARTITION}", m_partition); + fmc_start = RTL::str_replace(fmc_start, "${RUNINFO}", m_runinfo); + fmc_start = RTL::str_replace(fmc_start, "${NAME}", t->name); + arguments = RTL::str_replace(arguments, "${NODE}", node); + arguments = RTL::str_replace(arguments, "${PARTITION}", m_partition); + arguments = RTL::str_replace(arguments, "${RUNINFO}", m_runinfo); + arguments = RTL::str_replace(arguments, "${NAME}", t->name); + arguments = RTL::str_replace(arguments, "${ARCHITECTURE}", m_config); + utgid = RTL::str_replace(utgid, "${NODE}", node); + utgid = RTL::str_replace(utgid, "${PARTITION}", m_partition); + utgid = RTL::str_replace(utgid, "${RUNINFO}", m_runinfo); + utgid = RTL::str_replace(utgid, "${NAME}", t->name); map<int,int> num_instance, init_instance, task_instance; // Init counters diff --git a/Online/Storage/CMakeLists.txt b/Online/Storage/CMakeLists.txt index 7d092becfa9ffd5dc6b81e15ec3cc1d3d2627eef..2a703c5263c5edca3a8fd691a3966697d82c0528 100644 --- a/Online/Storage/CMakeLists.txt +++ b/Online/Storage/CMakeLists.txt @@ -29,16 +29,16 @@ find_package(MySQL) # REQUIRED) include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) # gaudi_add_library(StorageClient src/client/*.cpp - INCLUDE_DIRS Boost HTTP + INCLUDE_DIRS Boost HTTP OnlineBase PUBLIC_HEADERS Storage - LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt z Boost HTTP) + LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt z Boost HTTP OnlineBase) # target_compile_definitions(StorageClient PRIVATE -DSTORAGECLIENT=1) # gaudi_add_library(StorageServer src/server/*.cpp - INCLUDE_DIRS Boost HTTP sqldb dim SQLite3 MySQL + INCLUDE_DIRS Boost HTTP sqldb dim SQLite3 MySQL OnlineBase NO_PUBLIC_HEADERS - LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt z dim SQLite3 sqldb_sqlite Boost HTTP StorageClient) + LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt z dim SQLite3 sqldb_sqlite Boost HTTP StorageClient OnlineBase) # target_compile_definitions(StorageServer PRIVATE -DSTORAGECLIENT=1) if (MYSQL_FOUND) @@ -51,6 +51,6 @@ endif() gaudi_add_library(StorageCli tests/src/*.cpp INCLUDE_DIRS Boost HTTP sqldb SQLite3 NO_PUBLIC_HEADERS - LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt z Boost HTTP StorageClient) + LINK_LIBRARIES ${CMAKE_DL_LIBS} -lrt z Boost HTTP StorageClient OnlineBase) # gaudi_add_test(QMTest QMTEST) diff --git a/Online/Storage/Storage/client.h b/Online/Storage/Storage/client.h index 77518766db93f5743e9744e986d1089ef8bdc079..c40a73b86f43b7fd33ba1f00bdd51c8f11171169 100644 --- a/Online/Storage/Storage/client.h +++ b/Online/Storage/Storage/client.h @@ -78,7 +78,7 @@ namespace Online { const std::vector<header_t>& headers) const; /// Open connection to server - virtual boost::system::error_code open() const = 0; + virtual std::error_code open() const = 0; /// Exec generic statement virtual reply_t request(const std::string& cmd, const std::string& url, const reqheaders_t& headers=reqheaders_t()) const = 0; /// Connect client to given URI and execute an HTTP GET diff --git a/Online/Storage/Storage/client_async.h b/Online/Storage/Storage/client_async.h index 82e3fab8272801b74a97e728722f919cf19cfd23..52f1fe743e40d8d6f5f04c2b7d1e0bcac6b33318 100644 --- a/Online/Storage/Storage/client_async.h +++ b/Online/Storage/Storage/client_async.h @@ -17,7 +17,6 @@ /// Framework include files #include <Storage/client.h> -#include <Storage/communication.h> /// C/C++ include files #include <vector> @@ -64,7 +63,7 @@ namespace Online { virtual ~client_async(); /// Set the caller properties - virtual boost::system::error_code open() const override; + virtual std::error_code open() const override; /// Exec generic statement virtual reply_t request(const std::string& cmd, const std::string& url, const reqheaders_t& headers=reqheaders_t()) const override; diff --git a/Online/Storage/Storage/client_sync.h b/Online/Storage/Storage/client_sync.h index 8fe6168f7b7ddee7dfbd0bbcd9101eacd2aa4229..0e0d4b4a6c7542d49389c6ac30cbbb0947120081 100644 --- a/Online/Storage/Storage/client_sync.h +++ b/Online/Storage/Storage/client_sync.h @@ -17,7 +17,6 @@ /// Framework include files #include <Storage/client.h> -#include <Storage/communication.h> /// C/C++ include files #include <vector> @@ -64,7 +63,7 @@ namespace Online { virtual ~client_sync(); /// Set the caller properties - virtual boost::system::error_code open() const override; + virtual std::error_code open() const override; /// Exec generic statement virtual reply_t request(const std::string& cmd, const std::string& url, diff --git a/Online/Storage/Storage/communication.h b/Online/Storage/Storage/communication.h index fb343dcd9450d1be67ec9fef00a61077c5221065..4e18e52b652f3c13215adb09704ccd6292ef7827 100644 --- a/Online/Storage/Storage/communication.h +++ b/Online/Storage/Storage/communication.h @@ -19,14 +19,11 @@ #include <string> #include <vector> #include <chrono> +#include <system_error> -// Boost inlcude files -#include <boost/asio.hpp> - -// Framework include files +// Framework include files. Careful: Do not import BOOST dependencies here! #include <HTTP/Uri.h> #include <HTTP/HttpHeader.h> -#include <HTTP/HttpRequest.h> #include <HTTP/HttpReply.h> /// Namespace for the http server and client apps @@ -40,16 +37,12 @@ namespace Online { /// Namespace for the storage implementation namespace storage { - bool error_code_ok(const boost::system::error_code& ec, bool debug=true); - + bool error_code_ok(const std::error_code& ec, bool debug=true); typedef http::Uri uri_t; typedef http::HttpConnection connection_t; typedef http::HttpHeader header_t; - typedef http::HttpRequest request_t; typedef http::HttpReply reply_t; using http::to_vector; - using http::to_buffers; - } // End namespace storage } // End namespace Online #endif // ONLINE_STORAGE_COMMUNICATION_H diff --git a/Online/Storage/Storage/fdb_client.h b/Online/Storage/Storage/fdb_client.h index 9059d94a4f969543a42165b2feaf5f25c4d00e52..4fa53959a3eadd573edff5704f12d139c04ccf33 100644 --- a/Online/Storage/Storage/fdb_client.h +++ b/Online/Storage/Storage/fdb_client.h @@ -61,9 +61,9 @@ namespace Online { fdb_client& operator = (const fdb_client& copy) = delete; /// Save object record to database and return the location to store the data - reply_t save_object_record(const std::string& location, std::string& url, std::size_t len); + reply_t save_object_record(const std::string& location, std::string& url, std::size_t len, const client::reqheaders_t& opts={}); /// Save object data to disk at the specified location - reply_t save_object_data(const std::string& location, const void* data, std::size_t len); + reply_t save_object_data(const std::string& location, const void* data, std::size_t len, const client::reqheaders_t& opts={}); /// Save object data to disk at the specified location reply_t save_object(const std::string& location, std::vector<unsigned char>&& data); /// Save object data to disk at the specified location diff --git a/Online/Storage/Storage/fdb_dbase.h b/Online/Storage/Storage/fdb_dbase.h index 9ca7bd1b05b3125382bc993f450abe38138f2247..c6030864cc2b9fe90efd7ddebd18802861a85b19 100644 --- a/Online/Storage/Storage/fdb_dbase.h +++ b/Online/Storage/Storage/fdb_dbase.h @@ -15,14 +15,12 @@ #ifndef ONLINE_STORAGE_FDB_DBASE_H #define ONLINE_STORAGE_FDB_DBASE_H -/// Framework include files - -// Boost include files -#include <boost/system/error_code.hpp> - /// C/C++ include files #include <mutex> #include <string> +#include <memory> +#include <vector> +#include <system_error> /// Online Namespace namespace Online { @@ -44,7 +42,7 @@ namespace Online { public: /// Static constructor for concrete implementations template <typename T, typename... Args> - static std::unique_ptr<fdb_dbase_t> create(Args... args); + static std::unique_ptr<fdb_dbase_t> create(Args... args); public: @@ -80,8 +78,8 @@ namespace Online { int _debug { 0 }; /// Check the existence of a given object in the database - virtual boost::system::error_code - query_file(const std::string& object_name, file_t& file, int state) = 0; + virtual std::error_code + query_file(const std::string& object_name, file_t& file, int state) = 0; public: @@ -92,28 +90,28 @@ namespace Online { virtual ~handler_t(); /// Check the existence of a given object in the database - virtual boost::system::error_code query(std::string& object, - std::string& host, - std::string& date, - std::size_t& length); + virtual std::error_code query(std::string& object, + std::string& host, + std::string& date, + std::size_t& length); /// Check the existence of a given object in the database - virtual boost::system::error_code next( std::string& object, - std::string& host, - std::string& date, - std::size_t& length); + virtual std::error_code next( std::string& object, + std::string& host, + std::string& date, + std::size_t& length); /// Add a new object to the database - virtual boost::system::error_code add( const std::string& object, - const std::string& date, - std::size_t length, - const std::string& host) = 0; + virtual std::error_code add( const std::string& object, + const std::string& date, + std::size_t length, + const std::string& host) = 0; /// Remove an object from the database - virtual boost::system::error_code del( const std::string& object) = 0; + virtual std::error_code del( const std::string& object) = 0; /// lock database record - virtual boost::system::error_code set( const std::string& object, int value) = 0; + virtual std::error_code set( const std::string& object, int value) = 0; }; /// File database lock /** @@ -127,7 +125,7 @@ namespace Online { public: /// Standard constructor - lock_t(fdb_dbase_t* db) : fdb(db) { fdb->lock(); } + lock_t(fdb_dbase_t* db) : fdb(db) { fdb->lock(); } /// Standard destructor ~lock_t() { fdb->unlock(); } }; @@ -160,32 +158,32 @@ namespace Online { virtual std::string network_file(const std::string& host, const std::string& obj) const; /// Check the existence of a given object in the database - virtual boost::system::error_code query_object( const std::string& object_name, - std::string& access_name, - std::string& date, - std::size_t& length); + virtual std::error_code query_object( const std::string& object_name, + std::string& access_name, + std::string& date, + std::size_t& length); /// Get the next object with the name matching the prefix - virtual boost::system::error_code delete_next( const std::string& prefix, - std::string& access_name, - std::string& date, - std::size_t& length); + virtual std::error_code delete_next( const std::string& prefix, + std::string& access_name, + std::string& date, + std::size_t& length); /// Check the existence of a given object in the database - virtual boost::system::error_code delete_object(const std::string& object_name, - std::string& access_name, - std::string& date, - std::size_t& length); + virtual std::error_code delete_object(const std::string& object_name, + std::string& access_name, + std::string& date, + std::size_t& length); /// Add a new object to the database - virtual boost::system::error_code add_object( const std::string& object_name, - const std::string& date, - std::size_t length, - std::string& access_name); + virtual std::error_code add_object( const std::string& object_name, + const std::string& date, + std::size_t length, + std::string& access_name); /// Update the object state of an object in the database - virtual boost::system::error_code update_object_state(const std::string& object_name, - const std::string& state); + virtual std::error_code update_object_state(const std::string& object_name, + const std::string& state); }; diff --git a/Online/Storage/Storage/fdb_server.h b/Online/Storage/Storage/fdb_server.h index 64714b3971ef5c4970b1e9108217468b9cf44528..a1b019a35c16b6ef49b86b9bcc9751c1f2edf46d 100644 --- a/Online/Storage/Storage/fdb_server.h +++ b/Online/Storage/Storage/fdb_server.h @@ -16,6 +16,7 @@ #define ONLINE_STORAGE_FDB_SERVER_H /// Framework include files +#include <RTL/rtl.h> #include <HTTP/HttpServer.h> #include <Storage/communication.h> @@ -117,7 +118,7 @@ namespace Online { bool startup {false}; public: void create(int argc, char* argv[]) { - std::string localhost=boost::asio::ip::host_name(), log; + std::string localhost = RTL::nodeName(), log; int prt = LIB_RTL_INFO; local = localhost+":80"; @@ -137,9 +138,10 @@ namespace Online { RTL::Logger::install_fifolog(log.c_str(), RTL::Logger::log_args(prt)); if ( !file_dir.empty() && 0 != ::chdir(file_dir.c_str()) ) { + std::string err = std::make_error_code(std::errc(errno)).message(); ::lib_rtl_output(LIB_RTL_ERROR, "+++ Failed to change to working directory: '%s' [%s]", - file_dir.c_str(), ::strerror(errno)); + file_dir.c_str(), err.c_str()); ::exit(EINVAL); } std::stringstream str; diff --git a/Online/Storage/src/client/client.cpp b/Online/Storage/src/client/client.cpp index 70bde187eb7cf1a1e57865bb6038ea1ef73a63be..cf352c0ff61722c73f634a810bcac3580f4fc795 100644 --- a/Online/Storage/src/client/client.cpp +++ b/Online/Storage/src/client/client.cpp @@ -15,6 +15,7 @@ // Framework include files #include <Storage/client.h> +#include <RTL/rtl.h> // C/C++ header files #include <sstream> @@ -40,7 +41,7 @@ std::string client::build_request(const std::string& func, std::stringstream rq; rq << func << " " << url << " HTTP/1.1\r\n" << "User-Agent: " << "FDB-1.0\r\n" - << "Host: " << boost::asio::ip::host_name() << "\r\n"; + << "Host: " << RTL::nodeName() << "\r\n"; for(const auto& h : headers) rq << h.name << ": " << h.value << "\r\n"; for(const auto& h : user_headers) diff --git a/Online/Storage/src/client/client_async.cpp b/Online/Storage/src/client/client_async.cpp index c5f4b74289573592b197b4bc7ae28c5a6e1a29b7..0316c66c77d83d4ae1ef179dc38a1e50f3d389bf 100644 --- a/Online/Storage/src/client/client_async.cpp +++ b/Online/Storage/src/client/client_async.cpp @@ -50,12 +50,12 @@ public: { if ( socket.is_open() ) close(); } - system::error_code open(); + std::error_code open(); void close(); }; /// Open connection -system::error_code Online::storage::client_async::io_t::open() { +std::error_code Online::storage::client_async::io_t::open() { system::error_code ec(system::errc::success, system::system_category()); if ( !socket.is_open() ) { asio::ip::tcp::resolver::iterator it, end; @@ -66,10 +66,11 @@ system::error_code Online::storage::client_async::io_t::open() { if ( error_code_ok(ec) && con != end ) { socket.set_option(asio::socket_base::reuse_address(true)); socket.set_option(asio::socket_base::linger(true,0)); + } } } - return ec; + return std::make_error_code(std::errc(ec.value())); } /// Open connection @@ -82,7 +83,7 @@ void Online::storage::client_async::io_t::close() { } template <> -std::unique_ptr<client> client::create<client::async>(const string& host, const string& port, int tmo, int dbg) { +unique_ptr<client> client::create<client::async>(const string& host, const string& port, int tmo, int dbg) { auto obj = make_unique<client_async>(host, port, tmo, dbg); return obj; } @@ -99,11 +100,11 @@ client_async::~client_async() { } /// Initializing constructor -system::error_code client_async::open() const { +error_code client_async::open() const { if ( !io->socket.is_open() ) { return io->open(); } - return system::error_code(system::errc::success,system::system_category()); + return make_error_code(errc(0)); } /// Receive data buffer from server peer @@ -164,13 +165,14 @@ reply_t::status_type client_async::receive(reply_t& reply) const { /// Send data buffer reply_t::status_type client_async::send(const void* data, size_t len) const { if ( data && len > 0 ) { - system::error_code ec = io->open(); + error_code ec = io->open(); if ( error_code_ok(ec) ) { + system::error_code err; vector<asio::const_buffer> request = {asio::const_buffer(data, len)}; size_t req_len = asio::detail::buffer_size(request[0]); - size_t snd_len = asio::write(io->socket, request, ec); + size_t snd_len = asio::write(io->socket, request, err); if ( snd_len != req_len ) { - system::error_code errcode(errno,system::system_category()); + error_code errcode(errno,system::system_category()); io->close(); errno = ENOTCONN; return reply_t::service_unavailable; @@ -189,7 +191,8 @@ reply_t client_async::get_reply() const { unsigned int code; reply_t reply; asio::streambuf response; - boost::system::error_code ec; + system::error_code ec; + asio::read_until(io->socket, response, "\r\n", ec); @@ -224,13 +227,13 @@ reply_t client_async::get_reply() const { response.sgetn((char*)&reply.content[0], len); return reply; } - if ( ec == boost::system::errc::connection_reset ) + if ( ec == system::errc::connection_reset ) reply = reply_t::stock_reply(reply_t::internal_server_error); - else if ( ec == boost::system::errc::connection_aborted ) + else if ( ec == system::errc::connection_aborted ) reply = reply_t::stock_reply(reply_t::internal_server_error); - else if ( ec == boost::system::errc::network_down ) + else if ( ec == system::errc::network_down ) reply = reply_t::stock_reply(reply_t::bad_gateway); - else if ( ec == boost::system::errc::network_unreachable ) + else if ( ec == system::errc::network_unreachable ) reply = reply_t::stock_reply(reply_t::bad_gateway); else reply = reply_t::stock_reply(reply_t::internal_server_error); @@ -239,7 +242,7 @@ reply_t client_async::get_reply() const { } /// Exec generic statement -reply_t client_async::request(const std::string& cmd, const std::string& url, const reqheaders_t& headers) const { +reply_t client_async::request(const string& cmd, const string& url, const reqheaders_t& headers) const { reply_t reply; if ( !cmd.empty() && !url.empty() ) { string req = this->build_request(cmd, url, headers); @@ -257,7 +260,7 @@ reply_t client_async::request(const std::string& cmd, const std::string& url, co } /// Connect client to given URI and execute RPC call -reply_t client_async::get(const std::string& url, const reqheaders_t& headers) const { +reply_t client_async::get(const string& url, const reqheaders_t& headers) const { reqheaders_t hdrs(headers); hdrs.push_back({http::constants::content_length,"0"}); reply_t reply = this->request(http::constants::get, url, hdrs); @@ -278,7 +281,7 @@ reply_t client_async::get(const std::string& url, const reqheaders_t& headers) } /// Connect client to given URI and execute DELETE statement -reply_t client_async::del(const std::string& url, const reqheaders_t& headers) const { +reply_t client_async::del(const string& url, const reqheaders_t& headers) const { reqheaders_t hdrs(headers); hdrs.push_back({http::constants::content_length,"0"}); reply_t reply = this->request(http::constants::get, url, hdrs); @@ -299,7 +302,7 @@ reply_t client_async::del(const std::string& url, const reqheaders_t& headers) } /// Connect client to given URI and execute RPC call -reply_t client_async::put(const std::string& url, const void* data, size_t len, const reqheaders_t& headers) const { +reply_t client_async::put(const string& url, const void* data, size_t len, const reqheaders_t& headers) const { reqheaders_t hdrs(headers); hdrs.push_back(header_t(http::constants::content_length,len)); reply_t reply = this->request(http::constants::put, url, hdrs); @@ -321,7 +324,7 @@ reply_t client_async::put(const std::string& url, const void* data, size_t len, /// Connect client to given URI and execute RPC call -reply_t client_async::update(const std::string& url, +reply_t client_async::update(const string& url, const void* data, size_t len, const reqheaders_t& headers) const { diff --git a/Online/Storage/src/client/client_sync.cpp b/Online/Storage/src/client/client_sync.cpp index 8694145a00fac193c517cc0f0ca79836ee8dbeae..5b25c04d7026c4b323208cff2d10dda8fd42407e 100644 --- a/Online/Storage/src/client/client_sync.cpp +++ b/Online/Storage/src/client/client_sync.cpp @@ -50,12 +50,12 @@ public: { if ( socket.is_open() ) close(); } - system::error_code open(); + std::error_code open(); void close(); }; /// Open connection -system::error_code Online::storage::client_sync::io_t::open() { +error_code Online::storage::client_sync::io_t::open() { system::error_code ec(system::errc::success, system::system_category()); if ( !socket.is_open() ) { asio::ip::tcp::resolver::iterator it, end; @@ -69,13 +69,13 @@ system::error_code Online::storage::client_sync::io_t::open() { } } } - return ec; + return make_error_code(errc(ec.value())); } /// Open connection void Online::storage::client_sync::io_t::close() { if ( socket.is_open() ) { - system::error_code ec; + system::error_code ec(system::errc::success, system::system_category()); socket.shutdown(asio::ip::tcp::socket::shutdown_both, ec); socket.close(); //::lib_rtl_output(LIB_RTL_ERROR,"client_sync::io_t::close: Connection closed!\n"); @@ -83,7 +83,7 @@ void Online::storage::client_sync::io_t::close() { } template <> -std::unique_ptr<client> client::create<client::sync>(const string& host, const string& port, int tmo, int dbg) { +unique_ptr<client> client::create<client::sync>(const string& host, const string& port, int tmo, int dbg) { auto obj = make_unique<client_sync>(host, port, tmo, dbg); return obj; } @@ -100,11 +100,11 @@ client_sync::~client_sync() { } /// Initializing constructor -system::error_code client_sync::open() const { +error_code client_sync::open() const { if ( !io->socket.is_open() ) { return io->open(); } - return system::error_code(system::errc::success,system::system_category()); + return make_error_code(errc(0)); } /// Receive data buffer from server peer @@ -165,13 +165,13 @@ reply_t::status_type client_sync::receive(reply_t& reply) const { /// Send data buffer reply_t::status_type client_sync::send(const void* data, size_t len) const { if ( data && len > 0 ) { - system::error_code ec = io->open(); + error_code ec = io->open(); if ( error_code_ok(ec) ) { + system::error_code err; vector<asio::const_buffer> request = {asio::const_buffer(data, len)}; size_t req_len = asio::detail::buffer_size(request[0]); - size_t snd_len = asio::write(io->socket, request, ec); + size_t snd_len = asio::write(io->socket, request, err); if ( snd_len != req_len ) { - system::error_code errcode(errno,system::system_category()); io->close(); errno = ENOTCONN; return reply_t::service_unavailable; @@ -190,7 +190,7 @@ reply_t client_sync::get_reply() const { unsigned int code; reply_t reply; asio::streambuf response; - boost::system::error_code ec; + system::error_code ec; asio::read_until(io->socket, response, "\r\n", ec); @@ -225,13 +225,13 @@ reply_t client_sync::get_reply() const { response.sgetn((char*)&reply.content[0], len); return reply; } - if ( ec == boost::system::errc::connection_reset ) + if ( ec == system::errc::connection_reset ) reply = reply_t::stock_reply(reply_t::internal_server_error); - else if ( ec == boost::system::errc::connection_aborted ) + else if ( ec == system::errc::connection_aborted ) reply = reply_t::stock_reply(reply_t::internal_server_error); - else if ( ec == boost::system::errc::network_down ) + else if ( ec == system::errc::network_down ) reply = reply_t::stock_reply(reply_t::bad_gateway); - else if ( ec == boost::system::errc::network_unreachable ) + else if ( ec == system::errc::network_unreachable ) reply = reply_t::stock_reply(reply_t::bad_gateway); else reply = reply_t::stock_reply(reply_t::internal_server_error); @@ -240,7 +240,7 @@ reply_t client_sync::get_reply() const { } /// Exec generic statement -reply_t client_sync::request(const std::string& cmd, const std::string& url, const reqheaders_t& headers) const { +reply_t client_sync::request(const string& cmd, const string& url, const reqheaders_t& headers) const { reply_t reply; if ( !cmd.empty() && !url.empty() ) { string req = this->build_request(cmd, url, headers); @@ -258,7 +258,7 @@ reply_t client_sync::request(const std::string& cmd, const std::string& url, con } /// Connect client to given URI and execute RPC call -reply_t client_sync::get(const std::string& url, const reqheaders_t& headers) const { +reply_t client_sync::get(const string& url, const reqheaders_t& headers) const { reqheaders_t hdrs(headers); hdrs.push_back({http::constants::content_length,"0"}); reply_t reply = this->request(http::constants::get, url, hdrs); @@ -279,7 +279,7 @@ reply_t client_sync::get(const std::string& url, const reqheaders_t& headers) c } /// Connect client to given URI and execute DELETE statement -reply_t client_sync::del(const std::string& url, const reqheaders_t& headers) const { +reply_t client_sync::del(const string& url, const reqheaders_t& headers) const { reqheaders_t hdrs(headers); hdrs.push_back({http::constants::content_length,"0"}); reply_t reply = this->request(http::constants::del, url, hdrs); @@ -300,7 +300,7 @@ reply_t client_sync::del(const std::string& url, const reqheaders_t& headers) c } /// Connect client to given URI and execute RPC call -reply_t client_sync::put(const std::string& url, const void* data, size_t len, const reqheaders_t& headers) const { +reply_t client_sync::put(const string& url, const void* data, size_t len, const reqheaders_t& headers) const { reqheaders_t hdrs(headers); hdrs.push_back(header_t(http::constants::content_length,len)); reply_t reply = this->request(http::constants::put, url, hdrs); @@ -321,7 +321,7 @@ reply_t client_sync::put(const std::string& url, const void* data, size_t len, c } /// Connect client to given URI and execute RPC call -reply_t client_sync::update(const std::string& url, const void* data, size_t len, const reqheaders_t& headers) const { +reply_t client_sync::update(const string& url, const void* data, size_t len, const reqheaders_t& headers) const { reqheaders_t hdrs(headers); hdrs.push_back(header_t(http::constants::content_length,len)); reply_t reply = this->request(http::constants::update, url, hdrs); diff --git a/Online/Storage/src/client/communication.cpp b/Online/Storage/src/client/communication.cpp index 88ab8d78d23a9668575223aa388c2b4b5cce20f7..4e5990ebc45b9457a22984ca89e076c6774fae11 100644 --- a/Online/Storage/src/client/communication.cpp +++ b/Online/Storage/src/client/communication.cpp @@ -15,13 +15,29 @@ // Framework include files #include <Storage/communication.h> +#include <HTTP/Asio.h> // C/C++ include files #include <iostream> using namespace std; +namespace Online { namespace storage { + bool error_code_ok(const boost::system::error_code& ec, bool debug) { + if ( !ec ) { + return true; + } + if ( debug ) { + std::cout << "Bad error code[" + << ec.value() << "] (" + << ec.category().name() << ") " + << ec.message() << std::endl; + } + return false; + } + } +} -bool Online::storage::error_code_ok(const boost::system::error_code& ec, bool debug) { +bool Online::storage::error_code_ok(const std::error_code& ec, bool debug) { if ( !ec ) { return true; } diff --git a/Online/Storage/src/client/compress.cpp b/Online/Storage/src/client/compress.cpp index 24f78456db7db9a7b839615173e8feb2f4cbf95b..669d99cc51c835e4ea857aca9b63c3cc70ed64e8 100644 --- a/Online/Storage/src/client/compress.cpp +++ b/Online/Storage/src/client/compress.cpp @@ -17,6 +17,7 @@ #include <Storage/compress.h> // C/C++ include files +#include <system_error> #include <sstream> #include <cstring> #include <cerrno> @@ -160,7 +161,8 @@ namespace Online { window, 8, Z_DEFAULT_STRATEGY); if ( status < 0 ) { - str << "HTTP [Failed to initialize zlib/gzip" << ::strerror(EINVAL) << "]"; + str << "HTTP [Failed to initialize zlib/gzip " + << make_error_code(errc(EINVAL)).message() << "]"; goto Default; } strm.avail_in = data.size(); @@ -171,7 +173,8 @@ namespace Online { strm.next_out = out; status = ::deflate(&strm, Z_FINISH); if ( status < 0 ) { - str << "XMLRPC [Failed to deflate buffer with zlib/gzip" << ::strerror(EINVAL) << "]"; + str << "XMLRPC [Failed to deflate buffer with zlib/gzip " + << make_error_code(errc(EINVAL)).message() << "]"; ::deflateEnd (&strm); goto Default; } @@ -209,7 +212,8 @@ namespace Online { int window = windowBits + (gzip ? ENABLE_ZLIB_GZIP : 0); int status = ::inflateInit2(&strm, window); if ( status < 0 ) { - str << "XMLRPC [Failed to initialize zlib/gzip" << ::strerror(EINVAL); + str << "XMLRPC [Failed to initialize zlib/gzip " + << make_error_code(errc(EINVAL)).message() << "]"; goto Default; } strm.avail_in = data.size(); diff --git a/Online/Storage/src/client/fdb_client.cpp b/Online/Storage/src/client/fdb_client.cpp index 3067da8ef9420b77d4b160836e6c71ea53e6f740..7fa571d6d8833ff2aee8cd13e0b3e51f0ff2d1de 100644 --- a/Online/Storage/src/client/fdb_client.cpp +++ b/Online/Storage/src/client/fdb_client.cpp @@ -154,7 +154,7 @@ reply_t fdb_client::db_object_delete(const string& location, time_t& date, size_ } /// Save object record to database and return the location to store the data -reply_t fdb_client::save_object_record(const string& location, string& url, size_t len) { +reply_t fdb_client::save_object_record(const string& location, string& url, size_t len, const client::reqheaders_t& opts) { struct tm tim; time_t now = ::time(nullptr); client::reqheaders_t hdrs { @@ -163,6 +163,10 @@ reply_t fdb_client::save_object_record(const string& location, string& url, size { http::constants::date, ::gmtime_r(&now, &tim) }, { http::constants::expect, "100-continue" } }; + /// Add optional headers if required + if ( !opts.empty() ) { + hdrs.insert(hdrs.end(), opts.begin(), opts.end()); + } auto reply = fdbclient->request(http::constants::put, location, hdrs); if ( reply.status == reply_t::temp_redirect ) { for ( const auto& h : reply.headers ) { @@ -177,7 +181,7 @@ reply_t fdb_client::save_object_record(const string& location, string& url, size } /// Save object data to disk at the specified location -reply_t fdb_client::save_object_data(const string& location, const void* data, size_t len) { +reply_t fdb_client::save_object_data(const string& location, const void* data, size_t len, const client::reqheaders_t& opts) { struct tm tim; time_t now = ::time(nullptr); client::reqheaders_t hdrs { @@ -187,6 +191,10 @@ reply_t fdb_client::save_object_data(const string& location, const void* data, s uri_t u(location); unique_ptr<client> cl(create_client(u.host, u.port, dataTMO, this->debug)); if ( error_code_ok(cl->open(), this->debug) ) { + /// Add optional headers if required + if ( !opts.empty() ) { + hdrs.insert(hdrs.end(), opts.begin(), opts.end()); + } auto reply = cl->put(u.path, data, len, hdrs); if ( reply.status == reply_t::created ) { return reply; diff --git a/Online/Storage/src/server/fdb_db_server.cpp b/Online/Storage/src/server/fdb_db_server.cpp index 438d9d4d4354cd3f67922c857ec5456212ec30cd..8d03c8f6d65162e2b181968723e9f764e3c5c8fa 100644 --- a/Online/Storage/src/server/fdb_db_server.cpp +++ b/Online/Storage/src/server/fdb_db_server.cpp @@ -102,15 +102,15 @@ http::basic_http_server<db>::handler_t::handle_get(const request_t& req, reply_t size_t length = 0; string date, access_name, obj = object_name(req.uri); - boost::system::error_code ec; { + error_code ec; { dbase_t::lock_t lock(dbase.get()); ec = dbase->query_object(req.uri, access_name, date, length); } - if ( ec == boost::system::errc::no_such_file_or_directory ) { + if ( ec == std::errc::no_such_file_or_directory ) { rep = reply_t::stock_reply(reply_t::not_found); ++monitor->data.num_get_not_found; } - else if ( ec == boost::system::errc::permission_denied ) { + else if ( ec == std::errc::permission_denied ) { rep = reply_t::stock_reply(reply_t::unauthorized); ++monitor->data.num_get_unauthorized; } @@ -145,15 +145,15 @@ http::basic_http_server<db>::handler_t::handle_delete(const request_t& req, repl size_t length = 0; string date, access_name, obj = object_name(req.uri,"%"); - boost::system::error_code ec; { + std::error_code ec; { dbase_t::lock_t lock(dbase.get()); ec = dbase->delete_object(obj, access_name, date, length); } - if ( ec == boost::system::errc::no_such_file_or_directory ) { + if ( ec == std::errc::no_such_file_or_directory ) { rep = reply_t::stock_reply(reply_t::not_found); ++monitor->data.num_del_not_found; } - else if ( ec == boost::system::errc::permission_denied ) { + else if ( ec == std::errc::permission_denied ) { rep = reply_t::stock_reply(reply_t::unauthorized); ++monitor->data.num_del_unauthorized; } @@ -185,7 +185,8 @@ http::basic_http_server<db>::handler_t::handle_delete(const request_t& req, repl /// Specific handler for PUT requests template <> http::HttpRequestHandler::continue_action http::basic_http_server<db>::handler_t::handle_put(const request_t& req, reply_t& rep) { - const header_t *hdr_date, *hdr_len; + const header_t *hdr_date, *hdr_len, *hdr_location; + hdr_location = req.header(http::constants::location); if ( (hdr_date=req.header(http::constants::date)) == nullptr ) { header_t h(http::constants::error_cause,"Missing date header"); rep = reply_t::stock_reply(reply_t::bad_request); @@ -206,11 +207,15 @@ http::basic_http_server<db>::handler_t::handle_put(const request_t& req, reply_t const string& date = hdr_date->value; size_t len = hdr_len->as<size_t>(); string access_name; - boost::system::error_code ec; { + std::error_code ec; { dbase_t::lock_t lock(dbase.get()); ec = dbase->add_object(req.uri, date, len, access_name); + if ( hdr_location && error_code_ok(ec, this->debug) ) { + access_name = hdr_location->value; + dbase->update_object_state(req.uri, "WRITTEN"); + } } - if ( ec == boost::system::errc::permission_denied ) { + if ( ec == std::errc::permission_denied ) { header_t h(http::constants::error_cause,"Failed to add "+req.uri+" "+ec.message()); rep = reply_t::stock_reply(reply_t::unauthorized); ::lib_rtl_output(LIB_RTL_ERROR,"+++ %s: %s %-20s = %s", @@ -268,7 +273,7 @@ http::basic_http_server<db>::handler_t::handle_update(const request_t& req, repl rep.headers.emplace_back(move(h)); } else { - boost::system::error_code ec; { + std::error_code ec; { dbase_t::lock_t lock(dbase.get()); ec = dbase->update_object_state(req.uri, hdr_state->value); } diff --git a/Online/Storage/src/server/fdb_dbase.cpp b/Online/Storage/src/server/fdb_dbase.cpp index 192feaa82a78153b5cf8e12fd6941a65ce24a987..11aefcd0b1af14c3dde41efebcfaaef3b54ecb0f 100644 --- a/Online/Storage/src/server/fdb_dbase.cpp +++ b/Online/Storage/src/server/fdb_dbase.cpp @@ -19,7 +19,6 @@ // C/C++ files -using namespace boost; using namespace Online::storage; namespace { @@ -37,14 +36,14 @@ fdb_dbase_t::handler_t::~handler_t() { } /// Check the existence of a given object in the database -system::error_code +std::error_code fdb_dbase_t::handler_t::query(std::string& object, std::string& host, std::string& date, std::size_t& length) { file_t file; - system::error_code ec = this->query_file(object, file, handler_t::STATE_WRITTEN); - if ( ec == system::errc::success ) { + std::error_code ec = this->query_file(object, file, handler_t::STATE_WRITTEN); + if ( ec.value() == 0 ) { object = file.name; host = file.host; length = file.size; // ::atol(file.size.c_str()); @@ -53,31 +52,31 @@ fdb_dbase_t::handler_t::query(std::string& object, return ec; } ::lib_rtl_output(LIB_RTL_ERROR,"+++ Query: file '%s' NOT FOUND!", object.c_str()); - return system::error_code(system::errc::no_such_file_or_directory, system::system_category()); + return std::make_error_code(std::errc::no_such_file_or_directory); } /// Check the existence of a given object in the database -boost::system::error_code +std::error_code fdb_dbase_t::handler_t::next( std::string& object, std::string& host, std::string& date, std::size_t& length) { file_t file; - system::error_code ec = this->query_file(object, file, handler_t::STATE_WRITTEN); - if ( ec == system::errc::success ) { + std::error_code ec = this->query_file(object, file, handler_t::STATE_WRITTEN); + if ( ec.value() == 0 ) { object = file.name; host = file.host; length = file.size; // ::atol(file.size.c_str()); date = file.date; ec = this->set(object, handler_t::STATE_READ); - if ( ec == system::errc::success ) { + if ( ec.value() == 0 ) { ::lib_rtl_output(_prt(this), "+++ Next '%s'", object.c_str()); - return system::error_code(system::errc::success, system::system_category()); + return ec; } - return system::error_code(system::errc::protocol_error, system::system_category()); + return std::make_error_code(std::errc::protocol_error); } ::lib_rtl_output(LIB_RTL_ERROR,"+++ Query: file '%s' NOT FOUND!", object.c_str()); - return system::error_code(system::errc::no_such_file_or_directory, system::system_category()); + return std::make_error_code(std::errc::no_such_file_or_directory); } /// Standard constructor @@ -107,14 +106,14 @@ std::string fdb_dbase_t::network_file(const std::string& host, const std::string } /// Check the existence of a given object in the database -system::error_code fdb_dbase_t::query_object(const std::string& object, - std::string& access, - std::string& date, - std::size_t& length) +std::error_code fdb_dbase_t::query_object(const std::string& object, + std::string& access, + std::string& date, + std::size_t& length) { std::string host, obj = this->object_key(object); auto ec = this->_engine->query(obj, host, date, length); - if ( ec == system::errc::success ) { + if ( ec.value() == 0 ) { access = this->network_file(host, obj); ::lib_rtl_output(_prt(this), "+++ Lookup '%s'", obj.c_str()); return ec; @@ -125,17 +124,17 @@ system::error_code fdb_dbase_t::query_object(const std::string& object, } /// Check the existence of the next object of a sequence -system::error_code fdb_dbase_t::delete_next( const std::string& object, - std::string& access, - std::string& date, - std::size_t& length) +std::error_code fdb_dbase_t::delete_next( const std::string& object, + std::string& access, + std::string& date, + std::size_t& length) { std::string host, obj = this->object_key(object); auto ec = this->_engine->next(obj, host, date, length); - if ( ec == system::errc::success ) { + if ( ec.value() == 0 ) { ec = this->_engine->del(obj); access = this->network_file(host, obj); - if ( ec == system::errc::success ) { + if ( ec.value() == 0 ) { ::lib_rtl_output(_prt(this), "+++ Lookup '%s'", obj.c_str()); return ec; } @@ -146,17 +145,17 @@ system::error_code fdb_dbase_t::delete_next( const std::string& object, } /// Check the existence of a given object in the database -system::error_code fdb_dbase_t::delete_object(const std::string& object, - std::string& access, - std::string& date, - std::size_t& length) +std::error_code fdb_dbase_t::delete_object(const std::string& object, + std::string& access, + std::string& date, + std::size_t& length) { std::string host, obj = this->object_key(object); auto ec = this->_engine->query(obj, host, date, length); - if ( ec == system::errc::success ) { + if ( !ec ) { ec = this->_engine->del(obj); access = this->network_file(host, obj); - if ( ec == system::errc::success ) { + if ( !ec ) { ::lib_rtl_output(_prt(this), "+++ Remove '%s'", obj.c_str()); return ec; } @@ -167,7 +166,7 @@ system::error_code fdb_dbase_t::delete_object(const std::string& object, } /// Add a new object to the database -system::error_code +std::error_code fdb_dbase_t::add_object(const std::string& object, const std::string& date, std::size_t length, @@ -176,7 +175,7 @@ fdb_dbase_t::add_object(const std::string& object, std::string obj = this->object_key(object); std::string host = this->get_free_host_uri(object); auto ec = this->_engine->add(obj, date, length, host); - if ( ec == system::errc::success ) { + if ( !ec ) { access = this->network_file(host, obj); ::lib_rtl_output(_prt(this), "+++ Add '%s' %s %s", object.c_str(), this->_debug > 1 ? "access:" : "", @@ -189,24 +188,24 @@ fdb_dbase_t::add_object(const std::string& object, } /// Update the object state of an object in the database -boost::system::error_code +std::error_code fdb_dbase_t::update_object_state(const std::string& object, const std::string& state) { file_t file; - system::error_code ec; + std::error_code ec; std::string obj = this->object_key(object); if ( state == "WRITTEN" ) { ec = this->_engine->query_file(obj, file, handler_t::STATE_OPEN); - if ( ec == system::errc::success ) { + if ( !ec ) { ec = this->_engine->set(obj, handler_t::STATE_WRITTEN); } } else if ( state == "READ" ) { ec = this->_engine->query_file(obj, file, handler_t::STATE_WRITTEN); - if ( ec == system::errc::success ) { + if ( !ec ) { ec = this->_engine->set(obj, handler_t::STATE_READ); } } - if ( ec == system::errc::success ) { + if ( !ec ) { ::lib_rtl_output(this->_debug > 1 ? LIB_RTL_ALWAYS : LIB_RTL_DEBUG, "+++ Update '%s' state: %s", object.c_str(), state.c_str()); return ec; diff --git a/Online/Storage/src/server/fdb_fs_server.cpp b/Online/Storage/src/server/fdb_fs_server.cpp index bf8905ad7818ec97b8b739350fcfd34e107c7cd3..d2cc917e174f82df12a04a7a52e8e9957efeedb5 100644 --- a/Online/Storage/src/server/fdb_fs_server.cpp +++ b/Online/Storage/src/server/fdb_fs_server.cpp @@ -17,7 +17,7 @@ #include <HTTP/HttpReply.h> #include <Storage/client.h> #include <Storage/fdb_server.h> -#include <boost/filesystem.hpp> +#include <filesystem> #include <RTL/strdef.h> #include <dim/dis.h> @@ -115,22 +115,22 @@ namespace { } } /// - boost::system::error_code open_read (const std::string& file_name) { - boost::system::error_code ec; + std::error_code open_read (const std::string& file_name) { + std::error_code ec; fid = ::open(file_name.c_str(), O_LARGEFILE | O_RDONLY, S_IREAD); if ( -1 == fid ) { - ec = boost::system::error_code(errno, boost::system::system_category()); + ec = std::error_code(errno, std::system_category()); } return ec; } /// - boost::system::error_code open_write(const std::string& file_name) { - boost::system::error_code ec; + std::error_code open_write(const std::string& file_name) { + std::error_code ec; fid = ::open(file_name.c_str(), O_LARGEFILE | O_WRONLY | O_CREAT | O_EXCL | O_EXCL, S_IRWXG | S_IRWXU); if ( -1 == fid ) { - ec = boost::system::error_code(errno, boost::system::system_category()); + ec = std::error_code(errno, std::system_category()); } return ec; } @@ -161,10 +161,10 @@ namespace { return len; } /// - boost::system::error_code unlink(const std::string& name) { + std::error_code unlink(const std::string& name) { if ( 0 == ::unlink(name.c_str()) ) - return boost::system::error_code(boost::system::errc::success, boost::system::system_category()); - return boost::system::error_code(errno, boost::system::system_category()); + return std::error_code(0, std::system_category()); + return std::error_code(errno, std::system_category()); } }; @@ -261,7 +261,7 @@ http::basic_http_server<fs>::handler_t::handle_get(const request_t& req, reply_t ctxt->st_data = 0; // Now open the file, read a chunk and send it. // The rest gets sent by consecutive calls - boost::system::error_code ec = ctxt->open_read(fname); + std::error_code ec = ctxt->open_read(fname); if ( !error_code_ok(ec, this->debug) ) { rep = reply_t::stock_reply(reply_t::not_found); rep.headers.emplace_back(constants::error_cause,"File '"+fname+"' does not exist"); @@ -282,9 +282,10 @@ http::basic_http_server<fs>::handler_t::handle_get(const request_t& req, reply_t ctxt->st_data += rd; } else { + std::string err = std::make_error_code(std::errc(errno)).message(); ::lib_rtl_output(LIB_RTL_ERROR, "+++ %s: Failed to read '%s' [%s] only got %ld out of %ld bytes", req.method.c_str(), req.uri.c_str(), - ::strerror(errno), rd, len); + err.c_str(), rd, len); } if ( ctxt->st_data == ctxt->st_size ) { ::lib_rtl_output(LIB_RTL_INFO, "+++ %s: Last chunk '%s' %.1f MB", @@ -316,7 +317,7 @@ http::basic_http_server<fs>::handler_t::handle_get(const request_t& req, reply_t template <> http::HttpRequestHandler::continue_action http::basic_http_server<fs>::handler_t::handle_delete(const request_t& req, reply_t& rep) { auto* ctxt = (fs_io*)rep.context.get(); - boost::system::error_code ec; + std::error_code ec; if ( 0 == rep.bytes_sent ) { struct stat stat; const std::string fname = dbase->local_file(req.uri); @@ -363,8 +364,9 @@ http::basic_http_server<fs>::handler_t::handle_delete(const request_t& req, repl ctxt->st_data += rd; } else { + std::string err = std::make_error_code(std::errc(errno)).message(); ::lib_rtl_output(LIB_RTL_ERROR, "+++ %s: Failed to read '%s' [%s] only got %ld out of %ld bytes", - req.method.c_str(), req.uri.c_str(), ::strerror(errno), rd, len); + req.method.c_str(), req.uri.c_str(), err.c_str(), rd, len); } if ( ctxt->st_data == ctxt->st_size ) { const std::string fname = dbase->local_file(req.uri); @@ -427,7 +429,7 @@ http::basic_http_server<fs>::handler_t::handle_put(const request_t& req, reply_t ++monitor->data.numPUT_error; return write; } - boost::filesystem::path p = boost::filesystem::path(fname).parent_path(); + std::filesystem::path p = std::filesystem::path(fname).parent_path(); for( auto i=p.begin(); i != p.end(); ++i ) v.emplace_back(i->string()); dir = ""; @@ -440,10 +442,9 @@ http::basic_http_server<fs>::handler_t::handle_put(const request_t& req, reply_t ::lib_rtl_sleep(10); // Wait and then check if another thread created the directory if ( -1 == ::stat(dir.c_str(), &stat) ) { - char err[1024]; - ::strerror_r(errno, err, sizeof(err)); + std::string err = std::make_error_code(std::errc(errno)).message(); ::lib_rtl_output(LIB_RTL_ERROR, "+++ %s: Failed to create parent directory %s [%s]", - req.method.c_str(), dir.c_str(), err); + req.method.c_str(), dir.c_str(), err.c_str()); if ( errno == EACCES || errno == ENOENT || errno == EPERM || errno == EROFS ) rep = reply_t::stock_reply(reply_t::unauthorized); else @@ -465,7 +466,7 @@ http::basic_http_server<fs>::handler_t::handle_put(const request_t& req, reply_t ctxt->st_data = 0; // Now open the file, read a chunk and send it. // The rest gets sent by handle_request_cont_full - boost::system::error_code ec = ctxt->open_write(fname); + std::error_code ec = ctxt->open_write(fname); if ( !error_code_ok(ec, this->debug) ) { rep = reply_t::stock_reply(reply_t::forbidden); rep.headers.emplace_back(constants::error_cause, "Failed to open file "+fname+" ["+ec.message()+"]"); @@ -488,9 +489,10 @@ http::basic_http_server<fs>::handler_t::handle_put(const request_t& req, reply_t long wrt = ctxt->write(len, &req.content.at(0)); ctxt->st_data += wrt; if ( wrt != len ) { + std::string err = std::make_error_code(std::errc(errno)).message(); ::lib_rtl_output(LIB_RTL_ERROR, "+++ %s: Failed to write '%s' " "[%s] only wrote %ld out of %ld bytes", - req.method.c_str(), req.uri.c_str(), ::strerror(errno), wrt, len); + req.method.c_str(), req.uri.c_str(), err.c_str(), wrt, len); ++monitor->data.numPUT_error; } } diff --git a/Online/Storage/src/server/fdb_sqldb.cpp b/Online/Storage/src/server/fdb_sqldb.cpp index da1a0799c09eea567756dbbc56cd1416fd901ab2..52154f1a9c8ff432f1bb8a9144a7bf17c3016e5b 100644 --- a/Online/Storage/src/server/fdb_sqldb.cpp +++ b/Online/Storage/src/server/fdb_sqldb.cpp @@ -20,8 +20,9 @@ #include <RTL/rtl.h> // C/C++ files +#include <system_error> + -using namespace boost; using namespace Online::storage; /// Initializing constructor @@ -41,7 +42,7 @@ sqldb_handler_t::~sqldb_handler_t() { } /// Initialize object -system::error_code +std::error_code sqldb_handler_t::init(const std::string& db_name) { if ( !this->_inited ) { std::string err; @@ -56,7 +57,7 @@ sqldb_handler_t::init(const std::string& db_name) { "Host TEXT NOT NULL)"; if ( this->database.execute(err, sql) != sqldb::OK ) { ::lib_rtl_output(LIB_RTL_ERROR,"%s: Create table: SQL error: %s", nam, err.c_str()); - return system::error_code(system::errc::permission_denied, system::system_category()); + return std::make_error_code(std::errc::permission_denied); } ::lib_rtl_output(LIB_RTL_INFO,"FDB Database server: Database %s", nam); ::lib_rtl_output(LIB_RTL_INFO,"FDB Database server: Table FILES created successfully"); @@ -72,12 +73,12 @@ sqldb_handler_t::init(const std::string& db_name) { this->lock_record.prepare (database, "UPDATE Files SET State=?1 WHERE Name=?2 "); this->_inited = true; - return system::error_code(system::errc::success, system::system_category()); + return std::make_error_code(std::errc(0)); } ::lib_rtl_output(LIB_RTL_INFO,"%s: FAILED to access db: [%s]", nam, err.c_str()); - return system::error_code(system::errc::permission_denied, system::system_category()); + return std::make_error_code(std::errc::permission_denied); } - return system::error_code(system::errc::success, system::system_category()); + return std::make_error_code(std::errc(0)); } /// Finalize object @@ -93,7 +94,7 @@ void sqldb_handler_t::fini() { } /// Check the existence of a given object in the database -system::error_code +std::error_code sqldb_handler_t::query_file(const std::string& object_name, file_t& file, int state) { this->query_record.reset(); this->query_record.bind(0, object_name); @@ -106,13 +107,13 @@ sqldb_handler_t::query_file(const std::string& object_name, file_t& file, int st file.date = query_record.get<std::string>(3); file.host = query_record.get<std::string>(4); this->query_record.reset(); - return system::error_code(system::errc::success, system::system_category()); + return std::make_error_code(std::errc(0)); } - return system::error_code(system::errc::no_such_file_or_directory, system::system_category()); + return std::make_error_code(std::errc::no_such_file_or_directory); } /// Add a new object to the database -system::error_code +std::error_code sqldb_handler_t::add (const std::string& object_name, const std::string& date, std::size_t length, @@ -128,16 +129,16 @@ sqldb_handler_t::add (const std::string& object_name, this->database.commit(); this->insert_record.reset(); if ( ret == sqldb::DONE ) { - return system::error_code(system::errc::success, system::system_category()); + return std::make_error_code(std::errc(0)); } else if ( ret != sqldb::OK ) { - return system::error_code(system::errc::file_exists, system::system_category()); + return std::make_error_code(std::errc::file_exists); } - return system::error_code(system::errc::success, system::system_category()); + return std::make_error_code(std::errc(0)); } /// Remove an object from the database -system::error_code +std::error_code sqldb_handler_t::del (const std::string& object_name) { this->delete_record.bind(0, object_name); this->database.begin(); @@ -145,14 +146,14 @@ sqldb_handler_t::del (const std::string& object_name) { this->delete_record.reset(); this->database.commit(); if ( ret == sqldb::OK ) - return system::error_code(system::errc::success, system::system_category()); + return std::make_error_code(std::errc(0)); else if ( ret == sqldb::DONE ) - return system::error_code(system::errc::success, system::system_category()); - return system::error_code(system::errc::no_such_file_or_directory, system::system_category()); + return std::make_error_code(std::errc(0)); + return std::make_error_code(std::errc::no_such_file_or_directory); } /// lock database record -system::error_code +std::error_code sqldb_handler_t::set (const std::string& object_name, int value) { this->lock_record.bind(0, value); this->lock_record.bind(1, object_name); @@ -161,10 +162,10 @@ sqldb_handler_t::set (const std::string& object_name, int value) { this->lock_record.reset(); this->database.commit(); if ( ret == sqldb::DONE ) - return system::error_code(system::errc::success, system::system_category()); + return std::make_error_code(std::errc(0)); else if ( ret == sqldb::OK ) - return system::error_code(system::errc::success, system::system_category()); - return system::error_code(system::errc::no_such_file_or_directory, system::system_category()); + return std::make_error_code(std::errc(0)); + return std::make_error_code(std::errc::no_such_file_or_directory); } #include <dim/dis.h> diff --git a/Online/Storage/src/server/fdb_sqldb.h b/Online/Storage/src/server/fdb_sqldb.h index 46ca15dad47c4ca19fd1ffc83215dcddb3545fd1..1b0072e498326c1b9ae32e9ca02cbed5b7d2bf39 100644 --- a/Online/Storage/src/server/fdb_sqldb.h +++ b/Online/Storage/src/server/fdb_sqldb.h @@ -20,6 +20,7 @@ #include <sqldb/sqldb.h> // C/C++ include files +#include <system_error> /// Online Namespace namespace Online { @@ -46,8 +47,8 @@ namespace Online { sqldb::statement lock_record; /// Check the existence of a given object in the database - virtual boost::system::error_code - query_file(const std::string& object_name, file_t& file, int state) override; + virtual std::error_code + query_file(const std::string& object_name, file_t& file, int state) override; public: @@ -58,22 +59,22 @@ namespace Online { virtual ~sqldb_handler_t(); /// Initialize object - boost::system::error_code init(const std::string& db_name); + std::error_code init(const std::string& db_name); /// Finalize object void fini(); /// Add a new object to the database - boost::system::error_code add( const std::string& object, - const std::string& date, - std::size_t length, - const std::string& host) override; + std::error_code add( const std::string& object, + const std::string& date, + std::size_t length, + const std::string& host) override; /// Remove an object from the database - boost::system::error_code del( const std::string& object) override; + std::error_code del( const std::string& object) override; /// lock database record - boost::system::error_code set( const std::string& object, int value) override; + std::error_code set( const std::string& object, int value) override; }; } // End namespace storage } // End namespace Online diff --git a/Online/Storage/tests/src/Setup.cpp b/Online/Storage/tests/src/Setup.cpp index 187812f60aa6881ea9073dcbdf3fe2c30644d7b0..8ca2fd93febbfae78f531794d27b050fc9992710 100644 --- a/Online/Storage/tests/src/Setup.cpp +++ b/Online/Storage/tests/src/Setup.cpp @@ -21,8 +21,11 @@ // C/C++ include files #include <fstream> #include <iostream> -#include <boost/asio.hpp> -#include <boost/filesystem.hpp> +#include <filesystem> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> using namespace std; using namespace Online::storage; @@ -34,7 +37,7 @@ Setup::Setup(const std::string& n, int argc, char* argv[], void (*help)(int,char void (*hlp)(int,char**) = [](int, char**) {}; RTL::CLI cli(argc, argv, help ? help : hlp); - server = boost::asio::ip::host_name()+":80"; + server = RTL::nodeName()+":80"; cli.getopt("check", 4, check_file); cli.getopt("server", 4, server); cli.getopt("url", 3, url); @@ -77,9 +80,9 @@ vector<unsigned char> Setup::read_file(const string& fname) { int ret_stat = ::stat(fname.c_str(), &stat); if ( -1 == ret_stat ) { int err = errno; - ::lib_rtl_output(LIB_RTL_ERROR, - "%s: Cannot access file: %s [%s]", - name.c_str(), fname.c_str(), ::strerror(err)); + ::lib_rtl_output(LIB_RTL_ERROR, "%s: Cannot access file: %s [%s]", + name.c_str(), fname.c_str(), + make_error_code(errc(err)).message().c_str()); exit(err); } vector<unsigned char> data; @@ -102,7 +105,7 @@ vector<unsigned char> Setup::read_file(const string& fname) { size_t Setup::write_file(const reply_t& reply) { int fid = ::open(file.c_str(), O_LARGEFILE | O_WRONLY | O_CREAT, S_IRWXG | S_IRWXU); if ( -1 == fid ) { - auto ec = boost::system::error_code(errno, boost::system::system_category()); + auto ec = make_error_code(errc(errno)); ::lib_rtl_output(LIB_RTL_INFO, "%s: CANNOT open output file %s [%s]", name.c_str(), file.c_str(), ec.message().c_str()); diff --git a/Online/Storage/tests/src/fdb_cli.cpp b/Online/Storage/tests/src/fdb_cli.cpp index b0f4916452f9c21c9b1e34f0e4b00a97ff812a61..3889895c1c376499d02bb7e954cc2fff6a7d56d1 100644 --- a/Online/Storage/tests/src/fdb_cli.cpp +++ b/Online/Storage/tests/src/fdb_cli.cpp @@ -33,13 +33,12 @@ gentest.exe libStorageCli.so fdb_cli_db_delete -server=${HOST}:8000 -url=/o */ - // Framework inclde files #include "Setup.h" // C/C++ include files #include <iostream> -#include <boost/filesystem.hpp> +#include <filesystem> using namespace std; using namespace Online::storage; @@ -63,7 +62,7 @@ extern "C" int fdb_cli_get(int argc, char** argv) { size_t length = 0; time_t date = 0; if ( setup.file.empty() ) { - setup.file = boost::filesystem::path(setup.url).filename().string(); + setup.file = filesystem::path(setup.url).filename().string(); ::lib_rtl_output(LIB_RTL_INFO, "%s: Will save data to %s", setup.name.c_str(), setup.file.c_str()); } @@ -160,7 +159,7 @@ extern "C" int fdb_cli_delete(int argc, char** argv) { size_t length = 0; time_t date = 0; if ( setup.file.empty() ) { - setup.file = boost::filesystem::path(setup.url).filename().string(); + setup.file = filesystem::path(setup.url).filename().string(); ::lib_rtl_output(LIB_RTL_INFO, "%s: Will save data to %s", setup.name.c_str(), setup.file.c_str()); } diff --git a/Online/Storage/tests/src/fdb_client_test.cpp b/Online/Storage/tests/src/fdb_client_test.cpp index e2c1c5c465573fa518270a2f1cdfaffc8906b621..dab760e92f4735e7f3efd114eb153483d409d7a3 100644 --- a/Online/Storage/tests/src/fdb_client_test.cpp +++ b/Online/Storage/tests/src/fdb_client_test.cpp @@ -21,7 +21,9 @@ gentest.exe libStorageCli.so fdb_test_parse_uri "-url=http://pluscc08.lbdaq.cern // C/C++ include files #include <iostream> -#include <boost/filesystem.hpp> +#include <filesystem> +#include <sys/types.h> +#include <sys/stat.h> using namespace std; using namespace Online::storage; @@ -30,15 +32,15 @@ using namespace Online::fdb_test; //========================================================================== extern "C" int fdb_test_path(int argc, char** argv) { RTL::CLI cli(argc, argv, [](int, char**) {}); - std::string name; + string name; cli.getopt("path", 3, name); if ( !name.empty() ) { - std::string dir; - std::vector<std::string> v; - boost::filesystem::path p(name); + string dir; + vector<string> v; + filesystem::path p(name); p = p.parent_path(); for( auto i=p.begin(); i != p.end(); ++i ) { - std::cout << (*i) << endl; + cout << (*i) << endl; v.emplace_back(i->string()); } dir = ""; @@ -109,7 +111,7 @@ extern "C" int fdb_test_client_save(int argc, char** argv) { int err = errno; ::lib_rtl_output(LIB_RTL_ERROR, "fdb_test_save: Cannot access file: %s [%s]", - setup.file.c_str(), ::strerror(err)); + setup.file.c_str(), make_error_code(errc(err)).message().c_str()); return err; } uri_t url(setup.server); diff --git a/Online/Tell1Data/Tell1Data/RawFile.h b/Online/Tell1Data/Tell1Data/RawFile.h index fa2b91acced69f010bace9e7db9ad331b8256e09..7215a28923548239751bdc3ceae6aa8a601524df 100644 --- a/Online/Tell1Data/Tell1Data/RawFile.h +++ b/Online/Tell1Data/Tell1Data/RawFile.h @@ -49,19 +49,19 @@ namespace Online { /// Input buffer allocater signature struct Allocator { virtual ~Allocator() = default; - virtual unsigned char* operator()(size_t memsize) = 0; + virtual unsigned char* operator()(std::size_t memsize) = 0; }; /// In-place allocator using pre-defined buffer struct InPlaceAllocator : public Allocator { unsigned char* ptr = 0; - size_t len = 0; - InPlaceAllocator(unsigned char* p, size_t l); + std::size_t len = 0; + InPlaceAllocator(unsigned char* p, std::size_t l); InPlaceAllocator() = delete; InPlaceAllocator( InPlaceAllocator&& copy ) = delete; InPlaceAllocator( const InPlaceAllocator& copy ) = delete; virtual ~InPlaceAllocator() = default; InPlaceAllocator& operator=( const InPlaceAllocator& copy ) = delete; - virtual unsigned char* operator()(size_t length) override final { + virtual unsigned char* operator()(std::size_t length) override final { return (unsigned char*)((length<=len) ? ptr : 0); } }; @@ -91,9 +91,10 @@ namespace Online { /// Check if the file is mapped bool isMapped() const { return m_begin != m_end; } /// Acces the mapped file size - size_t mapped_size() const { return m_end - m_begin; } + std::size_t mapped_size() const { return m_end - m_begin; } /// Access the data size: file size of mapped size - size_t data_size() const; + std::size_t data_size() const; + /// Start of the mapped data size const unsigned char* begin() const { return m_begin; } /// End of the mapped data size @@ -111,11 +112,11 @@ namespace Online { /// Write chunk of data long write(const void* data, int len); /// Write chunk of data - long write(const void* data, size_t len); + long write(const void* data, std::size_t len); /// Open file in read mode int open(bool silent=true); /// Map memory of the file - int map_memory(const void* data, size_t len); + int map_memory(const void* data, std::size_t len); /// Unmap memory of the file int unmap_memory(); /// Open file in read mode with mapping @@ -132,36 +133,41 @@ namespace Online { int close(); /// Reset information (close and reset name) int reset(bool close=true); + /// Create a directory structure + static int mkdir(const char* dir_name, int protection, bool silent=true); + /// Delete a directory structure + static int rmdir(const char* dir_name, bool recursive, bool silent=true); + /// Read single event using dynamic allocation long read_event(EventType expected, EventType& found_type, Allocator& allocator, unsigned char** data); /// Read single event into fixed buffer long read_event(EventType expected, EventType& found_type, - unsigned char* data, size_t len); + unsigned char* data, std::size_t len); /// Read multiple events into fixed buffer (burst mode) std::pair<long,long> - read_multiple_events(size_t num_events, + read_multiple_events(std::size_t num_events, EventType expected, EventType& found_type, - unsigned char* p, size_t len); + unsigned char* p, std::size_t len); /// Search bad file and try to seek the next event record. Returns offset to next event long scanToNextMDF(); /// Save remainder of currently read file void saveRestOfFile(); /// Scan single record and check for consistency - int checkRecord(size_t offset, const void* data, size_t length) const; + int checkRecord(std::size_t offset, const void* data, std::size_t length) const; /// Check if the event header is correct - int checkEventHeader(size_t offset, const void* data, size_t length) const; + int checkEventHeader(std::size_t offset, const void* data, std::size_t length) const; /// Check content of bank - int checkBank(size_t offset, const void* data) const; + int checkBank(std::size_t offset, const void* data) const; /// Dump a set of raw banks - void dump(const unsigned char* data, size_t len) const; + void dump(const unsigned char* data, std::size_t len) const; /// Dump the content of a single raw bank to screen void dump (const Tell1Bank* bank) const; }; - inline RawFile::InPlaceAllocator::InPlaceAllocator(unsigned char* p, size_t l) + inline RawFile::InPlaceAllocator::InPlaceAllocator(unsigned char* p, std::size_t l) : ptr(p), len(l) { } diff --git a/Online/Tell1Data/src/RawFile.cpp b/Online/Tell1Data/src/RawFile.cpp index 7495f4d2cdfc8f2c8f5bf7972f567baf0b5581fe..d4ca583ef2856eec36989d5bd553d2d497ae171a 100644 --- a/Online/Tell1Data/src/RawFile.cpp +++ b/Online/Tell1Data/src/RawFile.cpp @@ -23,6 +23,8 @@ #include "RTL/rtl.h" /// C/C++ include files +#include <system_error> +#include <filesystem> #include <iostream> #include <iomanip> #include <sys/mman.h> @@ -90,7 +92,7 @@ long RawFile::seek(long offset, int whence) { } /// Return file size: either real file size of mapped size -size_t RawFile::data_size() const { +std::size_t RawFile::data_size() const { if ( isOpen() && !m_begin ) { struct stat sb; ::fstat(m_fd, &sb); /* To obtain file size */ @@ -175,7 +177,8 @@ int RawFile::reset(bool close_file) { int RawFile::open(bool silent) { int fd = ::open(cname(), O_RDONLY | O_BINARY | O_LARGEFILE, S_IREAD); if ( -1 == fd ) { - ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT OPEN file %s: [%s]", cname(), ::strerror(errno)); + std::string err = std::make_error_code(std::errc(errno)).message(); + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT OPEN %s: [%s]", cname(), err.c_str()); return m_fd = fd; } ::lib_rtl_output(silent ? LIB_RTL_DEBUG : LIB_RTL_INFO,"RawFile: Opened %s for processing.",cname()); @@ -186,7 +189,7 @@ int RawFile::open(bool silent) { int RawFile::openWrite(bool silent) { int fd = ::open(cname(), O_CREAT|O_WRONLY|O_BINARY|O_LARGEFILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); if ( -1 == fd ) { - ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT OPEN file %s: [%s]", cname(), ::strerror(errno)); + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT OPEN %s: [%s]", cname(), RTL::errorString(errno).c_str()); return m_fd = fd; } ::lib_rtl_output(silent ? LIB_RTL_DEBUG : LIB_RTL_INFO,"RawFile: Opened %s for writing.",cname()); @@ -201,6 +204,7 @@ int RawFile::openMapped(bool silent) { ::fstat(fd, &sb); /* To obtain file size */ void* ptr = ::mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if ( ptr == MAP_FAILED ) { + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT MMAP %s: [%s]", cname(), RTL::errorString(errno).c_str()); close(); return -1; } @@ -211,7 +215,7 @@ int RawFile::openMapped(bool silent) { } /// Map memory of the file -int RawFile::map_memory(const void* ptr, size_t len) { +int RawFile::map_memory(const void* ptr, std::size_t len) { m_begin = m_ptr = m_end = nullptr; this->close(); m_fd = -1; @@ -242,7 +246,7 @@ long RawFile::write(const void* data, int len) { } /// Write chunk of data -long RawFile::write(const void* data, size_t len) { +long RawFile::write(const void* data, std::size_t len) { const unsigned char* p = (const unsigned char*) data; long tmp = (long)len; while (tmp > 0) { @@ -322,6 +326,78 @@ int RawFile::unlink() { return sc; } +int RawFile::mkdir(const char* dir_name, int protection, bool silent) { + namespace fs = filesystem; + error_code ec, ecexist; + fs::path p = fs::path(dir_name); + fs::create_directories(p, ec); + if ( fs::exists(p, ecexist) ) { + fs::perms prot = fs::perms::none; + if ( protection&S_IRUSR ) prot |= fs::perms::owner_read; + if ( protection&S_IWUSR ) prot |= fs::perms::owner_write; + if ( protection&S_IXUSR ) prot |= fs::perms::owner_exec; + if ( protection&S_IRGRP ) prot |= fs::perms::group_read; + if ( protection&S_IWGRP ) prot |= fs::perms::group_write; + if ( protection&S_IXGRP ) prot |= fs::perms::group_exec; + if ( protection&S_IROTH ) prot |= fs::perms::others_read; + if ( protection&S_IWOTH ) prot |= fs::perms::others_write; + if ( protection&S_IXOTH ) prot |= fs::perms::others_exec; + fs::permissions(p, prot); + return 0; + } + if ( !silent ) { + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT create directory %s: %d [%s]", + dir_name, ec.value(), ec.message().c_str()); + } + return ec.value(); +} + +int RawFile::rmdir(const char* dir_name, bool recursive, bool silent) { + namespace fs = filesystem; + error_code ec; + fs::path p = fs::path(dir_name); + + if ( !fs::exists(p, ec) ) { + ec = make_error_code(errc(ENOENT)); + if ( !silent ) { + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT remove directory %s: %d [%s]", + dir_name, ec.value(), ec.message().c_str()); + } + return ec.value(); + } + else if ( !fs::is_directory(p,ec) ) { + if ( !silent ) { + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: Entry %s is no directory: %d [%s]", + dir_name, ec.value(), ec.message().c_str()); + } + return ec.value(); + } + else if ( recursive ) { + fs::remove_all(p, ec); + if ( ec ) { + if ( !silent ) { + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT remove directory %s: %d [%s]", + dir_name, ec.value(), ec.message().c_str()); + } + } + else if ( !silent ) { + ::lib_rtl_output(LIB_RTL_ALWAYS,"RawFile: Remove directory %s", dir_name); + } + return ec.value(); + } + auto ret = fs::remove(p, ec); + if ( !ret || ec ) { + if ( !silent ) { + ::lib_rtl_output(LIB_RTL_ERROR,"RawFile: CANNOT remove directory %s: %d [%s]", + dir_name, ec.value(), ec.message().c_str()); + } + } + else if ( !silent ) { + ::lib_rtl_output(LIB_RTL_ALWAYS,"RawFile: Remove directory %s", dir_name); + } + return ec.value(); +} + /// Read single event using dynamic allocation long RawFile::read_event(EventType expected, EventType& found_type, @@ -374,7 +450,7 @@ long RawFile::read_event(EventType expected, int buf_size = evt_size + (is_mdf ? 0 : sizeof(MEPEVENT) + sizeof(int)); unsigned char* data_ptr = allocator(buf_size); unsigned char* read_ptr = 0; - size_t read_len = 0; + std::size_t read_len = 0; if ( 0 == data_ptr ) { this->seek(file_position, SEEK_SET); return -1; @@ -396,7 +472,7 @@ long RawFile::read_event(EventType expected, e->packing = -1; e->valid = 1; e->magic = mep_magic_pattern(); - for (size_t j = 0; j < MEP_MAX_PACKING; ++j) { + for (std::size_t j = 0; j < MEP_MAX_PACKING; ++j) { e->events[j].begin = 0; e->events[j].evID = 0; e->events[j].status = EVENT_TYPE_OK; @@ -417,10 +493,10 @@ long RawFile::read_event(EventType expected, } /// Read single event into fixed buffer -long RawFile::read_event(EventType expected, - EventType& found_type, - unsigned char* data_ptr, - size_t len) +long RawFile::read_event(EventType expected, + EventType& found_type, + unsigned char* data_ptr, + std::size_t len) { unsigned char* data; InPlaceAllocator alloc(data_ptr, len); @@ -429,20 +505,20 @@ long RawFile::read_event(EventType expected, /// Read multiple events into fixed buffer (burst mode) std::pair<long,long> -RawFile::read_multiple_events(size_t num_events, +RawFile::read_multiple_events(std::size_t num_events, EventType expected, EventType& found_type, unsigned char* p, - size_t len) + std::size_t len) { if ( p && len > 0 ) { - size_t len_left = len; - long num_evts = 0; - size_t len_frame = 0; + std::size_t len_left = len; + std::size_t len_frame = 0; + long num_evts = 0; unsigned char* ptr = p; EventType found; off64_t file_position = this->seek(0, SEEK_CUR); - for (size_t i=0; i<num_events && ptr < p+len; ++i) { + for (std::size_t i=0; i<num_events && ptr < p+len; ++i) { // Type is tricky here: auto-switch to concrete mode if AUTO is enabled long evt_len = this->read_event(expected, found, ptr, len_left); if ( expected != AUTO_INPUT_TYPE && found != expected ) { @@ -475,11 +551,11 @@ RawFile::read_multiple_events(size_t num_events, /// Search bad file and try to seek the next event record. Returns offset to next event long RawFile::scanToNextMDF() { - unsigned char buff[128], *bend = buff+sizeof(buff); - off64_t file_position = this->seek(0, SEEK_CUR); - off64_t hdr_len = EventHeader::sizeOf(3); // Header version 3! - size_t num_file_byte = 0, read_len = sizeof(buff)-hdr_len; - unsigned char* qstart = buff+hdr_len; + unsigned char buff[128], *bend = buff+sizeof(buff); + off64_t file_position = this->seek(0, SEEK_CUR); + off64_t hdr_len = EventHeader::sizeOf(3); // Header version 3! + std::size_t num_file_byte = 0, read_len = sizeof(buff)-hdr_len; + unsigned char* qstart = buff+hdr_len; int status = 1, count = 0, _debug = 0; ::memset(buff,0,sizeof(buff)); @@ -496,7 +572,7 @@ long RawFile::scanToNextMDF() { //cout << "Bank[" << count << "]: " << EventPrintout::bankHeader(bank) << endl; } if ( hdr->headerVersion()>0 && hdr->headerVersion()<5 ) { - size_t siz = hdr->size0(); + std::size_t siz = hdr->size0(); if ( _debug ) { cout << "EventHeader:[" << count << ", " << long(p-qstart) << "] Size:" << siz << " " << hdr->size1() << " " << hdr->size2() @@ -545,7 +621,7 @@ void RawFile::saveRestOfFile() { cname(), !err.empty() ? err.c_str() : "????????"); return; } - size_t cnt = 0; + std::size_t cnt = 0; unsigned char buffer[10 * 1024]; for (int ret; (ret = this->read(buffer, sizeof(buffer))) > 0; ) { if ( !out.write(buffer, ret) ) { @@ -563,7 +639,7 @@ void RawFile::saveRestOfFile() { } /// Scan single record and check for consistency -int RawFile::checkRecord(size_t offset, const void* data, size_t length) const { +int RawFile::checkRecord(std::size_t offset, const void* data, std::size_t length) const { if ( data && length ) { const char* ptr = (const char*)data; bool bad_record = this->checkEventHeader(offset, data, length) != 1; @@ -585,7 +661,7 @@ int RawFile::checkRecord(size_t offset, const void* data, size_t length) const } /// Scan single record and check for consistency -int RawFile::checkEventHeader(size_t offset, const void* data, size_t length) const { +int RawFile::checkEventHeader(std::size_t offset, const void* data, std::size_t length) const { if ( data && length ) { const char* ptr = (const char*)data; const EventHeader* hdr = (const EventHeader*)ptr; @@ -617,7 +693,7 @@ int RawFile::checkEventHeader(size_t offset, const void* data, size_t length) c } /// Check content of bank -int RawFile::checkBank(size_t offset, const void* data) const { +int RawFile::checkBank(std::size_t offset, const void* data) const { const Tell1Bank* b = (const Tell1Bank*)data; typedef Tell1Printout _P; // Check bank's magic word @@ -644,7 +720,7 @@ int RawFile::checkBank(size_t offset, const void* data) const { } /// Dump a set of raw banks -void RawFile::dump(const unsigned char* data, size_t len) const { +void RawFile::dump(const unsigned char* data, std::size_t len) const { const unsigned char* ptr = data; const unsigned char* end = data + len; while( ptr < end ) { @@ -693,7 +769,7 @@ namespace { extern "C" int mdf_file_read(int argc, char** argv) { struct malloc_allocator final : public RawFile::Allocator { - unsigned char* operator()(size_t memsize) override { + unsigned char* operator()(std::size_t memsize) override { return (unsigned char*)::malloc(memsize); } } allocator; @@ -713,8 +789,8 @@ extern "C" int mdf_file_read(int argc, char** argv) { } for(long num_evt = 0, num_read = 0;;) { const unsigned char* data = 0; - RawFile::EventType found_type; - pair<long,long> ret; + RawFile::EventType found_type; + pair<long,long> ret; ret = mdf.read_multiple_events(packing, RawFile::MDF_INPUT_TYPE, found_type, @@ -727,8 +803,8 @@ extern "C" int mdf_file_read(int argc, char** argv) { const unsigned char* start = data; for(int i=0; i < ret.first; ++i) { const EventHeader* header = (const EventHeader*)start; - size_t length = header->size0(); - size_t hdrlen = header->sizeOf(header->headerVersion()); + std::size_t length = header->size0(); + std::size_t hdrlen = header->sizeOf(header->headerVersion()); ::lib_rtl_output(LIB_RTL_INFO,"ReadMDF: ++ =========================================================== ++"); ::lib_rtl_output(LIB_RTL_INFO,"ReadMDF: ++ Bank dump of subevent %3d Run:%d Orbit:%d bunchID:%d", i, header->subHeader().H1->runNumber(), diff --git a/Online/Tell1Data/src/Tell1Decoder.cpp b/Online/Tell1Data/src/Tell1Decoder.cpp index 0aaf5f66d0e8088de514de6cca5219f563765c11..9639b8836d26e529f695336a9045d5722a858f9a 100644 --- a/Online/Tell1Data/src/Tell1Decoder.cpp +++ b/Online/Tell1Data/src/Tell1Decoder.cpp @@ -689,83 +689,96 @@ std::string Online::Tell1Printout::bankType(const Tell1Bank* r) { std::string Online::Tell1Printout::bankType(int i) { #define PRINT(x) case Tell1Bank::x : return #x; switch(i) { - PRINT(L0Calo); // 0 - PRINT(L0DU); // 1 - PRINT(PrsE); // 2 - PRINT(EcalE); // 3 - PRINT(HcalE); // 4 - PRINT(PrsTrig); // 5 - PRINT(EcalTrig); // 6 - PRINT(HcalTrig); // 7 - PRINT(Velo); // 8 - PRINT(Rich); // 9 - PRINT(TT); // 10 - PRINT(IT); // 11 - PRINT(OT); // 12 - PRINT(Muon); // 13 - PRINT(L0PU); // 14 - PRINT(DAQ); // 15 - PRINT(ODIN); // 16 - PRINT(HltDecReports); // 17 - PRINT(VeloFull); // 18 - PRINT(TTFull); // 19 - PRINT(ITFull); // 20 - PRINT(EcalPacked); // 21 - PRINT(HcalPacked); // 22 - PRINT(PrsPacked); // 23 - PRINT(L0Muon); // 24 - PRINT(ITError); // 25 - PRINT(TTError); // 26 - PRINT(ITPedestal); // 27 - PRINT(TTPedestal); // 28 - PRINT(VeloError); // 29 - PRINT(VeloPedestal); // 30 - PRINT(VeloProcFull); // 31 - PRINT(OTRaw); // 32 - PRINT(OTError); // 33 - PRINT(EcalPackedError); // 34 - PRINT(HcalPackedError); // 35 - PRINT(PrsPackedError); // 36 - PRINT(L0CaloFull); // 37 - PRINT(L0CaloError); // 38 - PRINT(L0MuonCtrlAll); // 39 - PRINT(L0MuonProcCand); // 40 - PRINT(L0MuonProcData); // 41 - PRINT(L0MuonRaw); // 42 - PRINT(L0MuonError); // 43 - PRINT(GaudiSerialize); // 44 - PRINT(GaudiHeader); // 45 - PRINT(TTProcFull); // 46 - PRINT(ITProcFull); // 47 - PRINT(TAEHeader); // 48 - PRINT(MuonFull); // 49 - PRINT(MuonError); // 50 - PRINT(TestDet); // 51 - PRINT(L0DUError); // 52 - PRINT(HltRoutingBits); // 53 - PRINT(HltSelReports); // 54 - PRINT(HltVertexReports);// 55 - PRINT(HltLumiSummary); // 56 - PRINT(L0PUFull); // 57 - PRINT(L0PUError); // 58 - PRINT(DstBank); // 59 - PRINT(DstData); // 60 - PRINT(DstAddress); // 61 - PRINT(FileID); // 62 - PRINT(VP); // 63 - PRINT(FTCluster); // 64 - PRINT(VL); // 65 - PRINT(UT); // 66 - PRINT(UTFull); // 67 - PRINT(UTError); // 68 - PRINT(UTPedestal); // 69 - PRINT(HC); // 70 - PRINT(HltTrackReports); // 71 - PRINT(HCError); // 72 - PRINT(VPRetinaCluster); // 73 - PRINT(FTGeneric); // 74 - PRINT(FTCalibration); // 75 - PRINT(FTNZS); // 76 + PRINT(L0Calo); // 0 + PRINT(L0DU); // 1 + PRINT(PrsE); // 2 + PRINT(EcalE); // 3 + PRINT(HcalE); // 4 + PRINT(PrsTrig); // 5 + PRINT(EcalTrig); // 6 + PRINT(HcalTrig); // 7 + PRINT(Velo); // 8 + PRINT(Rich); // 9 + PRINT(TT); // 10 + PRINT(IT); // 11 + PRINT(OT); // 12 + PRINT(Muon); // 13 + PRINT(L0PU); // 14 + PRINT(DAQ); // 15 + PRINT(ODIN); // 16 + PRINT(HltDecReports); // 17 + PRINT(VeloFull); // 18 + PRINT(TTFull); // 19 + PRINT(ITFull); // 20 + PRINT(EcalPacked); // 21 + PRINT(HcalPacked); // 22 + PRINT(PrsPacked); // 23 + PRINT(L0Muon); // 24 + PRINT(ITError); // 25 + PRINT(TTError); // 26 + PRINT(ITPedestal); // 27 + PRINT(TTPedestal); // 28 + PRINT(VeloError); // 29 + PRINT(VeloPedestal); // 30 + PRINT(VeloProcFull); // 31 + PRINT(OTRaw); // 32 + PRINT(OTError); // 33 + PRINT(EcalPackedError); // 34 + PRINT(HcalPackedError); // 35 + PRINT(PrsPackedError); // 36 + PRINT(L0CaloFull); // 37 + PRINT(L0CaloError); // 38 + PRINT(L0MuonCtrlAll); // 39 + PRINT(L0MuonProcCand); // 40 + PRINT(L0MuonProcData); // 41 + PRINT(L0MuonRaw); // 42 + PRINT(L0MuonError); // 43 + PRINT(GaudiSerialize); // 44 + PRINT(GaudiHeader); // 45 + PRINT(TTProcFull); // 46 + PRINT(ITProcFull); // 47 + PRINT(TAEHeader); // 48 + PRINT(MuonFull); // 49 + PRINT(MuonError); // 50 + PRINT(TestDet); // 51 + PRINT(L0DUError); // 52 + PRINT(HltRoutingBits); // 53 + PRINT(HltSelReports); // 54 + PRINT(HltVertexReports); // 55 + PRINT(HltLumiSummary); // 56 + PRINT(L0PUFull); // 57 + PRINT(L0PUError); // 58 + PRINT(DstBank); // 59 + PRINT(DstData); // 60 + PRINT(DstAddress); // 61 + PRINT(FileID); // 62 + PRINT(VP); // 63 + PRINT(FTCluster); // 64 + PRINT(VL); // 65 + PRINT(UT); // 66 + PRINT(UTFull); // 67 + PRINT(UTError); // 68 + PRINT(UTPedestal); // 69 + PRINT(HC); // 70 + PRINT(HltTrackReports); // 71 + PRINT(HCError); // 72 + PRINT(VPRetinaCluster); // 73 + PRINT(FTGeneric); // 74 + PRINT(FTCalibration); // 75 + PRINT(FTNZS); // 76 + PRINT(Calo); // 77 + PRINT(CaloError); // 78 + PRINT(MuonSpecial); // 79 + PRINT(RichCommissioning); // 80 + PRINT(RichError); // 81 + PRINT(FTSpecial); // 82 + /// DAQ errors: + PRINT(DaqErrorFragmentThrottled); // 250 + PRINT(DaqErrorBXIDCorrupted) // 251 + PRINT(DaqErrorBXIDJump) // 252 + PRINT(DaqErrorFragmentMissing) // 253 + PRINT(DaqErrorFragmentTruncated) // 254 + PRINT(DaqErrorInvalid) // 255 default: if ( i >= Tell1Bank::DaqErrorBase ) diff --git a/Online/sqldb/sqldb/sqldb-imp.h b/Online/sqldb/sqldb/sqldb-imp.h index 06ff71dc5548778dc6efdcbf8b6251d875306d20..3856b2e4dcdb1075e40ccebbfb780bcb9448f0cf 100644 --- a/Online/sqldb/sqldb/sqldb-imp.h +++ b/Online/sqldb/sqldb/sqldb-imp.h @@ -77,7 +77,7 @@ namespace sqldb { struct tm tm; char buff[256]; ::localtime_r(&this->stamp, &tm); - size_t len = ::strftime(buff, sizeof(buff), format.c_str(), &tm); + std::size_t len = ::strftime(buff, sizeof(buff), format.c_str(), &tm); if ( len > 0 ) return buff; throw std::runtime_error("Invalid data conversion to time with format: "+format); } @@ -148,7 +148,7 @@ namespace sqldb { } /// Bind pointers for writing - SQLDB_INLINE void column_data::bind_pointer(const void* ptr, size_t len) { + SQLDB_INLINE void column_data::bind_pointer(const void* ptr, std::size_t len) { if ( len < sizeof(column_data::buf) ) { ::memcpy(this->buf, ptr, len); this->item.pointer = this->buf; @@ -244,7 +244,7 @@ namespace sqldb { } /// Access type specific field data - template <> SQLDB_INLINE blob_t record::get<blob_t>(size_t col) const { + template <> SQLDB_INLINE blob_t record::get<blob_t>(std::size_t col) const { auto& column = this->field(col); switch( column.type ) { case TYPE_BLOB: @@ -257,7 +257,7 @@ namespace sqldb { } /// Access type specific field data - template <> SQLDB_INLINE vblob_t record::get<vblob_t>(size_t col) const { + template <> SQLDB_INLINE vblob_t record::get<vblob_t>(std::size_t col) const { const auto& column = this->field(col); switch( column.type ) { case TYPE_BLOB: @@ -270,7 +270,7 @@ namespace sqldb { } /// Access type specific field data - template <> SQLDB_INLINE std::string record::get<std::string>(size_t col) const { + template <> SQLDB_INLINE std::string record::get<std::string>(std::size_t col) const { const auto& column = this->field(col); switch( column.type ) { case TYPE_BLOB: @@ -303,162 +303,162 @@ namespace sqldb { } /// Access type specific field data - template <> SQLDB_INLINE signed char record::get<signed char>(size_t col) const { + template <> SQLDB_INLINE signed char record::get<signed char>(std::size_t col) const { return to_integer<signed char>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE char record::get<char>(size_t col) const { + template <> SQLDB_INLINE char record::get<char>(std::size_t col) const { return to_integer<char>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE unsigned char record::get<unsigned char>(size_t col) const { + template <> SQLDB_INLINE unsigned char record::get<unsigned char>(std::size_t col) const { return to_integer<unsigned char>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE int16_t record::get<int16_t>(size_t col) const { + template <> SQLDB_INLINE int16_t record::get<int16_t>(std::size_t col) const { return to_integer<int16_t>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE uint16_t record::get<uint16_t>(size_t col) const { + template <> SQLDB_INLINE uint16_t record::get<uint16_t>(std::size_t col) const { return to_integer<uint16_t>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE int32_t record::get<int32_t>(size_t col) const { + template <> SQLDB_INLINE int32_t record::get<int32_t>(std::size_t col) const { return to_integer<int32_t>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE uint32_t record::get<uint32_t>(size_t col) const { + template <> SQLDB_INLINE uint32_t record::get<uint32_t>(std::size_t col) const { return to_integer<uint32_t>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE int64_t record::get<int64_t>(size_t col) const { + template <> SQLDB_INLINE int64_t record::get<int64_t>(std::size_t col) const { return to_integer<int64_t>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE uint64_t record::get<uint64_t>(size_t col) const { + template <> SQLDB_INLINE uint64_t record::get<uint64_t>(std::size_t col) const { return to_integer<uint64_t>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE float record::get<float>(size_t col) const { + template <> SQLDB_INLINE float record::get<float>(std::size_t col) const { return to_real<float>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE double record::get<double>(size_t col) const { + template <> SQLDB_INLINE double record::get<double>(std::size_t col) const { return to_real<double>(this->field(col)); } /// Access type specific field data - template <> SQLDB_INLINE time record::get<class time>(size_t col) const { + template <> SQLDB_INLINE time record::get<class time>(std::size_t col) const { return to_time(this->field(col)); } /// Generic bind of a single parameter column - SQLDB_INLINE sqldb_status record_bind::bind (size_t column, field_type typ, const void* data, size_t len) const { + SQLDB_INLINE sqldb_status record_bind::bind (std::size_t column, field_type typ, const void* data, std::size_t len) const { return stmt->_bind(column, typ, data, len); } /// Type specific bind operator for blobs - SQLDB_INLINE sqldb_status record_bind::bind(size_t col, const blob_t& data) const { + SQLDB_INLINE sqldb_status record_bind::bind(std::size_t col, const blob_t& data) const { return stmt->_bind(col, TYPE_BLOB, data.first, data.second); } /// Type specific bind operator for blobs - SQLDB_INLINE sqldb_status record_bind::bind(size_t col, const vblob_t& data) const { + SQLDB_INLINE sqldb_status record_bind::bind(std::size_t col, const vblob_t& data) const { return stmt->_bind(col, TYPE_BLOB, &data.at(0), data.size()); } /// Type specific bind operator for blobs - SQLDB_INLINE sqldb_status record_bind::bind(size_t col, const uint8_t* data, size_t len) const { + SQLDB_INLINE sqldb_status record_bind::bind(std::size_t col, const uint8_t* data, std::size_t len) const { return stmt->_bind(col, TYPE_BLOB, data, len); } /// Type specific bind operator for strings - SQLDB_INLINE sqldb_status record_bind::bind(size_t col, std::string& data) const { + SQLDB_INLINE sqldb_status record_bind::bind(std::size_t col, std::string& data) const { return stmt->_bind(col, TYPE_STRING, data.c_str(), data.length()); } /// Type specific bind operator for strings - SQLDB_INLINE sqldb_status record_bind::bind(size_t col, const std::string& data) const { + SQLDB_INLINE sqldb_status record_bind::bind(std::size_t col, const std::string& data) const { return stmt->_bind(col, TYPE_STRING, data.c_str(), data.length()); } /// Type specific bind operator for strings - SQLDB_INLINE sqldb_status record_bind::bind(size_t col, char* const data) const { + SQLDB_INLINE sqldb_status record_bind::bind(std::size_t col, char* const data) const { return stmt->_bind(col, TYPE_STRING, data ? data : "", data ? ::strlen(data) : 0); } /// Type specific bind operator for strings - SQLDB_INLINE sqldb_status record_bind::bind(size_t col, const char* const data) const { + SQLDB_INLINE sqldb_status record_bind::bind(std::size_t col, const char* const data) const { return stmt->_bind(col, TYPE_STRING, data ? data : "", data ? ::strlen(data) : 0); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<char>(size_t col, char data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<char>(std::size_t col, char data) const { return stmt->_bind(col, TYPE_TINY, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<signed char>(size_t col, signed char data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<signed char>(std::size_t col, signed char data) const { return stmt->_bind(col, TYPE_TINY, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<unsigned char>(size_t col, unsigned char data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<unsigned char>(std::size_t col, unsigned char data) const { return stmt->_bind(col, TYPE_TINY, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<int16_t>(size_t col, int16_t data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<int16_t>(std::size_t col, int16_t data) const { return stmt->_bind(col, TYPE_SHORT, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<uint16_t>(size_t col, uint16_t data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<uint16_t>(std::size_t col, uint16_t data) const { return stmt->_bind(col, TYPE_SHORT, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<int32_t>(size_t col, int32_t data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<int32_t>(std::size_t col, int32_t data) const { return stmt->_bind(col, TYPE_LONG, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<uint32_t>(size_t col, uint32_t data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<uint32_t>(std::size_t col, uint32_t data) const { return stmt->_bind(col, TYPE_LONG, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<int64_t>(size_t col, int64_t data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<int64_t>(std::size_t col, int64_t data) const { return stmt->_bind(col, TYPE_LONGLONG, &data, sizeof(data)); } /// Type specific bind operator for integer type - template <> SQLDB_INLINE sqldb_status record_bind::bind<uint64_t>(size_t col, uint64_t data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<uint64_t>(std::size_t col, uint64_t data) const { return stmt->_bind(col, TYPE_LONGLONG, &data, sizeof(data)); } /// Type specific bind operator for float type - template <> SQLDB_INLINE sqldb_status record_bind::bind<float>(size_t col, float data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<float>(std::size_t col, float data) const { return stmt->_bind(col, TYPE_FLOAT, &data, sizeof(data)); } /// Type specific bind operator for double type - template <> SQLDB_INLINE sqldb_status record_bind::bind<double>(size_t col, double data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<double>(std::size_t col, double data) const { return stmt->_bind(col, TYPE_DOUBLE, &data, sizeof(data)); } /// Type specific bind operator for time type - template <> SQLDB_INLINE sqldb_status record_bind::bind<class time>(size_t col, class time data) const { + template <> SQLDB_INLINE sqldb_status record_bind::bind<class time>(std::size_t col, class time data) const { return stmt->_bind(col, TYPE_TIME, &data.stamp, sizeof(data.stamp)); } @@ -530,7 +530,7 @@ namespace sqldb { } /// Generic bind of a single parameter column - SQLDB_INLINE sqldb_status statement::_bind(size_t column, field_type typ, const void* data, size_t len) const { + SQLDB_INLINE sqldb_status statement::_bind(std::size_t column, field_type typ, const void* data, std::size_t len) const { return intern->bind(column, typ, data, len); } diff --git a/Online/sqldb/sqldb/sqldb.h b/Online/sqldb/sqldb/sqldb.h index 3361b3950f8c68a4985b7143ce1fe0d2ddec1e85..658a807f43706d120b56c32069e4beda21ebc414 100644 --- a/Online/sqldb/sqldb/sqldb.h +++ b/Online/sqldb/sqldb/sqldb.h @@ -64,8 +64,8 @@ namespace sqldb { TYPE_TIME = 23 }; - typedef std::pair<const uint8_t*, size_t> blob_t; - typedef std::vector<unsigned char> vblob_t; + typedef std::pair<const uint8_t*, std::size_t> blob_t; + typedef std::vector<unsigned char> vblob_t; class statement; class database; @@ -266,7 +266,7 @@ namespace sqldb { this->buf[0] = 0; } /// Bind pointers for writing - void bind_pointer(const void* ptr, size_t len); + void bind_pointer(const void* ptr, std::size_t len); }; /// Database handle class @@ -423,13 +423,13 @@ namespace sqldb { record& operator = (const record& copy) = default; /// Access the number of result fields of the prepared statement - size_t field_count() const; + std::size_t field_count() const; /// Access raw data from result handle - column_data& field(size_t column) const; + column_data& field(std::size_t column) const; /// Check if the field is NULL - bool is_null(size_t column) const; + bool is_null(std::size_t column) const; /// Access type specific field data - template <typename T> T get (size_t column) const; + template <typename T> T get (std::size_t column) const; }; /// Record set class @@ -491,23 +491,23 @@ namespace sqldb { record_bind& operator = (const record_bind& copy) = default; /// Generic bind of a single parameter column - sqldb_status bind(size_t column, field_type typ, const void* data, size_t len) const; + sqldb_status bind(std::size_t column, field_type typ, const void* data, std::size_t len) const; /// Type specific bind operator for blobs - sqldb_status bind(size_t column, const blob_t& data) const; + sqldb_status bind(std::size_t column, const blob_t& data) const; /// Type specific bind operator for blobs - sqldb_status bind(size_t column, const vblob_t& data) const; + sqldb_status bind(std::size_t column, const vblob_t& data) const; /// Type specific bind operator for blobs - sqldb_status bind(size_t column, const uint8_t* data, size_t len) const; + sqldb_status bind(std::size_t column, const uint8_t* data, std::size_t len) const; /// Type specific bind operator for strings - sqldb_status bind(size_t column, char* const data) const; + sqldb_status bind(std::size_t column, char* const data) const; /// Type specific bind operator for strings - sqldb_status bind(size_t column, const char* const data) const; + sqldb_status bind(std::size_t column, const char* const data) const; /// Type specific bind operator for strings - sqldb_status bind(size_t column, std::string& data) const; + sqldb_status bind(std::size_t column, std::string& data) const; /// Type specific bind operator for strings - sqldb_status bind(size_t column, const std::string& data) const; + sqldb_status bind(std::size_t column, const std::string& data) const; /// Type specific bind operator for blobs - template <typename T> sqldb_status bind(size_t column, T data) const; + template <typename T> sqldb_status bind(std::size_t column, T data) const; }; /// Statement handle class @@ -554,16 +554,16 @@ namespace sqldb { /// Perform multiple backend operations virtual int action(action_type type) = 0; /// Bind a single column to the data passed - virtual sqldb_status bind(size_t col, field_type typ, const void* data, size_t len) = 0; + virtual sqldb_status bind(std::size_t col, field_type typ, const void* data, std::size_t len) = 0; }; std::shared_ptr<backend> intern; protected: /// Access raw data from result handle - column_data& _field(size_t column) const; + column_data& _field(std::size_t column) const; /// Generic bind of a single parameter column - sqldb_status _bind(size_t column, field_type typ, const void* data, size_t len) const; + sqldb_status _bind(std::size_t column, field_type typ, const void* data, std::size_t len) const; public: @@ -590,7 +590,7 @@ namespace sqldb { sqldb_status prepare(const database& db, const char* fmt, ...); /// Access the number of result fields of the prepared statement - size_t param_count() const; + std::size_t param_count() const; /// Check handle validity bool is_valid() const; @@ -620,7 +620,7 @@ namespace sqldb { record current_row() const; /// Access raw parameter data from statement handle - column_data& param(size_t column) const; + column_data& param(std::size_t column) const; }; /// Default constructor @@ -635,7 +635,7 @@ namespace sqldb { } /// Access the number of result fields of the prepared statement - inline size_t statement::param_count() const { + inline std::size_t statement::param_count() const { return intern->params.size(); } @@ -660,14 +660,14 @@ namespace sqldb { } /// Access raw parameter data from statement handle - inline column_data& statement::param(size_t column) const { + inline column_data& statement::param(std::size_t column) const { if ( column >= intern->params.size() ) invalid_statement("Invalid column identifier"); return intern->params.at(column); } /// Access raw data from result handle - inline column_data& statement::_field(size_t column) const { + inline column_data& statement::_field(std::size_t column) const { if ( column >= intern->fields.size() ) invalid_statement("Invalid column identifier"); return intern->fields.at(column); @@ -679,16 +679,16 @@ namespace sqldb { } /// Access the number of result fields of the prepared statement - inline size_t record::field_count() const { + inline std::size_t record::field_count() const { return this->stmt->intern->fields.size(); } /// Access raw data from result handle - inline column_data& record::field(size_t column) const { + inline column_data& record::field(std::size_t column) const { return this->stmt->_field(column); } - inline bool record::is_null(size_t col) const { + inline bool record::is_null(std::size_t col) const { return this->stmt->_field(col).null; } } // End namespace sqldb diff --git a/Online/sqldb/src/mysql.cpp b/Online/sqldb/src/mysql.cpp index bf5a1bad1a6432e5795f536c429c84a951993856..b701f40b33d51f286745e965808dc5cbf1a6455c 100644 --- a/Online/sqldb/src/mysql.cpp +++ b/Online/sqldb/src/mysql.cpp @@ -85,7 +85,7 @@ namespace sqldb { return sqldb::OK; } /// Generic parameter binding - sqldb_status bind_store(column_data* d, const unsigned char* ptr, size_t len) { + sqldb_status bind_store(column_data* d, const unsigned char* ptr, std::size_t len) { if ( ptr ) { d->bind_pointer(ptr, len); this->buffer = d->item.string; @@ -110,7 +110,7 @@ namespace sqldb { return this->bind_store_null(d); } /// Bind output field - sqldb_status bind_fetch(column_data* d, void* to, size_t len) { + sqldb_status bind_fetch(column_data* d, void* to, std::size_t len) { d->null = false; d->error = false; d->length = 0; @@ -217,10 +217,10 @@ namespace sqldb { /// Fetch next result row. Stop if result is NON-zero virtual sqldb_status fetch_one() { if ( this->_imp ) { - size_t nfld = this->_fbind.size(); + std::size_t nfld = this->_fbind.size(); if ( nfld > 0 ) { ::memset(&this->_fbind.front(), 0, nfld*sizeof(column_bind)); - for( size_t i=0; i < nfld; i++ ) { + for( std::size_t i=0; i < nfld; i++ ) { this->bind_fetch(i); if ( !mysql_ok(::mysql_stmt_bind_result(this->_imp, &this->_fbind.front())) ) return invalid_statement(::mysql_stmt_error(this->_imp)); @@ -231,7 +231,7 @@ namespace sqldb { return sqldb::NO_DATA; } else if( ret == MYSQL_DATA_TRUNCATED ) { - for( size_t i=0; i < nfld; i++ ) { + for( std::size_t i=0; i < nfld; i++ ) { auto& d = this->fields[i]; if( d.error && !d.null && d.length >= sizeof(d.buf) ) { auto& b = this->_fbind[i]; @@ -251,7 +251,7 @@ namespace sqldb { } /// Bind output field identified by column number - sqldb_status bind_fetch(size_t col) { + sqldb_status bind_fetch(std::size_t col) { auto* p = this; auto [d, b, f] = p->field(col); @@ -274,7 +274,7 @@ namespace sqldb { } /// Bind a single column to the data passed - virtual sqldb_status bind(size_t col, field_type typ, const void* data, size_t len) override { + virtual sqldb_status bind(std::size_t col, field_type typ, const void* data, std::size_t len) override { pointers_t ptr(data); auto [d, b] = this->param(col); ::memset(b, 0, sizeof(column_bind)); diff --git a/Online/sqldb/src/oracle.cpp b/Online/sqldb/src/oracle.cpp index 33e1806e2fe431b550535ac7bd39ff27356efd4d..f45ba5a76bdc3c9c0d38a5feadb7c60c7e6b6b4d 100644 --- a/Online/sqldb/src/oracle.cpp +++ b/Online/sqldb/src/oracle.cpp @@ -136,7 +136,7 @@ namespace sqldb { */ class column_bind { public: - size_t _column { 0 }; + std::size_t _column { 0 }; statement_backend* _stm { nullptr }; BindH _bind { nullptr }; DefineH _define { nullptr }; @@ -159,9 +159,9 @@ namespace sqldb { column_bind& operator = (const column_bind& copy) = delete; /// Generic parameter binding - sqldb_status bind_str(column_data& d, const char* ptr, size_t len); + sqldb_status bind_str(column_data& d, const char* ptr, std::size_t len); /// Generic parameter binding - sqldb_status bind_blob(column_data& d, const unsigned char* ptr, size_t len); + sqldb_status bind_blob(column_data& d, const unsigned char* ptr, std::size_t len); /// Type specific parameter bind sqldb_status bind_int(column_data& d, int32_t from); /// Type specific parameter bind @@ -171,7 +171,7 @@ namespace sqldb { /// Read lob data sqldb_status fetch_data(column_data& d); /// Bind output field - sqldb_status bind_fetch(column_data& d, void* ptr, size_t len); + sqldb_status bind_fetch(column_data& d, void* ptr, std::size_t len); }; /// Technology abstraction layer @@ -247,11 +247,11 @@ namespace sqldb { /// Fetch next result row. Stop if result is NON-zero sqldb_status fetch_one(); /// Bind output field identified by column number - sqldb_status bind_fetch(size_t col); + sqldb_status bind_fetch(std::size_t col); /// Prepare a new statement and allocate resources. sqldb_status prepare(const std::string& sql_str); /// Bind a single column to the data passed - virtual sqldb_status bind(size_t col, field_type typ, const void* data, size_t len) override; + virtual sqldb_status bind(std::size_t col, field_type typ, const void* data, std::size_t len) override; /// virtual int action(action_type type) override; }; @@ -314,7 +314,7 @@ namespace sqldb { } /// Generic parameter binding - sqldb_status column_bind::bind_str(column_data& d, const char* ptr, size_t len) { + sqldb_status column_bind::bind_str(column_data& d, const char* ptr, std::size_t len) { pointers_t p(ptr); d.bind_pointer(p.puint8, len); auto ret = ::OCIBindByPos(_stm->_stmt, &_bind, _stm->_error, @@ -324,7 +324,7 @@ namespace sqldb { } /// Generic parameter binding - sqldb_status column_bind::bind_blob(column_data& d, const unsigned char* ptr, size_t len) { + sqldb_status column_bind::bind_blob(column_data& d, const unsigned char* ptr, std::size_t len) { pointers_t p(ptr); d.bind_pointer(ptr, len); auto ret = ::OCIBindByPos(_stm->_stmt, &_bind, _stm->_error, @@ -386,7 +386,7 @@ namespace sqldb { } /// Bind output field - sqldb_status column_bind::bind_fetch(column_data& d, void* ptr, size_t len) { + sqldb_status column_bind::bind_fetch(column_data& d, void* ptr, std::size_t len) { result_t rc = OCI_SUCCESS; d.null = false; d.error = false; @@ -422,9 +422,9 @@ namespace sqldb { /// Fetch next result row. Stop if result is NON-zero sqldb_status statement_backend::fetch_one() { if ( _stmt ) { - size_t nfld = _fbind.size(); + std::size_t nfld = _fbind.size(); if ( nfld > 0 ) { - for( size_t i=0; i < nfld; i++ ) { + for( std::size_t i=0; i < nfld; i++ ) { if ( bind_fetch(i) != sqldb::OK ) { return invalid_statement(errmsg()); } @@ -432,7 +432,7 @@ namespace sqldb { } result_t ret = ::OCIStmtFetch(_stmt, _error, 1, OCI_FETCH_NEXT, OCI_DEFAULT); if( ret == OCI_SUCCESS ) { - for( size_t i=0; i < nfld; i++ ) { + for( std::size_t i=0; i < nfld; i++ ) { auto& d = fields[i]; if ( d.type == TYPE_BLOB ) { if ( sqldb::OK != _fbind[i].fetch_data(d) ) { @@ -447,7 +447,7 @@ namespace sqldb { } /// Bind output field identified by column number - sqldb_status statement_backend::bind_fetch(size_t col) { + sqldb_status statement_backend::bind_fetch(std::size_t col) { auto* p = this; auto [d, b, type] = p->field(col); b->_column = col; @@ -472,7 +472,7 @@ namespace sqldb { } /// Bind a single column to the data passed - sqldb_status statement_backend::bind(size_t col, field_type typ, const void* data, size_t len) { + sqldb_status statement_backend::bind(std::size_t col, field_type typ, const void* data, std::size_t len) { pointers_t ptr(data); auto [d, b] = param(col); d->type = typ; @@ -527,7 +527,7 @@ namespace sqldb { OCI_ATTR_PARAM_COUNT, _error); CHECK(ret); _types.clear(); - for(size_t i=0; i<count; ++i) { + for( std::size_t i=0; i<count; ++i ) { ub2 type; ParamH colhd { nullptr }; ret = ::OCIParamGet(stm, OCI_HTYPE_STMT, _error, (void**)&colhd, i); diff --git a/Online/sqldb/src/postgresql.cpp b/Online/sqldb/src/postgresql.cpp index 7e2688e7ac55de4fe28ba3ef2a4193df00a5b1a7..3ada100afa0ca67201c061ca5d7f6a7bd6a46bee 100644 --- a/Online/sqldb/src/postgresql.cpp +++ b/Online/sqldb/src/postgresql.cpp @@ -32,9 +32,9 @@ namespace sqldb { struct statement_backend; /// - std::string _escape(postgresql::dbase_t* hdl, const char* str, size_t length) { + std::string _escape(postgresql::dbase_t* hdl, const char* str, std::size_t length) { std::vector<char> buf(2*length+1); - size_t len = ::PQescapeStringConn(hdl, &buf.front(), str, length, 0); + std::size_t len = ::PQescapeStringConn(hdl, &buf.front(), str, length, 0); return std::string(&buf.front(), len); } /// @@ -135,15 +135,15 @@ namespace sqldb { /// Bind parameter to null value sqldb_status bind_store_null(column_data& d); /// Generic parameter binding - sqldb_status bind_store(column_data& d, const char* ptr, size_t len); + sqldb_status bind_store(column_data& d, const char* ptr, std::size_t len); /// Generic parameter binding - sqldb_status bind_store(column_data& d, const unsigned char* ptr, size_t len); + sqldb_status bind_store(column_data& d, const unsigned char* ptr, std::size_t len); /// Type specific parameter bind template <typename T> sqldb_status bind_store(column_data& d, T& to, const T* from); /// Bind output field sqldb_status bind_fetch_blob(column_data& d); /// Bind output field - template <typename T> sqldb_status bind_fetch(column_data& d, T* to, size_t len); + template <typename T> sqldb_status bind_fetch(column_data& d, T* to, std::size_t len); }; /// Technology abstraction layer for a Postgresql prepared statement @@ -172,8 +172,8 @@ namespace sqldb { std::vector<int> _param_fmt; std::vector<Oid> _param_typ; std::vector<column_bind> _fbind; - size_t _current_row {0}; - size_t _num_param {0}; + std::size_t _current_row {0}; + std::size_t _num_param {0}; template <typename T> T _to(const char* s) { T result; @@ -234,9 +234,9 @@ namespace sqldb { /// Execute prepared statement virtual sqldb_status execute(); /// Bind output field identified by column number - sqldb_status bind_fetch(size_t col); + sqldb_status bind_fetch(std::size_t col); /// Bind a single column to the data passed - virtual sqldb_status bind(size_t col, field_type typ, const void* data, size_t len) override; + virtual sqldb_status bind(std::size_t col, field_type typ, const void* data, std::size_t len) override; /// Action routine for various functions virtual int action(action_type type) override; }; @@ -252,7 +252,7 @@ namespace sqldb { } /// Generic parameter binding - sqldb_status column_bind::bind_store(column_data& d, const unsigned char* ptr, size_t len) { + sqldb_status column_bind::bind_store(column_data& d, const unsigned char* ptr, std::size_t len) { if ( ptr ) { d.bind_pointer(ptr, len); stmt->_param_ptr[col] = d.item.string; @@ -264,7 +264,7 @@ namespace sqldb { } /// Generic parameter binding - sqldb_status column_bind::bind_store(column_data& d, const char* ptr, size_t len) { + sqldb_status column_bind::bind_store(column_data& d, const char* ptr, std::size_t len) { if ( ptr ) { d.bind_pointer((const unsigned char*)ptr, len); stmt->_param_ptr[col] = d.item.string; @@ -289,7 +289,7 @@ namespace sqldb { } /// Bind output field - template <typename T> sqldb_status column_bind::bind_fetch(column_data& d, T* to, size_t len) { + template <typename T> sqldb_status column_bind::bind_fetch(column_data& d, T* to, std::size_t len) { T* ptr = (T*)::PQgetvalue(stmt->_result, stmt->_current_row, col); d.null = false; d.error = false; @@ -301,7 +301,7 @@ namespace sqldb { /// Bind output field sqldb_status column_bind::bind_fetch_blob(column_data& d) { unsigned char* ptr = (unsigned char*)::PQgetvalue(stmt->_result, stmt->_current_row, col); - size_t length = ::PQgetlength(stmt->_result, stmt->_current_row, col); + std::size_t length = ::PQgetlength(stmt->_result, stmt->_current_row, col); d.null = false; d.error = false; d.length = length; @@ -377,7 +377,7 @@ namespace sqldb { return sqldb::ERROR; } this->params.resize(this->_num_param); - for(size_t col=0; col < this->_num_param; ++col) { + for( std::size_t col=0; col < this->_num_param; ++col ) { Oid native_type = ::PQparamtype(res, col); this->_param_typ[col] = native_type; this->params[col].type = gen_field_type(native_type); @@ -389,7 +389,7 @@ namespace sqldb { } /// Bind a single column to the data passed - sqldb_status statement_backend::bind(size_t col, field_type typ, const void* data, size_t len) { + sqldb_status statement_backend::bind(std::size_t col, field_type typ, const void* data, std::size_t len) { pointers_t ptr(data); column_bind b(this, col); auto& d = this->params[col]; @@ -411,7 +411,7 @@ namespace sqldb { } /// Bind output field identified by column number - sqldb_status statement_backend::bind_fetch(size_t col) { + sqldb_status statement_backend::bind_fetch(std::size_t col) { auto typ = ::PQftype(this->_result, col); auto& d = this->fields[col]; column_bind b(this, col); diff --git a/Online/sqldb/src/sqldb.cpp b/Online/sqldb/src/sqldb.cpp index 4d884e95a19650611313f58536f4f5857bbca5d6..bb7481df76347861da8e89335ac96f2458e5cc57 100644 --- a/Online/sqldb/src/sqldb.cpp +++ b/Online/sqldb/src/sqldb.cpp @@ -104,64 +104,64 @@ namespace sqldb { return invalid_statement("Invalid recordset statement handle"); } - template <> __INLINE__ blob_t record_set::get<blob_t>(size_t col) const { + template <> __INLINE__ blob_t record_set::get<blob_t>(std::size_t col) const { auto& column = this->field(col); return blob_t(column.item.blob, column.length); } - template <> __INLINE__ vblob_t record_set::get<vblob_t>(size_t col) const { + template <> __INLINE__ vblob_t record_set::get<vblob_t>(std::size_t col) const { const auto& column = this->field(col); if ( column.item.blob ) return vblob_t(column.item.blob, column.item.blob+column.length); return vblob_t(); } - template <> __INLINE__ std::string record_set::get<std::string>(size_t col) const { + template <> __INLINE__ std::string record_set::get<std::string>(std::size_t col) const { const auto& column = this->field(col); return column.item.string ? column.item.string : ""; } - template <> __INLINE__ signed char record_set::get<signed char>(size_t col) const { + template <> __INLINE__ signed char record_set::get<signed char>(std::size_t col) const { return this->field(col).item.int8; } - template <> __INLINE__ char record_set::get<char>(size_t col) const { + template <> __INLINE__ char record_set::get<char>(std::size_t col) const { return this->field(col).item.int8; } - template <> __INLINE__ unsigned char record_set::get<unsigned char>(size_t col) const { + template <> __INLINE__ unsigned char record_set::get<unsigned char>(std::size_t col) const { return this->field(col).item.uint8; } - template <> __INLINE__ short record_set::get<short>(size_t col) const { + template <> __INLINE__ short record_set::get<short>(std::size_t col) const { return this->field(col).item.int16; } - template <> __INLINE__ unsigned short record_set::get<unsigned short>(size_t col) const { + template <> __INLINE__ unsigned short record_set::get<unsigned short>(std::size_t col) const { return this->field(col).item.uint16; } - template <> __INLINE__ int record_set::get<int>(size_t col) const { + template <> __INLINE__ int record_set::get<int>(std::size_t col) const { return this->field(col).item.int32; } - template <> __INLINE__ unsigned int record_set::get<unsigned int>(size_t col) const { + template <> __INLINE__ unsigned int record_set::get<unsigned int>(std::size_t col) const { return this->field(col).item.uint32; } - template <> __INLINE__ long record_set::get<long>(size_t col) const { + template <> __INLINE__ long record_set::get<long>(std::size_t col) const { return this->field(col).item.int64; } - template <> __INLINE__ unsigned long record_set::get<unsigned long>(size_t col) const { + template <> __INLINE__ unsigned long record_set::get<unsigned long>(std::size_t col) const { return this->field(col).item.uint64; } - template <> __INLINE__ float record_set::get<float>(size_t col) const { + template <> __INLINE__ float record_set::get<float>(std::size_t col) const { return this->field(col).item.real32; } - template <> __INLINE__ double record_set::get<double>(size_t col) const { + template <> __INLINE__ double record_set::get<double>(std::size_t col) const { return this->field(col).item.real64; } @@ -210,117 +210,117 @@ namespace sqldb { return sqldb::OK; } - template <> __INLINE__ blob_t basic_statement::get<blob_t>(size_t col) const { + template <> __INLINE__ blob_t basic_statement::get<blob_t>(std::size_t col) const { auto& column = this->field(col); return blob_t(column.item.blob, column.length); } - template <> __INLINE__ vblob_t basic_statement::get<vblob_t>(size_t col) const { + template <> __INLINE__ vblob_t basic_statement::get<vblob_t>(std::size_t col) const { const auto& column = this->field(col); if ( column.item.blob ) return vblob_t(column.item.blob, column.item.blob+column.length); return vblob_t(); } - template <> __INLINE__ std::string basic_statement::get<std::string>(size_t col) const { + template <> __INLINE__ std::string basic_statement::get<std::string>(std::size_t col) const { const auto& column = this->field(col); return column.item.string ? column.item.string : ""; } - template <> __INLINE__ signed char basic_statement::get<signed char>(size_t col) const { + template <> __INLINE__ signed char basic_statement::get<signed char>(std::size_t col) const { return this->field(col).item.int8; } - template <> __INLINE__ char basic_statement::get<char>(size_t col) const { + template <> __INLINE__ char basic_statement::get<char>(std::size_t col) const { return this->field(col).item.int8; } - template <> __INLINE__ unsigned char basic_statement::get<unsigned char>(size_t col) const { + template <> __INLINE__ unsigned char basic_statement::get<unsigned char>(std::size_t col) const { return this->field(col).item.uint8; } - template <> __INLINE__ short basic_statement::get<short>(size_t col) const { + template <> __INLINE__ short basic_statement::get<short>(std::size_t col) const { return this->field(col).item.int16; } - template <> __INLINE__ unsigned short basic_statement::get<unsigned short>(size_t col) const { + template <> __INLINE__ unsigned short basic_statement::get<unsigned short>(std::size_t col) const { return this->field(col).item.uint16; } - template <> __INLINE__ int basic_statement::get<int>(size_t col) const { + template <> __INLINE__ int basic_statement::get<int>(std::size_t col) const { return this->field(col).item.int32; } - template <> __INLINE__ unsigned int basic_statement::get<unsigned int>(size_t col) const { + template <> __INLINE__ unsigned int basic_statement::get<unsigned int>(std::size_t col) const { return this->field(col).item.uint32; } - template <> __INLINE__ long basic_statement::get<long>(size_t col) const { + template <> __INLINE__ long basic_statement::get<long>(std::size_t col) const { return this->field(col).item.int64; } - template <> __INLINE__ unsigned long basic_statement::get<unsigned long>(size_t col) const { + template <> __INLINE__ unsigned long basic_statement::get<unsigned long>(std::size_t col) const { return this->field(col).item.uint64; } - template <> __INLINE__ float basic_statement::get<float>(size_t col) const { + template <> __INLINE__ float basic_statement::get<float>(std::size_t col) const { return this->field(col).item.real32; } - template <> __INLINE__ double basic_statement::get<double>(size_t col) const { + template <> __INLINE__ double basic_statement::get<double>(std::size_t col) const { return this->field(col).item.real64; } /// Generic bind of a single parameter column - inline int basic_statement::bind (size_t column, field_type typ, const void* data, size_t len) const + inline int basic_statement::bind (std::size_t column, field_type typ, const void* data, std::size_t len) const { return intern->bind(column, typ, data, len); } - template <> __INLINE__ int basic_statement::bind<char>(size_t col, char data) const + template <> __INLINE__ int basic_statement::bind<char>(std::size_t col, char data) const { return intern->bind(col, TYPE_TINY, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<signed char>(size_t col, signed char data) const + template <> __INLINE__ int basic_statement::bind<signed char>(std::size_t col, signed char data) const { return intern->bind(col, TYPE_TINY, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<unsigned char>(size_t col, unsigned char data) const + template <> __INLINE__ int basic_statement::bind<unsigned char>(std::size_t col, unsigned char data) const { return intern->bind(col, TYPE_TINY, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<short>(size_t col, short data) const + template <> __INLINE__ int basic_statement::bind<short>(std::size_t col, short data) const { return intern->bind(col, TYPE_SHORT, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<unsigned short>(size_t col, unsigned short data) const + template <> __INLINE__ int basic_statement::bind<unsigned short>(std::size_t col, unsigned short data) const { return intern->bind(col, TYPE_SHORT, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<int>(size_t col, int data) const + template <> __INLINE__ int basic_statement::bind<int>(std::size_t col, int data) const { return intern->bind(col, TYPE_LONG, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<unsigned int>(size_t col, unsigned int data) const + template <> __INLINE__ int basic_statement::bind<unsigned int>(std::size_t col, unsigned int data) const { return intern->bind(col, TYPE_LONG, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<long>(size_t col, long data) const + template <> __INLINE__ int basic_statement::bind<long>(std::size_t col, long data) const { return intern->bind(col, TYPE_LONGLONG, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<unsigned long>(size_t col, unsigned long data) const + template <> __INLINE__ int basic_statement::bind<unsigned long>(std::size_t col, unsigned long data) const { return intern->bind(col, TYPE_LONGLONG, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<float>(size_t col, float data) const + template <> __INLINE__ int basic_statement::bind<float>(std::size_t col, float data) const { return intern->bind(col, TYPE_FLOAT, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<double>(size_t col, double data) const + template <> __INLINE__ int basic_statement::bind<double>(std::size_t col, double data) const { return intern->bind(col, TYPE_DOUBLE, &data, sizeof(data)); } - template <> __INLINE__ int basic_statement::bind<char* const>(size_t col, char* const data) const + template <> __INLINE__ int basic_statement::bind<char* const>(std::size_t col, char* const data) const { return intern->bind(col, TYPE_STRING, data ? data : "", data ? ::strlen(data) : 0); } - template <> __INLINE__ int basic_statement::bind<const char*>(size_t col, const char* data) const + template <> __INLINE__ int basic_statement::bind<const char*>(std::size_t col, const char* data) const { return intern->bind(col, TYPE_STRING, data ? data : "", data ? ::strlen(data) : 0); } - inline int basic_statement::bind(size_t col, const blob_t& data) const + inline int basic_statement::bind(std::size_t col, const blob_t& data) const { return intern->bind(col, TYPE_BLOB, data.first, data.second); } - inline int basic_statement::bind(size_t col, const vblob_t& data) const + inline int basic_statement::bind(std::size_t col, const vblob_t& data) const { return intern->bind(col, TYPE_BLOB, &data.at(0), data.size()); } - inline int basic_statement::bind(size_t col, const uint8_t* data, size_t len) const + inline int basic_statement::bind(std::size_t col, const uint8_t* data, std::size_t len) const { return intern->bind(col, TYPE_BLOB, data, len); } } /// End namespace sqldb diff --git a/Online/sqldb/src/sqlite.cpp b/Online/sqldb/src/sqlite.cpp index 8c54476aac68a93a0d04646d20b2240e79cca704..fe83721a43cb1724c71d6618ed7f91d4bcc6a49c 100644 --- a/Online/sqldb/src/sqlite.cpp +++ b/Online/sqldb/src/sqlite.cpp @@ -67,7 +67,7 @@ namespace sqldb { struct column_bind { public: sqlite::statement_t* stmt { nullptr }; - size_t column { 0 }; + std::size_t column { 0 }; public: sqldb_status bind_null(column_data& d) { d.length = 0; @@ -75,7 +75,7 @@ namespace sqldb { return sqldb::OK; } /// Generic parameter binding - sqldb_status bind_str(column_data& d, const char* ptr, size_t len) { + sqldb_status bind_str(column_data& d, const char* ptr, std::size_t len) { if ( ptr ) { pointers_t p(ptr); d.bind_pointer(p.puint8, len); @@ -85,7 +85,7 @@ namespace sqldb { return bind_null(d); } /// Generic parameter binding - sqldb_status bind_blob(column_data& d, const unsigned char* ptr, size_t len) { + sqldb_status bind_blob(column_data& d, const unsigned char* ptr, std::size_t len) { if ( ptr ) { d.bind_pointer(ptr, len); ::sqlite3_bind_blob(this->stmt, this->column+1, d.item.pointer, len, SQLITE_STATIC); @@ -147,7 +147,7 @@ namespace sqldb { return ::sqlite3_expanded_sql(this->_handle); } /// - sqldb_status bind(size_t col, field_type typ, const void* data, size_t len) override { + sqldb_status bind(std::size_t col, field_type typ, const void* data, std::size_t len) override { pointers_t ptr(data); column_data& d = this->params[col]; column_bind b {this->_handle, col}; @@ -171,7 +171,7 @@ namespace sqldb { if ( auto* h = this->_handle ) { int ret = ::sqlite3_step(h); if( ret == SQLITE_ROW ) { - for( size_t col=0; col < this->fields.size(); col++ ) { + for( std::size_t col=0; col < this->fields.size(); col++ ) { auto& d = this->fields[col]; int typ = ::sqlite3_column_type(h,col); d.type = gen_field_type(typ); @@ -213,8 +213,8 @@ namespace sqldb { } int ret = ::sqlite3_prepare_v2(db, sql_str.c_str(), sql_str.length()+1, &stmt, nullptr); if ( sqlite_ok(ret) ) { - size_t num_param = ::sqlite3_bind_parameter_count(stmt); - size_t num_field = ::sqlite3_column_count(stmt); + std::size_t num_param = ::sqlite3_bind_parameter_count(stmt); + std::size_t num_field = ::sqlite3_column_count(stmt); this->params.resize(num_param, column_data()); this->fields.resize(num_field, column_data()); this->_handle = stmt; diff --git a/TestBeam/job/Monitor.py b/TestBeam/job/Monitor.py index 7f7c559733f5d52c2633a9b0d02c9ec786777cd0..65a90ab94724bbc18426b4d0bf53a0aa54088888 100644 --- a/TestBeam/job/Monitor.py +++ b/TestBeam/job/Monitor.py @@ -31,9 +31,9 @@ writer.UseRawData = False writer.RequireODIN = False application.setup_hive(FlowManager("EventLoop"), 40) -##application.setup_algorithms(writer, 0.05) -writer = application.setup_algorithms(writer, 1.0) application.setup_monitoring() +#application.setup_algorithms(writer, 0.05) +application.setup_algorithms(writer, 1.0) application.monSvc.DimUpdateInterval = 1 application.config.burstPrintCount = 30000 @@ -44,7 +44,7 @@ application.config.numEventThreads = 15 application.config.MBM_numConnections = 8 application.config.MBM_numEventThreads = 5 # -application.config.execMode = 1 +application.config.execMode = 0 application.config.numEventThreads = 15 application.config.MBM_numConnections = 3 application.config.MBM_numEventThreads = 4 diff --git a/TestBeam/job/RcvMonitor.py b/TestBeam/job/RcvMonitor.py index e8eafa0160037921d13a498e55adb8d1eed89799..d350d4587f565becb5d47a475157a3fb9baef334 100644 --- a/TestBeam/job/RcvMonitor.py +++ b/TestBeam/job/RcvMonitor.py @@ -23,12 +23,12 @@ application = GaudiOnline.Passthrough(outputLevel=OnlineEnv.OutputLevel, application.setup_fifolog() application.setup_mbm_access('Monitor', True) application.setup_hive(FlowManager("EventLoop"), 40) +application.setup_monitoring() algo = None algo = Configurables.StoreExplorerAlg('Explorer') algo.PrintFreq = 0.0000005 wr = application.setup_algorithms(writer=algo, acceptRate=1.0) wr.RequireODIN = False -application.setup_monitoring() application.input.MakeRawEvent = True application.config.burstPrintCount = 20000 application.monSvc.DimUpdateInterval = 1 diff --git a/TestBeam/job/runTask.sh b/TestBeam/job/runTask.sh index a892f4c8bc2d09d3c727e497d345d6b74642c755..33d8dc510ae8605ac7bd044327c383d86816e59c 100755 --- a/TestBeam/job/runTask.sh +++ b/TestBeam/job/runTask.sh @@ -25,8 +25,8 @@ export DIM_DNS_NODE; # # Switch to the task directory and execute the controller process # --------------------------------------------------------------- -export CMTCONFIG=x86_64_v2-centos7-gcc10-do0; export CMTCONFIG=x86_64_v2-centos7-gcc10-opt; +export CMTCONFIG=x86_64_v2-centos7-gcc10-do0; # # if test -z "${SCRIPT}"; then @@ -45,19 +45,31 @@ echo "+++ SCRIPT: ${SCRIPT}"; echo "+++ SCRIPT_DIR: ${SCRIPT_DIR}"; echo "+++ PYTHONPATH ${TESTBEAM_DIR}/options:${PYTHONPATH}"; echo "+++ Task type: ${TASK_TYPE}"; -export PYTHONPATH=${TESTBEAM_DIR}/options:${PYTHONPATH}; +echo "+++ Partition: ${PARTITION}"; # -export INFO_OPTIONS=${TESTBEAM_DIR}/options/OnlineEnv.opts; +if test "${PARTITION}" = "TEST"; then + export PYTHONPATH=${TESTBEAM_DIR}/options:${PYTHONPATH}; + export INFO_OPTIONS=${TESTBEAM_DIR}/options/OnlineEnv.opts; +else + export PYTHONPATH=/group/online/dataflow/options/${PARTITION}:${TESTBEAM_DIR}/options:${PYTHONPATH}; + export INFO_OPTIONS=/group/online/dataflow/options/${PARTITION}/OnlineEnv.opts; +fi; +# +dataflow_task_cmd() +{ + #echo "genRunner.exe libDataflow.so dataflow_run_task -msg=Dataflow_OutputLogger -mon=Dataflow_DIMMonitoring -class=$1"; + echo "dataflow_task.exe -msg=Dataflow_OutputLogger -mon=Dataflow_DIMMonitoring -class=$1"; +} # 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 -msg=Dataflow_OutputLogger -mon=Dataflow_DIMMonitoring -class=$1"; - #echo "exec -a ${UTGID} genRunner.exe libDataflow.so dataflow_run_task -msg=Dataflow_OutputLogger -mon=Dataflow_DummyMonitoring -class=$1"; + #echo "exec -a ${UTGID} genRunner.exe libDataflow.so dataflow_run_task -msg=Dataflow_OutputLogger -mon=Dataflow_DIMMonitoring -class=$1"; + echo "exec -a ${UTGID} `dataflow_task_cmd $1`"; } # cd ${SCRIPT_DIR}; # +# if test -f "${TASK_SCRIPT}"; then . ${TASK_SCRIPT} $*; elif test -f ./${TASK_TYPE}.sh; then @@ -66,18 +78,24 @@ elif test -f "${OPTIONS}" -a -n "`echo ${OPTIONS} | grep .py`"; then if test -n "${DEBUG}"; then echo "GaudiPython: OPTIONS: ${OPTIONS}"; fi; - exec -a ${UTGID} genPython.exe `which gaudirun.py` ${OPTIONS} --application=Online::OnlineEventApp; + if test -z "${APPLICATION}"; then + APPLICATION=Online::OnlineEventApp; + fi; + exec -a ${UTGID} genPython.exe `which gaudirun.py` ${OPTIONS} --application=${APPLICATION}; elif test -f "${OPTIONS}" -a -n "`echo ${OPTIONS} | grep .opts`"; then if test -n "${DEBUG}"; then echo "Dataflow: OPTIONS: ${OPTIONS}"; fi; if test "${TASK_TYPE}" = "Receiver"; then export RTL_NO_BACKTRACE=1; - #/home/frankm/bin/valgrind --error-limit=no --track-origins=yes --leak-check=full `which dataflow_task.exe` -msg=fifo -mon=Dataflow_DIMMonitoring -class=${CLASS} -opts=${OPTIONS} ${AUTO_STARTUP} ${DEBUG_STARTUP} 1>/tmp/Receiver.log 2>&1; + #/home/frankm/bin/valgrind --error-limit=no --track-origins=yes --leak-check=full `dataflow_task_cmd ${CLASS}` -opts=${OPTIONS} ${AUTO_STARTUP} ${DEBUG_STARTUP} 1>/tmp/Receiver.log 2>&1; `dataflow_task ${CLASS}` -opts=${OPTIONS} ${AUTO_STARTUP} ${DEBUG_STARTUP}; else `dataflow_task ${CLASS}` -opts=${OPTIONS} ${AUTO_STARTUP} ${DEBUG_STARTUP}; fi; +elif test -f ./../../Online/FarmConfig/job/${TASK_TYPE}.sh; then + echo "[ERROR] ./../../Online/FarmConfig/job/${TASK_TYPE}.sh $*"; + . ./../../Online/FarmConfig/job/${TASK_TYPE}.sh $*; else echo "+++ Running generic default task as '${TASK_TYPE}'"; exec -a ${UTGID} genPython.exe ${SMICONTROLLERROOT}/scripts/DummyTask.py -utgid ${UTGID} -partition 103 -print ${OUTPUT_LEVEL}; diff --git a/TestBeam/options/HLT2Writer.opts b/TestBeam/options/HLT2Writer.opts index 76ffc33af8c78788d87455c958b32d2d024d35a7..cc04cdb558f335a91c4c7c7dea2a9d01d039a41f 100644 --- a/TestBeam/options/HLT2Writer.opts +++ b/TestBeam/options/HLT2Writer.opts @@ -1,6 +1,6 @@ #pragma print off //------------- Default Writer options: ------------------------------------------ -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" #include "$FARMCONFIGROOT/options/Monitoring.opts" // diff --git a/TestBeam/options/MBM.opts b/TestBeam/options/MBM.opts index b9713bd0a82f695bddd62423466a744d2547e771..e6e8809f057ffd057182e38946ea6741714e71b7 100644 --- a/TestBeam/options/MBM.opts +++ b/TestBeam/options/MBM.opts @@ -1,5 +1,5 @@ #pragma print off -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" OnlineEnv.MBM_setup = "-s=1000000 -e=50 -u=30 -b=18 -t=1 -y -i=Events -f -c -s=100000 -e=50 -u=15 -b=12 -t=1 -y -i=Output -f -c -s=100000 -e=50 -u=15 -b=12 -t=1 -y -i=Monitor -f -c"; // diff --git a/TestBeam/options/MDFProd.opts b/TestBeam/options/MDFProd.opts index 75f6179d95eaf921584dcf685e53174159c341a5..f4d77fc07baf7dc1f79e9f8b935c6aada9f69889 100644 --- a/TestBeam/options/MDFProd.opts +++ b/TestBeam/options/MDFProd.opts @@ -1,5 +1,5 @@ #pragma print off -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" #include "$FARMCONFIGROOT/options/Monitoring.opts" // @@ -28,9 +28,6 @@ Reader.Directories = {"/group/online/dataflow/cmtuser/data/mdf", }; Reader.FilePrefix = "file_"; // -//Reader.Directories = {"/daqarea1/objects/data/TEST/HLT2/13609000/13609549"}; -//Reader.FilePrefix = "Run_"; -// Reader.AllowedRuns = {"*"}; Reader.MuDelay = 0; Reader.DeleteFiles = false; diff --git a/TestBeam/options/MEPProd.opts b/TestBeam/options/MEPProd.opts index 874677b1c2b553283d5d2e7c4a8d8b44d7fde53b..b108ed7f00db636ea4512fed364c7719cf331b41 100644 --- a/TestBeam/options/MEPProd.opts +++ b/TestBeam/options/MEPProd.opts @@ -1,5 +1,5 @@ #pragma print off -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" #include "$FARMCONFIGROOT/options/Monitoring.opts" diff --git a/TestBeam/options/Receiver.opts b/TestBeam/options/Receiver.opts index 35bd7fa9f566891b5c71c2030224bd9b49dc3192..aa50acbcbdb0949f76033873f3164e59d7516409 100644 --- a/TestBeam/options/Receiver.opts +++ b/TestBeam/options/Receiver.opts @@ -1,5 +1,5 @@ #pragma print off -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" #include "$FARMCONFIGROOT/options/Monitoring.opts" diff --git a/TestBeam/options/Sender.opts b/TestBeam/options/Sender.opts index ac8913f3b0c595b9bba5d5d7c62fb659b4a93af0..9dc8984f2ed3eb163d0cd4393825daa72f8658de 100644 --- a/TestBeam/options/Sender.opts +++ b/TestBeam/options/Sender.opts @@ -1,5 +1,5 @@ #pragma print off -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" #include "$FARMCONFIGROOT/options/Monitoring.opts" // diff --git a/TestBeam/options/Storage.opts b/TestBeam/options/Storage.opts index e9fd0070f8aaae950035a3a3d628b2f76ccbb620..b00e0ff3b34f4380f988e25ca9db922f665597ea 100644 --- a/TestBeam/options/Storage.opts +++ b/TestBeam/options/Storage.opts @@ -1,5 +1,5 @@ #pragma print off -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" #include "$FARMCONFIGROOT/options/Monitoring.opts" // diff --git a/TestBeam/options/StorageWriter.opts b/TestBeam/options/StorageWriter.opts index 56442ce68bafe669fc54839be04c47b2228e0730..9aaeb8dd681c3e8141c8e5740ae4764be006036e 100644 --- a/TestBeam/options/StorageWriter.opts +++ b/TestBeam/options/StorageWriter.opts @@ -1,5 +1,5 @@ #include "$DATAFLOWROOT/options/StorageWriter.opts" -Writer.FileSizeMB = 4000; +Writer.MaxFileSizeMB = 4000; Writer.NumBuffers = 6; Writer.NumThreads = 4; EventProc.REQ2 = "EvType=2;TriggerMask=0xffffffff,0xffffffff,0xffffffff,0xffffffff;VetoMask=0,0,0,0;MaskType=ANY;UserType=USER;Frequency=PERC;Perc=5.0"; diff --git a/TestBeam/options/TAEProd.opts b/TestBeam/options/TAEProd.opts index debeeb3937fb48d7470b0df4e40f6a9d56827c3f..aa1f05de05f6a049d3dda9dd9b9f1d9a9cacdacf 100644 --- a/TestBeam/options/TAEProd.opts +++ b/TestBeam/options/TAEProd.opts @@ -1,5 +1,5 @@ #pragma print off -#include "OnlineEnv.opts" +#include "$INFO_OPTIONS" #include "$FARMCONFIGROOT/options/Logging.opts" #include "$FARMCONFIGROOT/options/Monitoring.opts" diff --git a/TestBeam/setup_comp.sh b/TestBeam/setup_comp.sh index 5099605a92bd28ba0ed492a0bacfb9281dff6ab3..183f27a90ed0e84fe865128ec7e54eaa32e23f85 100644 --- a/TestBeam/setup_comp.sh +++ b/TestBeam/setup_comp.sh @@ -10,7 +10,6 @@ # ========================================================================= # export MONITOR_BASE=`realpath /group/online/dataflow/cmtuser/TestBeam`; -export MONITOR_BASE=`realpath /home/frankm/upgrade_sw/ONLINE_v7r9/TestBeam`; export INSTALLATION=`dirname ${MONITOR_BASE}`; # #