otsdaq_demo  v2_05_02_indev
DemoDQMHistosConsumer_processor.cc
1 #include "otsdaq-demo/DataProcessorPlugins/DemoDQMHistosConsumer.h"
2 #include "otsdaq-demo/DemoRootUtilities/DemoDQMHistos.h"
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/Macros/ProcessorPluginMacros.h"
5 #include "otsdaq/MessageFacility/MessageFacility.h"
6 
7 using namespace ots;
8 
9 //==============================================================================
10 DemoDQMHistosConsumer::DemoDQMHistosConsumer(
11  std::string supervisorApplicationUID,
12  std::string bufferUID,
13  std::string processorUID,
14  const ConfigurationTree& theXDAQContextConfigTree,
15  const std::string& configurationPath)
16  : WorkLoop(processorUID)
17  , DQMHistosConsumerBase(
18  supervisorApplicationUID, bufferUID, processorUID, LowConsumerPriority)
19  , Configurable(theXDAQContextConfigTree, configurationPath)
20  , saveDQMFile_(theXDAQContextConfigTree.getNode(configurationPath)
21  .getNode("SaveDQMFile")
22  .getValue<bool>())
23  , DQMFilePath_(theXDAQContextConfigTree.getNode(configurationPath)
24  .getNode("DQMFilePath")
25  .getValue<std::string>())
26  , DQMFilePrefix_(theXDAQContextConfigTree.getNode(configurationPath)
27  .getNode("DQMFileNamePrefix")
28  .getValue<std::string>())
29  , dqmHistos_(new DemoDQMHistos())
30 
31 {
32 }
33 
34 //==============================================================================
35 DemoDQMHistosConsumer::~DemoDQMHistosConsumer(void) { closeFile(); }
36 
37 //==============================================================================
38 void DemoDQMHistosConsumer::startProcessingData(std::string runNumber)
39 {
40  // IMPORTANT
41  // The file must be always opened because even the LIVE DQM uses the pointer to it
42  DQMHistosBase::openFile(DQMFilePath_ + "/" + DQMFilePrefix_ + "_Run" + runNumber +
43  ".root");
44 
45  dqmHistos_->book(DQMHistosBase::theFile_);
46  DataConsumer::startProcessingData(runNumber);
47 }
48 
49 //==============================================================================
50 void DemoDQMHistosConsumer::stopProcessingData(void)
51 {
52  DataConsumer::stopProcessingData();
53  if(saveDQMFile_)
54  {
55  save();
56  }
57  closeFile();
58 }
59 
60 //==============================================================================
61 bool DemoDQMHistosConsumer::workLoopThread(toolbox::task::WorkLoop* /*workLoop*/)
62 {
63  //__COUT__ << DataProcessor::processorUID_ << " running, because workloop: " <<
64  // WorkLoop::continueWorkLoop_ << std::endl;
65  fastRead();
66  return WorkLoop::continueWorkLoop_;
67 }
68 
69 //==============================================================================
70 void DemoDQMHistosConsumer::fastRead(void)
71 {
72  //__COUT__ << processorUID_ << " running!" << std::endl;
73  // This is making a copy!!!
74  if(DataConsumer::read(dataP_, headerP_) < 0)
75  {
76  usleep(100);
77  return;
78  }
79  //__COUT__ << DataProcessor::processorUID_ << " UID: " << supervisorApplicationUID_ <<
80  // std::endl;
81 
82  // HW emulator
83  // Burst Type | Sequence | 8B data
84  //__COUT__ << "Size fill: " << dataP_->length() << std::endl;
85  dqmHistos_->fill(*dataP_, *headerP_);
86 
87  DataConsumer::setReadSubBuffer<std::string, std::map<std::string, std::string>>();
88 }
89 
90 //==============================================================================
91 void DemoDQMHistosConsumer::slowRead(void)
92 {
93  //__COUT__ << DataProcessor::processorUID_ << " running!" << std::endl;
94  // This is making a copy!!!
95  if(DataConsumer::read(data_, header_) < 0)
96  {
97  usleep(1000);
98  return;
99  }
100  //__COUT__ << DataProcessor::processorUID_ << " UID: " << supervisorApplicationUID_ <<
101  // std::endl; DQMHistos::fill(data_,header_);
102 }
103 
104 DEFINE_OTS_PROCESSOR(DemoDQMHistosConsumer)