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