Skip to content

Commit

Permalink
Merge pull request #55 from art-daq/eflumerf/ClangFormat
Browse files Browse the repository at this point in the history
Apply clang-format to all source files
  • Loading branch information
eflumerf authored Jan 14, 2025
2 parents aedc512 + 8266e53 commit c30d054
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 66 deletions.
28 changes: 14 additions & 14 deletions artdaq-core/Core/SharedMemoryManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ int artdaq::SharedMemoryManager::GetBufferForReading()
{
buffer_num = (ii + rp) % shm_ptr_->buffer_count;

//TLOG(TLVL_GETBUFFER + 1) << "Checking if buffer " << buffer_num << " is stale. Shm destructive_read_mode=" << shm_ptr_->destructive_read_mode;
// TLOG(TLVL_GETBUFFER + 1) << "Checking if buffer " << buffer_num << " is stale. Shm destructive_read_mode=" << shm_ptr_->destructive_read_mode;
ResetBuffer(buffer_num);

auto buf = getBufferInfo_(buffer_num);
Expand All @@ -331,7 +331,7 @@ int artdaq::SharedMemoryManager::GetBufferForReading()
{
TLOG(TLVL_GETBUFFER + 1) << "ID " << manager_id_ << " Buffer " << buffer_num << ": sem=" << FlagToString(semaphore.flags)
<< " (looking for " << FlagToString(BufferSemaphoreFlags::Full) << "), sem_id=" << semaphore.id << ", seq_id=" << sequence_id << ", last_seen_id_=" << last_seen_id_;
// Claim the buffer if it is in my sequence, I haven't claimed buffers before, or if we are in Broadcast mode
// Claim the buffer if it is in my sequence, I haven't claimed buffers before, or if we are in Broadcast mode
if (last_seen_id_ == 0 || !shm_ptr_->destructive_read_mode || sequence_id % reader_count == last_seen_id_ % reader_count || sequence_id + reader_count < last_seen_id_)
{
buffer_ptr = buf;
Expand All @@ -356,11 +356,11 @@ int artdaq::SharedMemoryManager::GetBufferForReading()

TLOG(TLVL_GETBUFFER) << "Returning " << buffer_num;
return buffer_num;
}
}
}
}

if (buffer_ptr == nullptr)
if (buffer_ptr == nullptr)
{
continue;
}
Expand Down Expand Up @@ -681,18 +681,18 @@ std::deque<int> artdaq::SharedMemoryManager::GetBuffersOwnedByManager()
return output;
}
TLOG(TLVL_BUFFER) << "GetBuffersOwnedByManager BEGIN";
for (size_t ii = 0; ii < buffer_count; ++ii)
for (size_t ii = 0; ii < buffer_count; ++ii)
{
auto buf = getBufferInfo_(ii);
if (buf == nullptr)
{
auto buf = getBufferInfo_(ii);
if (buf == nullptr)
{
continue;
}
if (buf->semaphore.load().id == manager_id_)
{
output.push_back(ii);
}
continue;
}
if (buf->semaphore.load().id == manager_id_)
{
output.push_back(ii);
}
}

TLOG(TLVL_BUFFER) << "GetBuffersOwnedByManager: own " << output.size() << " / " << buffer_count << " buffers.";
return output;
Expand Down
22 changes: 11 additions & 11 deletions artdaq-core/Core/SharedMemoryManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ public:
*/
size_t GetBufferCount() const { return IsValid() ? shm_ptr_->next_sequence_id : 0; }

/**
* \brief Get the number of reader instances connected to the Shared Memory
* \return The number of attached readers, as reported by the readers
*/
int GetReaderCount() { return IsValid() ? shm_ptr_->reader_count.load() : 0; }
/**
* \brief Get the number of reader instances connected to the Shared Memory
* \return The number of attached readers, as reported by the readers
*/
int GetReaderCount() { return IsValid() ? shm_ptr_->reader_count.load() : 0; }
/**
* \brief Gets the highest buffer number either written or read by this SharedMemoryManager
* \return The highest buffer id written or read by this SharedMemoryManager
Expand Down Expand Up @@ -398,16 +398,16 @@ private:
SharedMemoryManager& operator=(SharedMemoryManager const&) = delete;
SharedMemoryManager& operator=(SharedMemoryManager&&) = delete;

struct ShmBufferSem
{
struct ShmBufferSem
{
BufferSemaphoreFlags flags;
int id;

ShmBufferSem()
: flags(BufferSemaphoreFlags::Empty), id(-1){}
ShmBufferSem(BufferSemaphoreFlags f, int i)
ShmBufferSem()
: flags(BufferSemaphoreFlags::Empty), id(-1) {}
ShmBufferSem(BufferSemaphoreFlags f, int i)
: flags(f), id(i) {}
};
};

struct ShmBuffer
{
Expand Down
2 changes: 1 addition & 1 deletion artdaq-core/Data/ArtdaqMetadata.hh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ArtdaqMetadata;
*/
struct artdaq::ArtdaqMetadata
{
int rank{-1}; ///< Rank of the producing artdaq process
int rank{-1}; ///< Rank of the producing artdaq process
std::vector<uint16_t> fragment_ids{}; ///< Fragment IDs of the generating process (if any)
std::string metadata_tag{}; ///< User-defined tag, to help decoding the metadata_string
std::string metadata_string{}; ///< Unstructured string data
Expand Down
1 change: 0 additions & 1 deletion artdaq-core/Data/ContainerFragmentLoader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ inline void artdaq::ContainerFragmentLoader::addFragment(artdaq::Fragment& frag,
reset_index_ptr_();
}


inline void artdaq::ContainerFragmentLoader::addFragments(artdaq::Fragments& frags, bool allowDifferentTypes)
{
TLOG(TLVL_DEBUG + 33, "ContainerFragmentLoader") << "addFragments: Adding " << frags.size() << " Fragments to Container";
Expand Down
4 changes: 2 additions & 2 deletions artdaq-core/Data/MetadataFragment.cc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ artdaq::ArtdaqMetadata artdaq::MetadataFragment::get_metadata()
ArtdaqMetadata output;

auto ptr = reinterpret_cast<uint8_t const*>(artdaq_fragment_.dataBeginBytes());

size_t element_size = *reinterpret_cast<size_t const*>(ptr);
ptr += sizeof(size_t);
assert(element_size == sizeof(output.rank));
output.rank = *reinterpret_cast<int const*>(ptr);
ptr += element_size;

element_size = *reinterpret_cast<size_t const*>(ptr);
ptr += sizeof(size_t);
assert(element_size % sizeof(uint16_t) == 0);
Expand Down
4 changes: 2 additions & 2 deletions artdaq-core/Data/MetadataFragment.hh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef artdaq_core_Data_MetadataFragment_hh
#define artdaq_core_Data_MetadataFragment_hh

#include "artdaq-core/Data/Fragment.hh"
#include "artdaq-core/Data/ArtdaqMetadata.hh"
#include "artdaq-core/Data/Fragment.hh"

namespace artdaq {
class MetadataFragment;
Expand All @@ -12,7 +12,7 @@ class artdaq::MetadataFragment
{
public:
explicit MetadataFragment(artdaq::Fragment const& frag)
: artdaq_fragment_(frag){}
: artdaq_fragment_(frag) {}

ArtdaqMetadata get_metadata();

Expand Down
2 changes: 1 addition & 1 deletion artdaq-core/Data/classes.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <vector>
#include "artdaq-core/Core/QuickVec.hh"
#include "artdaq-core/Data/ArtdaqMetadata.hh"
#include "artdaq-core/Data/Fragment.hh"
#include "artdaq-core/Data/PackageBuildInfo.hh"
#include "artdaq-core/Data/RawEvent.hh"
#include "artdaq-core/Data/detail/ParentageMap.hh"
#include "artdaq-core/Data/ArtdaqMetadata.hh"
#include "canvas/Persistency/Common/Wrapper.h"
3 changes: 2 additions & 1 deletion artdaq-core/Plugins/FragmentNameHelper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ public:
else
{
auto systemTypes = artdaq::Fragment::MakeVerboseSystemTypeMap();
if (systemTypes.count(fragment.type())) {
if (systemTypes.count(fragment.type()))
{
TLOG(TLVL_DEBUG + 33) << "Matched fragment type " << static_cast<int>(fragment.type()) << " to extended system type " << systemTypes.at(fragment.type());
instance_name = systemTypes.at(fragment.type());
}
Expand Down
34 changes: 19 additions & 15 deletions artdaq-core/Utilities/configureMessageFacility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ std::string artdaq::generateMessageFacilityConfiguration(char const* progname, b
char* logFhiclCode = getenv("ARTDAQ_LOG_FHICL");
char* artdaqMfextensionsDir = getenv("ARTDAQ_MFEXTENSIONS_DIR");
char* useMFExtensionsS = getenv("ARTDAQ_MFEXTENSIONS_ENABLED");
char* run_number = getenv("ARTDAQ_RUN_NUMBER");
char* run_number = getenv("ARTDAQ_RUN_NUMBER");
bool useMFExtensions = false;
if (useMFExtensionsS != nullptr && !(strncmp(useMFExtensionsS, "0", 1) == 0))
{
Expand Down Expand Up @@ -109,20 +109,24 @@ std::string artdaq::generateMessageFacilityConfiguration(char const* progname, b
{
ss << " file: {";
ss << R"( type: "GenFile" threshold: "DEBUG" seperator: "-")";
// ss << " pattern: \"" << progname << fileExtraName << "-%?H%t-%p.log"
// << "\"";
if (run_number == nullptr) {
ss << " pattern: \"" << progname << fileExtraName << "-%?H%t-%p.log" << "\"";
}
else {
//-----------------------------------------------------------------------------
// Mu2e case: run number is defined
//-----------------------------------------------------------------------------
char c[10];
sprintf(c,"%06i",std::stoi(run_number));
ss << " pattern: \"" << progname << "-" << c << fileExtraName << "-%?H%t-%p.log" << "\"";
}

// ss << " pattern: \"" << progname << fileExtraName << "-%?H%t-%p.log"
// << "\"";
if (run_number == nullptr)
{
ss << " pattern: \"" << progname << fileExtraName << "-%?H%t-%p.log"
<< "\"";
}
else
{
//-----------------------------------------------------------------------------
// Mu2e case: run number is defined
//-----------------------------------------------------------------------------
char c[10];
sprintf(c, "%06i", std::stoi(run_number));
ss << " pattern: \"" << progname << "-" << c << fileExtraName << "-%?H%t-%p.log"
<< "\"";
}

ss << " timestamp_pattern: \"%Y%m%d%H%M%S\"";
ss << " directory: \"" << logfileDir << "\"";
ss << " append : false";
Expand Down
41 changes: 23 additions & 18 deletions test/Core/SharedMemoryManager_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(RoundRobin)
uint8_t data[0x1000];
std::generate_n(data, 0x1000, [&]() { return ++n; });

const int reader_count = 10;
const int reader_count = 10;
const size_t n_writes = 1'000'000;

auto reader_proc = [key, reader_count]() {
Expand All @@ -371,11 +371,12 @@ BOOST_AUTO_TEST_CASE(RoundRobin)
artdaq::SharedMemoryManager reader_man(key);
auto my_id = static_cast<size_t>(reader_man.GetMyId() - 1);

TLOG(TLVL_INFO) << "Reader " << my_id << " waiting for other readers..." << reader_man.GetReaderCount();
while (reader_man.GetReaderCount() < reader_count) {
TLOG(TLVL_INFO) << "Reader " << my_id << " waiting for other readers..." << reader_man.GetReaderCount();
while (reader_man.GetReaderCount() < reader_count)
{
reader_man.ReadyForRead();
std::this_thread::yield();
}
}

TLOG(TLVL_INFO) << "Reader " << my_id << " starting";
while (!reader_man.IsEndOfData())
Expand Down Expand Up @@ -403,21 +404,23 @@ BOOST_AUTO_TEST_CASE(RoundRobin)
TLOG(TLVL_INFO) << "Reader " << my_id << " read " << counter << " buffers, " << ooo_counter << " of them were out of round-robin order, and " << misses_after_start << " times there was no data available";
};

auto writer_proc = [&man, n_writes]() {
auto writer_proc = [&man, n_writes]() {
TLOG(TLVL_INFO) << "Writer Starting";
size_t write_counter = 0;
auto current_oom = 1;
auto start_time = std::chrono::steady_clock::now();
while (write_counter < n_writes) {
while (write_counter < n_writes)
{
if (man.ReadyForWrite(false))
{
if (write_counter % current_oom == 0) {
if (write_counter % current_oom == 0)
{
TLOG(TLVL_INFO) << "Writing buffer " << write_counter;
if (write_counter >= static_cast<size_t>((10 * current_oom) - 1))
{
current_oom *= 10;
}
}
}
}
int buf = man.GetBufferForWriting(false);
man.MarkBufferFull(buf);
write_counter++;
Expand All @@ -430,18 +433,20 @@ BOOST_AUTO_TEST_CASE(RoundRobin)
TLOG(TLVL_INFO) << "Writer proc END";
};

TLOG(TLVL_INFO) << "Starting threads";
std::vector<std::jthread> threads;
for (int ii = 0; ii < reader_count; ++ii) {
TLOG(TLVL_INFO) << "Starting threads";
std::vector<std::jthread> threads;
for (int ii = 0; ii < reader_count; ++ii)
{
threads.emplace_back(reader_proc);
}
}
threads.emplace_back(writer_proc);

TLOG(TLVL_INFO) << "Joining threads";
threads[threads.size() - 1].join();
for (auto& thread : threads) {
if(thread.joinable()) thread.join();
}
TLOG(TLVL_INFO) << "Joining threads";
threads[threads.size() - 1].join();
for (auto& thread : threads)
{
if (thread.joinable()) thread.join();
}

TLOG(TLVL_DEBUG) << "END TEST RoundRobin";
}
Expand Down

0 comments on commit c30d054

Please sign in to comment.