FairRoot/PandaRoot
PndMQTopix4Processor.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
15 #include <boost/thread.hpp>
16 #include <boost/bind.hpp>
17 #include <boost/archive/binary_oarchive.hpp>
18 #include <PndMQTopix4Processor.h>
19 
20 #include "baseMQtools.h"
21 
22 #include "FairMQLogger.h"
23 #include "mrfdata_8b.h"
24 #include "PndSdsDigiTopix4.h"
25 #include "PndMQStatus.h"
26 
27 #include "PndTopix4.h"
28 
29 
30 using namespace std;
31 
32 PndMQTopix4Processor::PndMQTopix4Processor() : fHasBoostSerialization(false)
33 {
34  using namespace baseMQ::tools::resolve;
35  bool checkOutputClass = false;
36 
37 
38  if (is_same<boost::archive::binary_oarchive, boost::archive::binary_oarchive>::value)
39  {
40  if (has_BoostSerialization<PndSdsDigiTopix4, void(boost::archive::binary_oarchive&, const unsigned int)>::value == 1)
41  {
42  checkOutputClass = true;
44  }
45  }
46  LOG(INFO) << "HasBoostSerialization: " << fHasBoostSerialization;
47 }
48 
50 {
51 }
52 
53 
55 {
56  int eventCounter = 0;
58  while (CheckCurrentState(RUNNING))
59  {
60  unique_ptr<FairMQMessage> input(fTransportFactory->CreateMessage());
61  unique_ptr<FairMQMessage> headerPart(fTransportFactory->CreateMessage());
62 
63  if (fChannels.at("data-in").at(0).Receive(headerPart) > 0)
64  {
65  int status = *(static_cast<int*>(headerPart->GetData()));
66 
67  //LOG(INFO) << "Status: " << status;
68 
69  if (status == PndMQStatus::RUNNING){
70  if (fChannels.at("data-in").at(0).Receive(input) > 0) {
71 
72  //LOG(INFO) << "Received data, processing...";
73  TMrfData_8b* message = new TMrfData_8b();
74  message->setNumWords(input->GetSize());
75  memcpy(reinterpret_cast<u_int8_t*>(&message->regdata[0]),input->GetData(), input->GetSize());
76  // LOG(INFO) << "Received message: \""
77  // << message->getNumWords() << " " << message->getNumBits()
78  // << "\"";
79  std::vector<ULong64_t> rawArray;
80  PndTopix4 topix;
81  rawArray = topix.GetRawData(message);
82  std::vector<std::vector<PndSdsDigiTopix4> > frames = fTopixDataReader.AnalyzeData(rawArray, 50);
84  for (auto frameIter : frames){
85  fPndSdsDigiTopix4Vector.insert(fPndSdsDigiTopix4Vector.end(), frameIter.begin(), frameIter.end());
86  }
87  if (fPndSdsDigiTopix4Vector.size() > 0){
88 
89  unique_ptr<FairMQMessage> header(fTransportFactory->CreateMessage(sizeof(int)));
90  memcpy(header->GetData(), &status, sizeof(int));
91  fChannels.at("data-out").at(0).SendPart(header);
92 
93  ostringstream obuffer;
94  boost::archive::binary_oarchive OutputArchive(obuffer);
95  OutputArchive << fPndSdsDigiTopix4Vector;
96  int outputSize = obuffer.str().length();
97  unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage(outputSize));
98  memcpy(msg->GetData(), obuffer.str().c_str(), outputSize);
99  fChannels.at("data-out").at(0).Send(msg);
100  // LOG(INFO) << "Data: " << frames.front().size() << std::endl;
101  }
102 
103  if (eventCounter%10000 == 0){
105  LOG(INFO) << "StatusValues taken: " << fStatusValues.size();
106 
107  unique_ptr<FairMQMessage> header(fTransportFactory->CreateMessage(sizeof(int)));
108  memcpy(header->GetData(), &status, sizeof(int));
109  fChannels.at("status-out").at(0).SendPart(header);
110 
111  ostringstream obuffer;
112  boost::archive::binary_oarchive OutputArchive(obuffer);
113  OutputArchive << fStatusValues;
114  int outputSize = obuffer.str().length();
115  unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage(outputSize));
116  memcpy(msg->GetData(), obuffer.str().c_str(), outputSize);
117  fChannels.at("status-out").at(0).Send(msg);
118  }
119 
120  eventCounter++;
121  }
122  } else if (status == PndMQStatus::STOP){
123  LOG(INFO) << "Catched STOP signal!";
124 
125  unique_ptr<FairMQMessage> header(fTransportFactory->CreateMessage(sizeof(int)));
126  memcpy(header->GetData(), &status, sizeof(int));
127  fChannels.at("data-out").at(0).Send(header);
128  //ChangeState("STOP");
129  }
130  }
131  }
132 }
133 
134 void PndMQTopix4Processor::SetProperty(const int key, const string& value)
135 {
136  switch (key)
137  {
138  case TimeCorr:
139  fTimeCorrStr = value;
140  fTimeStampCorrection = std::stod(fTimeCorrStr);
142  break;
143  default:
144  FairMQDevice::SetProperty(key, value);
145  break;
146  }
147 }
148 
149 string PndMQTopix4Processor::GetProperty(const int key, const string& default_ /*= ""*/)
150 {
151  switch (key)
152  {
153  case TimeCorr:
154  return fTimeCorrStr;
155  break;
156  default:
157  return FairMQDevice::GetProperty(key, default_);
158  }
159 }
160 
161 void PndMQTopix4Processor::SetProperty(const int key, const int value)
162 {
163  switch (key)
164  {
165  case FE:
166  fFE = value;
168  break;
169  default:
170  FairMQDevice::SetProperty(key, value);
171  break;
172  }
173 }
174 
175 int PndMQTopix4Processor::GetProperty(const int key, const int default_ /*= 0*/)
176 {
177  switch (key)
178  {
179  case FE:
180  return fFE;
181  default:
182  return FairMQDevice::GetProperty(key, default_);
183  }
184 }
185 
186 
PndMvdReadInToPix4TBData fTopixDataReader
Data class to store the digi output of a pixel module.
void setNumWords(const UInt_t &length)
Sets the length of the register to lengths words.
std::vector< std::vector< PndSdsDigiTopix4 > > AnalyzeData(std::vector< ULong64_t > &rawData, Double_t clockFrequency)
std::vector< int > fStatusValues
virtual std::string GetProperty(const int key, const std::string &default_="")
std::vector< ULong64_t > GetRawData(TMrfData_8b *data)
Definition: PndTopix4.cxx:25
std::vector< int > GetStatusValues() const
std::vector< PndSdsDigiTopix4 > fPndSdsDigiTopix4Vector
void SetTimeStampCorrection(Double_t val)
Base interface class for data storage and manipulation. Compatible with IO classes from MRF Suite...
std::vector< UChar_t > regdata
Internal storage for data structure.
virtual void SetProperty(const int key, const std::string &value)
int status[10]
Definition: f_Init.h:28