DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::timing Namespace Reference

< Message parameters More...

Namespaces

namespace  python
 
namespace  timingendpointinfo
 
namespace  timingfirmware
 
namespace  timingfirmwareinfo
 
namespace  timinghardwareinfo
 

Classes

struct  ActiveEndpointConfig
 
class  BoreasDesign
 Class for timing master with integrated HSI designs. More...
 
class  CDCLVD110Node
 uhal::Node implementing CDCLVD110 interface More...
 
class  CDRMuxDesignInterface
 Base class for timing endpoint design nodes. More...
 
class  ChronosDesign
 Class for timing master with integrated HSI designs. More...
 
class  ClockGeneratorInterface
 uhal::Node implementing clock gen. interface More...
 
class  DACNode
 uhal::Node implementing single I2C Master Slave connection to control SFP expander chips. More...
 
class  DACSlave
 Class for dac node. More...
 
class  EchoMonitorNode
 Class for master global node. More...
 
class  EndpointDesign
 Base class for timing endpoint design nodes. More...
 
class  EndpointDesignInterface
 Base class for timing endpoint design nodes. More...
 
class  EndpointNode
 Base class for timing IO nodes. More...
 
class  EndpointNodeInterface
 Base class for timing IO nodes. More...
 
class  FanoutDesign
 Class for timing fanout designs. More...
 
class  FIBIONode
 Class for the FIB board. More...
 
class  FIBV2IONode
 Class for the FIB board. More...
 
class  FLCmdGeneratorNode
 Class for master global node. More...
 
class  FMCIONode
 Class for the timing FMC board. More...
 
class  FrequencyCounterNode
 Base class for timing IO nodes. More...
 
class  GaiaDesign
 Class for timing fanout designs. More...
 
class  GIBIONode
 Class for the timing FMC board. More...
 
class  HadesDesign
 Class for timing master with integrated HSI designs. More...
 
class  HSIDesignInterface
 Base class for timing hsi design nodes. More...
 
class  HSINode
 Class for HSI nodes. More...
 
class  I2CMasterNode
 
class  I2CSFPNode
 
class  I2CSFPSlave
 I2C slave class to control SFP transceivers. More...
 
class  I2CSlave
 
class  IONode
 Base class for timing IO nodes. More...
 
class  IRIGTimestampNode
 Class for timestamp generator node. More...
 
class  KerberosDesign
 Class for timing fanout designs. More...
 
class  MasterDesign
 Base class for timing master designs. More...
 
class  MasterDesignInterface
 Base class for timing master designs. More...
 
class  MasterGlobalNode
 Class for master global node. More...
 
class  MasterMuxDesign
 Class for PDI timing master design on mux board. More...
 
class  MasterNode
 Class for PD-II/DUNE master timing nodes. More...
 
class  MasterNodeInterface
 Base class for timing IO nodes. More...
 
class  MIBIONode
 Class for the timing FMC board. More...
 
class  MIBV2IONode
 Class for the timing FMC board. More...
 
class  MuxDesignInterface
 Base class for timing endpoint design nodes. More...
 
class  OuroborosDesign
 Class for PDI timing master design (known as overlord). More...
 
class  OuroborosMuxDesign
 Class for PDI ouroboros timing master design. More...
 
class  PC059IONode
 Class for the PC059 board. More...
 
class  SFPMuxDesignInterface
 Class for timing fanout designs. More...
 
class  SFPMuxIONode
 Base class for boards which have a physical SFP mux. More...
 
class  SIChipSlave
 Utility class to interface to SI chips. More...
 
class  SIMIONode
 Class for the timing simulation IO. More...
 
struct  stol
 
struct  stoul
 
class  SwitchyardNode
 Class for master global node. More...
 
class  TimingNode
 Base class for timing nodes. More...
 
class  TimingSourceMuxDesignInterface
 Base class for timing endpoint design nodes. More...
 
class  TLUIONode
 Class for the TLU board. More...
 
class  TopDesign
 Base class for timing top design nodes with IO class. More...
 
class  TopDesignInterface
 Base class for timing top design nodes. More...
 
class  UpstreamCDRNode
 Class for master global node. More...
 
class  VLCmdGeneratorNode
 Class for master global node. More...
 

Typedefs

typedef std::map< std::string, uint32_t > Snapshot
 

Enumerations

enum  BoardType {
  kBoardFMC , kBoardSim , kBoardPC059 , kBoardMicrozed ,
  kBoardTLU , kBoardFIB , kBoardMIB , kBoardPC069 ,
  kBoardGIB , kBoardUnknown = 256
}
 
enum  CarrierType {
  kCarrierEnclustraA35 , kCarrierKC705 , kCarrierMicrozed , kCarrierATFC ,
  kCarrierAFC , kCarrierNexusVideo , kCarrierTrenzTE0712 , kCarrierUnknown = 256
}
 
enum  DesignType {
  kDesignMaster , kDesignOuroborosSim , kDesignOuroboros , kDesignTest ,
  kDesignEndpoint , kDesignFanout , kDesignOverlord , kDesignEndpoBICRT ,
  kDesignChronos , kDesignBoreas , kDesignKerberos , kDesignGaia ,
  kDesignCharon , kDesignHades , kDesignUnknown = 256
}
 
enum  BoardRevision {
  kFMCRev1 , kFMCRev2 , kFMCRev3 , kFMCRev4 ,
  kPC059Rev1 , kTLURev1 , kSIMRev1 , kFIBRev1 ,
  kMIBRev1 , kPC069a , kMIBRev2 , kGIBRev1 ,
  kPC069b , kFIBRev2 , kPC069c , kBoardRevisionUnknown = 256
}
 
enum  FixedLengthCommandType {
  TimeSync , Echo , SpillStart , SpillStop ,
  RunStart , RunStop , WibCalib , SSPCalib ,
  FakeTrig0 , FakeTrig1 , FakeTrig2 , FakeTrig3 ,
  BeamTrig , NoBeamTrig , ExtFakeTrig
}
 
enum  ClockSource {
  kInput0 = 0 , kInput1 = 1 , kInput2 = 2 , kInput3 = 3 ,
  kFreeRun = 255
}
 
enum  TimestampSource { kUpstream = 0 , kSoftware = 1 , kMixed = 2 }
 
enum  IRIGEpoch { kTAI = 0 , kUNIX = 1 }
 

Functions

template<typename T >
std::string to_string (const T &v)
 
template<typename M >
bool map_value_comparator (typename M::value_type &p1, typename M::value_type &p2)
 
template<typename T >
std::vector< T > sanitize (const std::vector< T > &vec)
 
template<typename T , typename U >
safe_enum_cast (const U &value, const std::vector< T > &valid, const T &def)
 
template<typename C >
std::string join (const C &strings, const std::string &delimiter=" ")
 Converts a vector of strings in a delimiter-separated string.
 
template<class T >
std::string format_reg_value (T reg_value, uint32_t base)
 
template<>
std::string format_reg_value (std::string reg_value, uint32_t)
 
template<>
std::string format_reg_value (uhal::ValWord< uint32_t > reg_value, uint32_t base)
 
template<class T >
std::string format_reg_table (T data, std::string title="", std::vector< std::string > headers={ "Register", "Value" })
 Format reg-value table.
 
template<class T >
std::string format_counters_table (std::vector< T > counters, std::vector< std::string > counter_node_titles={}, std::string table_title="", std::vector< std::string > counter_labels={}, std::string counter_labels_header="Cmd")
 Format reg-value table.
 
template<typename T >
std::string vec_fmt (const std::vector< T > &vec)
 
template<typename T >
std::string short_vec_fmt (const std::vector< T > &vec)
 
template<typename T , typename U >
safe_enum_cast (const U &value, const std::vector< T > &valid)
 
Snapshot snapshot (const uhal::Node &node)
 Walk & read the node structure.
 
Snapshot snapshot (const uhal::Node &node, const std::string &regex)
 Walk & read the sub-nodes whose IDs match this regex.
 
void millisleep (const double &time_in_milliseconds)
 
std::string strprintf (const char *fmt,...)
 
std::vector< std::string > shell_expand_paths (const std::string &path)
 
std::string shellExpandPath (const std::string &path)
 
void throw_if_not_file (const std::string &path)
 
uint8_t dec_rng (uint8_t word, uint8_t ibit, uint8_t nbits=1)
 
uint64_t tstamp2int (uhal::ValVector< uint32_t > raw_timestamp)
 
int64_t get_milliseconds_since_epoch ()
 
int64_t get_seconds_since_epoch ()
 
std::string format_timestamp (uhal::ValVector< uint32_t > raw_timestamp, uint32_t clock_frequency_hz)
 
std::string format_timestamp (uint64_t raw_timestamp, uint32_t clock_frequency_hz)
 
double convert_bits_to_float (uint64_t bits, bool is_double_precision=false)
 
BoardType convert_value_to_board_type (uint32_t Board_type)
 
CarrierType convert_value_to_carrier_type (uint32_t darrier_type)
 
DesignType convert_value_to_design_type (uint32_t design_type)
 
std::string format_firmware_version (uint32_t firmware_version)
 
uint32_t locate (float xx[], unsigned long n, float x)
 

Detailed Description

< Message parameters

Typedef Documentation

◆ Snapshot

typedef std::map<std::string, uint32_t> dunedaq::timing::Snapshot

Definition at line 27 of file definitions.hpp.

Enumeration Type Documentation

◆ BoardRevision

Enumerator
kFMCRev1 
kFMCRev2 
kFMCRev3 
kFMCRev4 
kPC059Rev1 
kTLURev1 
kSIMRev1 
kFIBRev1 
kMIBRev1 
kPC069a 
kMIBRev2 
kGIBRev1 
kPC069b 
kFIBRev2 
kPC069c 
kBoardRevisionUnknown 

Definition at line 74 of file definitions.hpp.

75{
76 kFMCRev1,
77 kFMCRev2,
78 kFMCRev3,
79 kFMCRev4,
80 kPC059Rev1,
81 kTLURev1,
82 kSIMRev1,
83 kFIBRev1,
84 kMIBRev1,
85 kPC069a,
87 kGIBRev1,
88 kPC069b,
89 kFIBRev2,
90 kPC069c,
92};

◆ BoardType

Enumerator
kBoardFMC 
kBoardSim 
kBoardPC059 
kBoardMicrozed 
kBoardTLU 
kBoardFIB 
kBoardMIB 
kBoardPC069 
kBoardGIB 
kBoardUnknown 

Definition at line 29 of file definitions.hpp.

30{
31 kBoardFMC,
32 kBoardSim,
33 kBoardPC059,
34 kBoardMicrozed,
35 kBoardTLU,
36 kBoardFIB,
37 kBoardMIB,
38 kBoardPC069,
39 kBoardGIB,
40 kBoardUnknown = 256
41};

◆ CarrierType

Enumerator
kCarrierEnclustraA35 
kCarrierKC705 
kCarrierMicrozed 
kCarrierATFC 
kCarrierAFC 
kCarrierNexusVideo 
kCarrierTrenzTE0712 
kCarrierUnknown 

Definition at line 43 of file definitions.hpp.

44{
45 kCarrierEnclustraA35,
46 kCarrierKC705,
47 kCarrierMicrozed,
50 kCarrierNexusVideo,
51 kCarrierTrenzTE0712, // include fpga part number?
52 kCarrierUnknown = 256
53};

◆ ClockSource

Enumerator
kInput0 
kInput1 
kInput2 
kInput3 
kFreeRun 

Definition at line 113 of file definitions.hpp.

114{
115 kInput0 = 0,
116 kInput1 = 1,
117 kInput2 = 2,
118 kInput3 = 3,
119 kFreeRun = 255
120};

◆ DesignType

Enumerator
kDesignMaster 
kDesignOuroborosSim 
kDesignOuroboros 
kDesignTest 
kDesignEndpoint 
kDesignFanout 
kDesignOverlord 
kDesignEndpoBICRT 
kDesignChronos 
kDesignBoreas 
kDesignKerberos 
kDesignGaia 
kDesignCharon 
kDesignHades 
kDesignUnknown 

Definition at line 55 of file definitions.hpp.

56{
57 kDesignMaster,
58 kDesignOuroborosSim,
59 kDesignOuroboros,
60 kDesignTest,
61 kDesignEndpoint,
62 kDesignFanout,
63 kDesignOverlord,
65 kDesignChronos,
66 kDesignBoreas,
67 kDesignKerberos,
68 kDesignGaia,
69 kDesignCharon,
70 kDesignHades,
71 kDesignUnknown = 256
72};

◆ FixedLengthCommandType

Enumerator
TimeSync 
Echo 
SpillStart 
SpillStop 
RunStart 
RunStop 
WibCalib 
SSPCalib 
FakeTrig0 
FakeTrig1 
FakeTrig2 
FakeTrig3 
BeamTrig 
NoBeamTrig 
ExtFakeTrig 

Definition at line 94 of file definitions.hpp.

◆ IRIGEpoch

Enumerator
kTAI 
kUNIX 

Definition at line 129 of file definitions.hpp.

130{
131 kTAI = 0,
132 kUNIX = 1
133};

◆ TimestampSource

Enumerator
kUpstream 
kSoftware 
kMixed 

Definition at line 122 of file definitions.hpp.

123{
124 kUpstream = 0,
125 kSoftware = 1,
126 kMixed = 2
127};

Function Documentation

◆ convert_bits_to_float()

double dunedaq::timing::convert_bits_to_float ( uint64_t bits,
bool is_double_precision = false )

""

Returns

Definition at line 242 of file toolbox.cpp.

243{
244 uint32_t mantissa_shift = is_double_precision ? 52 : 23; // NOLINT(build/unsigned)
245 uint64_t exponent_mask = is_double_precision ? 0x7FF0000000000000 : 0x7f800000; // NOLINT(build/unsigned)
246 uint32_t bias = is_double_precision ? 1023 : 127; // NOLINT(build/unsigned)
247 uint32_t sign_shift = is_double_precision ? 63 : 31; // NOLINT(build/unsigned)
248
249 int32_t sign = (bits >> sign_shift) & 0x01;
250 uint32_t exponent_biased = ((bits & exponent_mask) >> mantissa_shift); // NOLINT(build/unsigned)
251 int32_t exponent = exponent_biased - bias;
252
253 int32_t power = -1;
254 double mantissa = 0.0;
255 for (uint32_t i = 0; i < mantissa_shift; ++i) { // NOLINT(build/unsigned)
256 uint64_t mantissa_bit = (bits >> (mantissa_shift - i - 1)) & 0x01; // NOLINT(build/unsigned)
257 mantissa += mantissa_bit * pow(2.0, power);
258 --power;
259 }
260
261 if (exponent_biased == 0) {
262 ++exponent;
263 if (mantissa == 0)
264 return 0;
265 } else {
266 mantissa += 1.0;
267 }
268 return (sign ? -1 : 1) * pow(2.0, exponent) * mantissa;
269}

◆ convert_value_to_board_type()

BoardType dunedaq::timing::convert_value_to_board_type ( uint32_t Board_type)

Definition at line 274 of file toolbox.cpp.

275{
276 // not pleasnt, but works for now
277 if (board_type >= kBoardUnknown) {
278 throw UnknownBoardType(ERS_HERE, format_reg_value(board_type));
279 } else {
280 return static_cast<BoardType>(board_type);
281 }
282}
#define ERS_HERE
std::string format_reg_value(T reg_value, uint32_t base)
Definition toolbox.hxx:117

◆ convert_value_to_carrier_type()

CarrierType dunedaq::timing::convert_value_to_carrier_type ( uint32_t darrier_type)

Definition at line 287 of file toolbox.cpp.

288{
289 // not pleasnt, but works for now
290 if (carrier_type >= kCarrierUnknown) {
291 throw UnknownCarrierType(ERS_HERE, format_reg_value(carrier_type));
292 } else {
293 return static_cast<CarrierType>(carrier_type);
294 }
295}

◆ convert_value_to_design_type()

DesignType dunedaq::timing::convert_value_to_design_type ( uint32_t design_type)

Definition at line 300 of file toolbox.cpp.

301{
302 // not pleasnt, but works for now
303 if (design_type >= kDesignUnknown) {
304 throw UnknownDesignType(ERS_HERE, format_reg_value(design_type));
305 } else {
306 return static_cast<DesignType>(design_type);
307 }
308}

◆ dec_rng()

uint8_t dunedaq::timing::dec_rng ( uint8_t word,
uint8_t ibit,
uint8_t nbits = 1 )

Expand the path

Parameters
pathpath to expand
Returns
vector of expanded paths

Definition at line 167 of file toolbox.cpp.

168{
169 return (word >> ibit) & ((1 << nbits) - 1);
170}

◆ format_counters_table()

template<class T >
std::string dunedaq::timing::format_counters_table ( std::vector< T > counters,
std::vector< std::string > counter_node_titles = {},
std::string table_title = "",
std::vector< std::string > counter_labels = {},
std::string counter_labels_header = "Cmd" )

Format reg-value table.

Returns

Definition at line 216 of file toolbox.hxx.

221{
222
223 uint32_t counter_nodes_number = counter_nodes.size();
224 uint32_t table_width = 4 + (counter_nodes_number * 3);
225
226 std::vector<std::string> counter_node_titles_to_use;
227
228 if (!counter_node_titles.size()) {
229 for (uint32_t i = 0; i < counter_nodes.size(); ++i) {
230 counter_node_titles_to_use.push_back("Counters");
231 }
232 } else if (counter_nodes.size() != counter_node_titles.size()) {
233 throw FormatCountersTableNodesTitlesMismatch(ERS_HERE);
234 } else {
235 counter_node_titles_to_use = counter_node_titles;
236 }
237
238 uint32_t counter_number;
239 uint32_t counter_label_column_width = 0;
240
241 std::stringstream table_stream;
242 counter_number = counter_labels.size();
243
244 for (auto it = counter_labels.begin(); it != counter_labels.end(); ++it) {
245 counter_label_column_width = counter_label_column_width > it->size() ? counter_label_column_width : it->size();
246 }
247 counter_label_column_width =
248 counter_label_column_width > counter_labels_header.size() ? counter_label_column_width : counter_labels_header.size();
249
250 typedef std::vector<std::pair<std::string, std::string>> CounterValuesContainer;
251
252 std::vector<CounterValuesContainer> counter_value_containers;
253 std::vector<std::pair<uint32_t, uint32_t>> counter_value_column_widths;
254
255 for (auto node_iter = counter_nodes.begin(); node_iter != counter_nodes.end(); ++node_iter) {
256
257 CounterValuesContainer counter_values;
258
259 uint32_t counter_value_dec_column_width = 5;
260 uint32_t counter_value_hex_column_width = 5;
261
262 for (auto counter_iter = node_iter->begin(); counter_iter != node_iter->end(); ++counter_iter) {
263
264 std::string counter_value_dec = format_reg_value(*counter_iter, 10);
265 std::string counter_value_hex = format_reg_value(*counter_iter, 16);
266
267 counter_value_dec_column_width =
268 counter_value_dec_column_width > counter_value_dec.size() ? counter_value_dec_column_width : counter_value_dec.size();
269 counter_value_hex_column_width =
270 counter_value_hex_column_width > counter_value_hex.size() ? counter_value_hex_column_width : counter_value_hex.size();
271
272 counter_values.push_back(std::make_pair(counter_value_dec, counter_value_hex));
273 }
274
275 counter_value_containers.push_back(counter_values);
276 counter_value_column_widths.push_back(std::make_pair(counter_value_dec_column_width, counter_value_hex_column_width));
277 }
278
279 std::vector<uint32_t> counter_node_title_sizes;
280 // titles and border
281 std::stringstream counter_titles_row;
282 counter_titles_row << boost::format("| %=s |") % boost::io::group(std::setw(counter_label_column_width), "");
283 table_width = table_width + counter_label_column_width;
284 for (uint32_t i = 0; i < counter_nodes_number; ++i) {
285 uint32_t dec_width = counter_value_column_widths.at(i).first;
286 uint32_t hex_width = counter_value_column_widths.at(i).second;
287
288 uint32_t counter_title_size = counter_node_titles_to_use.at(i).size();
289
290 if (counter_title_size > (dec_width + hex_width + 3)) {
291
292 if ((counter_title_size - 3) % 2)
293 ++counter_title_size;
294
295 counter_value_column_widths.at(i).first = (counter_title_size - 3) / 2;
296 counter_value_column_widths.at(i).second = (counter_title_size - 3) / 2;
297
298 } else {
299 counter_title_size = (dec_width + hex_width + 3);
300 }
301 counter_titles_row << boost::format(" %=s |") %
302 boost::io::group(std::setw(counter_title_size), counter_node_titles_to_use.at(i));
303 counter_node_title_sizes.push_back(counter_title_size);
304 table_width = table_width + counter_title_size;
305 }
306 counter_titles_row << std::endl;
307
308 std::stringstream title_row_border;
309 title_row_border << boost::format("+-%=s-+") %
310 boost::io::group(std::setw(counter_label_column_width), std::setfill('-'), "");
311 for (uint32_t i = 0; i < counter_nodes_number; ++i) {
312 title_row_border << boost::format("-%=s-+") %
313 boost::io::group(std::setw(counter_node_title_sizes.at(i)), std::setfill('-'), "");
314 }
315 title_row_border << std::endl;
316
317 if (table_title.size())
318 table_stream << boost::format("%=s\n") % boost::io::group(std::setw(table_width), std::setfill('-'), table_title);
319
320 table_stream << title_row_border.str();
321 table_stream << counter_titles_row.str();
322 table_stream << title_row_border.str();
323 //
324
325 // headers
326 std::stringstream counter_headers;
327 counter_headers << boost::format("| %=s |") %
328 boost::io::group(std::setw(counter_label_column_width), counter_labels_header);
329 for (uint32_t j = 0; j < counter_nodes_number; ++j) {
330 uint32_t dec_width = counter_value_column_widths.at(j).first;
331 uint32_t hex_width = counter_value_column_widths.at(j).second;
332 counter_headers << boost::format(" %=s | %=s |") % boost::io::group(std::setw(dec_width), "cnts") %
333 boost::io::group(std::setw(hex_width), "hex");
334 }
335 table_stream << counter_headers.str() << std::endl;
336 //
337
338 // top counter row border
339 std::stringstream row_border;
340 row_border << boost::format("+-%=s-+") % boost::io::group(std::setw(counter_label_column_width), std::setfill('-'), "");
341 for (uint32_t j = 0; j < counter_nodes_number; ++j) {
342 uint32_t dec_width = counter_value_column_widths.at(j).first;
343 uint32_t hex_width = counter_value_column_widths.at(j).second;
344 row_border << boost::format("-%=s-+-%=s-+") % boost::io::group(std::setw(dec_width), std::setfill('-'), "") %
345 boost::io::group(std::setw(hex_width), std::setfill('-'), "");
346 }
347 row_border << std::endl;
348 table_stream << row_border.str();
349 //
350
351 // counter rows
352 for (uint32_t i = 0; i < counter_number; ++i) {
353 std::stringstream table_row_stream;
354
355 table_row_stream << boost::format("| %=s |") %
356 boost::io::group(std::setw(counter_label_column_width), counter_labels.at(i));
357
358 for (uint32_t j = 0; j < counter_nodes_number; ++j) {
359 uint32_t dec_width = counter_value_column_widths.at(j).first;
360 uint32_t hex_width = counter_value_column_widths.at(j).second;
361
362 std::string dec_value = counter_value_containers.at(j).at(i).first;
363 std::string hex_value = counter_value_containers.at(j).at(i).second;
364
365 table_row_stream << boost::format(" %=s | %=s |") % boost::io::group(std::setw(dec_width), dec_value) %
366 boost::io::group(std::setw(hex_width), hex_value);
367 }
368 table_stream << table_row_stream.str() << std::endl;
369 }
370 //
371
372 // bottom counter row border
373 table_stream << row_border.str();
374
375 return table_stream.str();
376}

◆ format_firmware_version()

std::string dunedaq::timing::format_firmware_version ( uint32_t firmware_version)

Definition at line 352 of file toolbox.cpp.

353{
354 int major_firmware_version = (firmware_version >> 16) & 0xff;
355 int minor_firmware_version = (firmware_version >> 8) & 0xff;
356 int patch_firmware_version = (firmware_version >> 0) & 0xff;
357
358 std::stringstream firmware_version_stream;
359 firmware_version_stream << "v" << major_firmware_version << "." << minor_firmware_version << "." << patch_firmware_version;
360 return firmware_version_stream.str();
361}

◆ format_reg_table()

template<class T >
std::string dunedaq::timing::format_reg_table ( T data,
std::string title = "",
std::vector< std::string > headers = { "Register", "Value" } )

Format reg-value table.

Returns

Definition at line 166 of file toolbox.hxx.

167{
168
169 uint32_t table_width = 7;
170 uint32_t reg_column_width = 0;
171 uint32_t val_column_width = 3;
172 std::stringstream table_stream;
173
174 for (auto it = data.begin(); it != data.end(); ++it) {
175 reg_column_width = reg_column_width > it->first.size() ? reg_column_width : it->first.size();
176 val_column_width =
177 val_column_width > format_reg_value(it->second).size() ? val_column_width : format_reg_value(it->second).size();
178 }
179
180 // header vector length check
181 reg_column_width = reg_column_width > headers.at(0).size() ? reg_column_width : headers.at(0).size();
182 val_column_width = val_column_width > headers.at(1).size() ? val_column_width : headers.at(1).size();
183
184 table_width = table_width + reg_column_width + val_column_width;
185
186 if (title.size())
187 table_stream << boost::format("%=s\n") % boost::io::group(std::setw(table_width), std::setfill('-'), title);
188
189 if (headers.at(0).size() || headers.at(1).size()) {
190 table_stream << boost::format("+-%=s-+-%=s-+\n") %
191 boost::io::group(std::setw(reg_column_width), std::setfill('-'), "") %
192 boost::io::group(std::setw(val_column_width), std::setfill('-'), "");
193 table_stream << boost::format("| %=s | %=s |\n") % boost::io::group(std::setw(reg_column_width), headers.at(0)) %
194 boost::io::group(std::setw(val_column_width), headers.at(1));
195 }
196
197 table_stream << boost::format("+-%=s-+-%=s-+\n") %
198 boost::io::group(std::setw(reg_column_width), std::setfill('-'), "") %
199 boost::io::group(std::setw(val_column_width), std::setfill('-'), "");
200
201 for (auto it = data.begin(); it != data.end(); ++it) {
202 table_stream << boost::format("| %=s | %=s |\n") % boost::io::group(std::setw(reg_column_width), it->first) %
203 boost::io::group(std::setw(val_column_width), format_reg_value(it->second));
204 }
205 table_stream << boost::format("+-%=s-+-%=s-+\n") %
206 boost::io::group(std::setw(reg_column_width), std::setfill('-'), "") %
207 boost::io::group(std::setw(val_column_width), std::setfill('-'), "");
208
209 return table_stream.str();
210}

◆ format_reg_value() [1/3]

template<>
std::string dunedaq::timing::format_reg_value ( std::string reg_value,
uint32_t  )
inline

Definition at line 137 of file toolbox.hxx.

138{
139 return reg_value;
140}

◆ format_reg_value() [2/3]

template<class T >
std::string dunedaq::timing::format_reg_value ( T reg_value,
uint32_t base = 16 )

Format reg-value

Returns

Definition at line 117 of file toolbox.hxx.

118{
119 std::stringstream value_stream;
120 if (base == 16) {
121 value_stream << "0x" << std::hex;
122 } else if (base == 10) {
123 value_stream << std::dec;
124 } else {
125 // TODO warning?
126 TLOG() << "Unsupported number base: " << base;
127 value_stream << std::dec;
128 }
129 value_stream << reg_value;
130 return value_stream.str();
131}
#define TLOG(...)
Definition macro.hpp:22

◆ format_reg_value() [3/3]

template<>
std::string dunedaq::timing::format_reg_value ( uhal::ValWord< uint32_t > reg_value,
uint32_t base )
inline

Definition at line 146 of file toolbox.hxx.

147{
148 std::stringstream value_stream;
149 if (base == 16) {
150 value_stream << "0x" << std::hex;
151 } else if (base == 10) {
152 value_stream << std::dec;
153 } else {
154 // TODO warning?
155 TLOG() << "format_reg_value: unsupported number base: " << base;
156 value_stream << std::dec;
157 }
158 value_stream << reg_value.value();
159 return value_stream.str();
160}

◆ format_timestamp() [1/2]

std::string dunedaq::timing::format_timestamp ( uhal::ValVector< uint32_t > raw_timestamp,
uint32_t clock_frequency_hz )

""

Returns

Definition at line 233 of file toolbox.cpp.

234{
235 uint64_t timestamp = tstamp2int(raw_timestamp); // NOLINT(build/unsigned)
236 return format_timestamp(timestamp, clock_frequency_hz);
237}
std::string format_timestamp(uhal::ValVector< uint32_t > raw_timestamp, uint32_t clock_frequency_hz)
Definition toolbox.cpp:233
uint64_t tstamp2int(uhal::ValVector< uint32_t > raw_timestamp)
Definition toolbox.cpp:175

◆ format_timestamp() [2/2]

std::string dunedaq::timing::format_timestamp ( uint64_t raw_timestamp,
uint32_t clock_frequency_hz )

""

Returns

Definition at line 219 of file toolbox.cpp.

220{
221 std::time_t sec_from_epoch = raw_timestamp / clock_frequency_hz;
222
223 struct tm* time = localtime(&sec_from_epoch); // NOLINT
224 char time_buffer[32];
225
226 strftime(time_buffer, sizeof time_buffer, "%a, %d %b %Y %H:%M:%S +0000", time);
227 return time_buffer;
228}

◆ get_milliseconds_since_epoch()

int64_t dunedaq::timing::get_milliseconds_since_epoch ( )

""

Returns

Definition at line 201 of file toolbox.cpp.

202{
203 // get the current time
204 const auto now = std::chrono::system_clock::now();
205
206 // transform the time into a duration since the epoch
207 const auto epoch = now.time_since_epoch();
208
209 // cast the duration into milliseconds
210 const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
211
212 // return the number of milliseconds
213 return milliseconds.count();
214}
static int64_t now()

◆ get_seconds_since_epoch()

int64_t dunedaq::timing::get_seconds_since_epoch ( )

""

Returns

Definition at line 183 of file toolbox.cpp.

184{
185 // get the current time
186 const auto now = std::chrono::system_clock::now();
187
188 // transform the time into a duration since the epoch
189 const auto epoch = now.time_since_epoch();
190
191 // cast the duration into seconds
192 const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(epoch);
193
194 // return the number of seconds
195 return seconds.count();
196}

◆ join()

template<typename C >
std::string dunedaq::timing::join ( const C & strings,
const std::string & delimiter = " " )

Converts a vector of strings in a delimiter-separated string.

Parameters
[in]aStringsCollection of strings
[in]aDelimiterA delimiter
Template Parameters
C{ description }
Returns
{ description_of_the_return_value }

Definition at line 95 of file toolbox.hxx.

96{
97
98 if (strings.empty())
99 return "";
100
101 std::ostringstream string_stream;
102
103 string_stream << *strings.begin();
104
105 for (auto str_iter = std::next(strings.begin()); str_iter != strings.end(); ++str_iter) {
106 string_stream << delimiter;
107 string_stream << *str_iter;
108 }
109
110 return string_stream.str();
111}

◆ locate()

uint32_t dunedaq::timing::locate ( float xx[],
unsigned long n,
float x )

Definition at line 318 of file toolbox.cpp.

319{
320 uint32_t j, ju, jm, jl; // NOLINT(build/unsigned)
321 int ascnd;
322 jl = 0; // Initialize lower
323 ju = n + 1; // and upper limits.
324 ascnd = (xx[n] >= xx[1]); // NOLINT
325
326 while (ju - jl > 1) // If we are not yet done,
327 {
328 jm = (ju + jl) >> 1; // compute a midpoint,
329
330 if ((x >= xx[jm]) == ascnd) // added additional parenthesis
331 {
332 jl = jm; // and replace either the lower limit
333 } else {
334 ju = jm; // or the upper limit, as appropriate.
335 }
336 } // Repeat until the test condition is satisfied.
337
338 if (x == xx[1]) { // NOLINT
339 j = 1; // Then set the output
340 } else if (x == xx[n]) { // NOLINT
341 j = n - 1;
342 } else {
343 j = jl;
344 }
345
346 return j;
347}

◆ map_value_comparator()

template<typename M >
bool dunedaq::timing::map_value_comparator ( typename M::value_type & p1,
typename M::value_type & p2 )

Definition at line 58 of file toolbox.hxx.

59{
60 return p1.second < p2.second;
61}

◆ millisleep()

void dunedaq::timing::millisleep ( const double & time_in_milliseconds)

Sleeps for a given number of milliseconds

Parameters
time_in_millisecondsNumber of milliseconds to sleep

Definition at line 83 of file toolbox.cpp.

84{
85 // using namespace uhal;
86 // logging();
87 double time_in_seconds(time_in_milliseconds / 1e3);
88 int integer_part(static_cast<int>(time_in_seconds));
89 double fractional_part(time_in_seconds - static_cast<double>(integer_part));
90 struct timespec sleep_time, return_time;
91 sleep_time.tv_sec = integer_part;
92 sleep_time.tv_nsec = static_cast<long>(fractional_part * 1e9); // NOLINT
93 nanosleep(&sleep_time, &return_time);
94}

◆ safe_enum_cast() [1/2]

template<typename T , typename U >
T dunedaq::timing::safe_enum_cast ( const U & value,
const std::vector< T > & valid )

◆ safe_enum_cast() [2/2]

template<typename T , typename U >
T dunedaq::timing::safe_enum_cast ( const U & value,
const std::vector< T > & valid,
const T & def )

Definition at line 85 of file toolbox.hxx.

86{
87 typename std::vector<T>::const_iterator it = std::find(valid.begin(), valid.end(), static_cast<T>(value));
88 return (it != valid.end() ? *it : def);
89}

◆ sanitize()

template<typename T >
std::vector< T > dunedaq::timing::sanitize ( const std::vector< T > & vec)

Definition at line 67 of file toolbox.hxx.

68{
69 // Sanitise the inputs, by copying
70 std::vector<uint32_t> sorted(vec);
71
72 // ...sorting...
73 std::sort(sorted.begin(), sorted.end());
74
75 // and delete the duplicates (erase+unique require a sorted vector to delete duplicates)
76 sorted.erase(std::unique(sorted.begin(), sorted.end()), sorted.end());
77
78 return sorted;
79}

◆ shell_expand_paths()

std::vector< std::string > dunedaq::timing::shell_expand_paths ( const std::string & path)

Expand the path

Parameters
pathpath to expand
Returns
vector of expanded paths

Definition at line 114 of file toolbox.cpp.

115{
116
117 std::vector<std::string> paths;
118 wordexp_t substituted_path;
119 int code = wordexp(path.c_str(), &substituted_path, WRDE_NOCMD);
120 if (code)
121 throw runtime_error("Failed expanding path: " + path);
122
123 for (std::size_t i = 0; i != substituted_path.we_wordc; i++)
124 paths.push_back(substituted_path.we_wordv[i]);
125
126 wordfree(&substituted_path);
127
128 return paths;
129}

◆ shellExpandPath()

std::string dunedaq::timing::shellExpandPath ( const std::string & path)

Performs variable subsitutition on path

Parameters
pathPath to expand
Returns
Expanded path

Definition at line 134 of file toolbox.cpp.

135{
136 std::vector<std::string> paths = shell_expand_paths(path);
137
138 if (paths.size() > 1)
139 throw runtime_error("Failed to expand: multiple matches found");
140
141 return paths[0];
142}
std::vector< std::string > shell_expand_paths(const std::string &path)
Definition toolbox.cpp:114

◆ short_vec_fmt()

template<typename T >
std::string dunedaq::timing::short_vec_fmt ( const std::vector< T > & vec)

Definition at line 399 of file toolbox.hxx.

400{
401 if (vec.size() == 0)
402 return "[]";
403 else if (vec.size() == 1)
404 return "[" + boost::lexical_cast<std::string>(vec.at(0)) + "]";
405
406 std::ostringstream oss;
407 oss << "[";
408
409 // Initial search range
410 T first = vec.at(0);
411 T last = first;
412 for (typename std::vector<T>::const_iterator it = vec.begin() + 1; it != vec.end(); it++) {
413 // if *it is contiguous to last, carry on searching
414 if ((*it) == (last + 1)) {
415 last = *it;
416 continue;
417 }
418
419 if (first == last)
420 // if first and last are the same, this is an isolated number
421 oss << first << ",";
422 else
423 // otherwise it's a range
424 oss << first << "-" << last << ",";
425
426 // *it is the first value of the new range
427 first = *it;
428 last = *it;
429 }
430
431 // Process the last range
432 if (first == last)
433 oss << first << ",";
434 else
435 oss << first << "-" << last << ",";
436
437 // Is this actually necessary?
438 // Replace final "," with a "]"
439 oss.seekp(oss.tellp() - 1l);
440 oss << "]";
441
442 return oss.str();
443}

◆ snapshot() [1/2]

Snapshot dunedaq::timing::snapshot ( const uhal::Node & node)

Walk & read the node structure.

snapshot( node ) -> { subnode:value }

snapshot( node ) -> { subnode:value }

Definition at line 42 of file toolbox.cpp.

43{
45 std::map<string, uhal::ValWord<uint32_t>> value_words; // NOLINT(build/unsigned)
46
47 for (string n : node.getNodes()) {
48 value_words.insert(make_pair(n, node.getNode(n).read()));
49 }
50 node.getClient().dispatch();
51
52 Snapshot vals;
53 std::map<string, uhal::ValWord<uint32_t>>::iterator it; // NOLINT(build/unsigned)
54 for (it = value_words.begin(); it != value_words.end(); ++it)
55 vals.insert(make_pair(it->first, it->second.value()));
56
57 return vals;
58}

◆ snapshot() [2/2]

Snapshot dunedaq::timing::snapshot ( const uhal::Node & node,
const std::string & regex )

Walk & read the sub-nodes whose IDs match this regex.

Definition at line 63 of file toolbox.cpp.

64{
65 std::map<string, uhal::ValWord<uint32_t>> value_words; // NOLINT(build/unsigned)
66
67 for (string n : node.getNodes(regex)) {
68 value_words.insert(make_pair(n, node.getNode(n).read()));
69 }
70 node.getClient().dispatch();
71
72 Snapshot vals;
73 std::map<string, uhal::ValWord<uint32_t>>::iterator it; // NOLINT(build/unsigned)
74 for (it = value_words.begin(); it != value_words.end(); ++it)
75 vals.insert(make_pair(it->first, it->second.value()));
76
77 return vals;
78}

◆ strprintf()

std::string dunedaq::timing::strprintf ( const char * fmt,
... )

Formats a std::string in printf fashion

Parameters
[in]aFmtFormat string
[in]...List of arguments
Returns
A formatted string

Definition at line 99 of file toolbox.cpp.

100{
101 char* ret;
102 va_list ap;
103 va_start(ap, fmt);
104 vasprintf(&ret, fmt, ap); // NOLINT
105 va_end(ap);
106 std::string str(ret);
107 free(ret);
108 return str;
109}

◆ throw_if_not_file()

void dunedaq::timing::throw_if_not_file ( const std::string & path)

Checks that the input path corresponds to an existing filesystem item which is a file

Parameters
pathPath to file

Definition at line 147 of file toolbox.cpp.

148{
149
150 // FIXME: Review the implementation. The function never returns
151 namespace fs = boost::filesystem;
152
153 // Check that the path exists and that it's not a directory
154 fs::path cfgFile(path);
155 if (!fs::exists(cfgFile)) {
156 throw FileNotFound(ERS_HERE, path);
157 } else if (fs::is_directory(cfgFile)) {
158 throw FileIsDirectory(ERS_HERE, path);
159 }
160
161 // return true;
162}

◆ to_string()

template<typename T >
std::string dunedaq::timing::to_string ( const T & v)

Definition at line 49 of file toolbox.hxx.

50{
51 return boost::lexical_cast<std::string>(v);
52}

◆ tstamp2int()

uint64_t dunedaq::timing::tstamp2int ( uhal::ValVector< uint32_t > raw_timestamp)

""

Returns

Definition at line 175 of file toolbox.cpp.

176{
177 return (uint64_t)raw_timestamp[0] + ((uint64_t)raw_timestamp[1] << 32); // NOLINT(build/unsigned)
178}

◆ vec_fmt()

template<typename T >
std::string dunedaq::timing::vec_fmt ( const std::vector< T > & vec)

Definition at line 382 of file toolbox.hxx.

383{
384 std::ostringstream oss;
385 oss << "[";
386
387 for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); it++)
388 oss << *it << ",";
389 oss.seekp(oss.tellp() - 1l);
390 oss << "]";
391
392 return oss.str();
393}