artdaq  v3_00_01
Globals.hh
1 #ifndef ARTDAQ_DAQDATA_GLOBALS_HH
2 #define ARTDAQ_DAQDATA_GLOBALS_HH
3 
4 #include "artdaq-core/Utilities/configureMessageFacility.hh"
5 #include "tracemf.h"
6 #include <sstream>
7 #include "artdaq-utilities/Plugins/MetricManager.hh"
8 #include "artdaq-core/Utilities/TimeUtils.hh"
9 
10 #define my_rank artdaq::Globals::my_rank_
11 #define app_name artdaq::Globals::app_name_
12 #define metricMan artdaq::Globals::metricMan_
13 #define seedAndRandom() artdaq::Globals::seedAndRandom_()
14 
15 //https://stackoverflow.com/questions/21594140/c-how-to-ensure-different-random-number-generation-in-c-when-program-is-execut
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 
20 
24 namespace artdaq
25 {
29  class Globals
30  {
31  public:
32  static int my_rank_;
33  static MetricManager* metricMan_;
34  static std::string app_name_;
35 
40  static uint32_t seedAndRandom_()
41  {
42  static bool initialized_ = false;
43  if (!initialized_) {
44  int fp = open("/dev/random", O_RDONLY);
45  if (fp == -1) abort();
46  unsigned seed;
47  unsigned pos = 0;
48  while (pos < sizeof(seed))
49  {
50  int amt = read(fp, (char *)&seed + pos, sizeof(seed) - pos);
51  if (amt <= 0) abort();
52  pos += amt;
53  }
54  srand(seed);
55  close(fp);
56  initialized_ = true;
57  }
58  return rand();
59  }
60  };
61 }
62 
63 #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:40
static int my_rank_
The rank of the current application.
Definition: Globals.hh:32
static std::string app_name_
The name of the current application, to be used in logging and metrics.
Definition: Globals.hh:34
static MetricManager * metricMan_
A handle to MetricManager.
Definition: Globals.hh:33
The artdaq::Globals class contains several variables which are useful across the entire artdaq system...
Definition: Globals.hh:29