PandaRoot
PndMQFileSink.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 PndMQFileSink_H_
28 #define PndMQFileSink_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 
40 #include "FairMQDevice.h"
41 #include "FairMQLogger.h"
42 
43 #include "PndSdsDigiTopix4.h"
44 
45 #include "baseMQtools.h"
46 
47 #include "TMessage.h"
48 
49 #ifndef __CINT__
50 #include <boost/thread.hpp>
51 #include <boost/bind.hpp>
52 #include <boost/serialization/access.hpp>
53 #include <boost/archive/text_iarchive.hpp>
54 #include <boost/archive/binary_iarchive.hpp>
55 #include <boost/serialization/vector.hpp>
56 #endif //__CINT__
57 
58 class TVector3;
59 class TFile;
60 class TTree;
61 class TClonesArray;
62 
63 using namespace std;
64 
65 class PndMQFileSink : public FairMQDevice {
66  public:
67  PndMQFileSink() : fOutFile(nullptr), fTree(nullptr), fOutput(nullptr), fHitVector(), fHasBoostSerialization(false)
68  {
69  gSystem->ResetSignal(kSigInterrupt);
70  gSystem->ResetSignal(kSigTermination);
71 
72  // Check if boost serialization is available if it is chosen
73  using namespace baseMQ::tools::resolve;
74  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
75  if (is_same<boost::archive::binary_iarchive, boost::archive::binary_iarchive>::value || is_same<boost::archive::binary_iarchive, boost::archive::text_iarchive>::value) {
76  if (has_BoostSerialization<PndSdsDigiTopix4, void(boost::archive::binary_iarchive &, const unsigned int)>::value == 1) {
77  fHasBoostSerialization = true;
78  }
79  }
80  }
81 
82  virtual ~PndMQFileSink()
83  {
84  fTree->Write();
85  fOutFile->Close();
86  if (fHitVector.size() > 0) {
87  fHitVector.clear();
88  }
89  }
90 
91  virtual void InitOutputFile(TString defaultId = "100")
92  {
93  fOutput = new TClonesArray("PndSdsDigiTopix4");
94 
95  fOutFile = new TFile("Filesink1.root", "recreate");
96  fTree = new TTree("MQOut", "Test output");
97  fTree->Branch("Output", "TClonesArray", &fOutput, 64000, 99);
98  }
99 
100  template <class Archive>
101  void serialize(Archive &ar, const unsigned int version)
102  {
103  ar &fHitVector;
104  }
105 
106  protected:
107  virtual void Run();
108 
109  private:
110  TFile *fOutFile;
111  TTree *fTree;
112  TClonesArray *fOutput;
113 
114 #ifndef __CINT__ // for BOOST serialization
115  friend class boost::serialization::access;
116  vector<PndSdsDigiTopix4> fHitVector;
117  bool fHasBoostSerialization;
118 #endif // for BOOST serialization
119 
121  // PndMQFileSink(const PndMQFileSink&);
122  // PndMQFileSink operator=(const PndMQFileSink&);
123 };
124 
125 #endif /* PndMQFileSink_H_ */
Data class to store the digi output of a pixel module.
STL namespace.
virtual void InitOutputFile(TString defaultId="100")
Definition: PndMQFileSink.h:91
virtual ~PndMQFileSink()
Definition: PndMQFileSink.h:82
void serialize(Archive &ar, const unsigned int version)