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