TpcDAQToOffline_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TpcDAQToOffline
3 // Module Type: producer
4 // File: TpcDAQToOffline_module.cc
5 //
6 // Generated at Mon Sep 1 10:00:30 2014 by Jonathan Davies using artmod
7 // from cetpkgsupport v1_06_02.
8 ////////////////////////////////////////////////////////////////////////
9 
10 // framework includes
18 #include "fhiclcpp/ParameterSet.h"
20 
21 #include "art_root_io/TFileService.h"
22 #include "art_root_io/TFileDirectory.h"
24 
25 // lbne-artdaq and lbne-raw-data includes
26 #include "lbne-raw-data/Overlays/TpcMilliSliceFragment.hh"
27 #include "lbne-raw-data/Services/ChannelMap/ChannelMapService.h"
28 #include "artdaq-core/Data/Fragment.hh"
30 
31 // larsoft includes
33 #include "lardataobj/RawData/raw.h"
35 #include "tpcFragmentToRawDigits.h"
37 
38 // C++
39 #include <memory>
40 #include <iostream>
41 #include <fstream>
42 #include <sstream>
43 #include <TTree.h>
44 
45 const int MaxSamples = 15000;
46 const int MaxChannels = 2048;
47 
48 namespace DAQToOffline {
49  class TpcDAQToOffline;
50 }
51 
53 public:
54  explicit TpcDAQToOffline(fhicl::ParameterSet const & pset);
55  // The destructor generated by the compiler is fine for classes
56  // without bare pointers or other resource use.
57 
58  // Plugins should not be copied or assigned.
59  TpcDAQToOffline(TpcDAQToOffline const &) = delete;
60  TpcDAQToOffline(TpcDAQToOffline &&) = delete;
61  TpcDAQToOffline & operator = (TpcDAQToOffline const &) = delete;
63  void produce(art::Event & evt) override;
64  void reconfigure(const fhicl::ParameterSet &pset);
65  void printParameterSet();
66  void beginJob() override;
67 private:
68  void Reset();
69 
74  bool fDebug;
75  bool fMakeTree;
76  raw::Compress_t fCompression; ///< compression type to use
77  unsigned int fZeroThreshold; ///< Zero suppression threshold
78 
80 
81  TTree* fTree;
82  int DigSize;
83  int NSamples;
87 };
88 
89 
91 
92  this->reconfigure(pset);
93 
94  produces< std::vector<raw::RawDigit> > (fOutputDataLabel);
95 
96 }
97 
99 
100  fFragType = pset.get<std::string>("FragType");
101  fRawDataLabel = pset.get<std::string>("RawDataLabel");
102  fOutputDataLabel = pset.get<std::string>("OutputDataLabel");
103  fUseChannelMap = pset.get<bool>("UseChannelMap");
104  fDebug = pset.get<bool>("Debug");
105  fMakeTree = pset.get<bool>("MakeTree");
106  fZeroThreshold=0;
108  if(fDebug) printParameterSet();
109 
110 }
111 
114  fTree = tfs->make<TTree>("FlatDigitTree","FlatDigitTree");
115  fTree->Branch("NSamples",&NSamples,"NSamples/I" );
116  fTree->Branch("DigSize" ,&DigSize, "DigSize/I" );
117  fTree->Branch("Channel" ,&Channel ,"Channel[DigSize]/F" );
118  fTree->Branch("Pedestal",&Pedestal,"Pedestal[DigSize]/F");
119  fTree->Branch("ADCs" ,&ADCs ,"ADCs[DigSize][15000]/F");
120 }
121 
123 
124  for(int i=0;i<20;i++) std::cout << "=";
125  std::cout << std::endl;
126  std::cout << "Parameter Set" << std::endl;
127  for(int i=0;i<20;i++) std::cout << "=";
128  std::cout << std::endl;
129 
130  std::cout << "fFragType: " << fFragType << std::endl;
131  std::cout << "fRawDataLabel: " << fRawDataLabel << std::endl;
132  std::cout << "fOutputDataLabel: " << fOutputDataLabel << std::endl;
133  std::cout << "fDebug: ";
134  if(fDebug) std::cout << "true" << std::endl;
135  else std::cout << "false" << std::endl;
136 
137  for(int i=0;i<20;i++) std::cout << "=";
138  std::cout << std::endl;
139 
140 
141 }
142 
144 {
145  art::Handle<artdaq::Fragments> rawFragments;
146  evt.getByLabel(fRawDataLabel, fFragType, rawFragments);
147 
148  art::EventNumber_t eventNumber = evt.event();
149 
150  // Check if there is RCE data in this event
151  // Don't crash code if not present, just don't save anything
152  try { rawFragments->size(); }
153  catch(std::exception const&) {
154  std::cout << "WARNING: Raw RCE data not found in event " << eventNumber << std::endl;
155  std::vector<raw::RawDigit> digits;
156  evt.put(std::make_unique<std::vector<raw::RawDigit>>(std::move(digits)), fOutputDataLabel);
157  return;
158  }
159 
160  //Check that the data is valid
161  if(!rawFragments.isValid()){
162  std::cerr << "Run: " << evt.run()
163  << ", SubRun: " << evt.subRun()
164  << ", Event: " << eventNumber
165  << " is NOT VALID" << std::endl;
166  throw cet::exception("rawFragments NOT VALID");
167  }
168 
169  lbne::TpcNanoSlice::Header::nova_timestamp_t firstTimestamp;
170  std::vector<std::pair< std::pair<unsigned int,unsigned int>, lbne::TpcNanoSlice::Header::nova_timestamp_t> > DigitsIndexList;
171  auto digits = tpcFragmentToRawDigits(*rawFragments, DigitsIndexList, firstTimestamp, fChannelMap, fUseChannelMap, fDebug, fCompression, fZeroThreshold);
172 
173  // Make a flat rce tree.....
174  Reset();
175  DigSize = digits.size();
176  NSamples = digits[0].Samples();
177  if (NSamples && fMakeTree) {
178  std::cout << "Digits has size " << digits.size() << " digits[0] has " << digits[0].Samples() << std::endl;
179  dune::DetPedestalDUNE pedestals("dune35t");
180  pedestals.SetDetName("dune35t");
181  pedestals.SetUseDefaults(false);
182  pedestals.SetUseDB(true);
183  pedestals.Update(evt.run());
184 
185  for (int dig=0; dig<DigSize; ++dig ) {
186  int Chan = digits[dig].Channel();
187  Channel[dig] = Chan;
188  Pedestal[dig] = pedestals.PedMean(Chan);
189  for (int tick=0; tick<NSamples; ++tick) {
190  ADCs[dig][tick] = digits[dig].ADC(tick);
191  }
192  }
193  fTree->Fill();
194  }
195 
197  std::cout << "JPD: this_time_stamp: " << this_time_stamp.value() << std::endl;
198  std::cout << "JPD: event.time().value(): " << evt.time().value() << std::endl;
199 
200  evt.put(std::make_unique<decltype(digits)>(std::move(digits)), fOutputDataLabel);
201 }
202 
204  for (int ii=0; ii<MaxChannels; ++ii) {
205  Channel[ii] = -1;
206  Pedestal[ii] = -1;
207  for (int kk=0; kk<MaxSamples; ++kk) {
208  ADCs[ii][kk] = -1;
209  }
210  }
211 }
212 
unsigned int fZeroThreshold
Zero suppression threshold.
void produce(art::Event &evt) override
EventNumber_t event() const
Definition: DataViewImpl.cc:96
enum raw::_compress Compress_t
void SetUseDefaults(bool f)
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
Definition of basic raw digits.
raw::Compress_t fCompression
compression type to use
no compression
Definition: RawTypes.h:9
constexpr TimeValue_t value() const
Definition: Timestamp.h:23
std::vector< raw::RawDigit > tpcFragmentToRawDigits(artdaq::Fragments const &rawFragments, std::vector< std::pair< std::pair< unsigned int, unsigned int >, lbne::TpcNanoSlice::Header::nova_timestamp_t > > &DigitsIndexList, lbne::TpcNanoSlice::Header::nova_timestamp_t &firstTimestamp, art::ServiceHandle< lbne::ChannelMapService > const &channelMap, bool useChannelMap, bool debug, raw::Compress_t compression, unsigned int zeroThreshold)
bool isValid() const
Definition: Handle.h:183
const int MaxSamples
virtual float PedMean(raw::ChannelID_t ch) const
Retrieve pedestal information.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
Timestamp time() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
art::Timestamp make_art_timestamp_from_nova_timestamp(lbne::TpcNanoSlice::Header::nova_timestamp_t this_nova_timestamp)
def move(depos, offset)
Definition: depos.py:107
Collect all the RawData header files together.
T get(std::string const &key) const
Definition: ParameterSet.h:231
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:74
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
RunNumber_t run() const
Definition: DataViewImpl.cc:82
const int MaxChannels
float ADCs[MaxChannels][MaxSamples]
art::ServiceHandle< lbne::ChannelMapService > fChannelMap
ChannelMappingService::Channel Channel
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
void reconfigure(const fhicl::ParameterSet &pset)
TCEvent evt
Definition: DataStructs.cxx:7
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
TpcDAQToOffline(fhicl::ParameterSet const &pset)
TpcDAQToOffline & operator=(TpcDAQToOffline const &)=delete
bool Update(uint64_t ts)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void SetDetName(std::string detName)