APAIORdReader_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: APAIORdReader
3 // Plugin Type: producer (art v3_02_06)
4 // File: APAIORdReader_module.cc
5 //
6 // Generated at Fri Aug 9 10:57:30 2019 by Thomas Junk using cetskelgen
7 // from cetlib version v3_07_02.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 class APAIORdReader;
20 #include "TSystem.h"
21 #include "TROOT.h"
22 #include "TString.h"
24 #include <memory>
25 
26 
28 public:
29  explicit APAIORdReader(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  APAIORdReader(APAIORdReader const&) = delete;
35  APAIORdReader(APAIORdReader&&) = delete;
36  APAIORdReader& operator=(APAIORdReader const&) = delete;
38 
39  // Required functions.
40  void produce(art::Event& e) override;
41 
42 private:
43 
44  // Declare member data here.
46  uint32_t fAPAmin;
47  uint32_t fAPAmax;
48 
49 };
50 
51 
53  : EDProducer{p} // ,
54 // More initializers here.
55 {
56  fInputDirBaseName = p.get<std::string>("InputDirBaseName","APAIO");
57  fAPAmin = p.get<uint32_t>("APAMin",0);
58  fAPAmax = p.get<uint32_t>("APAMax",150);
59  produces<std::vector<raw::RawDigit>>();
60 
61 }
62 
64 {
65  // Implementation of required member function here.
66 
67  std::unique_ptr<std::vector<raw::RawDigit>> digcol(new std::vector<raw::RawDigit>);
68 
69  auto runno = e.run();
70  auto subrunno = e.subRun();
71  auto eventno = e.event();
72 
73  TString inputdir=fInputDirBaseName;
74  inputdir += "r";
75  TString rnst="";
76  rnst.Form("%08d",runno);
77  inputdir += rnst;
78  inputdir += "s";
79  TString srnst="";
80  srnst.Form("%05d",subrunno);
81  inputdir += srnst;
82  inputdir += "e";
83  TString est="";
84  est.Form("%08d",eventno);
85  inputdir += est;
86  gSystem->ExpandPathName(inputdir);
87 
88  void* dirp = gSystem->OpenDirectory(inputdir);
89  const char* entry;
90 
91  size_t version=0;
92 
93  TString fullfilename = "";
94  while((entry = (char*)gSystem->GetDirEntry(dirp)))
95  {
96  TString str=entry;
97  if (str.Contains("apa"))
98  {
99  fullfilename = inputdir;
100  fullfilename += "/";
101  fullfilename += entry;
102  //std::cout << " APAIORdReader found file: " << fullfilename << std::endl;
103  FILE *infile = fopen(fullfilename,"r");
104  while (infile != NULL)
105  {
106  uint32_t chan=0;
107  uint32_t samples=0;
108  raw::Compress_t compression = raw::kNone;
109  float pedestal=0;
110  float sigma=0;
111  uint32_t nadc=0;
112 
113  fread(&version,sizeof(version),1,infile);
114  if (feof(infile)) break;
115 
116  fread(&chan,sizeof(chan),1,infile);
117  //std::cout << "chan: " << chan << std::endl;
118  uint32_t apanum = chan/2560;
119  if (apanum > fAPAmax || apanum < fAPAmin) break;
120 
121  fread(&samples,sizeof(samples),1,infile);
122  fread(&compression,sizeof(compression),1,infile);
123  fread (&pedestal,sizeof(pedestal),1,infile);
124  fread (&sigma,sizeof(sigma),1,infile);
125  fread(&nadc,sizeof(nadc),1,infile);
126  raw::RawDigit::ADCvector_t adcs(nadc);
127  fread(adcs.data(),sizeof(adcs.front()),adcs.size(),infile);
128  digcol->emplace_back(chan,samples,adcs,compression);
129  digcol->back().SetPedestal(pedestal,sigma);
130  }
131  if (infile != NULL) fclose(infile);
132  }
133  }
134  gSystem->FreeDirectory(dirp);
135  e.put(std::move(digcol));
136 }
137 
EventNumber_t event() const
Definition: DataViewImpl.cc:85
enum raw::_compress Compress_t
QList< Entry > entry
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void produce(art::Event &e) override
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
Definition of basic raw digits.
no compression
Definition: RawTypes.h:9
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
string infile
def move(depos, offset)
Definition: depos.py:107
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
std::string fInputDirBaseName
RunNumber_t run() const
Definition: DataViewImpl.cc:71
p
Definition: test.py:223
APAIORdReader(fhicl::ParameterSet const &p)
APAIORdReader & operator=(APAIORdReader const &)=delete
static QCString str