FairRoot/PandaRoot
PndMQTopix4DigiToHit.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 <boost/archive/binary_iarchive.hpp>
19 #include "PndMQTopix4DigiToHit.h"
20 
21 #include "PndMQStatus.h"
22 
23 #include "baseMQtools.h"
24 
25 #include "FairMQLogger.h"
26 #include "mrfdata_8b.h"
27 #include "PndSdsDigiTopix4.h"
28 #include <iomanip>
29 
30 
31 using namespace std;
32 
33 PndMQTopix4DigiToHit::PndMQTopix4DigiToHit() : fHasBoostSerialization(false),
34  fClusterFinder(20, 32, 1.8), fHitProducer(0.01, 0.01, 20, 32), fEventBuilder(50), fClusterSize(11), fStatusOutput(true)
35 {
36  using namespace baseMQ::tools::resolve;
37  bool checkOutputClass = false;
38 
39  if (is_same<boost::archive::binary_oarchive, boost::archive::binary_oarchive>::value)
40  {
41  if (has_BoostSerialization<PndSdsDigiTopix4, void(boost::archive::binary_oarchive&, const unsigned int)>::value == 1)
42  {
43  checkOutputClass = true;
45  }
46  }
47  LOG(INFO) << "HasBoostSerialization: " << fHasBoostSerialization;
48 }
49 
51 {
52 }
53 
54 
56 {
58  FairMQChannel& dataInChannel = fChannels.at("data-in").at(0);
59  FairMQChannel& dataOutChannel = fChannels.at("data-out").at(0);
60  bool statusChannelPresent = false;
61 
62  if (fStatusOutput){
63  try {
64  (fChannels.at("status-out"));
65  }
66  catch (...){
67  fStatusOutput = false;
68  LOG(INFO) << "No Status-Out channel!";
69  }
70  }
71 
72  while (CheckCurrentState(RUNNING))
73  {
74  std::unique_ptr<FairMQMessage> header(fTransportFactory->CreateMessage());
75  std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
77  if (dataInChannel.Receive(header) > 0)
78  {
79  status = *(static_cast<int*>(header->GetData()));
80 
81  if (dataInChannel.ExpectsAnotherPart())
82  {
83  if (dataInChannel.Receive(msg) > 0) {
84  string msgStr(static_cast<char*>(msg->GetData()), msg->GetSize());
85  istringstream ibuffer(msgStr);
86 
87  boost::archive::binary_iarchive InputArchive(ibuffer);
88 
89  try {
90  InputArchive >> fTopixDigis;
91  }
92  catch (boost::archive::archive_exception& e)
93  {
94  LOG(ERROR) << e.what();
95  }
96  }
97  }
98  }
99 // LOG(INFO) << "InputData: ";
100 // for (auto itr : fTopixDigis){
101 // LOG(INFO) << std::setw(12) << std::hex << itr.GetTimeStamp();
102 // }
103 
105  std::vector<std::vector<PndSdsDigiTopix4> > separatedData = fEventBuilder.GetSeparatedData();
106 
107  for (auto & eventIter : separatedData){
108  std::vector<PndSdsHit> hits;
109  if (eventIter.size() > 1){
110  std::vector<std::vector<int> > cluster = fClusterFinder.GetClusters(eventIter);
111 // LOG(INFO) << "Multiple Event Found with " << eventIter.size() << " digs and " << cluster.size() << " clusters";
112  for (auto clusterIter : cluster){
113  std::vector<PndSdsDigiTopix4> clusterDigis;
114  for (auto digiIter : clusterIter){
115  clusterDigis.push_back((eventIter)[digiIter]);
116 // LOG(INFO) << "Digis " << digiIter << " TimeStamp: " << (eventIter)[digiIter].GetTimeStamp();
117 // LOG(INFO) << "ClusterDigis: " << clusterDigis.rbegin()->GetTimeStamp();
118  }
119  //PndSdsHit myHit = fDummy.GetHit(clusterDigis);
120  //fHitProducer.GetHit(clusterDigis);
121  if (clusterDigis.size() < fClusterSize.size() - 1) //counts the sizes of clusters. All above fClusterSize.size() -1 are added to last bin
122  fClusterSize[clusterDigis.size()]++;
123  else
124  fClusterSize[fClusterSize.size() - 1]++;
125 
126  hits.push_back(fHitProducer.GetHit(clusterDigis));
127  }
128  } else {
129  //PndSdsHit myHit = fDummy.GetHit(eventIter);
130  //fHitProducer.GetHit(eventIter);
131  hits.push_back(fHitProducer.GetHit(eventIter));
132  }
133  fTopixHitsEvent.push_back(hits);
134  }
135 
136  if (status == PndMQStatus::STOP){
137  LOG(INFO) << "Received STOP-Signal!" << std::endl;
138  }
139 
140  unique_ptr<FairMQMessage> headerOut(fTransportFactory->CreateMessage(sizeof(int)));
141  memcpy(headerOut->GetData(), &status, sizeof(int));
142  dataOutChannel.SendPart(headerOut);
143 
144  std::ostringstream obuffer;
145  boost::archive::binary_oarchive OutputArchive(obuffer);
146  OutputArchive << fTopixHitsEvent;
147  int outputSize = obuffer.str().length();
148  unique_ptr<FairMQMessage> msg2(fTransportFactory->CreateMessage(outputSize));
149  memcpy(msg2->GetData(), obuffer.str().c_str(), outputSize);
150  dataOutChannel.Send(msg2);
151 
152  if (fStatusOutput == true){
153  unique_ptr<FairMQMessage> headerOut2(fTransportFactory->CreateMessage(sizeof(int)));
154  memcpy(headerOut->GetData(), &status, sizeof(int));
155  fChannels.at("status-out").at(0).SendPart(headerOut2);
156 
157  std::ostringstream obuffer2;
158  boost::archive::binary_oarchive OutputArchive2(obuffer2);
159  OutputArchive2 << fClusterSize;
160  int outputSize2 = obuffer2.str().length();
161  unique_ptr<FairMQMessage> msg3(fTransportFactory->CreateMessage(outputSize2));
162  memcpy(msg3->GetData(), obuffer2.str().c_str(), outputSize2);
163  fChannels.at("status-out").at(0).Send(msg3);
164  }
165 
166 // LOG(INFO) << "OutputEventBuilding: ";
167 // for (auto outerIter : fTopixHitsEvent){
168 // LOG(INFO) << "Event: ";
169 // for (auto innerIter : outerIter) {
170 // LOG(INFO)<< innerIter;
171 // }
172 // }
173  fTopixDigis.clear();
174  fTopixHitsEvent.clear();
175  }
176  }
177 }
PndSdsHit GetHit(std::vector< PndSdsDigiTopix4 > pixelArray)
PndMvdTopixClusterFinder fClusterFinder
std::vector< PndSdsDigiTopix4 > fTopixDigis
Data class to store the digi output of a pixel module.
std::deque< std::vector< PndSdsHit > > fTopixHitsEvent
std::vector< int > fClusterSize
PndMQGapEventBuilderToPix fEventBuilder
std::vector< std::vector< Int_t > > GetClusters(std::vector< PndSdsDigiTopix4 > &hits)
std::vector< std::vector< PndSdsDigiTopix4 > > GetSeparatedData()
PndMQTopixHitProducer fHitProducer
void FillData(std::vector< PndSdsDigiTopix4 > data)
CbmHit * hits[nHits]
Definition: RiemannTest.C:19
int status[10]
Definition: f_Init.h:28