APAIORdWriter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: APAIORdWriter
3 // Plugin Type: analyzer (art v3_02_06)
4 // File: APAIORdWriter_module.cc
5 //
6 // Generated at Thu Aug 8 16:29:17 2019 by Thomas Junk using cetskelgen
7 // from cetlib version v3_07_02.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 #include "TSystem.h"
20 #include "TROOT.h"
21 #include "TString.h"
23 
24 class APAIORdWriter;
25 
26 
28 public:
29  explicit APAIORdWriter(fhicl::ParameterSet const& p);
30  // The compiler-generated destructor is fine for non-base
31  // classes without bare pointers or other resource use.
32 
33  // Plugins should not be copied or assigned.
34  APAIORdWriter(APAIORdWriter const&) = delete;
35  APAIORdWriter(APAIORdWriter&&) = delete;
36  APAIORdWriter& operator=(APAIORdWriter const&) = delete;
38 
39  // Required functions.
40  void analyze(art::Event const& e) override;
41 
42 private:
43 
44  // Declare member data here.
45 
48 
49 };
50 
51 
53  : EDAnalyzer{p} // ,
54  // More initializers here.
55 {
56  // Call appropriate consumes<>() for any products to be retrieved by this module.
57 
58  fRawDigitLabel = p.get<std::string>("RawDigitLabel","daq");
59  fOutputDirBaseName = p.get<std::string>("OutputDirBaseName","APAIO");
60  consumes<std::vector<raw::RawDigit>>(fRawDigitLabel);
61 }
62 
64 {
65  auto runno = e.run();
66  auto subrunno = e.subRun();
67  auto eventno = e.event();
68 
69  auto rdighandle = e.getValidHandle<std::vector<raw::RawDigit>>(fRawDigitLabel);
70  if (rdighandle->size()==0) return;
71 
72  TString outdir=fOutputDirBaseName;
73  outdir += "r";
74  TString rnst="";
75  rnst.Form("%08d",runno);
76  outdir += rnst;
77  outdir += "s";
78  TString srnst="";
79  srnst.Form("%05d",subrunno);
80  outdir += srnst;
81  outdir += "e";
82  TString est="";
83  est.Form("%08d",eventno);
84  outdir += est;
85 
86  TString cmd;
87  cmd = "touch " + outdir;
88  gSystem->Exec(cmd); // todo -- test these system commands for failure
89  cmd = "rm -rf " + outdir;
90  gSystem->Exec(cmd);
91  cmd = "mkdir " + outdir;
92  gSystem->Exec(cmd);
93 
94  // todo -- get these from the geometry
95  size_t napas = 150;
96  size_t nchans_per_apa = 2560;
97 
98  size_t version = 1; // data format version
99 
100  // todo -- make an index of channel ID's found in the raw digits and sort them. Then look in the sorted vector using lower_bound
101  // so we don't have to do a double loop of APAs*channels. This may be fast enough as is.
102 
103  for (uint32_t iapaindex = 0; iapaindex < napas; ++iapaindex)
104  {
105  //std::cout << "Writing output for apa: " << iapaindex << std::endl;
106  FILE *ofile=NULL;
107  TString ofilename=outdir;
108  ofilename += "/apa";
109  TString apast="";
110  apast.Form("%03d",iapaindex);
111  ofilename += apast;
112  for (auto const& rawdigit : *rdighandle)
113  {
114  uint32_t chan = rawdigit.Channel();
115  uint32_t apa = chan / nchans_per_apa;
116  if (apa == iapaindex)
117  {
118  if (ofile == NULL)
119  {
120  ofile = fopen(ofilename,"w");
121  }
122  fwrite(&version,sizeof(version),1,ofile);
123  fwrite(&chan,sizeof(chan),1,ofile);
124  uint32_t samples = rawdigit.Samples();
125  fwrite(&samples,sizeof(samples),1,ofile);
126  raw::Compress_t compression = rawdigit.Compression();
127  fwrite(&compression,sizeof(compression),1,ofile);
128  float pedestal = rawdigit.GetPedestal();
129  float sigma = rawdigit.GetSigma();
130  fwrite (&pedestal,sizeof(pedestal),1,ofile);
131  fwrite (&sigma,sizeof(sigma),1,ofile);
132 
133  // todo: optionally compress data further
134  auto adcs = rawdigit.ADCs();
135  uint32_t nadc = adcs.size();
136  fwrite(&nadc,sizeof(nadc),1,ofile);
137  //std::cout << "writing " << adcs.size() << " adcs with size: " << sizeof(adcs.front()) << " for channel: " << chan << std::endl;
138  fwrite(adcs.data(),sizeof(adcs.front()),adcs.size(),ofile);
139  }
140  }
141  if (ofile != NULL) fclose(ofile);
142  }
143 }
144 
EventNumber_t event() const
Definition: DataViewImpl.cc:85
enum raw::_compress Compress_t
std::string string
Definition: nybbler.cc:12
Definition of basic raw digits.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::string fOutputDirBaseName
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
std::string fRawDigitLabel
RunNumber_t run() const
Definition: DataViewImpl.cc:71
void analyze(art::Event const &e) override
APAIORdWriter & operator=(APAIORdWriter const &)=delete
p
Definition: test.py:223
APAIORdWriter(fhicl::ParameterSet const &p)
list cmd
Definition: getreco.py:22