PandaRoot
PndMQFileSamplerHits.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 PndMQFileSamplerHits_H_
16 #define PndMQFileSamplerHits_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/binary_oarchive.hpp>
44 #include <boost/serialization/vector.hpp>
45 #endif //__CINT__
46 
47 class TVector3;
48 class TFile;
49 class TTree;
50 class TClonesArray;
51 
52 using namespace std;
53 
54 class PndMQFileSamplerHits : public FairMQDevice {
55  public:
56  public:
57  enum { InputFile = FairMQDevice::Last, Last };
58 
59  PndMQFileSamplerHits(std::string inputFileName = "")
60  : fInFile(nullptr), fTree(nullptr), fInput(nullptr), fHitVector(), fHasBoostSerialization(false), fInputFileName(inputFileName), fBranchNameList(0)
61  {
62  gSystem->ResetSignal(kSigInterrupt);
63  gSystem->ResetSignal(kSigTermination);
64 
65  // Check if boost serialization is available if it is chosen
66  using namespace baseMQ::tools::resolve;
67  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
68  if (is_same<boost::archive::binary_oarchive, boost::archive::binary_oarchive>::value) {
69  if (has_BoostSerialization<PndSdsHit, void(boost::archive::binary_oarchive &, const unsigned int)>::value == 1) {
70  fHasBoostSerialization = true;
71  }
72  }
73  }
74 
76  {
77  // fBranchNameList->Write("BranchList", TObject::kSingleKey);
78  // fTree->Write();
79  fInFile->Close();
80  if (fHitVector.size() > 0) {
81  fHitVector.clear();
82  }
83  }
84 
85  virtual void SetFileName(std::string fileName) { fInputFileName = fileName; }
86 
87  virtual void InitInputFile()
88  {
89  fInput = new TClonesArray("PndSdsHit");
90 
91  fInFile = new TFile(fInputFileName.c_str(), "read");
92  fTree = (TTree *)fInFile->Get("pndsim");
93  fTree->SetBranchAddress("Output", &fInput);
94  }
95 
96  template <class Archive>
97  void serialize(Archive &ar, const unsigned int version)
98  {
99  ar &fHitVector;
100  }
101 
102  void SetProperty(const int key, const std::string &value)
103  {
104  switch (key) {
105  case InputFile: fInputFileName = value; break;
106  default: FairMQDevice::SetProperty(key, value); break;
107  }
108  }
109 
110  std::string GetProperty(const int key, const std::string &default_ /*= ""*/)
111  {
112  switch (key) {
113  case InputFile: return fInputFileName;
114  default: return FairMQDevice::GetProperty(key, default_);
115  }
116  }
117 
118  protected:
119  virtual void Run();
120 
121  private:
122  TFile *fInFile;
123  TTree *fTree;
124  TClonesArray *fInput;
125  TList *fBranchNameList;
126  std::string fInputFileName;
127 
128 #ifndef __CINT__ // for BOOST serialization
129  friend class boost::serialization::access;
130  // vector<PndSdsHit> fHitVector;
131  vector<vector<PndSdsHit>> fHitVector;
132  bool fHasBoostSerialization;
133 #endif // for BOOST serialization
134 
136  // PndMQFileSamplerHits(const PndMQFileSamplerHits&);
137  // PndMQFileSamplerHits operator=(const PndMQFileSamplerHits&);
138 };
139 
140 #endif /* PndMQFileSamplerHits_H_ */
virtual void SetFileName(std::string fileName)
void serialize(Archive &ar, const unsigned int version)
STL namespace.
virtual void InitInputFile()
void SetProperty(const int key, const std::string &value)
std::string GetProperty(const int key, const std::string &default_)
PndMQFileSamplerHits(std::string inputFileName="")