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