Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
io_online.hh File Reference

Go to the source code of this file.

Functions

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

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 31 of file io_online.hh.

32{
33 hit.channel_id = daqhit.getPMT();
34 hit.tot = daqhit.getToT();
35 hit.tdc = daqhit.getT(); // GetT() just return the bare TDC
36}
JPMT_t getPMT() const
Get PMT.
Definition JDAQHit.hh:75
JTDC_t getT() const
Get time.
Definition JDAQHit.hh:86
JTOT_t getToT() const
Get time-over-threshold.
Definition JDAQHit.hh:97
unsigned int tdc
hit tdc (=time in ns)
Definition Hit.hh:16
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
Definition Hit.hh:15
unsigned int tot
tot value as stored in raw data (int for pyroot)
Definition Hit.hh:17

◆ 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 44 of file io_online.hh.

45{
46 hit.id = hit.pmt_id = 0;
47
48 hit.dom_id = daqhit.getModuleID();
49 hit.channel_id = daqhit.getPMT();
50 hit.tot = daqhit.getToT();
51 hit.tdc = daqhit.getT(); // GetT() just return the bare TDC
52}
int getModuleID() const
Get module identifier.
int pmt_id
global PMT identifier as found in evt files
Definition Hit.hh:20
int dom_id
module identifier from the data (unique in the detector).
Definition Hit.hh:14
int id
Definition Hit.hh:11

◆ 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 60 of file io_online.hh.

61{
62 evt.run_id = de.getRunNumber();
63 evt.det_id = de.getDetectorID();
64 evt.frame_index = de.getFrameIndex();
65 evt.trigger_counter = de.getCounter();
66 evt.overlays = de.getOverlays();
68 evt.t.SetSec( de.getTimesliceStart().getUTCseconds() );
69 evt.t.SetNanoSec( de.getTimesliceStart().getUTC16nanosecondcycles() * 16 );
70
71 // The only way to know the hits that are also in the triggeredhits collection
72 // is by dom and channel id and time.
73
74 Hit h;
76
77 const std::vector<JDAQSnapshotHit>& snapshotHits = de.getHits<JDAQSnapshotHit>();
78 const std::vector<JDAQTriggeredHit>& triggeredHits = de.getHits<JDAQTriggeredHit>();
79
80 // http://stackoverflow.com/questions/10735135/reallocation-in-stdvector-after-stdvector-reserve
81 evt.hits.clear();
82 evt.hits.reserve(snapshotHits.size());
83
84 for (auto& daqhit : snapshotHits ) // JDAQSnapshotHit
85 {
86 read( h, daqhit );
87 h.trig = 0;
88 evt.hits.push_back( h );
89 M[ h.dom_id ][ h.channel_id ][ h.tdc ] = &(*evt.hits.rbegin());
90 }
91
92 for (auto& daqtrighit : triggeredHits)
93 {
94 Hit* g = M[daqtrighit.getModuleID()][daqtrighit.getPMT()][daqtrighit.getT()];
95
96 if (g)
97 g->trig = daqtrighit.getTriggerMask ();
98 else
99 THROW(Exception, "Failed to flag snaphot hit " << (int) daqtrighit.getModuleID() << "." << (int) daqtrighit.getPMT() << " " << daqtrighit.getT());
100 }
101}
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General exception.
Definition Exception.hh:13
int getDetectorID() const
Get detector identifier.
int getRunNumber() const
Get run number.
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
int getFrameIndex() const
Get frame index.
unsigned int getOverlays() const
Get number of overlays.
static JTriggerMask_t getTriggerMask(const JDAQTriggeredHit &hit)
Get trigger mask of given hit.
Definition JDAQEvent.hh:226
const std::vector< T > & getHits() const
Get container with hits.
JTriggerCounter_t getCounter() const
Get trigger counter.
uint32_t getUTC16nanosecondcycles() const
Get minor time.
uint32_t getUTCseconds() const
Get major time.
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter=' ')
Read test summary.
int frame_index
from the raw data
Definition Evt.hh:29
int run_id
DAQ run identifier.
Definition Evt.hh:26
ULong64_t trigger_mask
trigger mask from raw data (i.e. the trigger bits)
Definition Evt.hh:30
std::vector< Hit > hits
list of hits
Definition Evt.hh:38
int det_id
detector identifier from DAQ
Definition Evt.hh:23
ULong64_t trigger_counter
trigger counter
Definition Evt.hh:31
TTimeStamp t
UTC time of the timeslice, or the event_time for MC. (default: 01 Jan 1970 00:00:00)
Definition Evt.hh:33
unsigned int overlays
number of overlaying triggered events
Definition Evt.hh:32
Definition Hit.hh:10
ULong64_t trig
non-zero if the hit is a trigger hit.
Definition Hit.hh:18

◆ 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 110 of file io_online.hh.

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

◆ get_summary_slice()

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

Get summary slice from given file with given frame index.

This function will (re)build an index each time it encounters a new TFile as input.

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

Definition at line 145 of file io_online.hh.

146{
147 static TFile* _f = 0;
148 static TTree* S = 0;
149 static TBranch* BS = 0;
150 JDAQSummaryslice *r = 0 ;
151
152 if (!f) THROW(Exception, "get_summary_slice called with TFile pointer that is null");
153
154
155 // in principle, event if the pointer-value is the same, we could have been given a new file
156
157 if ( !_f || _f->GetUUID().Compare( f->GetUUID() ) != 0 ) // setup for tree reading and build tree index
158 {
159 _f = f;
160
161 // first we have to deal with the following....
162 // The streamer of JDAQSummaryFrame needs to know what to do since
163 // this information is not written to root file.
164
165 const char* name = JDAQSummaryslice::Class()->GetName();
166
167 JDAQSummaryFrame::ROOT_IO_VERSION = ((TStreamerInfo*)_f -> GetStreamerInfoList()->FindObject(name))->GetClassVersion();
168
169 S = (TTree*) _f->Get( TTREE_ONLINE_SUMMARYSLICE );
170
171 if (!S)
172 {
173 THROW(Exception, "Failed to get summary slice TTree : " << TTREE_ONLINE_SUMMARYSLICE );
174 }
175
176 BS = S->GetBranch( TBRANCH_ONLINE_SUMMARYSLICE );
177
178 if (!BS)
179 {
180 THROW(Exception, "Failed to get brach :" << TBRANCH_ONLINE_SUMMARYSLICE );
181 }
182
183 std::cout << "building index to lookup summary slices..." << std::endl;
184 int n = S->BuildIndex("frame_index");
185 (void) n;
186 BS->SetAddress( &r );
187 }
188
189 int nbytes = S->GetEntryWithIndex( frame_index ); // returns -1 if not found
190 if ( nbytes <= 0 )
191 {
192 THROW(Exception, "Failed to find summary slice entry with frame_index " << frame_index);
193 }
194 return r;
195}
static int ROOT_IO_VERSION
Streamer version of JDAQSummaryslice as obtained from ROOT file.
const int n
Definition JPolint.hh:791
static const char *const TTREE_ONLINE_SUMMARYSLICE
ROOT TTree name.
Definition root.hh:17
static const char *const TBRANCH_ONLINE_SUMMARYSLICE
ROOT TBranch name.
Definition root.hh:26