PTBToOffline_module.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 ////////////////////////////////////////////////////////////////////////
3 // Class: PTBToOffline
4 // Module Type: producer
5 // File: PTBToOffline_module.cc
6 //
7 // Repackage PTB data into External Trigger data products
8 //
9 // Karl Warburton k.warburton@sheffield.ac.uk
10 //
11 ////////////////////////////////////////////////////////////////////////
12 
20 #include "fhiclcpp/ParameterSet.h"
22 
23 #include <memory>
24 #include <iostream>
25 #include <map>
26 
27 //lbne-artdaq includes
28 #include "lbne-raw-data/Overlays/PennMilliSlice.hh"
29 #include "lbne-raw-data/Overlays/PennMicroSlice.hh"
30 #include "artdaq-core/Data/Fragment.hh"
31 
32 //larsoft includes
33 #include "lardataobj/RawData/raw.h"
36 
37 //daqinput35t includes
38 
40 #include "PennToOffline.h"
41 
42 namespace DAQToOffline {
43  class PTBToOffline;
44 }
45 
47 public:
48  explicit PTBToOffline(fhicl::ParameterSet const & pset);
49  // The destructor generated by the compiler is fine for classes
50  // without bare pointers or other resource use.
51 
52  // Plugins should not be copied or assigned.
53  PTBToOffline(PTBToOffline const &) = delete;
54  PTBToOffline(PTBToOffline &&) = delete;
55  PTBToOffline & operator = (PTBToOffline const &) = delete;
56  PTBToOffline & operator = (PTBToOffline &&) = delete;
57  void produce(art::Event & evt) override;
58  void reconfigure(fhicl::ParameterSet const& pset);
59  void printParameterSet();
60 
61 private:
62 
66  double fNOvAClockFrequency; //MHz
69 
70  std::map<int,int> fPTBMap;
71 };
72 
73 
75 : EDProducer(pset)
76 {
77 
78  this->reconfigure(pset);
79 
80  produces< std::vector<raw::ExternalTrigger> > (fOutputDataLabel);
81 
82  //first_FirstSample = -1;
83  //first_TimeStamp = -1;
84 }
85 
87 
88  fFragType = pset.get<std::string>("FragType");
89  fRawDataLabel = pset.get<std::string>("RawDataLabel");
90  fOutputDataLabel = pset.get<std::string>("OutputDataLabel");
91  fNOvAClockFrequency = pset.get<double>("NOvAClockFrequency"); // in MHz
92  fPTBMapFile = pset.get<std::string>("PTBMapFile");
93  fPTBMapDir = pset.get<std::string>("PTBMapDir");
94 
96 
97  BuildPTBChannelMap(fPTBMapDir, fPTBMapFile, fPTBMap);
98 }
99 
101 
102  mf::LogDebug("PTBToOffline") << "====================================" << "\n"
103  << "Parameter Set" << "\n"
104  << "====================================" << "\n"
105  << "fFragType: " << fFragType << "\n"
106  << "fRawDataLabel: " << fRawDataLabel << "\n"
107  << "fOutputDataLabel: " << fOutputDataLabel << "\n"
108  << "====================================" << "\n";
109 }
110 
111 
113 {
114 
115  art::Handle<artdaq::Fragments> rawFragments;
116  evt.getByLabel(fRawDataLabel, fFragType, rawFragments);
117 
118  // Check if there is PTB data in this event
119  // Don't crash code if not present, just don't save anything
120  try { rawFragments->size(); }
121  catch(std::exception const&) {
122  mf::LogWarning("PTBToOffline") << "WARNING: Raw PTB data not found in event " << evt.event();
123  std::vector<raw::ExternalTrigger> Triggers;
124  evt.put(std::make_unique<std::vector<raw::ExternalTrigger>>(std::move(Triggers)), fOutputDataLabel);
125  return;
126  }
127 
128  // Check that the data is valid
129  if(!rawFragments.isValid()){
130  mf::LogError("PTBToOffline") << "Run: " << evt.run()
131  << ", SubRun: " << evt.subRun()
132  << ", Event: " << evt.event()
133  << " is NOT VALID";
134  throw cet::exception("raw NOT VALID");
135  return;
136  }
137 
138  lbne::PennMicroSlice::Payload_Timestamp *FirstPTBTimestamp = nullptr;
139  auto triggers = PennFragmentToExternalTrigger(*rawFragments, fPTBMap, FirstPTBTimestamp);
140 
141  std::cout << "Returned from PennFragmentToExternalTriggers and triggers has size " << triggers.size() << std::endl;
142 
143  evt.put(std::make_unique<decltype(triggers)>(std::move(triggers)), fOutputDataLabel);
144 }
145 
EventNumber_t event() const
Definition: DataViewImpl.cc:96
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void BuildPTBChannelMap(std::string MapDir, std::string MapFile, std::map< int, int > &channelMap)
void produce(art::Event &evt) override
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool isValid() const
Definition: Handle.h:183
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
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
std::map< int, int > fPTBMap
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
RunNumber_t run() const
Definition: DataViewImpl.cc:82
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
PTBToOffline & operator=(PTBToOffline const &)=delete
PTBToOffline(fhicl::ParameterSet const &pset)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TCEvent evt
Definition: DataStructs.cxx:7
std::vector< raw::ExternalTrigger > PennFragmentToExternalTrigger(artdaq::Fragments const &Fragments, std::map< int, int > &channelMap, lbne::PennMicroSlice::Payload_Timestamp *&FirstPTBTimestamp)
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
void reconfigure(fhicl::ParameterSet const &pset)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)