PandaRoot
PndMQFileSinkHits.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 PndMQFileSinkHits_H_
16 #define PndMQFileSinkHits_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 #include "TList.h"
28 #include "TObjString.h"
29 
30 #include "FairMQDevice.h"
31 #include "FairMQLogger.h"
32 
33 #include "PndSdsHit.h"
34 
35 #include "baseMQtools.h"
36 
37 #include "TMessage.h"
38 
39 #ifndef __CINT__
40 #include <boost/thread.hpp>
41 #include <boost/bind.hpp>
42 #include <boost/serialization/access.hpp>
43 #include <boost/archive/text_iarchive.hpp>
44 #include <boost/archive/binary_iarchive.hpp>
45 #include <boost/serialization/vector.hpp>
46 #endif //__CINT__
47 
48 class TVector3;
49 class TFile;
50 class TTree;
51 class TClonesArray;
52 
53 using namespace std;
54 
55 class PndMQFileSinkHits : public FairMQDevice {
56  public:
57  PndMQFileSinkHits(std::string outputFileName = "FilesSinkHits.root")
58  : fOutFile(nullptr), fTree(nullptr), fOutput(nullptr), fHitVector(), fHasBoostSerialization(false), fOutputFileName(outputFileName), fBranchNameList(0)
59  {
60  gSystem->ResetSignal(kSigInterrupt);
61  gSystem->ResetSignal(kSigTermination);
62 
63  // Check if boost serialization is available if it is chosen
64  using namespace baseMQ::tools::resolve;
65  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
66  if (is_same<boost::archive::binary_iarchive, boost::archive::binary_iarchive>::value || is_same<boost::archive::binary_iarchive, boost::archive::text_iarchive>::value) {
67  if (has_BoostSerialization<PndSdsHit, void(boost::archive::binary_iarchive &, const unsigned int)>::value == 1) {
68  fHasBoostSerialization = true;
69  }
70  }
71  }
72 
74  {
75  fBranchNameList->Write("BranchList", TObject::kSingleKey);
76  // fTree->Write();
77  // fOutFile->Close();
78  if (fHitVector.size() > 0) {
79  fHitVector.clear();
80  }
81  }
82 
83  virtual void SetFileName(std::string fileName) { fOutputFileName = fileName; }
84 
85  virtual void InitOutputFile(TString defaultId = "100")
86  {
87  fOutput = new TClonesArray("PndSdsHit");
88 
89  std::stringstream ss;
90  // ss << "/Volumes/RAMDisk/";
91  ss << fOutputFileName.c_str();
92 
93  fOutFile = new TFile(ss.str().c_str(), "recreate");
94  fTree = new TTree("pndsim", "Test output");
95  fTree->Branch("Output", "TClonesArray", &fOutput, 64000, 99);
96  fBranchNameList = new TList();
97  fBranchNameList->AddLast(new TObjString("Output"));
98  }
99 
100  template <class Archive>
101  void serialize(Archive &ar, const unsigned int version)
102  {
103  ar &fHitVector;
104  }
105 
106  protected:
107  virtual void Run();
108 
109  private:
110  TFile *fOutFile;
111  TTree *fTree;
112  TClonesArray *fOutput;
113  TList *fBranchNameList;
114  std::string fOutputFileName;
115 
116 #ifndef __CINT__ // for BOOST serialization
117  friend class boost::serialization::access;
118  vector<vector<PndSdsHit>> fHitVector;
119  bool fHasBoostSerialization;
120 #endif // for BOOST serialization
121 
123  // PndMQFileSinkHits(const PndMQFileSinkHits&);
124  // PndMQFileSinkHits operator=(const PndMQFileSinkHits&);
125 };
126 
127 #endif /* PndMQFileSinkHits_H_ */
PndMQFileSinkHits(std::string outputFileName="FilesSinkHits.root")
STL namespace.
virtual void SetFileName(std::string fileName)
virtual ~PndMQFileSinkHits()
virtual void InitOutputFile(TString defaultId="100")
void serialize(Archive &ar, const unsigned int version)