otsdaq-mu2e-stm  5.02.01
dqm.cc
1 // Include DQM code
2 #include "Mu2e-STMDAQ/dqm/dqm.hh"
3 
4 // Minimum required memory for struct
5 const size_t MIN_SHM_SIZE = 4096;
6 
7 // Constructor: Initializes shared memory for storing DQM data
8 DQM::DQM(const Config& cfg_,
9  const std::shared_ptr<AsyncLogger>& logger_,
10  const std::shared_ptr<SignalHandler>& signal_,
11  const int CHAN_)
12  : cfg(cfg_), logger(logger_), signal(signal_), CHAN(CHAN_)
13 {
14  // try {
15 
16  // // Read shared memory name and size from the Config class
17  // shm_name = cfg.getValue<std::string>("stm.DQM.name");
18  // shm_size = cfg.getValue<int>("stm.DQM.size");
19 
20  // // Check if the size is too small
21  // if (shm_size < MIN_SHM_SIZE) {
22  // logger->log("Error: DQM dhared memory size too small! Increase size in config.xml",0);
23  // }
24 
25  // logger->log("Loaded Config: Shared Memory Name = " + shm_name + ", Size = " + std::to_string(shm_size) + " bytes",1);
26 
27  // // Remove shared memory if it exists
28  // try {
29  // if (shared_memory_object::remove(shm_name.c_str())) {
30  // std::cout << "Removed existing shared memory segment: " << shm_name << std::endl;
31  // }
32  // } catch (const std::exception& e) {
33  // std::cerr << "Error removing old shared memory: " << e.what() << std::endl;
34  // }
35 
36  // // Open or create shared memory
37  // shm = shared_memory_object(open_or_create, shm_name.c_str(), read_write);
38 
39  // // Resize it to the correct size
40  // shm.truncate(shm_size);
41 
42  // // Map the shared memory region
43  // region = mapped_region(shm, read_write);
44 
45  // // Zero initialize the shared memory
46  // std::memset(region.get_address(), 0, shm_size);
47 
48  // // Initialize the shared memory data structure
49  // void* addr = region.get_address();
50  // DQMData* data = static_cast<DQMData*>(addr);
51  // std::memset(data, 0, sizeof(shm_size));
52  // data->threshold = 1000.0f; // Default threshold for alerts
53  // data->paused = 0; // Initialize pause flag (0 = running, 1 = paused)
54 
55  // logger->log("Shared memory initialized successfully.",1);
56 
57  // }
58  // catch (const std::exception& e) {
59  // logger->log("Error initializing shared memory.",0);
60  // throw;
61  // }
62 
63  // Initialise function map for Operation Manager
64  functionMap["dqm_thread"] = [this](std::shared_ptr<DataStruct>& buffer) {
65  dqm_thread(buffer);
66  };
67 }
68 
69 // Thread to get DQM information from data buffer
70 void DQM::dqm_thread(std::shared_ptr<DataStruct>& buffer) {}
71 
72 // // Function to update shared memory with latest buffer and processing statistics
73 // void DQM::updateBufferData(uint64_t bytesProcessed,
74 // const std::vector<uint64_t>& threadBytes,
75 // const std::vector<std::vector<int16_t>>& bufferData) {
76 
77 // try {
78 
79 // // Get pointer to shared memory data structure
80 // void* addr = region.get_address();
81 // DQMData* data = static_cast<DQMData*>(addr);
82 
83 // // Update total bytes processed across all worker threads
84 // data->totalBytesProcessed = bytesProcessed;
85 
86 // // Update number of active worker threads
87 // data->activeThreads = threadBytes.size();
88 
89 // // Store per-thread byte processing data
90 // for (size_t i = 0; i < threadBytes.size(); ++i) {
91 // data->threadBytesProcessed[i] = threadBytes[i];
92 // }
93 
94 // // Store buffer data and calculate averages
95 // data->bufferCount = bufferData.size();
96 
97 // // Loop over buffer data
98 // for (size_t i = 0; i < bufferData.size(); ++i) {
99 // // Determine how many data points to store (up to BUFFER_MAX_ENTRIES)
100 // size_t sampleCount = std::min(bufferData[i].size(), (size_t)BUFFER_MAX_ENTRIES);
101 // data->bufferSizes[i] = sampleCount;
102 
103 // // Copy buffer data into shared memory
104 // std::memcpy(data->bufferData[i], bufferData[i].data(), sampleCount * sizeof(int16_t));
105 
106 // // Compute the average value for the buffer
107 // int64_t sum = 0.0f;
108 // for (size_t j = 0; j < sampleCount; ++j) {
109 // sum += bufferData[i][j];
110 // }
111 // data->bufferAverages[i] = (sampleCount > 0) ? static_cast<float>(sum) / sampleCount : 0.0f;
112 // }
113 
114 // data->baseline_mean_prev = prev_mean;
115 // data->baseline_rms_prev = prev_rms;
116 // data->baseline_mean_current = curr_mean;
117 // data->baseline_rms_current = curr_rms;
118 
119 // data->baseline_inst_count = times_ns.size();
120 // for (int i = 0; i < times_ns.size(); ++i) {
121 // data->baseline_inst_time[i] = times_ns[i];
122 // data->baseline_inst[i] = inst_means[i];
123 // data->baseline_inst_rms[i] = inst_rms[i];
124 // }
125 
126 // }
127 
128 // }
129 // catch (const std::exception& e) {
130 // std::cerr << "Error updating shared memory: " << e.what() << std::endl;
131 // }
132 //}
Definition: config.hh:19