otsdaq  v1_01_03
 All Classes Namespaces Functions
AssociativeMemoryEventBuilder.cc
1 #include "otsdaq-core/EventBuilder/AssociativeMemoryEventBuilder.h"
2 #include "otsdaq-core/EventBuilder/Event.h"
3 #include "otsdaq-core/MessageFacility/MessageFacility.h"
4 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
5 
6 #include <iostream>
7 
8 using namespace ots;
9 
10 
11 //========================================================================================================================
12 AssociativeMemoryEventBuilder::AssociativeMemoryEventBuilder(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID, ConsumerPriority priority)
13 : WorkLoop (processorUID)
14 , VirtualEventBuilder (supervisorApplicationUID, bufferUID, processorUID)
15 , bcoIsComplete_ (true)
16 , currentBCO_ (0)
17 {}
18 
19 //========================================================================================================================
20 AssociativeMemoryEventBuilder::~AssociativeMemoryEventBuilder(void)
21 {}
22 
23 //========================================================================================================================
24 void AssociativeMemoryEventBuilder::build(const std::string& buffer)
25 {
26  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "********************************Begin buffer: " << buffer << std::endl;
27  theDataDecoder_.convertBuffer(buffer,convertedBuffer_, true);
28  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Buffer size: " << convertedBuffer_.size() << std::endl;
29  while (!convertedBuffer_.empty())
30  {
31  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Data: " << hex << convertedBuffer_.front() << dec << " size: " << convertedBuffer_.size() << std::endl;
32  if(theDataDecoder_.isBCOHigh(convertedBuffer_.front()) || theDataDecoder_.isBCOLow(convertedBuffer_.front()))
33  {
34  if(bcoIsComplete_)
35  {
36  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " High: " << hex << convertedBuffer_.front() << dec << std::endl;
37  currentBCO_ = 0;
38  theDataDecoder_.insertBCOHigh(currentBCO_,convertedBuffer_.front());
39  bcoIsComplete_ = false;
40  convertedBuffer_.pop();
41  if(convertedBuffer_.empty())
42  return;
43  }
44  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Low: " << hex << convertedBuffer_.front() << dec << std::endl;
45  theDataDecoder_.insertBCOLow(currentBCO_,convertedBuffer_.front());//After a BCO High there must be a Low
46  if(memory_.find(currentBCO_) == memory_.end())
47  memory_[currentBCO_] = new Event(currentBCO_);
48  bcoIsComplete_ = true;
49  convertedBuffer_.pop();
50  continue;
51  }
52  if(bcoIsComplete_)
53  {
54  if(memory_.find(currentBCO_) != memory_.end())
55  {
56  //if(theDataDecoder_.isTriggerHigh(convertedBuffer_.front()))
57  // memory_[currentBCO_]->setTriggerNumber(theDataDecoder_.decodeTriggerHigh(convertedBuffer_.front()));
58  //else
59  // memory_[currentBCO_]->setRawHit(convertedBuffer_.front());
60 
61  }
62  else
63  {
64  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl;
65  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Data is coming before any high BCO you MUST fix the start procedure!" << std::endl;
66  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl;
67  }
68  }
69  else
70  {
71  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl;
72  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " Data is missing the low bco!" << std::endl;
73  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "****************************************************************" << std::endl;
74  }
75  convertedBuffer_.pop();
76  }
77  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << "********************************End buffer: " << buffer << std::endl;
78 }
79 
80 //========================================================================================================================
81 std::queue<Event*>& AssociativeMemoryEventBuilder::getCompleteEvents(void)
82 {
83  return getCompleteEvents(512);
84 }
85 
86 //========================================================================================================================
87 std::queue<Event*>& AssociativeMemoryEventBuilder::getAllEvents(void)
88 {
89  return getCompleteEvents(0);
90 }
91 
92 //========================================================================================================================
93 std::queue<Event*>& AssociativeMemoryEventBuilder::getCompleteEvents(unsigned int bcoDifference)
94 {
95  uint64_t currentBCO = memory_.rbegin()->second->getBCONumber();
96 
97  for(std::map<uint64_t,Event*>::iterator it=memory_.begin(); it!=memory_.end(); it++)
98  if(currentBCO - it->second->getBCONumber() >= bcoDifference)
99  {
100  completeEvents_.push(it->second);//The pointer is not erased because now it is owned by the completeEvents_ queue
101  memory_.erase(it--);
102  }
103  return VirtualEventBuilder::completeEvents_;
104 }
105