$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
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 //https://stackoverflow.com/questions/21594140/c-how-to-ensure-different-random-number-generation-in-c-when-program-is-execut 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 // 23-May-2018, KAB: added the option to return the partition number data member 00082 // and gave it precedence over the env var since it is typcally based on information 00083 // that the user specified on the command line. 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"); // 0-127 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 00111 static std::string GetMFIteration_() 00112 { 00113 std::unique_lock<std::mutex> lk(mftrace_mutex_); 00114 return mftrace_iteration_; 00115 } 00116 00121 static std::string GetMFModuleName_() 00122 { 00123 std::unique_lock<std::mutex> lk(mftrace_mutex_); 00124 return mftrace_module_; 00125 } 00126 00131 static void SetMFIteration_(std::string name) 00132 { 00133 std::unique_lock<std::mutex> lk(mftrace_mutex_); 00134 mftrace_iteration_ = name; 00135 } 00136 00141 static void SetMFModuleName_(std::string name) 00142 { 00143 std::unique_lock<std::mutex> lk(mftrace_mutex_); 00144 mftrace_module_ = name; 00145 } 00146 00150 static void CleanUpGlobals() 00151 { 00152 metricMan_.reset(nullptr); 00153 portMan_.reset(nullptr); 00154 } 00155 }; 00156 } 00157 00158 #include "artdaq-core/Utilities/configureMessageFacility.hh" 00159 #include "tracemf.h" 00160 #include "artdaq-core/Utilities/TimeUtils.hh" 00161 #include "fhiclcpp/ParameterSet.h" 00162 #include "fhiclcpp/types/Atom.h" 00163 #include "fhiclcpp/types/Table.h" 00164 #include "fhiclcpp/types/Sequence.h" 00165 #include "fhiclcpp/types/TableFragment.h" 00166 #include "fhiclcpp/types/ConfigurationTable.h" 00167 #endif // ARTDAQ_DAQDATA_GLOBALS_HH