PackedDump_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: PackedDump
3 // Plugin Type: analyzer (art v2_10_03)
4 // File: PackedDump_module.cc
5 //
6 // Generated at Thu Jun 14 08:21:34 2018 by Philip Rodrigues using cetskelgen
7 // from cetlib version v3_02_00.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
22 
23 #include <fstream>
24 #include <arpa/inet.h>
25 
26 class PackedDump;
27 
28 
29 class PackedDump : public art::EDAnalyzer {
30 public:
31  explicit PackedDump(fhicl::ParameterSet const & p);
32  // The compiler-generated destructor is fine for non-base
33  // classes without bare pointers or other resource use.
34 
35  // Plugins should not be copied or assigned.
36  PackedDump(PackedDump const &) = delete;
37  PackedDump(PackedDump &&) = delete;
38  PackedDump & operator = (PackedDump const &) = delete;
39  PackedDump & operator = (PackedDump &&) = delete;
40 
41  // Required functions.
42  void analyze(art::Event const & e) override;
43 
44 private:
45 
48  std::ofstream m_outputFile;
49 };
50 
51 
53  :
54  EDAnalyzer(p),
55  m_outputFilename(p.get<std::string>("OutputFile")),
56  m_outputFile(m_outputFilename, std::ios::out | std::ios::binary)
57 {
58  // A little test code to check we can do the bit packing properly
59 
60  // const size_t nsamples=16;
61  // const uint16_t samples[nsamples]={
62  // 0, 1, 2, 3, 4, 5, 6, 7,
63  // 8, 9, 10, 11, 12, 13, 14, 15
64  // };
65  // for(size_t i=0; i<nsamples; i+=8){
66  // uint32_t word0=samples[i] | (samples[i+1] << 12) | (samples[i+2] << 24);
67  // uint32_t word1=(samples[i+2] >> 4) | (samples[i+3] << 4) | (samples[i+4] << 16) | (samples[i+5] << 28);
68  // uint32_t word2=(samples[i+5] >> 4) | (samples[i+6] << 8) | (samples[i+7] << 20);
69 
70  // m_outputFile.write((char*)&word0, sizeof(uint32_t));
71  // m_outputFile.write((char*)&word1, sizeof(uint32_t));
72  // m_outputFile.write((char*)&word2, sizeof(uint32_t));
73 
74  // uint32_t word0_net=htonl(word0);
75  // uint32_t word1_net=htonl(word1);
76  // uint32_t word2_net=htonl(word2);
77 
78  // m_outputFile.write((char*)&word0_net, sizeof(uint32_t));
79  // m_outputFile.write((char*)&word1_net, sizeof(uint32_t));
80  // m_outputFile.write((char*)&word2_net, sizeof(uint32_t));
81  // }
82 }
83 
85 {
86  // Create a map from offline channel number to RawDigit
87  std::vector<const raw::RawDigit*> inputDigitsHandle;
88  std::map<unsigned int, const raw::RawDigit*> channelToDigit;
89  e.getView("daq", inputDigitsHandle);
90  for(size_t c=0; c<inputDigitsHandle.size(); ++c){
91  const raw::RawDigit* dig=inputDigitsHandle[c];
92  channelToDigit[dig->Channel()] = dig;
93  }
94 
95  // Set a bunch of these to 1 to just do a subset to start with
96  const size_t nCrate=1;
97  const size_t nSlot=1;
98  const size_t nFiber=1;
99  const size_t nFEMBChannel=128;
100  const size_t nTDC=4492;
101 
102  // We loop down to the level of a board and then, for a given
103  // board, emit frame. Each frame starts with 0xdeadbeef, followed
104  // by the tdc, followed by each 12-bit FMB channel value, in order
105  // of FEMB channel
106  for(unsigned int crate=0; crate<nCrate; ++crate){
107  for(unsigned int slot=0; slot<nSlot; ++slot){
108  for(unsigned int fiber=0; fiber<nFiber; ++fiber){
109  for(uint32_t tdc=0; tdc<nTDC; ++tdc){
110  uint32_t header=0xdeadbeef;
111  m_outputFile.write((char*)&header, sizeof(uint32_t));
112  m_outputFile.write((char*)&tdc, sizeof(uint32_t));
113  for(unsigned int fembChannel=0; fembChannel<nFEMBChannel-1; fembChannel+=8){
114 
115  unsigned short samples[8];
116  for(int i=0; i<8; ++i){
117  // args are: unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int fembchannel
118  unsigned int offlineChan=m_channelMap->GetOfflineNumberFromDetectorElements(crate, slot, fiber, fembChannel+i, dune::PdspChannelMapService::kRCE);
119  // std::cout << "Fiber " << fiber << " FEMB channel " << (fembChannel+8) << " maps to offline " << offlineChan << std::endl;
120  samples[i]=channelToDigit[offlineChan]->ADC(tdc);
121  }
122  uint32_t word0=samples[0] | (samples[1] << 12) | (samples[2] << 24);
123  uint32_t word1=(samples[2] >> 8) | (samples[3] << 4) | (samples[4] << 16) | (samples[5] << 28);
124  uint32_t word2=(samples[5] >> 4) | (samples[6] << 8) | (samples[7] << 20);
125 
126  m_outputFile.write((char*)&word0, sizeof(uint32_t));
127  m_outputFile.write((char*)&word1, sizeof(uint32_t));
128  m_outputFile.write((char*)&word2, sizeof(uint32_t));
129  }
130  }
131  }
132  }
133  }
134  uint32_t eof=0xffffffff;
135  m_outputFile.write((char*)&eof, sizeof(uint32_t));
136 }
137 
139 
140 // Local Variables:
141 // mode: c++
142 // c-basic-offset: 4
143 // End:
PackedDump & operator=(PackedDump const &)=delete
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
std::string string
Definition: nybbler.cc:12
art::ServiceHandle< dune::PdspChannelMapService > m_channelMap
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
void analyze(art::Event const &e) override
STL namespace.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
unsigned int GetOfflineNumberFromDetectorElements(unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int fembchannel, FelixOrRCE frswitch)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
struct dune::tde::crate crate
std::ofstream m_outputFile
p
Definition: test.py:223
PackedDump(fhicl::ParameterSet const &p)
std::string m_outputFilename
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:500
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115