00001 #include "otsdaq-core/EventBuilder/AssociativeMemoryEventBuilder.h" 00002 #include "otsdaq-core/EventBuilder/Event.h" 00003 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00004 #include "otsdaq-core/Macros/CoutMacros.h" 00005 00006 #include <iostream> 00007 00008 using namespace ots; 00009 00010 00011 //======================================================================================================================== 00012 AssociativeMemoryEventBuilder::AssociativeMemoryEventBuilder(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID, ConsumerPriority priority) 00013 : WorkLoop (processorUID) 00014 , VirtualEventBuilder (supervisorApplicationUID, bufferUID, processorUID) 00015 , bcoIsComplete_ (true) 00016 , currentBCO_ (0) 00017 {} 00018 00019 //======================================================================================================================== 00020 AssociativeMemoryEventBuilder::~AssociativeMemoryEventBuilder(void) 00021 {} 00022 00023 //======================================================================================================================== 00024 void AssociativeMemoryEventBuilder::build(const std::string& buffer) 00025 { 00026 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "********************************Begin buffer: " << buffer << std::endl; 00027 theDataDecoder_.convertBuffer(buffer,convertedBuffer_, true); 00028 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Buffer size: " << convertedBuffer_.size() << std::endl; 00029 while (!convertedBuffer_.empty()) 00030 { 00031 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Data: " << hex << convertedBuffer_.front() << dec << " size: " << convertedBuffer_.size() << std::endl; 00032 if(theDataDecoder_.isBCOHigh(convertedBuffer_.front()) || theDataDecoder_.isBCOLow(convertedBuffer_.front())) 00033 { 00034 if(bcoIsComplete_) 00035 { 00036 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " High: " << hex << convertedBuffer_.front() << dec << std::endl; 00037 currentBCO_ = 0; 00038 theDataDecoder_.insertBCOHigh(currentBCO_,convertedBuffer_.front()); 00039 bcoIsComplete_ = false; 00040 convertedBuffer_.pop(); 00041 if(convertedBuffer_.empty()) 00042 return; 00043 } 00044 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Low: " << hex << convertedBuffer_.front() << dec << std::endl; 00045 theDataDecoder_.insertBCOLow(currentBCO_,convertedBuffer_.front());//After a BCO High there must be a Low 00046 if(memory_.find(currentBCO_) == memory_.end()) 00047 memory_[currentBCO_] = new Event(currentBCO_); 00048 bcoIsComplete_ = true; 00049 convertedBuffer_.pop(); 00050 continue; 00051 } 00052 if(bcoIsComplete_) 00053 { 00054 if(memory_.find(currentBCO_) != memory_.end()) 00055 { 00056 //if(theDataDecoder_.isTriggerHigh(convertedBuffer_.front())) 00057 // memory_[currentBCO_]->setTriggerNumber(theDataDecoder_.decodeTriggerHigh(convertedBuffer_.front())); 00058 //else 00059 // memory_[currentBCO_]->setRawHit(convertedBuffer_.front()); 00060 00061 } 00062 else 00063 { 00064 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl; 00065 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Data is coming before any high BCO you MUST fix the start procedure!" << std::endl; 00066 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl; 00067 } 00068 } 00069 else 00070 { 00071 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl; 00072 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Data is missing the low bco!" << std::endl; 00073 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl; 00074 } 00075 convertedBuffer_.pop(); 00076 } 00077 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "********************************End buffer: " << buffer << std::endl; 00078 } 00079 00080 //======================================================================================================================== 00081 std::queue<Event*>& AssociativeMemoryEventBuilder::getCompleteEvents(void) 00082 { 00083 return getCompleteEvents(512); 00084 } 00085 00086 //======================================================================================================================== 00087 std::queue<Event*>& AssociativeMemoryEventBuilder::getAllEvents(void) 00088 { 00089 return getCompleteEvents(0); 00090 } 00091 00092 //======================================================================================================================== 00093 std::queue<Event*>& AssociativeMemoryEventBuilder::getCompleteEvents(unsigned int bcoDifference) 00094 { 00095 uint64_t currentBCO = memory_.rbegin()->second->getBCONumber(); 00096 00097 for(std::map<uint64_t,Event*>::iterator it=memory_.begin(); it!=memory_.end(); it++) 00098 if(currentBCO - it->second->getBCONumber() >= bcoDifference) 00099 { 00100 completeEvents_.push(it->second);//The pointer is not erased because now it is owned by the completeEvents_ queue 00101 memory_.erase(it--); 00102 } 00103 return VirtualEventBuilder::completeEvents_; 00104 } 00105