FairRoot/PandaRoot
PndMQTopix4Sampler.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 <memory> // unique_ptr
16 
17 #include <boost/thread.hpp>
18 #include <boost/bind.hpp>
19 #include <PndMQTopix4Sampler.h>
20 
21 #include "FairMQLogger.h"
22 #include "mrfdata_8b.h"
23 #include "PndMQStatus.h"
24 
25 using namespace std;
26 
28  : fFileName()
29 {
30 }
31 
32 void PndMQTopix4Sampler::CustomCleanup(void *data, void *object)
33 {
34  delete (TMrfData_8b*)object;
35 }
36 
38 {
40 }
41 
43 {
44  bool stop = false;
45 
46  while (CheckCurrentState(RUNNING) && stop == false)
47  {
48  //boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
49 
50  TMrfData_8b* data = 0;
52 
53  unique_ptr<FairMQMessage> header(fTransportFactory->CreateMessage(sizeof(int)));
54 
55  int flag = -1;
56  if (stop == false){
57  flag = PndMQStatus::RUNNING;
58  memcpy(header->GetData(), &flag, sizeof(int));
59  unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage(reinterpret_cast<u_int8_t*>(&data->regdata[0]),data->getNumWords(),CustomCleanup,data));
60  // LOG(INFO) << "Sending Words\"" << data->getNumWords() << "\"" << " Bits: " << data->getNumBits();
61  fChannels.at("data-out").at(0).SendPart(header);
62  fChannels.at("data-out").at(0).Send(msg);
63  }
64  else
65  {
66  flag = PndMQStatus::STOP;
67  memcpy(header->GetData(), &flag, sizeof(int));
68  fChannels.at("data-out").at(0).Send(header);
69  }
70  }
71 }
72 
74 {
75 }
76 
77 void PndMQTopix4Sampler::SetProperty(const int key, const string& value)
78 {
79  switch (key)
80  {
81  case FileName:
82  fFileName = value;
84  break;
85  default:
86  FairMQDevice::SetProperty(key, value);
87  break;
88  }
89 }
90 
91 string PndMQTopix4Sampler::GetProperty(const int key, const string& default_ /*= ""*/)
92 {
93  switch (key)
94  {
95  case FileName:
96  return fFileName;
97  break;
98  default:
99  return FairMQDevice::GetProperty(key, default_);
100  }
101 }
102 
103 void PndMQTopix4Sampler::SetProperty(const int key, const int value)
104 {
105  switch (key)
106  {
107  default:
108  FairMQDevice::SetProperty(key, value);
109  break;
110  }
111 }
112 
113 int PndMQTopix4Sampler::GetProperty(const int key, const int default_ /*= 0*/)
114 {
115  switch (key)
116  {
117  default:
118  return FairMQDevice::GetProperty(key, default_);
119  }
120 }
virtual std::string GetProperty(const int key, const std::string &default_="")
virtual Bool_t ReadInDataFromFile(TMrfData_8b *&data)
PndMvdReadInToPix4TBData fTopixDataReader
static void CustomCleanup(void *data, void *hint)
virtual void SetProperty(const int key, const std::string &value)
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.
void SetFileName(std::vector< std::string > fileName)
const UInt_t & getNumWords() const
Retrieves the length of the register in words.