Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
io_online.hh
Go to the documentation of this file.
1 #ifndef IOONLINEINCLUDED
2 #define IOONLINEINCLUDED
3 
4 #include "Evt.hh"
5 #include "Hit.hh"
6 #include "Trk.hh"
7 #include "Exception.hh"
8 
9 #include "../online/JDAQEvent.hh"
10 #include "../online/JDAQKeyHit.hh"
11 #include "../online/JDAQTimeslice.hh"
12 #include "../online/JDAQSummaryslice.hh"
13 
14 #include "TStreamerInfo.h"
15 #include "TFile.h"
16 #include "TTree.h"
17 
18 #include <map>
19 #include <vector>
20 
21 
22 using namespace KM3NETDAQ;
23 
24 /**
25  * Read a hit from a DAQ hit.
26  *
27  * \param hit hit
28  * \param daqhit DAQ hit
29  */
30 inline void read(Hit& hit, const JDAQHit& daqhit )
31 {
32  hit.channel_id = daqhit.getPMT();
33  hit.tot = daqhit.getToT();
34  hit.t = daqhit.getT();
35 }
36 
37 /**
38  * Read a hit from a DAQ key hit.
39  *
40  * \param hit hit
41  * \param daqhit DAQ key hit
42  */
43 inline void read(Hit& hit, const JDAQKeyHit& daqhit )
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 }
52 
53 /**
54  * Read an event from a DAQ event.
55  *
56  * \param evt evt
57  * \param de DAQ event
58  */
59 inline void read(Evt& evt, const JDAQEvent& de)
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 }
101 
102 /**
103  * Read an event from a DAQ time slice.
104  *
105  * \param evt evt
106  * \param ts DAQ time slice
107  */
108 
109 inline void read( Evt& evt, const JDAQTimeslice& ts )
110 {
111  evt.run_id = ts.getRunNumber();
112  evt.frame_index = ts.getFrameIndex();
113  evt.t.SetSec( ts.getTimesliceStart().getUTCseconds() );
114  evt.t.SetNanoSec( ts.getTimesliceStart().getUTC16nanosecondcycles() *16 );
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 }
132 
133 //inline void read(Det& det, const JDAQSummaryslice& ss )
134 //{
135 // for(auto& sf: ss ) // JDAQSummarysclice derives from vector<JDAQSummaryFrame>
136 // {
137 // Dom& dom = det.doms[ sf.getModuleID() ];
138 // for(auto& pmt: dom.pmts ) pmt.rate = sf.getRate( pmt.channel_id );
139 // }
140 //}
141 
142 /**
143  * Get summary slice from given file with given frame index.
144  *
145  * \param f pointer to ROOT file
146  * \param frame_index frame index
147  * \return pointer to summary slice
148  */
149 inline JDAQSummaryslice* get_summary_slice( TFile* f , int frame_index )
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("KM3NETDAQ::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  int nbytes = S->GetEntryWithIndex( frame_index );
187  if ( nbytes == 0 )
188  {
189  THROW(Exception, "Failed to find entry with frame_index " << frame_index);
190  }
191  return r;
192 
193 }
194 
195 #endif
DAQ key hit.
Definition: JDAQKeyHit.hh:19
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
int getModuleID() const
Get module identifier.
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
JDAQSummaryslice * get_summary_slice(TFile *f, int frame_index)
Get summary slice from given file with given frame index.
Definition: io_online.hh:149
int getDetectorID() const
Get detector identifier.
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
Definition: io_ascii.hh:139
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
ULong64_t trigger_counter
trigger counter
Definition: Evt.hh:30
static int ROOT_IO_VERSION
Streamer version of JDAQSummaryslice as obtained from ROOT file.
data_type r[M+1]
Definition: JPolint.hh:709
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:86
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:75
int getRunNumber() const
Get run number.
int getFrameIndex() const
Get frame index.
then JPizza f
Definition: JPizza.sh:46
static JTriggerMask_t getTriggerMask(const JDAQTriggeredHit &hit)
Get trigger mask of given hit.
Definition: JDAQEvent.hh:228
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:97
int frame_index
from the raw data
Definition: Evt.hh:28
unsigned int overlays
number of overlaying triggered events
Definition: Evt.hh:31
const std::vector< T > & getHits() const
Get container with hits.
Hit data structure.
Definition: JDAQHit.hh:34
JUINT32_t getUTC16nanosecondcycles() const
Get time.
Data time slice.
unsigned int getOverlays() const
Get number of overlays.
int run_id
DAQ run identifier.
Definition: Evt.hh:25
JUINT32_t getUTCseconds() const
Get time.
int id
Definition: Hit.hh:11
int det_id
detector identifier from DAQ
Definition: Evt.hh:22
int trig
non-zero if the hit is a trigger hit.
Definition: Hit.hh:18
do set_variable SIGMA_NS set_variable OUTLIERS set_variable OUTPUT_FILE matrix[${ALPHA_DEG}\deg\] root $JPP JMatrixNZ a $DETECTOR f $INPUT_FILE o $OUTPUT_FILE S
Definition: JMatrixNZ.sh:56
Definition: Hit.hh:8
TTimeStamp t
UTC time of the start of the timeslice the event came from.
Definition: Evt.hh:32
General exception.
Definition: Exception.hh:13
double t
hit time (from calibration or MC truth)
Definition: Hit.hh:23
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:14
alias put_queue eval echo n
Definition: qlib.csh:19
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, .., 31} local to moduke.
Definition: Hit.hh:15
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
JTriggerCounter_t getCounter() const
Get trigger counter.
ULong64_t trigger_mask
trigger mask from raw data (i.e. the trigger bits)
Definition: Evt.hh:29
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19