tdaq-develop-2025-02-12
FEProducerVInterface.cc
1 #include "otsdaq/FECore/FEProducerVInterface.h"
2 #include "otsdaq/DataManager/DataManager.h"
3 #include "otsdaq/DataManager/DataManagerSingleton.h"
4 
5 using namespace ots;
6 
7 #undef __MF_SUBJECT__
8 #define __MF_SUBJECT__ "FEProducer"
9 #define mfSubject_ (std::string("FEProducer-") + DataProcessor::processorUID_)
10 
11 //==============================================================================
12 FEProducerVInterface::FEProducerVInterface(
13  const std::string& interfaceUID,
14  const ConfigurationTree& theXDAQContextConfigTree,
15  const std::string& interfaceConfigurationPath)
16  : FEVInterface(interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
18  theXDAQContextConfigTree.getBackNode(interfaceConfigurationPath, 4)
19  .getValueAsString(),
20  theXDAQContextConfigTree
21  .getNode(interfaceConfigurationPath + "/" + "LinkToDataBufferTable", 4)
22  .getValueAsString(),
23  interfaceUID /*processorID*/,
24  100 /*bufferSize*/)
25 {
26  // NOTE!! be careful to not decorate with __FE_COUT__ because in the constructor the
27  // base class versions of function (e.g. getInterfaceType) are called because the
28  // derived class has not been instantiate yet!
29  __GEN_COUT__ << "'" << interfaceUID << "' Constructed." << __E__;
30 
31  __GEN_COUTV__(interfaceConfigurationPath);
32  ConfigurationTree appNode =
33  theXDAQContextConfigTree.getBackNode(interfaceConfigurationPath, 2);
34 
35  __GEN_COUTV__(appNode.getValueAsString());
36 
37 } // end constructor()
38 
39 FEProducerVInterface::~FEProducerVInterface(void)
40 {
41  __FE_COUT__ << "Destructor." << __E__;
42  // Take out of DataManager vector!
43 
44  __GEN_COUT__ << "FEProducer '" << DataProcessor::processorUID_
45  << "' is unregistering from DataManager Supervisor Buffer '"
46  << DataProcessor::supervisorApplicationUID_ << ":"
47  << DataProcessor::bufferUID_ << ".'" << std::endl;
48 
49  DataManager* dataManager =
50  (DataManagerSingleton::getInstance(supervisorApplicationUID_));
51 
52  dataManager->unregisterFEProducer(bufferUID_, DataProcessor::processorUID_);
53 
54  {
55  __GEN_SS__;
56  dataManager->dumpStatus(&ss);
57  std::cout << ss.str() << __E__;
58  }
59 
60  __GEN_COUT__ << "FEProducer '" << DataProcessor::processorUID_ << "' unregistered."
61  << __E__;
62 
63  __FE_COUT__ << "Destructed." << __E__;
64 }
65 
66 //==============================================================================
89 void FEProducerVInterface::copyToNextBuffer(const std::string& dataToWrite)
90 {
91  __FE_COUT__ << "Write Data: "
92  << BinaryStringMacros::binaryNumberToHexString(dataToWrite) << __E__;
93 
94  DataProducerBase::write<std::string, std::map<std::string, std::string> >(
95  dataToWrite);
96  //
97  // FEProducerVInterface::getNextBuffer();
98  //
99  // __FE_COUT__ << "Have next buffer " << FEProducerVInterface::dataP_ << __E__;
100  // __FE_COUT__ << "Have next buffer size " << FEProducerVInterface::dataP_->size() <<
101  //__E__;
102  //
103  //
104  // FEProducerVInterface::dataP_->resize(dataToWrite.size());
105  //
106  // __FE_COUT__ << "Have next buffer size " << FEProducerVInterface::dataP_->size() <<
107  //__E__;
108  //
109  // //*FEProducerVInterface::dataP_ = dataToWrite; //copy
110  // memcpy((void *)&(*FEProducerVInterface::dataP_)[0] /*dest*/,
111  // (void *)&dataToWrite[0] /*src*/, 8 /*numOfBytes*/);
112  //
113  // __FE_COUT__ << "Data copied " << FEProducerVInterface::dataP_->size() << __E__;
114  //
115  // __FE_COUT__ << "Copied Data: " <<
116  // BinaryStringMacros::binaryNumberToHexString(*FEProducerVInterface::dataP_)
117  //<<
118  //__E__;
119  //
120  //
121  // FEProducerVInterface::writeCurrentBuffer();
122 
123 } // end copyToNextBuffer()
124 
125 //==============================================================================
137 {
138  if(DataProducerBase::attachToEmptySubBuffer(FEProducerVInterface::dataP_,
139  FEProducerVInterface::headerP_) < 0)
140  {
141  __GEN_SS__
142  << "There are no available buffers! Retrying...after waiting 10 milliseconds!"
143  << std::endl;
144  __GEN_SS_THROW__;
145  }
146 
147  return FEProducerVInterface::dataP_;
148 } // end getNextBuffer()
149 
150 //==============================================================================
155 {
156  __FE_COUT__ << "Writing data of size " << FEProducerVInterface::dataP_->size()
157  << __E__;
158 
159  DataProducerBase::setWrittenSubBuffer<std::string,
160  std::map<std::string, std::string> >();
161 
162  __FE_COUT__ << "Data written." << __E__;
163 
164 } // end writeCurrentBuffer()
const std::string & getValueAsString(bool returnLinkTableValue=false) const
void unregisterFEProducer(const std::string &bufferID, const std::string &feProducerID)
Definition: DataManager.cc:641
void dumpStatus(std::ostream *out=(std::ostream *)&(std::cout)) const
Definition: DataManager.cc:36
virtual void writeCurrentBuffer(void)
virtual void copyToNextBuffer(const std::string &dataToWrite)
virtual std::string * getNextBuffer(void)