tdaq-develop-2025-02-12
VisualDataManagerV2.cc
1 #include "otsdaq-utilities/VisualizationV2/VisualDataManagerV2.h"
2 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
3 #include "otsdaq/DataManager/DQMHistosConsumerBase.h"
4 #include "otsdaq/DataManager/DataManager.h"
5 #include "otsdaq/DataManager/DataProcessor.h"
6 
7 #include "otsdaq/DataProcessorPlugins/RawDataVisualizerConsumer.h"
8 
9 #include <cassert>
10 #include <chrono> // std::chrono::seconds
11 #include <iostream>
12 #include <sstream>
13 #include <thread> // std::this_thread::sleep_for
14 
15 using namespace ots;
16 
17 //==============================================================================
19  const ConfigurationTree& theXDAQContextConfigTree,
20  const std::string& supervisorConfigurationPath)
21  : DataManager(theXDAQContextConfigTree, supervisorConfigurationPath)
22  , theLiveDQMHistos_(nullptr)
23  , theRawDataConsumer_(nullptr)
27 {
28 }
29 
30 //==============================================================================
31 VisualDataManagerV2::~VisualDataManagerV2(void) {}
32 
33 //==============================================================================
34 void VisualDataManagerV2::configure(void) { DataManager::configure(); }
35 
36 //==============================================================================
37 void VisualDataManagerV2::halt(void)
38 {
39  theLiveDQMHistos_ = nullptr;
40  DataManager::halt();
41 }
42 
43 //==============================================================================
44 void VisualDataManagerV2::pause(void)
45 {
46  __CFG_COUT__ << "Pausing..." << std::endl;
47  DataManager::pause();
48 }
49 
50 //==============================================================================
51 void VisualDataManagerV2::resume(void) { DataManager::resume(); }
52 
53 //==============================================================================
54 void VisualDataManagerV2::start(std::string runNumber)
55 {
56  __CFG_COUT__ << "Start!" << __E__;
57 
58  theLiveDQMHistos_ = nullptr;
59  theRawDataConsumer_ = nullptr;
60 
61  DataManager::start(runNumber);
62 
63  auto buffers = theXDAQContextConfigTree_
64  .getNode(theConfigurationPath_ + "/LinkToDataBufferTable")
65  .getChildren();
66 
67  __CFG_COUT__ << "Buffer count " << buffers.size() << __E__;
68 
69  for(const auto& buffer : buffers)
70  {
71  __CFG_COUT__ << "Data Buffer Name: " << buffer.first << std::endl;
72  if(buffer.second.getNode(TableViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
73  {
74  std::vector<std::string> producers;
75  std::vector<std::string> consumers;
76  auto bufferConfigurationMap =
77  buffer.second.getNode("LinkToDataProcessorTable").getChildren();
78  for(const auto& bufferConfiguration : bufferConfigurationMap)
79  {
80  __CFG_COUT__ << "Processor id: " << bufferConfiguration.first
81  << std::endl;
82  if(bufferConfiguration.second
83  .getNode(TableViewColumnInfo::COL_NAME_STATUS)
84  .getValue<bool>() &&
85  (bufferConfiguration.second.getNode("ProcessorType")
86  .getValue<std::string>() == "Consumer"))
87  {
88  __CFG_COUT__
89  << "Consumer Plugin Type = "
90  << bufferConfiguration.second.getNode("ProcessorPluginName")
91  << __E__;
92 
93  auto bufferIt = buffers_.at(buffer.first);
94  for(const auto& consumer : bufferIt.consumers_)
95  {
96  __CFG_COUT__
97  << "CONSUMER PROCESSOR: " << consumer->getProcessorID()
98  << std::endl;
99  if(consumer->getProcessorID() ==
100  bufferConfiguration.second.getNode("ProcessorUID")
101  .getValue<std::string>())
102  {
103  __CFG_COUT__ << "CONSUMER: " << consumer->getProcessorID()
104  << std::endl;
105 
106  try
107  {
108  __CFG_COUT__ << "Trying for DQMHistosConsumerBase."
109  << __E__;
110  theLiveDQMHistos_ =
111  dynamic_cast<DQMHistosConsumerBase*>(consumer);
112 
113  __CFG_COUT__ << "Did we succeed? " << theLiveDQMHistos_
114  << __E__;
115  }
116  catch(...)
117  {
118  } // ignore failures
119 
120  if(theLiveDQMHistos_ == nullptr)
121  {
122  __CFG_COUT__ << "Trying for raw data consumer." << __E__;
123 
124  try
125  {
126  theRawDataConsumer_ =
127  dynamic_cast<RawDataVisualizerConsumer*>(
128  consumer);
129  }
130  catch(...)
131  {
132  }
133 
134  __CFG_COUT__ << "Did we succeed? " << theRawDataConsumer_
135  << __E__;
136  }
137 
138  if(!theLiveDQMHistos_ && !theRawDataConsumer_)
139  {
140  __CFG_SS__ << "No valid visualizer consumer!" << __E__;
141  __CFG_SS_THROW__;
142  }
143  }
144  }
145  }
146  }
147  }
148  }
149 }
150 
151 //==============================================================================
152 void VisualDataManagerV2::stop(void)
153 {
154  theLiveDQMHistos_ = nullptr;
155  DataManager::stop();
156 }
157 
158 //==============================================================================
159 void VisualDataManagerV2::load(std::string fileName, std::string type)
160 {
161  if(type == "Histograms")
162  theFileDQMHistos_.load(fileName);
163  // else if(type == "Monicelli")
164  // theMonicelliEventAnalyzer_.load(fileName);
165  // else if(type == "Geometry")
166  // theMonicelliGeometryConverter_.loadGeometry(fileName);
167 }
168 
169 //==============================================================================
170 DQMHistosBase* VisualDataManagerV2::getLiveDQMHistos(void) { return theLiveDQMHistos_; }
171 
172 //==============================================================================
173 DQMHistosBase& VisualDataManagerV2::getFileDQMHistos(void) { return theFileDQMHistos_; }
174 //==============================================================================
175 const std::string& VisualDataManagerV2::getRawData(void)
176 {
177  //__CFG_COUT__ << __E__;
178 
179  return theRawDataConsumer_->getLastRawDataBuffer();
180 }
181 
184 //{
185 // return theMonicelliEventAnalyzer_.getEvents();
186 //}
187 //
190 //{
191 // return theMonicelliGeometryConverter_.getGeometry();
192 //}
VisualDataManagerV2(const ConfigurationTree &theXDAQContextConfigTree, const std::string &supervisorConfigurationPath)
DQMHistosBase * getLiveDQMHistos(void)
Getters.