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