diff --git a/src/InputFilter.cc b/src/InputFilter.cc index ef20005cabb46e5fbaafe541cdf56d933cf48352..923e8766fb31fa7987a925b76aabe754e1bf4492 100644 --- a/src/InputFilter.cc +++ b/src/InputFilter.cc @@ -123,12 +123,11 @@ void *InputFilter::operator()(void *) { char *buffer = nextSlice_->begin(); // Available buffer size size_t bufferSize = nextSlice_->avail(); - ssize_t bytesRead = 0; nbReads_++; // It is optional to use the provided buffer - bytesRead = readInput(&buffer, bufferSize); + ssize_t bytesRead = readInput(&buffer, bufferSize); // This should really not happen assert(bytesRead != 0); diff --git a/src/OutputBySize.cc b/src/OutputBySize.cc index 65345af6bfd77e2749136d668993596c5da89fc7..73518787aa152ba2f787b8086a95565b02806f5d 100644 --- a/src/OutputBySize.cc +++ b/src/OutputBySize.cc @@ -135,7 +135,7 @@ static std::string format_run_file_stem(std::string &filename_prefix, uint32_t r char run_order_stem[PATH_MAX]; snprintf(run_order_stem, sizeof(run_order_stem), "%s_%06d_%06d.dat", filename_prefix.c_str(), run_number, file_count); - return std::string(run_order_stem); + return {run_order_stem}; } void OutputBySizeStream::close_and_move_current_file() { diff --git a/src/OutputBySize.h b/src/OutputBySize.h index c5818334cec7597281c15ec4149534f4b5f264cf..4bcc6ddd12041bba767be26d82dafb9742902436 100644 --- a/src/OutputBySize.h +++ b/src/OutputBySize.h @@ -13,9 +13,8 @@ //! Filter that writes each buffer to a file. class OutputBySizeStream : public tbb::filter { public: - OutputBySizeStream(const std::string output_filename_base, - const std::string &output_filename_prefix, ctrl &c, - StreamProcessor::ProcessorType processorType_); + OutputBySizeStream(std::string output_filename_base, const std::string &output_filename_prefix, + ctrl &c, StreamProcessor::ProcessorType processorType_); void *operator()(void *item) /*override*/; private: diff --git a/src/OutputFileHandler.cc b/src/OutputFileHandler.cc index f004c354445ca77114fc3707663f88bad4571e98..fa37c2064a20527fbb17e358dfcf9ca8bcea11d8 100644 --- a/src/OutputFileHandler.cc +++ b/src/OutputFileHandler.cc @@ -20,7 +20,7 @@ void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() { if (outputFile_.exists()) { LOG(TRACE) << "queueing file: " << outputFile_.getFileName() << " for closing, queue size now " << files_to_close_.size(); - if (this->OutputFileHandler::getCMSSWHeaders() == true) { + if (this->OutputFileHandler::getCMSSWHeaders()) { outputFile_.setFileHeader(createFileHeader(outputFile_.Lumisection())); outputFile_.writeFileHeader(); } @@ -35,7 +35,7 @@ void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() { } // resetting for next file NOrbits_ = 0; - if (this->OutputFileHandler::getCMSSWHeaders() == true) { + if (this->OutputFileHandler::getCMSSWHeaders()) { file_size_ = sizeof(FRDFileHeader_v2); } else { file_size_ = 0; @@ -45,26 +45,26 @@ void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() { } OutputFile OutputFileHandler::getFile(uint32_t run, uint32_t index) { + bool is_new_run = (current_run_number_ != static_cast<int>(run)); + bool is_new_index = (current_index_ != static_cast<int>(index)); + // TODO: We should maybe move this out of this function... - if (current_run_number_ > 0 && current_run_number_ != run && getCMSSWHeaders()) { + if (current_run_number_ > 0 && is_new_run && getCMSSWHeaders()) { OutputFileHandler::write_EoR_file(); } - if (current_run_number_ != run || current_index_ != index) { + if (is_new_run || is_new_index) { enqueue_current_file_for_close_and_move_maybe(); - if (current_run_number_ != run) { - LOG(TRACE) << "Previous run: " << current_run_number_ << "."; - LOG(TRACE) << "New run: " << run << "."; - } - if (current_index_ != index) { - LOG(TRACE) << "Previous index: " << current_index_ << "."; - LOG(TRACE) << "New index: " << index << "."; - } - if (current_run_number_ != run) { + if (is_new_run) { run_NOrbits_ = 0; + LOG(TRACE) << "Previous run: " << current_run_number_ << " | New run: " << run; } - current_index_ = index; - current_run_number_ = run; + if (is_new_index) { + LOG(TRACE) << "Previous index: " << current_index_ << " | New index: " << index; + } + + current_index_ = static_cast<int>(index); + current_run_number_ = static_cast<int>(run); std::stringstream path_ss; path_ss << base_path_ << "/run" << std::setfill('0') << std::setw(6) << current_run_number_; run_dir_ = path_ss.str(); @@ -126,7 +126,7 @@ void OutputFileHandler::open_new_file() { } outputFile_ = outputFile; // reserve space for CMSSW header if required - if (this->OutputFileHandler::getCMSSWHeaders() == true) { + if (this->OutputFileHandler::getCMSSWHeaders()) { fseek(outputFile_.getFilePtr(), sizeof(FRDFileHeader_v2), SEEK_SET); } } @@ -135,7 +135,7 @@ void OutputFileHandler::open_new_file() { std::string OutputFileHandler::format_filename(uint32_t run_number, uint32_t index, uint32_t ls) { std::ostringstream ofilename; - if (this->OutputFileHandler::getCMSSWHeaders() == true) { + if (this->OutputFileHandler::getCMSSWHeaders()) { ofilename << "run" << std::setfill('0') << std::setw(6) << run_number << "_ls" << std::setfill('0') << std::setw(4) << ls << "_index" << std::setfill('0') << std::setw(6) << index % (max_index_per_ls_ + 1) << ".raw"; @@ -169,7 +169,7 @@ void OutputFileHandler::close_and_rename::operator()() const { } if (outputFile.Index() == outputfilehandler_->max_index_per_ls_ && - outputfilehandler_->getCMSSWHeaders() == true) { // end of lumisection + outputfilehandler_->getCMSSWHeaders()) { // end of lumisection outputfilehandler_->write_EoLS_file(outputFile.Lumisection()); } } @@ -200,7 +200,6 @@ void OutputFileHandler::write_EoLS_file(uint32_t ls) { ls_file_size_ = 0; run_NOrbits_ += ls_NOrbits_; ls_NOrbits_ = 0; - std::string EoLS_file_string = EoLS_file_string_stream.str(); EoLS_file << EoLS_file_string_stream.str(); EoLS_file.close(); } diff --git a/src/config.cc b/src/config.cc index 41d547e6bf6a6d23d6e0ac82ac82dced627146a4..9456345c2ef1444bfabb8865f0060fbc53e03a10 100644 --- a/src/config.cc +++ b/src/config.cc @@ -69,7 +69,7 @@ uint32_t config::getSourceID() { } else if (getProcessorType() == StreamProcessor::ProcessorType::CALO) { source_id = 2; } else { - if (getCMSSWHeaders() == true) { + if (getCMSSWHeaders()) { LOG(ERROR) << "PROCESSOR_TYPE INCOMPATIBLE WITH CMSSW HEADER OUTPUT OPTION, PLEASE DISABLE " "CMSSW HEADERS OR CHANGE PROCESSOR_TYPE, EXITING"; throw std::invalid_argument( diff --git a/src/log.h b/src/log.h index fc98230cb6013afe6765ba8e15bd4cfa34c5cf2f..1088ef6f3d610fc6e7305b6596d945d55670b354 100644 --- a/src/log.h +++ b/src/log.h @@ -40,7 +40,7 @@ inline std::string simplify_pretty(const char *fname) { } pos++; } - }; + } if (pos == std::string::npos) { // Failed to obtain the name, return the full one @@ -95,7 +95,7 @@ inline std::ostream &operator<<(std::ostream &os, enum LOG_LEVEL severity) { return os << "<3> "; case FATAL: return os << "<1> "; - }; + } return os; } @@ -105,7 +105,7 @@ inline void set_filter_min_severity(enum LOG_LEVEL filter) { severity_filter = f // https://stackoverflow.com/questions/2179623/how-does-qdebug-stuff-add-a-newline-automatically/2179782#2179782 struct log { - log() {} + log() = default; ~log() { std::lock_guard<std::mutex> guard(log_lock); diff --git a/src/processor.cc b/src/processor.cc index eac1c3606a73a717345c8f7e62818f5b28ad601b..6dbca8d5ea6cdb982445eea6f3e223325992b501 100644 --- a/src/processor.cc +++ b/src/processor.cc @@ -30,7 +30,7 @@ StreamProcessor::StreamProcessor(const bool doZS_, ProcessorType processorType_, BrilHistoQueue<std::array<uint32_t, constants::NBXPerOrbit + constants::NFramesInHistoHeader>> StreamProcessor::BrilQueue; -StreamProcessor::~StreamProcessor() {} +StreamProcessor::~StreamProcessor() = default; // checks that the packet size is an integer multiple of the BX block size, // minus the header/trailers @@ -106,7 +106,7 @@ StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitCalo(orbit_trailer std::pair<uint32_t, bool> orbit_header = std::pair<uint32_t, bool>{ ProcessOrbitHeader(rd_ptr)}; //.second is the warning test enable bit rd_ptr += 32; // +32 to account for orbit header - if (cmsswHeaders == true) { + if (cmsswHeaders) { wr_ptr += sizeof(FRDFileHeader_v2); } // reserving space for cmssw orbit header @@ -242,7 +242,7 @@ StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitMuon(orbit_trailer std::pair<uint32_t, bool> orbit_header = std::pair<uint32_t, bool>{ ProcessOrbitHeader(rd_ptr)}; //.second is the warning test enable bit rd_ptr += 32; // +32 to account for orbit header - if (cmsswHeaders == true) { + if (cmsswHeaders) { wr_ptr += 28; } // reserving space for cmssw orbit header @@ -411,7 +411,7 @@ void StreamProcessor::process(Slice &input, Slice &out) { // 12 bytes for each muon/count then 12 bytes for each bx header int orbit_size_bytes = meta.counts * 12 + 12 * meta.filled_bxs; - if (cmsswHeaders == true) { + if (cmsswHeaders) { additional_header_size = fillFRDEventHeader_V6(wr_ptr, orbit_size_bytes, meta.orbit); } @@ -426,7 +426,7 @@ void StreamProcessor::process(Slice &input, Slice &out) { // + 6 words from calo L2 int orbit_size_bytes = 4 * ((8 * 7) + 3) * meta.filled_bxs; - if (cmsswHeaders == true) { + if (cmsswHeaders) { additional_header_size = fillFRDEventHeader_V6(wr_ptr, orbit_size_bytes, meta.orbit); } diff --git a/src/scdaq.cc b/src/scdaq.cc index 1843b92a01024f20efa8fbeae4f3ded081f95d7a..6d873ed6d1e9d5dcbebbb3742a7f62310ae06f65 100644 --- a/src/scdaq.cc +++ b/src/scdaq.cc @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) { // Instantiate multiple pipelines (up to the directive-defined limit) with the settings from the // config instances. MultiPipeline multi_pipeline(configs); - int ret = 0; + int ret; try { // Launch blocking call to run the pipelines in parallel until all streams are severed ret = multi_pipeline.Run(); diff --git a/src/tools.h b/src/tools.h index c444fa177e73e67ffd9c0b9d9ef34f867f11ccf7..435fe10a1d8059bd73fe4795daa21513fd326086 100644 --- a/src/tools.h +++ b/src/tools.h @@ -19,26 +19,25 @@ namespace tools { * A thread-safe version of strerror: Returns a C++ std::string describing * error_code */ -inline const std::string strerror(int error_code) { +inline std::string strerror(int error_code) { char local_buf[128]; char *buf = local_buf; // NOTE: The returned buf may not be the same as the original buf buf = strerror_r(error_code, buf, sizeof(local_buf)); - // Make a proper C++ string out of the returned buffer - std::string str(buf); - return str; + // Return a proper C++ string out of the buffer + return {buf}; } /* * A thread-safe version of strerror: Returns a C++ std::string describing ERRNO */ -inline const std::string strerror() { return tools::strerror(errno); } +inline std::string strerror() { return tools::strerror(errno); } /* * A thread-safe version of "perror". Prepends a custom message before the error * code and returns everything in std::string */ -inline const std::string strerror(const std::string &msg) { return msg + ": " + tools::strerror(); } +inline std::string strerror(const std::string &msg) { return msg + ": " + tools::strerror(); } /* * Helper function to reset the board via SCONE