PandaRoot
PndMQFileSamplerHits.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 /********************************************************************************
14  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
15  * *
16  * This software is distributed under the terms of the *
17  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
18  * copied verbatim in the file "LICENSE" *
19  ********************************************************************************/
27 #ifndef PndMQFileSamplerHits_H_
28 #define PndMQFileSamplerHits_H_
29 
30 #include <iostream>
31 
32 #include "Rtypes.h"
33 #include "TFile.h"
34 #include "TTree.h"
35 #include "TClonesArray.h"
36 #include "TVector3.h"
37 #include "TString.h"
38 #include "TSystem.h"
39 #include "TList.h"
40 #include "TObjString.h"
41 
42 #include "FairMQDevice.h"
43 #include "FairMQLogger.h"
44 
45 #include "PndSdsHit.h"
46 
47 #include "baseMQtools.h"
48 
49 #include "TMessage.h"
50 
51 #ifndef __CINT__
52 #include <boost/thread.hpp>
53 #include <boost/bind.hpp>
54 #include <boost/serialization/access.hpp>
55 #include <boost/archive/binary_oarchive.hpp>
56 #include <boost/serialization/vector.hpp>
57 #endif //__CINT__
58 
59 class TVector3;
60 class TFile;
61 class TTree;
62 class TClonesArray;
63 
64 using namespace std;
65 
66 class PndMQFileSamplerHits : public FairMQDevice {
67  public:
68  public:
69  enum { InputFile = FairMQDevice::Last, Last };
70 
71  PndMQFileSamplerHits(std::string inputFileName = "")
72  : fInFile(nullptr), fTree(nullptr), fInput(nullptr), fHitVector(), fHasBoostSerialization(false), fInputFileName(inputFileName), fBranchNameList(0)
73  {
74  gSystem->ResetSignal(kSigInterrupt);
75  gSystem->ResetSignal(kSigTermination);
76 
77  // Check if boost serialization is available if it is chosen
78  using namespace baseMQ::tools::resolve;
79  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
80  if (is_same<boost::archive::binary_oarchive, boost::archive::binary_oarchive>::value) {
81  if (has_BoostSerialization<PndSdsHit, void(boost::archive::binary_oarchive &, const unsigned int)>::value == 1) {
82  fHasBoostSerialization = true;
83  }
84  }
85  }
86 
88  {
89  // fBranchNameList->Write("BranchList", TObject::kSingleKey);
90  // fTree->Write();
91  fInFile->Close();
92  if (fHitVector.size() > 0) {
93  fHitVector.clear();
94  }
95  }
96 
97  virtual void SetFileName(std::string fileName) { fInputFileName = fileName; }
98 
99  virtual void InitInputFile()
100  {
101  fInput = new TClonesArray("PndSdsHit");
102 
103  fInFile = new TFile(fInputFileName.c_str(), "read");
104  fTree = (TTree *)fInFile->Get("pndsim");
105  fTree->SetBranchAddress("Output", &fInput);
106  }
107 
108  template <class Archive>
109  void serialize(Archive &ar, const unsigned int version)
110  {
111  ar &fHitVector;
112  }
113 
114  void SetProperty(const int key, const std::string &value)
115  {
116  switch (key) {
117  case InputFile: fInputFileName = value; break;
118  default: FairMQDevice::SetProperty(key, value); break;
119  }
120  }
121 
122  std::string GetProperty(const int key, const std::string &default_ /*= ""*/)
123  {
124  switch (key) {
125  case InputFile: return fInputFileName;
126  default: return FairMQDevice::GetProperty(key, default_);
127  }
128  }
129 
130  protected:
131  virtual void Run();
132 
133  private:
134  TFile *fInFile;
135  TTree *fTree;
136  TClonesArray *fInput;
137  TList *fBranchNameList;
138  std::string fInputFileName;
139 
140 #ifndef __CINT__ // for BOOST serialization
141  friend class boost::serialization::access;
142  // vector<PndSdsHit> fHitVector;
143  vector<vector<PndSdsHit>> fHitVector;
144  bool fHasBoostSerialization;
145 #endif // for BOOST serialization
146 
148  // PndMQFileSamplerHits(const PndMQFileSamplerHits&);
149  // PndMQFileSamplerHits operator=(const PndMQFileSamplerHits&);
150 };
151 
152 #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="")