PandaRoot
PndMQFileSink.h
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 #ifndef PndMQFileSink_H_
16 #define PndMQFileSink_H_
17 
18 #include <iostream>
19 
20 #include "Rtypes.h"
21 #include "TFile.h"
22 #include "TTree.h"
23 #include "TClonesArray.h"
24 #include "TVector3.h"
25 #include "TString.h"
26 #include "TSystem.h"
27 
28 #include "FairMQDevice.h"
29 #include "FairMQLogger.h"
30 
31 #include "PndSdsDigiTopix4.h"
32 
33 #include "baseMQtools.h"
34 
35 #include "TMessage.h"
36 
37 #ifndef __CINT__
38 #include <boost/thread.hpp>
39 #include <boost/bind.hpp>
40 #include <boost/serialization/access.hpp>
41 #include <boost/archive/text_iarchive.hpp>
42 #include <boost/archive/binary_iarchive.hpp>
43 #include <boost/serialization/vector.hpp>
44 #endif //__CINT__
45 
46 class TVector3;
47 class TFile;
48 class TTree;
49 class TClonesArray;
50 
51 using namespace std;
52 
53 class PndMQFileSink : public FairMQDevice {
54  public:
55  PndMQFileSink() : fOutFile(nullptr), fTree(nullptr), fOutput(nullptr), fHitVector(), fHasBoostSerialization(false)
56  {
57  gSystem->ResetSignal(kSigInterrupt);
58  gSystem->ResetSignal(kSigTermination);
59 
60  // Check if boost serialization is available if it is chosen
61  using namespace baseMQ::tools::resolve;
62  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
63  if (is_same<boost::archive::binary_iarchive, boost::archive::binary_iarchive>::value || is_same<boost::archive::binary_iarchive, boost::archive::text_iarchive>::value) {
64  if (has_BoostSerialization<PndSdsDigiTopix4, void(boost::archive::binary_iarchive &, const unsigned int)>::value == 1) {
65  fHasBoostSerialization = true;
66  }
67  }
68  }
69 
70  virtual ~PndMQFileSink()
71  {
72  fTree->Write();
73  fOutFile->Close();
74  if (fHitVector.size() > 0) {
75  fHitVector.clear();
76  }
77  }
78 
79  virtual void InitOutputFile(TString defaultId = "100")
80  {
81  fOutput = new TClonesArray("PndSdsDigiTopix4");
82 
83  fOutFile = new TFile("Filesink1.root", "recreate");
84  fTree = new TTree("MQOut", "Test output");
85  fTree->Branch("Output", "TClonesArray", &fOutput, 64000, 99);
86  }
87 
88  template <class Archive>
89  void serialize(Archive &ar, const unsigned int version)
90  {
91  ar &fHitVector;
92  }
93 
94  protected:
95  virtual void Run();
96 
97  private:
98  TFile *fOutFile;
99  TTree *fTree;
100  TClonesArray *fOutput;
101 
102 #ifndef __CINT__ // for BOOST serialization
103  friend class boost::serialization::access;
104  vector<PndSdsDigiTopix4> fHitVector;
105  bool fHasBoostSerialization;
106 #endif // for BOOST serialization
107 
109  // PndMQFileSink(const PndMQFileSink&);
110  // PndMQFileSink operator=(const PndMQFileSink&);
111 };
112 
113 #endif /* PndMQFileSink_H_ */
Data class to store the digi output of a pixel module.
STL namespace.
virtual void InitOutputFile(TString defaultId="100")
Definition: PndMQFileSink.h:79
virtual ~PndMQFileSink()
Definition: PndMQFileSink.h:70
void serialize(Archive &ar, const unsigned int version)
Definition: PndMQFileSink.h:89