otsdaq  v2_04_01
FEProducerVInterface.cc
1 #include "otsdaq-core/FECore/FEProducerVInterface.h"
2 #include "otsdaq-core/DataManager/DataManager.h"
3 #include "otsdaq-core/DataManager/DataManagerSingleton.h"
4 
5 using namespace ots;
6 
7 #undef __MF_SUBJECT__
8 #define __MF_SUBJECT__ (std::string("FEProducer-") + DataProcessor::processorUID_)
9 
10 //========================================================================================================================
11 FEProducerVInterface::FEProducerVInterface(
12  const std::string& interfaceUID,
13  const ConfigurationTree& theXDAQContextConfigTree,
14  const std::string& interfaceConfigurationPath)
15  : FEVInterface(interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
17  theXDAQContextConfigTree.getBackNode(interfaceConfigurationPath, 4)
18  .getValueAsString(),
19  theXDAQContextConfigTree
20  .getNode(interfaceConfigurationPath + "/" + "LinkToDataBufferTable", 4)
21  .getValueAsString(),
22  interfaceUID /*processorID*/,
23  100 /*bufferSize*/)
24 {
25  // NOTE!! be careful to not decorate with __FE_COUT__ because in the constructor the
26  // base class versions of function (e.g. getInterfaceType) are called because the
27  // derived class has not been instantiate yet!
28  __COUT__ << "'" << interfaceUID << "' Constructed." << __E__;
29 
30  __COUTV__(interfaceConfigurationPath);
31  ConfigurationTree appNode =
32  theXDAQContextConfigTree.getBackNode(interfaceConfigurationPath, 2);
33 
34  __COUTV__(appNode.getValueAsString());
35 
36 } // end constructor()
37 
38 FEProducerVInterface::~FEProducerVInterface(void)
39 {
40  __FE_COUT__ << "Destructor." << __E__;
41  // Take out of DataManager vector!
42 
43  __COUT__ << "FEProducer '" << DataProcessor::processorUID_
44  << "' is unregistering from DataManager Supervisor Buffer '"
45  << DataProcessor::supervisorApplicationUID_ << ":"
46  << DataProcessor::bufferUID_ << ".'" << std::endl;
47 
48  DataManager* dataManager =
49  (DataManagerSingleton::getInstance(supervisorApplicationUID_));
50 
51  dataManager->unregisterFEProducer(bufferUID_, DataProcessor::processorUID_);
52 
53  {
54  __SS__;
55  dataManager->dumpStatus(&ss);
56  std::cout << ss.str() << __E__;
57  }
58 
59  __COUT__ << "FEProducer '" << DataProcessor::processorUID_ << "' unregistered."
60  << __E__;
61 
62  __FE_COUT__ << "Destructed." << __E__;
63 }
64 
65 //========================================================================================================================
66 // copyToNextBuffer
67 // This function copies a data string into the next
68 // available buffer.
69 //
70 // Here is example code for filling a data string to write
71 //
72 // unsigned long long value = 0xA5; //this is 8-bytes
73 // std::string buffer;
74 // buffer.resize(8); //NOTE: this is inexpensive according to
75 // Lorenzo/documentation in C++11 (only increases size once and doesn't decrease size)
76 // memcpy((void
77 //*)&buffer /*dest*/,(void *)&value /*src*/, 8 /*numOfBytes*/);
78 //
79 // Note: This is somewhat inefficient because it makes a copy of the data.
80 // It would be more efficient to call
81 // FEProducerVInterface::getNextBuffer()
82 // ... fill the retrieved data string
83 // FEProducerVInterface::writeCurrentBuffer()
84 //
85 // If you are using the same dataToWrite string over and over.. it might not be that
86 // inefficient to use this.
87 //
88 void FEProducerVInterface::copyToNextBuffer(const std::string& dataToWrite)
89 {
90  __FE_COUT__ << "Write Data: "
91  << BinaryStringMacros::binaryTo8ByteHexString(dataToWrite) << __E__;
92 
93  DataProducerBase::write<std::string, std::map<std::string, std::string> >(
94  dataToWrite);
95  //
96  // FEProducerVInterface::getNextBuffer();
97  //
98  // __FE_COUT__ << "Have next buffer " << FEProducerVInterface::dataP_ << __E__;
99  // __FE_COUT__ << "Have next buffer size " << FEProducerVInterface::dataP_->size() <<
100  //__E__;
101  //
102  //
103  // FEProducerVInterface::dataP_->resize(dataToWrite.size());
104  //
105  // __FE_COUT__ << "Have next buffer size " << FEProducerVInterface::dataP_->size() <<
106  //__E__;
107  //
108  // //*FEProducerVInterface::dataP_ = dataToWrite; //copy
109  // memcpy((void *)&(*FEProducerVInterface::dataP_)[0] /*dest*/,
110  // (void *)&dataToWrite[0] /*src*/, 8 /*numOfBytes*/);
111  //
112  // __FE_COUT__ << "Data copied " << FEProducerVInterface::dataP_->size() << __E__;
113  //
114  // __FE_COUT__ << "Copied Data: " <<
115  // BinaryStringMacros::binaryTo8ByteHexString(*FEProducerVInterface::dataP_)
116  //<<
117  //__E__;
118  //
119  //
120  // FEProducerVInterface::writeCurrentBuffer();
121 
122 } // end copyToNextBuffer()
123 
124 //========================================================================================================================
125 // getNextBuffer
126 // This function retrieves the next buffer data string.
127 
128 // Note: This is more efficient than FEProducerVInterface::writeToBuffer
129 // because it does NOT makes a copy of the data.
130 //
131 // You need to now
132 // ... fill the retrieved data string
133 // FEProducerVInterface::writeCurrentBuffer()
134 //
135 std::string* FEProducerVInterface::getNextBuffer(void)
136 {
137  if(DataProducerBase::attachToEmptySubBuffer(FEProducerVInterface::dataP_,
138  FEProducerVInterface::headerP_) < 0)
139  {
140  __SS__
141  << "There are no available buffers! Retrying...after waiting 10 milliseconds!"
142  << std::endl;
143  __SS_THROW__;
144  }
145 
146  return FEProducerVInterface::dataP_;
147 } // end getNextBuffer()
148 
149 //========================================================================================================================
150 // writeCurrentBuffer
151 // This function writes the current buffer data string to the buffer.
152 //
153 void FEProducerVInterface::writeCurrentBuffer(void)
154 {
155  __FE_COUT__ << "Writing data of size " << FEProducerVInterface::dataP_->size()
156  << __E__;
157 
158  DataProducerBase::setWrittenSubBuffer<std::string,
159  std::map<std::string, std::string> >();
160 
161  __FE_COUT__ << "Data written." << __E__;
162 
163 } // end writeCurrentBuffer()
void unregisterFEProducer(const std::string &bufferID, const std::string &feProducerID)
Definition: DataManager.cc:632