Skip to content

Commit

Permalink
drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Aug 16, 2024
1 parent c00425d commit a0e6be7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/minos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
to be used for communication with the Feminos.
*******************************************************************************/

#include "bufpool.h"
#include "cmdfetcher.h"
#include "evbuilder.h"
Expand Down Expand Up @@ -262,15 +263,15 @@ int main(int argc, char** argv) {

// prometheus manager
auto& prometheus_manager = mclient_prometheus::PrometheusManager::Instance();
auto& graph_manager = mclient_graph::GraphManager::Instance();
auto& storage_manager = mclient_storage::StorageManager::Instance();
auto& graph_manager = mclient_graph::GraphManager::Instance();

// delay 1 second
/*
int eventId = 0;
while (true) {
storage_manager.Clear();
auto& event = storage_manager.event;
event.event_id = eventId++;
event.id = eventId++;
// random between 1 and 5
int nSignals = rand() % 5 + 1;
Expand All @@ -283,12 +284,13 @@ int main(int argc, char** argv) {
event.add_signal(id, data);
}
cout << "Event ID: " << storage_manager.event.event_id << endl;
cout << "Event ID: " << storage_manager.event.id << endl;
graph_manager.DrawEvent(event);
std::this_thread::sleep_for(std::chrono::seconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds{100});
}
*/

int err;

Expand Down
9 changes: 9 additions & 0 deletions src/minos/mclient/evbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and timestamps depending on event builder mode
#include <sys/sem.h>
#include <sys/shm.h>

#include "graph.h"
#include "prometheus.h"
#include "storage.h"

Expand Down Expand Up @@ -435,11 +436,14 @@ int EventBuilder_ProcessBuffer(EventBuilder* eb, void* bu) {

auto& prometheusManager = mclient_prometheus::PrometheusManager::Instance();
auto& storageManager = mclient_storage::StorageManager::Instance();
auto& graphManager = mclient_graph::GraphManager::Instance();

prometheusManager.SetEventId(ShMem_DaqInfo->eventId);
prometheusManager.SetNumberOfSignalsInEvent(ShMem_DaqInfo->nSignals);

storageManager.event = mclient_storage::Event{};

storageManager.event.id = ShMem_DaqInfo->eventId;
storageManager.event.timestamp = ShMem_DaqInfo->timeStamp; // TODO: check if this is the correct timestamp

// AFAIK the first number is the signal id and the rest is the signal data
Expand All @@ -456,6 +460,11 @@ int EventBuilder_ProcessBuffer(EventBuilder* eb, void* bu) {
// checkpoint the file
storageManager.file->Write("", TObject::kOverwrite);

if (graphManager.GetSecondsSinceLastDraw() > 1) {
// Avoid drawing too often
graphManager.DrawEvent(storageManager.event);
}

// printf( "TIME START : %d\n", timeStart );
// printf( "Event time : %lf\n",
// ShMem_DaqInfo->timeStamp );
Expand Down
16 changes: 8 additions & 8 deletions src/minos/root/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <TAxis.h>
#include <TLegend.h>
#include <TSystem.h>
#include <TText.h>
#include <TThread.h>
#include <TSystem.h>

#include <iostream>

Expand All @@ -21,9 +21,6 @@ GraphManager::GraphManager() {
canvas = std::make_unique<TCanvas>("canvas", "mclient", 1600, 900);

multiGraph = std::make_unique<TMultiGraph>("multiGraph", "mclient");

multiGraph->GetXaxis()->SetTitle("Time bin");
multiGraph->GetYaxis()->SetTitle("ADC value");
}

void GraphManager::DrawEvent(const mclient_storage::Event& event) {
Expand All @@ -35,7 +32,6 @@ void GraphManager::DrawEvent(const mclient_storage::Event& event) {
graph.SetTitle(Form("Channel %d", channel));

for (size_t j = 0; j < data.size(); j++) {
cout << "j: " << j << " data[j]: " << data[j] << endl;
graph.SetPoint(j, j, data[j]);
}

Expand All @@ -44,22 +40,26 @@ void GraphManager::DrawEvent(const mclient_storage::Event& event) {
graph.SetLineColor(i + 1);
}

// update draw
multiGraph->Clear();
for (auto& graph: graphs) {
multiGraph->Add(&graph);
}

multiGraph->SetTitle(Form("Event %d", event.id));

multiGraph->GetXaxis()->SetTitle("Time bin");
multiGraph->GetYaxis()->SetTitle("ADC value");

multiGraph->GetXaxis()->SetRangeUser(0, mclient_storage::Event::SIGNAL_SIZE);
multiGraph->GetXaxis()->SetNdivisions(mclient_storage::Event::SIGNAL_SIZE / 64, 5, 0);

canvas->cd();

multiGraph->Draw("AL");

canvas->Update();
canvas->Pad()->Draw();

gSystem->ProcessEvents();

app->Run();
lastDrawTime = std::chrono::system_clock::now();
}
7 changes: 7 additions & 0 deletions src/minos/root/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ class GraphManager {

void DrawEvent(const mclient_storage::Event& event);

double GetSecondsSinceLastDraw() {
auto duration = std::chrono::system_clock::now() - lastDrawTime;
return std::chrono::duration<double>(duration).count();
}

private:
std::unique_ptr<TCanvas> canvas;
std::vector<TGraph> graphs;
std::unique_ptr<TMultiGraph> multiGraph;
std::unique_ptr<TApplication> app;

std::chrono::time_point<std::chrono::system_clock> lastDrawTime = std::chrono::system_clock::now() - std::chrono::hours(1);
};

} // namespace mclient_graph
Expand Down
4 changes: 2 additions & 2 deletions src/minos/root/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Event {
public:
constexpr static size_t SIGNAL_SIZE = 512;
unsigned long long timestamp = 0;
unsigned int event_id = 0;
unsigned int id = 0;
std::vector<unsigned short> signal_ids;
std::vector<unsigned short> signal_data; // all data points from all signals concatenated (same order as signal_ids)

Expand Down Expand Up @@ -54,7 +54,7 @@ class StorageManager {
file = std::make_unique<TFile>("events.root", "RECREATE");
tree = std::make_unique<TTree>("EventTree", "Tree of DAQ signal events");
tree->Branch("timestamp", &event.timestamp, "timestamp/L");
tree->Branch("event_id", &event.event_id, "event_id/i");
tree->Branch("event_id", &event.id, "event_id/i");
tree->Branch("signals.id", &event.signal_ids);
tree->Branch("signals.data", &event.signal_data);
}
Expand Down

0 comments on commit a0e6be7

Please sign in to comment.