FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ex2Processor.h
Go to the documentation of this file.
1 #ifndef EX2PROCESSOR_H
2 #define EX2PROCESSOR_H
3 
4 #include "BoostSerializer.h"
5 #include "MyDigi.h"
6 #include "MyHit.h"
7 #include "RootSerializer.h"
8 #include "SerializerExample2.h"
9 
10 #include <FairMQDevice.h>
11 #include <FairMQParts.h>
12 #include <TMath.h>
13 
14 class Ex2Processor : public FairMQDevice
15 {
16  public:
18  : fInput(nullptr)
19  , fOutput(nullptr)
20  , fNumMsgs(0)
21  {}
22 
23  Ex2Processor(const Ex2Processor&);
25 
26  virtual ~Ex2Processor() {}
27 
28  protected:
29  virtual void Init()
30  {
31  fNumMsgs = fConfig->GetValue<int>("num-msgs");
32  fOutput = new TClonesArray("MyHit");
33  }
34 
35  virtual void Run()
36  {
37  int receivedMsgs = 0;
38  int sentMsgs = 0;
39 
40  while (!NewStatePending()) {
41  FairMQParts partsIn;
42 
43  if (Receive(partsIn, "data1") > 0) {
44  Ex2Header* header = nullptr;
45  Deserialize<SerializerEx2>(*(partsIn.At(0)), header);
46  Deserialize<RootSerializer>(*(partsIn.At(1)), fInput);
47 
48  receivedMsgs++;
49 
50  Exec(fInput, fOutput);
51 
52  FairMQParts partsOut;
53  partsOut.AddPart(std::move(partsIn.At(0)));
54  partsOut.AddPart(NewMessage());
55 
56  Serialize<BoostSerializer<Ex2Header>>(*(partsOut.At(0)), *header);
57  Serialize<BoostSerializer<MyHit>>(*(partsOut.At(1)), fOutput);
58  Send(partsOut, "data2");
59  sentMsgs++;
60 
61  if (fNumMsgs != 0) {
62  if (receivedMsgs == fNumMsgs) {
63  break;
64  }
65  }
66  }
67  }
68  LOG(info) << "Received " << receivedMsgs << " and sent " << sentMsgs << " messages!";
69  }
70 
71  // do some random dummy task
72  void Exec(TClonesArray* digis, TClonesArray* hits)
73  {
74  hits->Delete();
75  for (int idigi(0); idigi < digis->GetEntriesFast(); idigi++) {
76  TVector3 pos;
77  TVector3 dpos;
78  // Double_t timestamp = 0;
79  // Double_t timestampErr = 0;
80  Int_t fDetID = 0;
81  Int_t fMCIndex = 0;
82  MyDigi* digi = (MyDigi*)digis->At(idigi);
83  pos.SetXYZ(digi->GetX() + 0.5, digi->GetY() + 0.5, digi->GetZ() + 0.5);
84  dpos.SetXYZ(1 / TMath::Sqrt(12), 1 / TMath::Sqrt(12), 1 / TMath::Sqrt(12));
85  MyHit* hit = new ((*hits)[idigi]) MyHit(fDetID, fMCIndex, pos, dpos);
86  hit->SetTimeStamp(digi->GetTimeStamp());
88  }
89  }
90 
91  private:
92  TClonesArray* fInput;
93  TClonesArray* fOutput;
94  int fNumMsgs;
95 };
96 
97 #endif
void SetXYZ(Int_t x, Int_t y, Int_t z)
Definition: MyDigi.h:39
virtual ~Ex2Processor()
Definition: Ex2Processor.h:26
virtual void Run()
Definition: Ex2Processor.h:35
Int_t GetZ() const
Definition: MyDigi.h:51
Int_t GetX() const
Definition: MyDigi.h:49
virtual void Init()
Definition: Ex2Processor.h:29
Int_t GetY() const
Definition: MyDigi.h:50
Definition: MyHit.h:32
Ex2Processor & operator=(const Ex2Processor &)
Double_t GetTimeStampError() const
Definition: FairTimeStamp.h:45
Definition: MyDigi.h:32
Double_t GetTimeStamp() const
Definition: FairTimeStamp.h:44
void Exec(TClonesArray *digis, TClonesArray *hits)
Definition: Ex2Processor.h:72
void SetTimeStamp(Double_t t)
Definition: FairTimeStamp.h:47
void SetTimeStampError(Double_t t)
Definition: FairTimeStamp.h:48