artdaq  v3_00_03
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 //https://stackoverflow.com/questions/21594140/c-how-to-ensure-different-random-number-generation-in-c-when-program-is-execut
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <stdlib.h>
16 
17 
21 namespace artdaq
22 {
26  class Globals
27  {
28  public:
29  static int my_rank_;
30  static MetricManager* metricMan_;
31  static std::string app_name_;
32 
37  static uint32_t seedAndRandom_()
38  {
39  static bool initialized_ = false;
40  if (!initialized_) {
41  int fp = open("/dev/random", O_RDONLY);
42  if (fp == -1) abort();
43  unsigned seed;
44  unsigned pos = 0;
45  while (pos < sizeof(seed))
46  {
47  int amt = read(fp, (char *)&seed + pos, sizeof(seed) - pos);
48  if (amt <= 0) abort();
49  pos += amt;
50  }
51  srand(seed);
52  close(fp);
53  initialized_ = true;
54  }
55  return rand();
56  }
57  };
58 }
59 
60 #include "artdaq-core/Utilities/configureMessageFacility.hh"
61 #include "tracemf.h"
62 #include "artdaq-core/Utilities/TimeUtils.hh"
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:37
static int my_rank_
The rank of the current application.
Definition: Globals.hh:29
static std::string app_name_
The name of the current application, to be used in logging and metrics.
Definition: Globals.hh:31
static MetricManager * metricMan_
A handle to MetricManager.
Definition: Globals.hh:30
The artdaq::Globals class contains several variables which are useful across the entire artdaq system...
Definition: Globals.hh:26