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