00001 #ifndef ARTDAQ_DAQDATA_GLOBALS_HH
00002 #define ARTDAQ_DAQDATA_GLOBALS_HH
00003
00004 #include <sstream>
00005 #include "artdaq-utilities/Plugins/MetricManager.hh"
00006
00007 #define my_rank artdaq::Globals::my_rank_
00008 #define app_name artdaq::Globals::app_name_
00009 #define metricMan artdaq::Globals::metricMan_
00010 #define seedAndRandom() artdaq::Globals::seedAndRandom_()
00011
00012 #define mftrace_iteration artdaq::Globals::mftrace_iteration_
00013 #define mftrace_module artdaq::Globals::mftrace_module_
00014 #define SetMFModuleName(name) mftrace_module = name
00015 #define SetMFIteration(name) mftrace_iteration = name
00016
00017
00018 #include <fcntl.h>
00019 #include <unistd.h>
00020 #include <stdlib.h>
00021
00022
00026 namespace artdaq
00027 {
00031 class Globals
00032 {
00033 public:
00034 static int my_rank_;
00035 static MetricManager* metricMan_;
00036 static std::string app_name_;
00037 static int partition_number_;
00038
00039 static std::string mftrace_module_;
00040 static std::string mftrace_iteration_;
00041
00046 static uint32_t seedAndRandom_()
00047 {
00048 static bool initialized_ = false;
00049 if (!initialized_)
00050 {
00051 int fp = open("/dev/random", O_RDONLY);
00052 if (fp == -1) abort();
00053 unsigned seed;
00054 unsigned pos = 0;
00055 while (pos < sizeof(seed))
00056 {
00057 int amt = read(fp, (char *)&seed + pos, sizeof(seed) - pos);
00058 if (amt <= 0) abort();
00059 pos += amt;
00060 }
00061 srand(seed);
00062 close(fp);
00063 initialized_ = true;
00064 }
00065 return rand();
00066 }
00067
00072 static int GetPartitionNumber()
00073 {
00074 uint32_t part_u = 0;
00075
00076
00077
00078
00079 if (partition_number_ >= 0)
00080 {
00081 part_u = static_cast<uint32_t>(partition_number_);
00082 }
00083 else
00084 {
00085 auto part = getenv("ARTDAQ_PARTITION_NUMBER");
00086 if (part != nullptr)
00087 {
00088 try
00089 {
00090 auto part_s = std::string(part);
00091 part_u = static_cast<uint32_t>(std::stoll(part_s, 0, 0));
00092 }
00093 catch (std::invalid_argument) {}
00094 catch (std::out_of_range) {}
00095 }
00096 }
00097
00098 return (part_u & 0x7F);
00099 }
00100 };
00101 }
00102
00103 #include "artdaq-core/Utilities/configureMessageFacility.hh"
00104 #include "tracemf.h"
00105 #include "artdaq-core/Utilities/TimeUtils.hh"
00106 #include "fhiclcpp/ParameterSet.h"
00107 #include "fhiclcpp/types/Atom.h"
00108 #include "fhiclcpp/types/Table.h"
00109 #include "fhiclcpp/types/Sequence.h"
00110 #include "fhiclcpp/types/TableFragment.h"
00111 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00112 # include "fhiclcpp/types/ConfigurationTable.h"
00113 #endif
00114 #endif // ARTDAQ_DAQDATA_GLOBALS_HH