DataDumpHDF_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: DataDumpHDF
3 // Plugin Type: analyzer (art v3_03_01)
4 // File: DataDumpHDF_module.cc
5 //
6 // Generated at Tue Nov 19 13:37:52 2019 by Tingjun Yang using cetskelgen
7 // from cetlib version v3_08_00.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 #include "art_root_io/TFileService.h"
20 
24 
25 #include "TTree.h"
26 #include "TTimeStamp.h"
27 
28 #include <fstream>
29 #include <vector>
30 #include <algorithm>
31 
32 #include "hep_hpc/hdf5/File.hpp"
33 #include "hep_hpc/hdf5/Ntuple.hpp"
34 
35 using wire_nt_t = hep_hpc::hdf5::Ntuple<float>;
36 using evt_nt_t = hep_hpc::hdf5::Ntuple<unsigned int, double>;
37 
38 inline std::array<unsigned int, 3>
40 {
41  return { e.run(), e.subRun(), e.id().event() };
42 }
43 
45  art::Ptr<recob::Wire> const & w2){
46  return (w1->Channel()<w2->Channel());
47 }
48 
49 namespace pdune {
50  class DataDumpHDF;
51 }
52 
54 public:
55  explicit DataDumpHDF(fhicl::ParameterSet const& p);
56  // The compiler-generated destructor is fine for non-base
57  // classes without bare pointers or other resource use.
58 
59  // Plugins should not be copied or assigned.
60  DataDumpHDF(DataDumpHDF const&) = delete;
61  DataDumpHDF(DataDumpHDF&&) = delete;
62  DataDumpHDF& operator=(DataDumpHDF const&) = delete;
63  DataDumpHDF& operator=(DataDumpHDF&&) = delete;
64 
65  // Required functions.
66  void analyze(art::Event const& e) noexcept;
67  void beginJob();
68  virtual ~DataDumpHDF() noexcept;
69 
70 
71 protected:
72 
73 //geo::GeometryCore const* fGeom;
74  //TTree *fTree;
75  double evttime;
76 // std::vector<unsigned short> channel;
77 // std::vector<unsigned short> tick;
78 // std::vector<float> adc;
80 
81 };
82 
83 
85  : EDAnalyzer{p} // ,
86  // More initializers here.
87 {
88  // Call appropriate consumes<>() for any products to be retrieved by this module.
89 }
91 {
92 }
93 
94 
96 {
97 
98 //fGeom = &*(art::ServiceHandle<geo::Geometry>());
99 
100  hdffile = hep_hpc::hdf5::File(Form("r%d_e%d.h5",e.run(),e.event()), H5F_ACC_TRUNC);
101  auto event_id = get_eid(e);
102 
103  art::Timestamp ts = e.time();
104  if (ts.timeHigh() == 0){
105  TTimeStamp tts(ts.timeLow());
106  evttime = tts.AsDouble();
107  }
108  else{
109  TTimeStamp tts(ts.timeHigh(), ts.timeLow());
110  evttime = tts.AsDouble();
111  }
112 // channel.clear();
113 // tick.clear();
114 // adc.clear();
115 
116  //std::ofstream outfile (Form("r%de%d.txt",run,event));
117 
118  //wire_nt_t wiresigs(hdffile, "wiresigs", {{"eid",4}});
119  wire_nt_t wiresigs(hdffile, "wiresigs", {"adc"});
120  evt_nt_t evtids(hdffile, "evtids", {{"eid",3}, "evttime"});
121  evtids.insert(event_id.data(), evttime);
122 
123  art::InputTag itag("caldata","dataprep");
124  std::vector < art::Ptr < recob::Wire > > wires;
125  auto wireListHandle = e.getHandle < std::vector < recob::Wire > >(itag);
126  if (wireListHandle) {
127  art::fill_ptr_vector(wires, wireListHandle);
128  }
129 
130  std::sort(wires.begin(), wires.end(), chIncrease);
131 // auto const& wires =
132 // e.getValidHandle<std::vector<recob::Wire> >("caldata:dataprep");
133 // //std::vector<recob::Wire> const& wireVector(*wires);
134 
135  for (auto & wire : wires){
136  int channel = wire->Channel();
137  if (!((channel>=2080 && channel < 2560)||
138  (channel>=7200 && channel < 7680)||
139  (channel>=12320 && channel < 12800))) continue;
140  if (channel%1000==0) std::cout<<"Channel = "<<channel<<std::endl;
141 
142  const recob::Wire::RegionsOfInterest_t& signalROI = wire->SignalROI();
143  int lasttick = 0;
144  for(const auto& range : signalROI.get_ranges()){
145  const auto& waveform = range.data();
146  // ROI start time
147  raw::TDCtick_t roiFirstBinTick = range.begin_index();
148  for (int i = lasttick; i<roiFirstBinTick; ++i){
149  wiresigs.insert(0.);
150  }
151  for(size_t idx = 0; idx < waveform.size(); idx++){
152  wiresigs.insert(waveform[idx]);
153  ++lasttick;
154  }
155  }
156  for (int i = lasttick; i<6000; ++i){
157  wiresigs.insert(0.);
158  }
159  }
160 // int nticks = wire->Signal().size();
161 // for (int j = 0; j < nticks; j++){
162 // float adc = wire->Signal()[j];
163 // wiresigs.insert(adc);
164 // }
165 // if (nticks <6000){
166 // for (int j = nticks; j < 6000; j++)
167 // wiresigs.insert(0.);
168 // }
169 
170  std::cout<<"event_time: "<<evttime<<std::endl;
171 
172 }
173 
175 {
176 }
177 
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
void analyze(art::Event const &e) noexcept
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
uint8_t channel
Definition: CRTFragment.hh:201
hep_hpc::hdf5::File hdffile
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
bool chIncrease(art::Ptr< recob::Wire > const &w1, art::Ptr< recob::Wire > const &w2)
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
virtual ~DataDumpHDF() noexcept
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:231
hep_hpc::hdf5::Ntuple< float > wire_nt_t
DataDumpHDF & operator=(DataDumpHDF const &)=delete
std::array< unsigned int, 3 > get_eid(art::Event const &e)
p
Definition: test.py:223
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
DataDumpHDF(fhicl::ParameterSet const &p)
hep_hpc::hdf5::Ntuple< unsigned int, double > evt_nt_t
EventNumber_t event() const
Definition: EventID.h:116
Declaration of basic channel signal object.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
EventID id() const
Definition: Event.cc:34
QTextStream & endl(QTextStream &s)