$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/FECore/FEProducerVInterface.h" 00002 #include "otsdaq-core/DataManager/DataManager.h" 00003 #include "otsdaq-core/DataManager/DataManagerSingleton.h" 00004 00005 using namespace ots; 00006 00007 #undef __MF_SUBJECT__ 00008 #define __MF_SUBJECT__ (std::string("FEProducer-") + DataProcessor::processorUID_) 00009 00010 //======================================================================================================================== 00011 FEProducerVInterface::FEProducerVInterface( 00012 const std::string& interfaceUID, 00013 const ConfigurationTree& theXDAQContextConfigTree, 00014 const std::string& interfaceConfigurationPath) 00015 : FEVInterface(interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath) 00016 , DataProducerBase( 00017 theXDAQContextConfigTree.getBackNode(interfaceConfigurationPath, 4) 00018 .getValueAsString(), 00019 theXDAQContextConfigTree 00020 .getNode(interfaceConfigurationPath + "/" + "LinkToDataBufferTable", 4) 00021 .getValueAsString(), 00022 interfaceUID /*processorID*/, 00023 100 /*bufferSize*/) 00024 { 00025 // NOTE!! be careful to not decorate with __FE_COUT__ because in the constructor the 00026 // base class versions of function (e.g. getInterfaceType) are called because the 00027 // derived class has not been instantiate yet! 00028 __COUT__ << "'" << interfaceUID << "' Constructed." << __E__; 00029 00030 __COUTV__(interfaceConfigurationPath); 00031 ConfigurationTree appNode = 00032 theXDAQContextConfigTree.getBackNode(interfaceConfigurationPath, 2); 00033 00034 __COUTV__(appNode.getValueAsString()); 00035 00036 } // end constructor() 00037 00038 FEProducerVInterface::~FEProducerVInterface(void) 00039 { 00040 __FE_COUT__ << "Destructor." << __E__; 00041 // Take out of DataManager vector! 00042 00043 __COUT__ << "FEProducer '" << DataProcessor::processorUID_ 00044 << "' is unregistering from DataManager Supervisor Buffer '" 00045 << DataProcessor::supervisorApplicationUID_ << ":" 00046 << DataProcessor::bufferUID_ << ".'" << std::endl; 00047 00048 DataManager* dataManager = 00049 (DataManagerSingleton::getInstance(supervisorApplicationUID_)); 00050 00051 dataManager->unregisterFEProducer(bufferUID_, DataProcessor::processorUID_); 00052 00053 { 00054 __SS__; 00055 dataManager->dumpStatus(&ss); 00056 std::cout << ss.str() << __E__; 00057 } 00058 00059 __COUT__ << "FEProducer '" << DataProcessor::processorUID_ << "' unregistered." 00060 << __E__; 00061 00062 __FE_COUT__ << "Destructed." << __E__; 00063 } 00064 00065 //======================================================================================================================== 00066 // copyToNextBuffer 00067 // This function copies a data string into the next 00068 // available buffer. 00069 // 00070 // Here is example code for filling a data string to write 00071 // 00072 // unsigned long long value = 0xA5; //this is 8-bytes 00073 // std::string buffer; 00074 // buffer.resize(8); //NOTE: this is inexpensive according to 00075 // Lorenzo/documentation in C++11 (only increases size once and doesn't decrease size) 00076 // memcpy((void 00077 //*)&buffer /*dest*/,(void *)&value /*src*/, 8 /*numOfBytes*/); 00078 // 00079 // Note: This is somewhat inefficient because it makes a copy of the data. 00080 // It would be more efficient to call 00081 // FEProducerVInterface::getNextBuffer() 00082 // ... fill the retrieved data string 00083 // FEProducerVInterface::writeCurrentBuffer() 00084 // 00085 // If you are using the same dataToWrite string over and over.. it might not be that 00086 // inefficient to use this. 00087 // 00088 void FEProducerVInterface::copyToNextBuffer(const std::string& dataToWrite) 00089 { 00090 __FE_COUT__ << "Write Data: " 00091 << BinaryStringMacros::binaryTo8ByteHexString(dataToWrite) << __E__; 00092 00093 DataProducerBase::write<std::string, std::map<std::string, std::string> >( 00094 dataToWrite); 00095 // 00096 // FEProducerVInterface::getNextBuffer(); 00097 // 00098 // __FE_COUT__ << "Have next buffer " << FEProducerVInterface::dataP_ << __E__; 00099 // __FE_COUT__ << "Have next buffer size " << FEProducerVInterface::dataP_->size() << 00100 //__E__; 00101 // 00102 // 00103 // FEProducerVInterface::dataP_->resize(dataToWrite.size()); 00104 // 00105 // __FE_COUT__ << "Have next buffer size " << FEProducerVInterface::dataP_->size() << 00106 //__E__; 00107 // 00108 // //*FEProducerVInterface::dataP_ = dataToWrite; //copy 00109 // memcpy((void *)&(*FEProducerVInterface::dataP_)[0] /*dest*/, 00110 // (void *)&dataToWrite[0] /*src*/, 8 /*numOfBytes*/); 00111 // 00112 // __FE_COUT__ << "Data copied " << FEProducerVInterface::dataP_->size() << __E__; 00113 // 00114 // __FE_COUT__ << "Copied Data: " << 00115 // BinaryStringMacros::binaryTo8ByteHexString(*FEProducerVInterface::dataP_) 00116 //<< 00117 //__E__; 00118 // 00119 // 00120 // FEProducerVInterface::writeCurrentBuffer(); 00121 00122 } // end copyToNextBuffer() 00123 00124 //======================================================================================================================== 00125 // getNextBuffer 00126 // This function retrieves the next buffer data string. 00127 00128 // Note: This is more efficient than FEProducerVInterface::writeToBuffer 00129 // because it does NOT makes a copy of the data. 00130 // 00131 // You need to now 00132 // ... fill the retrieved data string 00133 // FEProducerVInterface::writeCurrentBuffer() 00134 // 00135 std::string* FEProducerVInterface::getNextBuffer(void) 00136 { 00137 if(DataProducerBase::attachToEmptySubBuffer(FEProducerVInterface::dataP_, 00138 FEProducerVInterface::headerP_) < 0) 00139 { 00140 __SS__ 00141 << "There are no available buffers! Retrying...after waiting 10 milliseconds!" 00142 << std::endl; 00143 __SS_THROW__; 00144 } 00145 00146 return FEProducerVInterface::dataP_; 00147 } // end getNextBuffer() 00148 00149 //======================================================================================================================== 00150 // writeCurrentBuffer 00151 // This function writes the current buffer data string to the buffer. 00152 // 00153 void FEProducerVInterface::writeCurrentBuffer(void) 00154 { 00155 __FE_COUT__ << "Writing data of size " << FEProducerVInterface::dataP_->size() 00156 << __E__; 00157 00158 DataProducerBase::setWrittenSubBuffer<std::string, 00159 std::map<std::string, std::string> >(); 00160 00161 __FE_COUT__ << "Data written." << __E__; 00162 00163 } // end writeCurrentBuffer()