FairRoot/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 {
55  public:
57  : fOutFile(NULL)
58  , fTree(NULL)
59  , fOutput(NULL)
60  , fHitVector()
61  , fHasBoostSerialization(false)
62  {
63  gSystem->ResetSignal(kSigInterrupt);
64  gSystem->ResetSignal(kSigTermination);
65 
66  // Check if boost serialization is available if it is chosen
67  using namespace baseMQ::tools::resolve;
68  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
69  if (is_same<boost::archive::binary_iarchive, boost::archive::binary_iarchive>::value || is_same<boost::archive::binary_iarchive, boost::archive::text_iarchive>::value)
70  {
71  if (has_BoostSerialization<PndSdsDigiTopix4, void(boost::archive::binary_iarchive&, const unsigned int)>::value == 1)
72  {
73  fHasBoostSerialization = true;
74  }
75  }
76  }
77 
78  virtual ~PndMQFileSink()
79  {
80  fTree->Write();
81  fOutFile->Close();
82  if (fHitVector.size() > 0)
83  {
84  fHitVector.clear();
85  }
86  }
87 
88  virtual void InitOutputFile(TString defaultId = "100")
89  {
90  fOutput = new TClonesArray("PndSdsDigiTopix4");
91 
92  fOutFile = new TFile("Filesink1.root", "recreate");
93  fTree = new TTree("MQOut", "Test output");
94  fTree->Branch("Output", "TClonesArray", &fOutput, 64000, 99);
95  }
96 
97  template <class Archive>
98  void serialize(Archive& ar, const unsigned int version)
99  {
100  ar& fHitVector;
101  }
102 
103  protected:
104  virtual void Run();
105 
106  private:
107  TFile* fOutFile;
108  TTree* fTree;
109  TClonesArray* fOutput;
110 
111 #ifndef __CINT__ // for BOOST serialization
112  friend class boost::serialization::access;
113  vector<PndSdsDigiTopix4> fHitVector;
115 #endif // for BOOST serialization
116 
118 // PndMQFileSink(const PndMQFileSink&);
119 // PndMQFileSink operator=(const PndMQFileSink&);
120 };
121 
122 #endif /* PndMQFileSink_H_ */
Data class to store the digi output of a pixel module.
bool fHasBoostSerialization
TFile * fOutFile
vector< PndSdsDigiTopix4 > fHitVector
virtual void InitOutputFile(TString defaultId="100")
Definition: PndMQFileSink.h:88
TString fOutFile
Definition: run_full.C:10
TClonesArray * fOutput
fRun Run(0, nEvents)
virtual ~PndMQFileSink()
Definition: PndMQFileSink.h:78
void serialize(Archive &ar, const unsigned int version)
Definition: PndMQFileSink.h:98