FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMQPixAltFileSinkBin.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 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
16 
17 #include "PixelPayload.h"
18 
19 #include <FairMQLogger.h>
20 
21 using namespace std;
22 
24  : fInputChannelName("data-in")
25  , fAckChannelName("")
26  , fFileName()
27  , fOutFile(nullptr)
28 {}
29 
31 {
32  fFileName = fConfig->GetValue<std::string>("file-name");
33  fInputChannelName = fConfig->GetValue<std::string>("in-channel");
34  fAckChannelName = fConfig->GetValue<std::string>("ack-channel");
35 
36  LOG(info) << "SHOULD CREATE THE FILE AND TREE";
37 
38  fOutFile.open(fFileName, std::fstream::out | std::fstream::binary);
39 
40  OnData(fInputChannelName, &FairMQPixAltFileSinkBin::StoreData);
41 }
42 
43 bool FairMQPixAltFileSinkBin::StoreData(FairMQParts& parts, int /*index*/)
44 {
45  if (parts.Size() == 0)
46  return true; // probably impossible, but still check
47 
48  // the first part should be the event header
49  PixelPayload::EventHeader* payloadE = static_cast<PixelPayload::EventHeader*>(parts.At(0)->GetData());
50 
51  // LOG(debug) << "GOT EVENT " << payloadE->fMCEntryNo << " OF RUN " << payloadE->fRunId << " (part " <<
52  // payloadE->fPartNo << ")";
53 
54  // the second part should be the array of PixelPayload::Hit
55  PixelPayload::Hit* payloadH = static_cast<PixelPayload::Hit*>(parts.At(1)->GetData());
56  int hitArraySize = parts.At(1)->GetSize();
57  int nofHits = hitArraySize / sizeof(PixelPayload::Hit);
58 
59  fOutFile.write((char*)&(payloadE->fRunId), sizeof(payloadE->fRunId));
60  fOutFile.write((char*)&(payloadE->fMCEntryNo), sizeof(payloadE->fMCEntryNo));
61  fOutFile.write((char*)&(payloadE->fPartNo), sizeof(payloadE->fPartNo));
62  fOutFile.write((char*)&nofHits, sizeof(nofHits));
63 
64  float posX, posY, posZ, dposX, dposY, dposZ;
65  for (int ihit = 0; ihit < nofHits; ihit++) {
66  posX = (float)payloadH->posX;
67  posY = (float)payloadH->posY;
68  posZ = (float)payloadH->posZ;
69  dposX = (float)payloadH->dposX;
70  dposY = (float)payloadH->dposY;
71  dposZ = (float)payloadH->dposZ;
72  fOutFile.write(reinterpret_cast<char*>(&(payloadH->fDetectorID)), sizeof(payloadH->fDetectorID));
73  // fOutFile.write(reinterpret_cast<char*>(&(payloadH->posX)), sizeof(payloadH->posX));
74  // fOutFile.write(reinterpret_cast<char*>(&(payloadH->posY)), sizeof(payloadH->posY));
75  // fOutFile.write(reinterpret_cast<char*>(&(payloadH->posZ)), sizeof(payloadH->posZ));
76  // fOutFile.write(reinterpret_cast<char*>(&(payloadH->dposX)), sizeof(payloadH->dposX));
77  // fOutFile.write(reinterpret_cast<char*>(&(payloadH->dposY)), sizeof(payloadH->dposY));
78  // fOutFile.write(reinterpret_cast<char*>(&(payloadH->dposZ)), sizeof(payloadH->dposZ));
79  fOutFile.write(reinterpret_cast<char*>(&posX), sizeof(posX));
80  fOutFile.write(reinterpret_cast<char*>(&posY), sizeof(posY));
81  fOutFile.write(reinterpret_cast<char*>(&posZ), sizeof(posZ));
82  fOutFile.write(reinterpret_cast<char*>(&dposX), sizeof(dposX));
83  fOutFile.write(reinterpret_cast<char*>(&dposY), sizeof(dposY));
84  fOutFile.write(reinterpret_cast<char*>(&dposZ), sizeof(dposZ));
85  }
86 
87  if (fAckChannelName != "") {
88  unique_ptr<FairMQMessage> msg(NewMessage());
89  Send(msg, fAckChannelName);
90  }
91  return true;
92 }
93 
bool StoreData(FairMQParts &, int)