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