FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMQPrimaryGeneratorDevice.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017 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  ********************************************************************************/
8 
16 #ifndef FAIRMQPRIMARYGENERATORDEVICE_H_
17 #define FAIRMQPRIMARYGENERATORDEVICE_H_
18 
19 #include <FairMQDevice.h>
20 #include <cstdint>
21 #include <string>
22 #include <thread>
23 
24 class FairMCEventHeader;
26 class TObject;
27 class FairStack;
28 
29 class FairMQPrimaryGeneratorDevice : public FairMQDevice
30 {
31  public:
34 
35  virtual void SendPrimaries();
36 
37  void SetNofEvents(int64_t nofev) { fNofEvents = nofev; };
38  void SetGenerator(FairPrimaryGenerator* primGen) { fPrimaryGenerator = primGen; };
39 
40  void SetChunkSize(int64_t ti) { fChunkSize = ti; };
41 
42  void RunInPushMode(bool tb = true) { fRunConditional = tb; };
43  void RunInRepMode(bool tb = true) { fRunConditional = !tb; };
44 
45  void ListenForAcks();
46 
47  void SetGeneratorChannelName(std::string tstr) { fGeneratorChannelName = tstr; }
48  void SetAckChannelName(std::string tstr) { fAckChannelName = tstr; }
49 
50  protected:
51  bool Reply(FairMQMessagePtr&, int);
52  virtual void InitTask();
53  virtual void PreRun();
54  virtual void PostRun();
55  virtual bool ConditionalRun();
56 
57  private:
58  std::string fGeneratorChannelName;
59  std::string fAckChannelName;
60 
61  bool fRunConditional; // if true run ConditionalRun, if false run Reply
62 
63  FairPrimaryGenerator* fPrimaryGenerator;
64  FairMCEventHeader* fMCEventHeader;
65  FairStack* fStack;
66  int64_t fNofEvents;
67  int64_t fEventCounter;
68 
69  int64_t fChunkSize; // to set the maximal number of primaries sent in one bunch
70  int64_t fChunkPointer; // to set the first primary to be sent
71 
72  bool GenerateAndSendData();
73  void SendObject(TObject* obj, std::string chan);
74 
77 
78  std::thread fAckListener;
79 };
80 
81 #endif /* FAIRMQPRIMARYGENERATORDEVICE_H_ */
void SetGenerator(FairPrimaryGenerator *primGen)
bool Reply(FairMQMessagePtr &, int)
void SetGeneratorChannelName(std::string tstr)