LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LArRawInputDriverJP250L.cxx
Go to the documentation of this file.
1 
9 
14 
17 
18 extern "C" {
19 #include <sys/types.h>
20 #include <dirent.h>
21 }
22 
23 // ======================================================================
24 // JP250L conversion of raw DAQ file to ART format
25 
26 namespace lris {
27  // ======================================================================
28  // class c'tor/d'tor:
31  art::SourceHelper const &pm)
32  : principalMaker_(pm)
33  , m_current(0)
34  , m_data(0)
35  {
37  helper.reconstitutes<std::vector<raw::RawDigit>, art::InEvent>("daq");
38  helper.reconstitutes<sumdata::RunData, art::InRun> ("daq");
39  }
40 
41  // ======================================================================
43  {
44  delete [] m_data;
45  }
46 
47  // ======================================================================
48  void LArRawInputDriverJP250L::readFile(std::string const &name,
50  {
51  TFile m_f(name.c_str());
52  TTree* runTree = dynamic_cast<TTree*>(m_f.Get("runTree"));
53 
54  m_eventTree = dynamic_cast<TTree*>(m_f.Get("eventTree"));
55  m_eventTree->SetDirectory(0);
56  m_nEvent = m_eventTree->GetEntries();
57 
58  // run information
59  runTree->SetBranchAddress("runID",&m_runID);
60  runTree->SetBranchAddress("unixtime",&m_unixtime);
61  runTree->SetBranchAddress("nChannels",&m_nChannels);
62  runTree->SetBranchAddress("nSamples",&m_nSamples);
63  runTree->GetEntry(0);
64 
65  // have to add 1 to the runID because it can't be zero
66  // adding 1 to every runID ensures that all runIDs are bumped in the same way
67  m_runID += 1;
68 
69  const int nLength=(m_nSamples+4)*m_nChannels;
70  m_data = new unsigned short[nLength];
71  m_eventTree->SetBranchAddress("data",m_data);
72 
73  // Fill and return a new Fileblock.
74  // The string tells you what the version of the LArRawInputDriver is
75  fb = new art::FileBlock(art::FileFormatVersion(1, "LArRawInputJP250L 2013_01"),
76  name);
77 
78 
79  return;
80  }
81 
82  // ======================================================================
84  art::SubRunPrincipal* const & /* inSR */,
85  art::RunPrincipal* &outR,
86  art::SubRunPrincipal* &outSR,
87  art::EventPrincipal* &outE)
88  {
89 
90  if(m_current > m_nEvent) return false;
91 
92  m_eventTree->GetEntry(m_current);
93 
94  raw::DAQHeader daqHeader;
95  daqHeader.SetRun(m_runID);
96  daqHeader.SetTimeStamp(m_unixtime);
97  daqHeader.SetNChannels(m_nChannels);
98  // set the event number to start at 1 - ART likes to start numbering
99  // things from 1
100  daqHeader.SetEvent(m_current+1);
101 
102  // the following DAQHeader fields are not used by JP250L at this time
103  //daqHeader.SetStatus(1);
104  //daqHeader.SetFixedWord(h1.fixed);
105  //daqHeader.SetFileFormat(h1.format);
106  //daqHeader.SetSoftwareVersion(h1.software);
107  //daqHeader.SetSpareWord(h1.spare);
108 
109  // make unique_ptrs for the data products to store in the event
110  std::unique_ptr<raw::DAQHeader> daqcol( new raw::DAQHeader(daqHeader) );
111  std::unique_ptr<std::vector<raw::RawDigit> > rdcol( new std::vector<raw::RawDigit> );
112 
113  // loop over the signals and break them into
114  // one RawDigit for each channel
115  std::vector<short> adcVec(m_nSamples,0);
116  for(unsigned int n = 0; n < m_nChannels; ++n){
117  adcVec.clear();
118  for(unsigned int i = 0; i < m_nSamples; ++i){
119  adcVec.push_back(m_data[(m_nSamples+4)*n+(4+i)]);
120  }
121  rdcol->push_back(raw::RawDigit(n,m_nSamples,adcVec));
122  }
123 
124  art::RunNumber_t rn = daqHeader.GetRun();
125  art::SubRunNumber_t sn = 1;
126  art::EventNumber_t en = daqHeader.GetEvent();
127  art::Timestamp tstamp = daqHeader.GetTimeStamp();
128 
129  // Make the Run and SubRun principals
130  // this step is done once per run.
131  if (m_current < 1){
132  std::unique_ptr<sumdata::RunData> rundata(new sumdata::RunData("jpl250l") );
133  outR = principalMaker_.makeRunPrincipal(rn, tstamp);
135  sn,
136  tstamp);
137  art::put_product_in_principal(std::move(rundata), *outR, "daq");
138  }
139 
140 
141  // make the Event principal
143  sn,
144  en,
145  tstamp);
146 
147  // Put products in the event.
148  // first argument places the desired data product in the file
149  // second argument is event record to associate it to
150  // third argument is the label of the module storing the
151  // information. "daq" is standard in LArSoft
152  art::put_product_in_principal(std::move(rdcol),
153  *outE,
154  "daq"); // Module label
155  art::put_product_in_principal(std::move(daqcol),
156  *outE,
157  "daq"); // Module label
158 
159  // increment the entry to get out of the TTree for the next time through the loop
160  ++m_current;
161 
162  return true;
163  }
164 
165 }
unsigned int m_unixtime
unix timestamp of the start of the run
unsigned int m_nEvent
number of triggers in the TTree
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:68
void SetRun(unsigned short i)
Definition: DAQHeader.h:95
std::enable_if_t< P::branch_type==InEvent||P::branch_type==InResults > put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
void readFile(std::string const &name, art::FileBlock *&fb)
unsigned short m_runID
run ID, has to start from 1
void SetTimeStamp(time_t t)
Definition: DAQHeader.h:98
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
Definition: SourceHelper.cc:59
Definition of basic raw digits.
LArRawInputDriverJP250L(fhicl::ParameterSet const &pset, art::ProductRegistryHelper &helper, art::SourceHelper const &pm)
TTree * m_eventTree
TTree containing information from each trigger.
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:36
Source to convert JP250L files to LArSoft files.
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
TFile fb("Li6.root")
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
void SetNChannels(uint32_t i)
Definition: DAQHeader.h:100
unsigned short * m_data
the ADC of each time sample for each channel
bool readNext(art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
unsigned short m_nChannels
number of channels in the detector
unsigned short m_nSamples
number of time samples per channel
Conversion of binary data to root files.
unsigned short GetRun() const
Definition: DAQHeader.h:105
art::SourceHelper const & principalMaker_
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
unsigned short GetEvent() const
Definition: DAQHeader.h:107
Char_t n[5]
unsigned int m_current
current entry in the TTree
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::shared_ptr< History > &&history) const
Definition: SourceHelper.cc:83
void SetEvent(unsigned short i)
Definition: DAQHeader.h:97
art framework interface to geometry description
time_t GetTimeStamp() const
Definition: DAQHeader.h:108
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119