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