Skip to content
Snippets Groups Projects
Commit 371b59a1 authored by Giovanna Lazzari Miotto's avatar Giovanna Lazzari Miotto :mushroom:
Browse files

[lint] Qualify variables as const and constexpr

[lint] Make read-only arrays const

[lint] Avoid string copies by const referencing

[lint] Make value computed by constants `constexpr`
parent d5345032
No related branches found
No related tags found
1 merge request!79[chore] Apply minor changes to address compiler and linter warnings
...@@ -42,7 +42,7 @@ static void create_output_directory(std::string &output_directory) { ...@@ -42,7 +42,7 @@ static void create_output_directory(std::string &output_directory) {
LOG(TRACE) << "Created output directory: " << output_directory << "'."; LOG(TRACE) << "Created output directory: " << output_directory << "'.";
} }
OutputBySizeStream::OutputBySizeStream(const std::string output_filename_base, OutputBySizeStream::OutputBySizeStream(const std::string &output_filename_base,
const std::string &output_filename_prefix, ctrl &c, const std::string &output_filename_prefix, ctrl &c,
StreamProcessor::ProcessorType processorType_) StreamProcessor::ProcessorType processorType_)
: tbb::filter(serial_in_order), : tbb::filter(serial_in_order),
...@@ -54,7 +54,7 @@ OutputBySizeStream::OutputBySizeStream(const std::string output_filename_base, ...@@ -54,7 +54,7 @@ OutputBySizeStream::OutputBySizeStream(const std::string output_filename_base,
control(c), control(c),
current_file(nullptr), current_file(nullptr),
current_run_number(0), current_run_number(0),
journal_name(my_output_filename_base + "/" + output_filename_prefix + '_' + journal_file), journal_name(my_output_filename_base + "/" + my_output_filename_prefix + '_' + journal_file),
min_buffer_queue_size_(1000), min_buffer_queue_size_(1000),
bril_(processorType_ == StreamProcessor::ProcessorType::BRIL) { bril_(processorType_ == StreamProcessor::ProcessorType::BRIL) {
LOG(TRACE) << "Created output filter at " << static_cast<void *>(this); LOG(TRACE) << "Created output filter at " << static_cast<void *>(this);
...@@ -64,7 +64,7 @@ OutputBySizeStream::OutputBySizeStream(const std::string output_filename_base, ...@@ -64,7 +64,7 @@ OutputBySizeStream::OutputBySizeStream(const std::string output_filename_base,
create_output_directory(output_directory); create_output_directory(output_directory);
} }
static void update_journal(std::string journal_name, uint32_t run_number, uint32_t index) { static void update_journal(const std::string &journal_name, uint32_t run_number, uint32_t index) {
std::string new_journal_name = journal_name + ".new"; std::string new_journal_name = journal_name + ".new";
// Create a new journal file // Create a new journal file
...@@ -82,7 +82,7 @@ static void update_journal(std::string journal_name, uint32_t run_number, uint32 ...@@ -82,7 +82,7 @@ static void update_journal(std::string journal_name, uint32_t run_number, uint32
} }
} }
static bool read_journal(std::string journal_name, uint32_t &run_number, uint32_t &index) { static bool read_journal(const std::string &journal_name, uint32_t &run_number, uint32_t &index) {
std::ifstream journal(journal_name); std::ifstream journal(journal_name);
if (journal.is_open()) { if (journal.is_open()) {
journal >> run_number >> index; journal >> run_number >> index;
...@@ -130,7 +130,7 @@ void *OutputBySizeStream::operator()(void *item) { ...@@ -130,7 +130,7 @@ void *OutputBySizeStream::operator()(void *item) {
* Create a properly formatted file name * Create a properly formatted file name
* TODO: Change to C++ * TODO: Change to C++
*/ */
static std::string format_run_file_stem(std::string &filename_prefix, uint32_t run_number, static std::string format_run_file_stem(const std::string &filename_prefix, uint32_t run_number,
int32_t file_count) { int32_t file_count) {
char run_order_stem[PATH_MAX]; char run_order_stem[PATH_MAX];
snprintf(run_order_stem, sizeof(run_order_stem), "%s_%06d_%06d.dat", filename_prefix.c_str(), snprintf(run_order_stem, sizeof(run_order_stem), "%s_%06d_%06d.dat", filename_prefix.c_str(),
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
//! Filter that writes each buffer to a file. //! Filter that writes each buffer to a file.
class OutputBySizeStream : public tbb::filter { class OutputBySizeStream : public tbb::filter {
public: public:
OutputBySizeStream(std::string output_filename_base, const std::string &output_filename_prefix, OutputBySizeStream(const std::string &output_filename_base,
ctrl &c, StreamProcessor::ProcessorType processorType_); const std::string &output_filename_prefix, ctrl &c,
StreamProcessor::ProcessorType processorType_);
void *operator()(void *item) override; void *operator()(void *item) override;
private: private:
......
...@@ -102,8 +102,8 @@ inline std::pair<uint32_t, bool> StreamProcessor::ProcessOrbitHeader(char *rd_pt ...@@ -102,8 +102,8 @@ inline std::pair<uint32_t, bool> StreamProcessor::ProcessOrbitHeader(char *rd_pt
// data corresponding to the non-empty bunch-crossings, as marked in bx_vect // data corresponding to the non-empty bunch-crossings, as marked in bx_vect
StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitCalo(orbit_trailer *trailer, StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitCalo(orbit_trailer *trailer,
char *rd_ptr, char *wr_ptr, char *rd_ptr, char *wr_ptr,
char *rd_end_ptr, const char *rd_end_ptr,
char *wr_end_ptr) { const char *wr_end_ptr) {
std::pair<uint32_t, bool> orbit_header = std::pair<uint32_t, bool>{ std::pair<uint32_t, bool> orbit_header = std::pair<uint32_t, bool>{
ProcessOrbitHeader(rd_ptr)}; //.second is the warning test enable bit ProcessOrbitHeader(rd_ptr)}; //.second is the warning test enable bit
rd_ptr += 32; // +32 to account for orbit header rd_ptr += 32; // +32 to account for orbit header
...@@ -203,7 +203,7 @@ size_t StreamProcessor::fillFRDEventHeader_V6(char *wr_ptr_FRDHead, uint32_t inp ...@@ -203,7 +203,7 @@ size_t StreamProcessor::fillFRDEventHeader_V6(char *wr_ptr_FRDHead, uint32_t inp
return (sizeof(frdEventHeader_V6) + sizeof(source_id)); return (sizeof(frdEventHeader_V6) + sizeof(source_id));
} }
uint32_t StreamProcessor::FillBril(char *rd_ptr, char *wr_ptr, char *end_ptr) const { uint32_t StreamProcessor::FillBril(char *rd_ptr, char *wr_ptr, const char *end_ptr) const {
std::array<uint32_t, constants::NBXPerOrbit + constants::NFramesInHistoHeader> histo_arr; std::array<uint32_t, constants::NBXPerOrbit + constants::NFramesInHistoHeader> histo_arr;
while (rd_ptr != end_ptr) { while (rd_ptr != end_ptr) {
...@@ -226,8 +226,8 @@ uint32_t StreamProcessor::FillBril(char *rd_ptr, char *wr_ptr, char *end_ptr) co ...@@ -226,8 +226,8 @@ uint32_t StreamProcessor::FillBril(char *rd_ptr, char *wr_ptr, char *end_ptr) co
} }
rd_ptr += sizeof(brilFrame); rd_ptr += sizeof(brilFrame);
} }
auto packed_size = static_cast<uint32_t>(sizeof(uint32_t)) * constexpr auto packed_size = static_cast<uint32_t>(sizeof(uint32_t)) *
(constants::NBXPerOrbit + constants::NFramesInHistoHeader); (constants::NBXPerOrbit + constants::NFramesInHistoHeader);
memcpy(wr_ptr, (char *)&histo_arr, packed_size); memcpy(wr_ptr, (char *)&histo_arr, packed_size);
BrilQueue.push(histo_arr); BrilQueue.push(histo_arr);
...@@ -238,8 +238,8 @@ uint32_t StreamProcessor::FillBril(char *rd_ptr, char *wr_ptr, char *end_ptr) co ...@@ -238,8 +238,8 @@ uint32_t StreamProcessor::FillBril(char *rd_ptr, char *wr_ptr, char *end_ptr) co
// corresponding to the non-empty bunch-crossings, as marked in bx_vect // corresponding to the non-empty bunch-crossings, as marked in bx_vect
StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitMuon(orbit_trailer *trailer, StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitMuon(orbit_trailer *trailer,
char *rd_ptr, char *wr_ptr, char *rd_ptr, char *wr_ptr,
char *rd_end_ptr, const char *rd_end_ptr,
char *wr_end_ptr) { const char *wr_end_ptr) {
std::pair<uint32_t, bool> orbit_header = std::pair<uint32_t, bool>{ std::pair<uint32_t, bool> orbit_header = std::pair<uint32_t, bool>{
ProcessOrbitHeader(rd_ptr)}; //.second is the warning test enable bit ProcessOrbitHeader(rd_ptr)}; //.second is the warning test enable bit
rd_ptr += 32; // +32 to account for orbit header rd_ptr += 32; // +32 to account for orbit header
......
...@@ -42,10 +42,10 @@ class StreamProcessor : public tbb::filter { ...@@ -42,10 +42,10 @@ class StreamProcessor : public tbb::filter {
bool GetTrailer(Slice &input, char *&rd_ptr); bool GetTrailer(Slice &input, char *&rd_ptr);
inline std::pair<uint32_t, bool> ProcessOrbitHeader(char *rd_ptr); inline std::pair<uint32_t, bool> ProcessOrbitHeader(char *rd_ptr);
fillOrbitMetadata FillOrbitMuon(orbit_trailer *trailer, char *rd_ptr, char *wr_ptr, fillOrbitMetadata FillOrbitMuon(orbit_trailer *trailer, char *rd_ptr, char *wr_ptr,
char *rd_end_ptr, char *wr_end_ptr); const char *rd_end_ptr, const char *wr_end_ptr);
fillOrbitMetadata FillOrbitCalo(orbit_trailer *trailer, char *rd_ptr, char *wr_ptr, fillOrbitMetadata FillOrbitCalo(orbit_trailer *trailer, char *rd_ptr, char *wr_ptr,
char *rd_end_ptr, char *wr_end_ptr); const char *rd_end_ptr, const char *wr_end_ptr);
uint32_t FillBril(char *rd_ptr, char *wr_ptr, char *end_ptr) const; uint32_t FillBril(char *rd_ptr, char *wr_ptr, const char *end_ptr) const;
uint64_t nbPackets; uint64_t nbPackets;
const bool doZS; const bool doZS;
const ProcessorType processorType; const ProcessorType processorType;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment