Jpp  18.0.1-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
io_online.hh File Reference
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "km3net-dataformat/offline/Trk.hh"
#include "km3net-dataformat/offline/Exception.hh"
#include "km3net-dataformat/online/JDAQEvent.hh"
#include "km3net-dataformat/online/JDAQKeyHit.hh"
#include "km3net-dataformat/online/JDAQTimeslice.hh"
#include "km3net-dataformat/online/JDAQSummaryslice.hh"
#include "TStreamerInfo.h"
#include "TFile.h"
#include "TTree.h"
#include "km3net-dataformat/definitions/root.hh"
#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

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 }
unsigned int tdc
hit tdc (=time in ns)
Definition: Hit.hh:16
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
unsigned int tot
tot value as stored in raw data (int for pyroot)
Definition: Hit.hh:17
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
Definition: Hit.hh:15
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
unsigned int tdc
hit tdc (=time in ns)
Definition: Hit.hh:16
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
int id
Definition: Hit.hh:11
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:14
unsigned int tot
tot value as stored in raw data (int for pyroot)
Definition: Hit.hh:17
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
Definition: Hit.hh:15
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();
67  evt.trigger_mask = de.getTriggerMask();
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 }
DAQ key hit.
Definition: JDAQKeyHit.hh:19
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
int getDetectorID() const
Get detector identifier.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
ULong64_t trigger_counter
trigger counter
Definition: Evt.hh:31
unsigned int tdc
hit tdc (=time in ns)
Definition: Hit.hh:16
int getRunNumber() const
Get run number.
int getFrameIndex() const
Get frame index.
static JTriggerMask_t getTriggerMask(const JDAQTriggeredHit &hit)
Get trigger mask of given hit.
Definition: JDAQEvent.hh:228
int frame_index
from the raw data
Definition: Evt.hh:29
unsigned int overlays
number of overlaying triggered events
Definition: Evt.hh:32
const std::vector< T > & getHits() const
Get container with hits.
JUINT32_t getUTC16nanosecondcycles() const
Get minor time.
unsigned int getOverlays() const
Get number of overlays.
int run_id
DAQ run identifier.
Definition: Evt.hh:26
JUINT32_t getUTCseconds() const
Get major time.
int det_id
detector identifier from DAQ
Definition: Evt.hh:23
Definition: Hit.hh:8
TTimeStamp t
UTC time of the timeslice, or the event_time for MC. (default: 01 Jan 1970 00:00:00) ...
Definition: Evt.hh:33
General exception.
Definition: Exception.hh:13
ULong64_t trig
non-zero if the hit is a trigger hit.
Definition: Hit.hh:18
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:14
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
Definition: Hit.hh:15
std::vector< Hit > hits
list of hits
Definition: Evt.hh:38
JTriggerCounter_t getCounter() const
Get trigger counter.
ULong64_t trigger_mask
trigger mask from raw data (i.e. the trigger bits)
Definition: Evt.hh:30
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 }
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
int getDetectorID() const
Get detector identifier.
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
int getRunNumber() const
Get run number.
int getFrameIndex() const
Get frame index.
int frame_index
from the raw data
Definition: Evt.hh:29
JUINT32_t getUTC16nanosecondcycles() const
Get minor time.
int run_id
DAQ run identifier.
Definition: Evt.hh:26
JUINT32_t getUTCseconds() const
Get major time.
int id
Definition: Hit.hh:11
int det_id
detector identifier from DAQ
Definition: Evt.hh:23
Definition: Hit.hh:8
TTimeStamp t
UTC time of the timeslice, or the event_time for MC. (default: 01 Jan 1970 00:00:00) ...
Definition: Evt.hh:33
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:14
std::vector< Hit > hits
list of hits
Definition: Evt.hh:38
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 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
o $QUALITY_ROOT d $DEBUG!CHECK_EXIT_CODE JPlot1D f
Definition: JDataQuality.sh:76
data_type r[M+1]
Definition: JPolint.hh:779
const int n
Definition: JPolint.hh:697
static const char *const TBRANCH_ONLINE_SUMMARYSLICE
ROOT TBranch name.
Definition: root.hh:25
General exception.
Definition: Exception.hh:13
static const char *const TTREE_ONLINE_SUMMARYSLICE
ROOT TTree name.
Definition: root.hh:17