artdaq  v3_01_00
Globals.hh
1 #ifndef ARTDAQ_DAQDATA_GLOBALS_HH
2 #define ARTDAQ_DAQDATA_GLOBALS_HH
3 
4 #include <sstream>
5 #include "artdaq-utilities/Plugins/MetricManager.hh"
6 
7 #define my_rank artdaq::Globals::my_rank_
8 #define app_name artdaq::Globals::app_name_
9 #define metricMan artdaq::Globals::metricMan_
10 #define seedAndRandom() artdaq::Globals::seedAndRandom_()
11 
12 #define mftrace_iteration artdaq::Globals::mftrace_iteration_
13 #define mftrace_module artdaq::Globals::mftrace_module_
14 #define SetMFModuleName(name) mftrace_module = name
15 #define SetMFIteration(name) mftrace_iteration = name
16 
17 //https://stackoverflow.com/questions/21594140/c-how-to-ensure-different-random-number-generation-in-c-when-program-is-execut
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <stdlib.h>
21 
22 
26 namespace artdaq
27 {
31  class Globals
32  {
33  public:
34  static int my_rank_;
35  static MetricManager* metricMan_;
36  static std::string app_name_;
37 
38  // MessageFacility's module and iteration are thread-local, but we want to use them to represent global state in artdaq.
39  static std::string mftrace_module_;
40  static std::string mftrace_iteration_;
41 
46  static uint32_t seedAndRandom_()
47  {
48  static bool initialized_ = false;
49  if (!initialized_) {
50  int fp = open("/dev/random", O_RDONLY);
51  if (fp == -1) abort();
52  unsigned seed;
53  unsigned pos = 0;
54  while (pos < sizeof(seed))
55  {
56  int amt = read(fp, (char *)&seed + pos, sizeof(seed) - pos);
57  if (amt <= 0) abort();
58  pos += amt;
59  }
60  srand(seed);
61  close(fp);
62  initialized_ = true;
63  }
64  return rand();
65  }
66  };
67 }
68 
69 #include "artdaq-core/Utilities/configureMessageFacility.hh"
70 #include "tracemf.h"
71 #include "artdaq-core/Utilities/TimeUtils.hh"
72 #endif // ARTDAQ_DAQDATA_GLOBALS_HH
static uint32_t seedAndRandom_()
Seed the C random number generator with the current time (if that has not been done already) and gene...
Definition: Globals.hh:46
static int my_rank_
The rank of the current application.
Definition: Globals.hh:34
static std::string app_name_
The name of the current application, to be used in logging and metrics.
Definition: Globals.hh:36
static MetricManager * metricMan_
A handle to MetricManager.
Definition: Globals.hh:35
The artdaq::Globals class contains several variables which are useful across the entire artdaq system...
Definition: Globals.hh:31