00001 #ifndef ARTDAQ_DAQDATA_GLOBALS_HH
00002 #define ARTDAQ_DAQDATA_GLOBALS_HH
00003
00004 #include <sstream>
00005 #include "artdaq-utilities/Plugins/MetricManager.hh"
00006 #include "artdaq/DAQdata/PortManager.hh"
00007
00008 #define my_rank artdaq::Globals::my_rank_
00009 #define app_name artdaq::Globals::app_name_
00010 #define metricMan artdaq::Globals::metricMan_
00011 #define portMan artdaq::Globals::portMan_
00012 #define seedAndRandom() artdaq::Globals::seedAndRandom_()
00013 #define GetPartitionNumber() artdaq::Globals::getPartitionNumber_()
00014
00015 #define GetMFIteration() artdaq::Globals::GetMFIteration_()
00016 #define GetMFModuleName() artdaq::Globals::GetMFModuleName_()
00017 #define SetMFModuleName(name) artdaq::Globals::SetMFModuleName_(name)
00018 #define SetMFIteration(name) artdaq::Globals::SetMFIteration_(name)
00019
00020
00021 #include <fcntl.h>
00022 #include <unistd.h>
00023 #include <stdlib.h>
00024
00025
00029 namespace artdaq
00030 {
00034 class Globals
00035 {
00036 public:
00037 static int my_rank_;
00038 static std::unique_ptr<MetricManager> metricMan_;
00039 static std::unique_ptr<PortManager> portMan_;
00040 static std::string app_name_;
00041 static int partition_number_;
00042
00043 static std::mutex mftrace_mutex_;
00044 static std::string mftrace_module_;
00045 static std::string mftrace_iteration_;
00046
00051 static uint32_t seedAndRandom_()
00052 {
00053 static bool initialized_ = false;
00054 if (!initialized_)
00055 {
00056 int fp = open("/dev/random", O_RDONLY);
00057 if (fp == -1) abort();
00058 unsigned seed;
00059 unsigned pos = 0;
00060 while (pos < sizeof(seed))
00061 {
00062 int amt = read(fp, (char *)&seed + pos, sizeof(seed) - pos);
00063 if (amt <= 0) abort();
00064 pos += amt;
00065 }
00066 srand(seed);
00067 close(fp);
00068 initialized_ = true;
00069 }
00070 return rand();
00071 }
00072
00077 static int getPartitionNumber_()
00078 {
00079 uint32_t part_u = 0;
00080
00081
00082
00083
00084 if (partition_number_ >= 0)
00085 {
00086 part_u = static_cast<uint32_t>(partition_number_);
00087 }
00088 else
00089 {
00090 auto part = getenv("ARTDAQ_PARTITION_NUMBER");
00091 if (part != nullptr)
00092 {
00093 try
00094 {
00095 auto part_s = std::string(part);
00096 part_u = static_cast<uint32_t>(std::stoll(part_s, 0, 0));
00097 }
00098 catch (std::invalid_argument) {}
00099 catch (std::out_of_range) {}
00100 }
00101 partition_number_ = part_u & 0x7F;
00102 }
00103
00104 return (part_u & 0x7F);
00105 }
00106
00107 static std::string GetMFIteration_()
00108 {
00109 std::unique_lock<std::mutex> lk(mftrace_mutex_);
00110 return mftrace_iteration_;
00111 }
00112
00113 static std::string GetMFModuleName_()
00114 {
00115 std::unique_lock<std::mutex> lk(mftrace_mutex_);
00116 return mftrace_module_;
00117 }
00118
00119 static void SetMFIteration_(std::string name)
00120 {
00121 std::unique_lock<std::mutex> lk(mftrace_mutex_);
00122 mftrace_iteration_ = name;
00123 }
00124
00125 static void SetMFModuleName_(std::string name)
00126 {
00127 std::unique_lock<std::mutex> lk(mftrace_mutex_);
00128 mftrace_module_ = name;
00129 }
00130
00131 static void CleanUpGlobals()
00132 {
00133 metricMan_.reset(nullptr);
00134 portMan_.reset(nullptr);
00135 }
00136 };
00137 }
00138
00139 #include "artdaq-core/Utilities/configureMessageFacility.hh"
00140 #include "tracemf.h"
00141 #include "artdaq-core/Utilities/TimeUtils.hh"
00142 #include "fhiclcpp/ParameterSet.h"
00143 #include "fhiclcpp/types/Atom.h"
00144 #include "fhiclcpp/types/Table.h"
00145 #include "fhiclcpp/types/Sequence.h"
00146 #include "fhiclcpp/types/TableFragment.h"
00147 #include "fhiclcpp/types/ConfigurationTable.h"
00148 #endif // ARTDAQ_DAQDATA_GLOBALS_HH