PDSPNearlineHeader_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 // Header module //
3 // Saves the run and subrun ids and the time of first event into a TTree //
4 // May 2018 //
5 // georgios.christodoulou <at> cern.ch //
6 ///////////////////////////////////////////////////////////////////////////
7 
8 #ifndef PDSPNearlineHeader_module
9 #define PDSPNearlineHeader_module
10 
11 // Framework includes
16 #include "art_root_io/TFileService.h"
18 #include "fhiclcpp/ParameterSet.h"
19 
20 // ROOT includes
21 #include "TTree.h"
22 #include "TFile.h"
23 #include "TString.h"
24 #include "TTimeStamp.h"
25 
26 // C++ Includes
27 #include <fstream>
28 #include <string>
29 #include <sstream>
30 #include <cmath>
31 #include <algorithm>
32 #include <iostream>
33 #include <vector>
34 
36 
38  public:
39 
40  explicit PDSPNearlineHeaderModule(fhicl::ParameterSet const& pset);
41  virtual ~PDSPNearlineHeaderModule();
42 
43  void beginJob();
44  void analyze(const art::Event& evt);
45 
46  private:
47 
48  int fRun;
49  int fSubRun;
50  //uint64_t fTimeStamp;
51  double fTimeStamp;
52 
54 
55  std::vector<TString> runset;
56 
57  };
58 
59 
60  //-----------------------------------------------------------------------
62 
64 
65  // Define output tree
66  fPDSPNearlineHeaderTree = tfs->make<TTree>("PDSPNearlineHeader", "PDSP Nearline header tree");
67  fPDSPNearlineHeaderTree->Branch("fRun", &fRun, "fRun/I");
68  fPDSPNearlineHeaderTree->Branch("fSubRun", &fSubRun, "fSubRun/I");
69  fPDSPNearlineHeaderTree->Branch("fTimeStamp", &fTimeStamp, "fTimeStamp/D");
70  }
71 
72  //-----------------------------------------------------------------------
74 
75  //-----------------------------------------------------------------------
77 
78  //-----------------------------------------------------------------------
80 
81  fRun = evt.run();
82  fSubRun = evt.subRun();
83  //fTimeStamp = evt.time().value();
84 
85  art::Timestamp ts = evt.time();
86  //std::cout<<ts.timeHigh()<<" "<<ts.timeLow()<<std::endl;
87  if (ts.timeHigh() == 0){
88  TTimeStamp ts2(ts.timeLow());
89  fTimeStamp = ts2.AsDouble();
90  }
91  else{
92  TTimeStamp ts2(ts.timeHigh(), ts.timeLow());
93  fTimeStamp = ts2.AsDouble();
94  }
95 
96  TString tempstring = Form("%i-%i",fRun,fSubRun);
97 
98  int num_items = std::count(runset.begin(), runset.end(), tempstring);
99  if(num_items == 0){ // run-subrun not in vector - add it and save
100  runset.push_back(tempstring);
101  fPDSPNearlineHeaderTree->Fill();
102  }
103  }
104 } // namespace
105 
107 
108 #endif
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Timestamp time() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
TCEvent evt
Definition: DataStructs.cxx:7