Jpp
Functions
io_online.hh File Reference
#include "Evt.hh"
#include "Hit.hh"
#include "Trk.hh"
#include "Exception.hh"
#include "../online/JDAQEvent.hh"
#include "../online/JDAQKeyHit.hh"
#include "../online/JDAQTimeslice.hh"
#include "../online/JDAQSummaryslice.hh"
#include "TStreamerInfo.h"
#include "TFile.h"
#include "TTree.h"
#include <map>
#include <vector>

Go to the source code of this file.

Functions

void read (Hit &hit, const JDAQHit &daqhit)
 Read a hit from a DAQ hit. More...
 
void read (Hit &hit, const JDAQKeyHit &daqhit)
 Read a hit from a DAQ key hit. More...
 
void read (Evt &evt, const JDAQEvent &de)
 Read an event from a DAQ event. More...
 
void read (Evt &evt, const JDAQTimeslice &ts)
 Read an event from a DAQ time slice. More...
 
JDAQSummarysliceget_summary_slice (TFile *f, int frame_index)
 Get summary slice from given file with given frame index. More...
 

Function Documentation

◆ read() [1/4]

void read ( Hit hit,
const JDAQHit daqhit 
)
inline

Read a hit from a DAQ hit.

Parameters
hithit
daqhitDAQ hit

Definition at line 30 of file io_online.hh.

31 {
32  hit.channel_id = daqhit.getPMT();
33  hit.tot = daqhit.getToT();
34  hit.t = daqhit.getT();
35 }

◆ read() [2/4]

void read ( Hit hit,
const JDAQKeyHit daqhit 
)
inline

Read a hit from a DAQ key hit.

Parameters
hithit
daqhitDAQ key hit

Definition at line 43 of file io_online.hh.

44 {
45  hit.id = hit.pmt_id = 0;
46 
47  hit.dom_id = daqhit.getModuleID();
48  hit.channel_id = daqhit.getPMT();
49  hit.tot = daqhit.getToT();
50  hit.t = daqhit.getT();
51 }

◆ read() [3/4]

void read ( Evt evt,
const JDAQEvent de 
)
inline

Read an event from a DAQ event.

Parameters
evtevt
deDAQ event

Definition at line 59 of file io_online.hh.

60 {
61  evt.run_id = de.getRunNumber();
62  evt.det_id = de.getDetectorID();
63  evt.frame_index = de.getFrameIndex();
64  evt.trigger_counter = de.getCounter();
65  evt.overlays = de.getOverlays();
66  evt.trigger_mask = de.getTriggerMask();
67  evt.t.SetSec( de.getTimesliceStart().getUTCseconds() );
68  evt.t.SetNanoSec( de.getTimesliceStart().getUTC16nanosecondcycles() *16 );
69 
70  // The only way to the hits that are also in the triggeredhits collection
71  // is by dom and channel id and time.
72 
73  Hit h;
75 
76  const std::vector<JDAQSnapshotHit>& snapshotHits = de.getHits<JDAQSnapshotHit>();
77  const std::vector<JDAQTriggeredHit>& triggeredHits = de.getHits<JDAQTriggeredHit>();
78 
79  // http://stackoverflow.com/questions/10735135/reallocation-in-stdvector-after-stdvector-reserve
80  evt.hits.clear();
81  evt.hits.reserve(snapshotHits.size());
82 
83  for(auto& daqhit : snapshotHits ) // JDAQSnapshotHit
84  {
85  read( h, daqhit );
86  h.trig = false;
87  evt.hits.push_back( h );
88  M[ h.dom_id ][ h.channel_id ][ h.t ] = &(*evt.hits.rbegin());
89  }
90 
91  for(auto& daqtrighit: triggeredHits)
92  {
93  Hit* g = M[daqtrighit.getModuleID()][daqtrighit.getPMT()][daqtrighit.getT()];
94  if (g) g->trig = daqtrighit.getTriggerMask ();
95  else
96  {
97  THROW(Exception, "Failed to flag snaphot hit" << (int) daqtrighit.getPMT() << " " << daqtrighit.getT());
98  }
99  }
100 }

◆ read() [4/4]

void read ( Evt evt,
const JDAQTimeslice ts 
)
inline

Read an event from a DAQ time slice.

Parameters
evtevt
tsDAQ time slice

Definition at line 108 of file io_online.hh.

109 {
110  evt.run_id = ts.getRunNumber();
111  evt.frame_index = ts.getFrameIndex();
112  evt.t.SetSec( ts.getTimesliceStart().getUTCseconds() );
113  evt.t.SetNanoSec(ts.getTimesliceStart().getTimeNanoSecond()-ts.getTimesliceStart().getUTCseconds()*1e9);
114 
115  evt.hits.clear();
116 
117  // a timeslice is a vector of JDAQSuperFrame's, which is a JDAQFrame, which
118  // is an stl::vector-like object (supporting stl-like iteration.)
119 
120  Hit h; h.id =0; h.pmt_id =0;
121 
122  for(auto& sf : ts )
123  {
124  for(auto& daqhit: sf )
125  {
126  read( h, daqhit);
127  h.dom_id = sf.getModuleID();
128  evt.hits.push_back(h);
129  }
130  }
131 }

◆ get_summary_slice()

JDAQSummaryslice* get_summary_slice ( TFile *  f,
int  frame_index 
)
inline

Get summary slice from given file with given frame index.

Parameters
fpointer to ROOT file
frame_indexframe index
Returns
pointer to summary slice

Definition at line 149 of file io_online.hh.

150 {
151  static TFile* _f =0;
152  static TTree* S =0;
153  static TBranch* BS=0;
154  JDAQSummaryslice *r =0 ;
155 
156  if (_f != f) // setup for tree reading and build tree index
157  {
158  _f = f;
159 
160  // first we have to deal with the following....
161  // The streamer of JDAQSummaryFrame needs to know what to do since
162  // this information is not written to root file.
163 
164  JDAQSummaryFrame::ROOT_IO_VERSION = ((TStreamerInfo*)_f -> GetStreamerInfoList()->FindObject("JDAQSummaryslice"))->GetClassVersion();
165 
166  //print ("JDAQSummaryFrame::ROOT_IO_VERSION set to", JDAQSummaryFrame::ROOT_IO_VERSION );
167 
168  S = (TTree*) _f->Get("KM3NET_SUMMARYSLICE");
169 
170  if (!S)
171  {
172  THROW(Exception, "Failed to get KM3NET_SUMMARYSLICE TTree.");
173  }
174  BS = S->GetBranch("KM3NET_SUMMARYSLICE");
175  if (!BS)
176  {
177  THROW(Exception, "Failed to get KM3NET_SUMMARYSLICE TBranch.");
178  }
179 
180  std::cout <<"building index to lookup timeslices..." << std::endl;
181  int n = S->BuildIndex("frame_index");
182  (void) n;
183  BS->SetAddress( &r );
184  }
185 
186  // print (frame_index) ;
187  int nbytes = S->GetEntryWithIndex( frame_index );
188  if ( nbytes == 0 )
189  {
190  THROW(Exception, "Failed to find entry with frame_index " << frame_index);
191  }
192  return r;
193 
194 }
read
void read(Hit &hit, const JDAQHit &daqhit)
Read a hit from a DAQ hit.
Definition: io_online.hh:30
Evt::hits
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
Hit
Definition: Hit.hh:7
KM3NETDAQ::JDAQHit::getPMT
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
KM3NETDAQ::JDAQTriggerCounter::getCounter
JTriggerCounter_t getCounter() const
Get trigger counter.
Definition: JDAQTriggerCounter.hh:99
Hit::pmt_id
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:18
KM3NETDAQ::JDAQChronometer::getTimesliceStart
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
Definition: JDAQChronometer.hh:144
KM3NETDAQ::JDAQUTCExtended::getUTCseconds
JUINT32_t getUTCseconds() const
Get time.
Definition: JDAQUTCExtended.hh:78
Evt::run_id
int run_id
DAQ run identifier.
Definition: Evt.hh:25
JTOOLS::n
const int n
Definition: JPolint.hh:628
std::vector
Definition: JSTDTypes.hh:12
KM3NETDAQ::JDAQChronometer::getFrameIndex
int getFrameIndex() const
Get frame index.
Definition: JDAQChronometer.hh:132
KM3NETDAQ::JDAQModuleIdentifier::getModuleID
int getModuleID() const
Get module identifier.
Definition: JDAQModuleIdentifier.hh:72
KM3NETDAQ::JDAQChronometer::getDetectorID
int getDetectorID() const
Get detector identifier.
Definition: JDAQChronometer.hh:110
KM3NETDAQ::JDAQTriggeredHit
DAQ triggered hit.
Definition: JDAQTriggeredHit.hh:20
Hit::t
double t
hit time (from calibration or MC truth)
Definition: Hit.hh:21
Hit::tot
unsigned int tot
tot value as stored in raw data (int for pyroot)
Definition: Hit.hh:15
KM3NETDAQ::JDAQHit::getT
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
KM3NETDAQ::JDAQEvent::getHits
const std::vector< T > & getHits() const
Get container with hits.
Hit::id
int id
Definition: Hit.hh:9
KM3NETDAQ::JDAQEventHeader::getOverlays
unsigned int getOverlays() const
Get number of overlays.
Definition: JDAQEventHeader.hh:87
Hit::dom_id
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:12
KM3NETDAQ::JDAQUTCExtended::getUTC16nanosecondcycles
JUINT32_t getUTC16nanosecondcycles() const
Get time.
Definition: JDAQUTCExtended.hh:89
KM3NETDAQ::JDAQSummaryslice
Data summary slice.
Definition: JDAQSummaryslice.hh:25
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
Hit::trig
int trig
non-zero if the hit is a trigger hit.
Definition: Hit.hh:16
KM3NETDAQ::JDAQHit::getToT
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
KM3NETDAQ::JDAQKeyHit
DAQ key hit.
Definition: JDAQKeyHit.hh:19
Exception
General exception.
Definition: Exception.hh:13
std::map
Definition: JSTDTypes.hh:16
KM3NETDAQ::JDAQChronometer::getRunNumber
int getRunNumber() const
Get run number.
Definition: JDAQChronometer.hh:121
Evt::t
TTimeStamp t
UTC time of the start of the timeslice the event came from.
Definition: Evt.hh:32
Evt::frame_index
int frame_index
from the raw data
Definition: Evt.hh:28
Evt::overlays
unsigned int overlays
number of overlaying triggered events
Definition: Evt.hh:31
Evt::trigger_mask
ULong64_t trigger_mask
trigger mask from raw data (i.e. the trigger bits)
Definition: Evt.hh:29
KM3NETDAQ::JDAQUTCExtended::getTimeNanoSecond
double getTimeNanoSecond() const
Get time (limited to 16 ns cycles).
Definition: JDAQUTCExtended.hh:100
JTOOLS::r
data_type r[M+1]
Definition: JPolint.hh:709
Evt::det_id
int det_id
detector identifier from DAQ
Definition: Evt.hh:22
KM3NETDAQ::JDAQEvent::getTriggerMask
static JTriggerMask_t getTriggerMask(const JDAQTriggeredHit &hit)
Get trigger mask of given hit.
Definition: JDAQEvent.hh:228
Hit::channel_id
unsigned int channel_id
PMT channel id {0,1, .., 31} local to moduke.
Definition: Hit.hh:13
Evt::trigger_counter
ULong64_t trigger_counter
trigger counter
Definition: Evt.hh:30