Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Namespaces | Functions | Variables
io_ascii.hh File Reference
#include <string>
#include <istream>
#include <ostream>
#include <sstream>
#include "Evt.hh"
#include "Hit.hh"
#include "Trk.hh"
#include "Head.hh"
#include "Exception.hh"
#include "../definitions/w2list_gseagen.hh"
#include "TDatabasePDG.h"

Go to the source code of this file.

Namespaces

 mc_keys
 
 mc_usr_keys
 
 io_stringutil
 

Functions

bool io_stringutil::startswith (const std::string &a, const std::string &b)
 Check if string starts with given text. More...
 
std::string io_stringutil::trim (const std::string &s)
 Remove leading and trailing white spaces. More...
 
int pdg_code (int geant3_code)
 Convert Geant3 to PDG particle type. More...
 
int geant3_code (int pdg_code)
 Convert PDG to Geant3 particle type. More...
 
bool read (Vec &v, std::istream &is)
 Read a Vec(tor) from a stream. More...
 
bool write (const Vec &v, std::ostream &os)
 Write a Vec(tor) to a stream. More...
 
bool read (Hit &h, std::istream &is, bool read_mc=false)
 Read a hit from a stream. More...
 
bool write (const Hit &h, std::ostream &os, const std::string &tag=mc_keys::hit_t)
 Write a hit to a stream. More...
 
bool read (Trk &t, Evt &evt, std::istream &is, const std::string &tag=mc_keys::track_in_t)
 Read track from a stream. More...
 
bool write (const Trk &t, const Evt &evt, std::ostream &os, std::string tag=mc_keys::track_in_t)
 Write track to a stream. More...
 
std::vector< double > read_line_to_vector (std::istream &is)
 Read data. More...
 
template<typename T >
void push_front (std::vector< T > &vec, T &value)
 Put value in front of data. More...
 
bool read (Evt &evt, std::istream &is, bool skip_hits=false)
 Read event from a stream. More...
 
bool write (const Evt &evt, std::ostream &os)
 Write event to a stream. More...
 
bool read (Head &hdr, std::istream &is)
 Read header from a stream. More...
 
bool write (const Head &hdr, std::ostream &os)
 Write header to a stream. More...
 

Variables

const char *const mc_keys::auto_t = "auto"
 
const char *const mc_keys::start_run_t = "start_run:"
 
const char *const mc_keys::start_event_t = "start_event:"
 
const char *const mc_keys::hit_t = "hit:"
 
const char *const mc_keys::hit_raw_t = "hit_raw:"
 
const char *const mc_keys::track_in_t = "track_in:"
 
const char *const mc_keys::track_t = "track:"
 
const char *const mc_keys::track_fit_t = "track_fit:"
 
const char *const mc_keys::neutrino_t = "neutrino:"
 
const char *const mc_keys::track_primary_t = "track_primary:"
 
const char *const mc_keys::weights_t = "weights:"
 
const char *const mc_keys::w2list_t = "w2list:"
 
const char *const mc_keys::w3list_t = "w3list:"
 
const char *const mc_keys::hourangle_t = "hourangle:"
 
const char *const mc_keys::center_on_can_t = "center_on_can:"
 
const char *const mc_keys::muon_decay_t = "muon_decay:"
 
const char *const mc_keys::end_event_t = "end_event:"
 
const char *const mc_usr_keys::energy_lost_in_can = "energy_lost_in_can"
 
const char *const mc_usr_keys::muon_decay_x = "muon_decay_x"
 
const char *const mc_usr_keys::muon_decay_y = "muon_decay_y"
 
const char *const mc_usr_keys::muon_decay_z = "muon_decay_z"
 
const char *const mc_usr_keys::center_on_can_x = "center_on_can_x"
 
const char *const mc_usr_keys::center_on_can_y = "center_on_can_y"
 
const char *const mc_usr_keys::center_on_can_z = "center_on_can_z"
 
const char *const mc_usr_keys::hourangle = "hourangle"
 

Function Documentation

int pdg_code ( int  geant3_code)
inline

Convert Geant3 to PDG particle type.

Parameters
geant3_codeGeant3 code
Returns
PDG code

Definition at line 108 of file io_ascii.hh.

109 {
110  if ( geant3_code == -1 ) return -1; // used for k40 hits
111  if ( geant3_code < 0 ) return pdg_code( -geant3_code ); // used for scattered
112 
113  return TDatabasePDG::Instance()->ConvertGeant3ToPdg( geant3_code );
114 }
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:108
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:122
int geant3_code ( int  pdg_code)
inline

Convert PDG to Geant3 particle type.

Parameters
pdg_codePDG code
Returns
Geant3 code

Definition at line 122 of file io_ascii.hh.

123 {
124  if (pdg_code == -1 ) return -1;
125  if (pdg_code == +311 ) return geant3_code( 130 ); // K0 -> K0long
126  if (pdg_code == -311 ) return geant3_code( 130 ); // K0bar -> K0long
127 
128  return TDatabasePDG::Instance()->ConvertPdgToGeant3( pdg_code );
129 }
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:108
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:122
bool read ( Vec v,
std::istream &  is 
)
inline

Read a Vec(tor) from a stream.

Parameters
vvector
isinput stream
Returns
true if correctly read; else false

Definition at line 139 of file io_ascii.hh.

140 {
141  is >> v.x >> v.y >> v.z;
142  return !is.fail();
143 }
double z
Definition: Vec.hh:14
is
Definition: JDAQCHSM.chsm:167
double y
Definition: Vec.hh:14
double x
Definition: Vec.hh:14
bool write ( const Vec v,
std::ostream &  os 
)
inline

Write a Vec(tor) to a stream.

Parameters
vvector
osoutput stream
Returns
true if correctly written; else false

Definition at line 152 of file io_ascii.hh.

153 {
154  os << v.x << ' ' << v.y << ' ' << v.z;
155  return !os.fail();
156 }
double z
Definition: Vec.hh:14
double y
Definition: Vec.hh:14
double x
Definition: Vec.hh:14
bool read ( Hit h,
std::istream &  is,
bool  read_mc = false 
)
inline

Read a hit from a stream.

Parameters
hhit
isinput stream
read_mcoption to read also type and origin
Returns
true if correctly read; else false

Definition at line 166 of file io_ascii.hh.

167 {
168  h.dom_id = 0; // need a proper det file to
169  h.channel_id = 0; // set these.
170 
171  is >> h.id >> h.pmt_id >> h.a >> h.t;
172  if ( !read_mc )
173  {
174  return !is.fail();
175  }
176  else
177  {
178  is >> h.type >> h.origin;
179  }
180 
181  // If we get here without failing, we will return true, but
182  // will attempt to read also pure_a and pure_t which may
183  // or may not be present, depending on the km3 version.
184 
185  bool r = !is.fail();
186  is >> h.pure_a >> h.pure_t;
187  if (is.fail())
188  {
189  h.pure_a = h.pure_t = 0 ;
190  is.clear();
191  }
192  return r;
193 }
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
data_type r[M+1]
Definition: JPolint.hh:709
is
Definition: JDAQCHSM.chsm:167
int origin
track id of the track that created this hit
Definition: Hit.hh:31
double pure_t
photon time before pmt simultion (MC only)
Definition: Hit.hh:28
double a
hit amplitude (in p.e.)
Definition: Hit.hh:24
double pure_a
amptitude before pmt simution (MC only)
Definition: Hit.hh:29
int id
Definition: Hit.hh:11
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
unsigned int channel_id
PMT channel id {0,1, .., 31} local to moduke.
Definition: Hit.hh:15
int type
particle type or parametrisation used for hit (mc only)
Definition: Hit.hh:30
bool write ( const Hit h,
std::ostream &  os,
const std::string &  tag = mc_keys::hit_t 
)
inline

Write a hit to a stream.

Parameters
hhit
osoutput stream
tagtag
Returns
true if correctly written; else false

Definition at line 204 of file io_ascii.hh.

205 {
206  int om_id = h.pmt_id; // todo: deal with this better.
207 
208  os << tag << ' ' << h.id << ' ' << om_id << ' ' << h.a << ' ' << h.t;
209  if ( tag != mc_keys::hit_raw_t ) {
210  os << ' ' << h.type << ' ' << h.origin << ' ' << h.pure_a << ' ' << h.pure_t;
211  }
212  os << std::endl;
213  return !os.fail();
214 }
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
int origin
track id of the track that created this hit
Definition: Hit.hh:31
double pure_t
photon time before pmt simultion (MC only)
Definition: Hit.hh:28
double a
hit amplitude (in p.e.)
Definition: Hit.hh:24
double pure_a
amptitude before pmt simution (MC only)
Definition: Hit.hh:29
int id
Definition: Hit.hh:11
double t
hit time (from calibration or MC truth)
Definition: Hit.hh:23
const char *const hit_raw_t
Definition: io_ascii.hh:24
int type
particle type or parametrisation used for hit (mc only)
Definition: Hit.hh:30
bool read ( Trk t,
Evt evt,
std::istream &  is,
const std::string &  tag = mc_keys::track_in_t 
)
inline

Read track from a stream.

Parameters
ttrack
evtevent (for storing nu info in w2list)
isinput stream
tagtag
Returns
true if correctly read; else false

Definition at line 226 of file io_ascii.hh.

227 {
228  using namespace std;
229 
230  string line;
231  getline( is, line );
232  istringstream ii(line);
233 
234  ii >> t.id >> t.pos >> t.dir >> t.E >> t.t;
235 
236  if (!ii) return false;
237 
238  t.len = 0.0;
239  t.clearusr();
240  t.comment = tag;
241 
242  if ( tag == mc_keys::track_in_t)
243  {
244  ii >> t.type; if (!ii) return false;
245  t.type = pdg_code( t.type );
246  ii >> t.len;
247  if (!ii) return true; // missing length is not an error
248 
249  double eloss = 0;
250  ii >> eloss;
251  if (!ii) return true; // missing eloss is not an error
252 
254  }
255 
256  if ( tag == mc_keys::neutrino_t )
257  {
258  if (evt.w2list.size() < 11 ) evt.w2list.resize(11);
259 
260  ii >> evt.w2list[W2LIST_GSEAGEN_BX] >>
261  evt.w2list[W2LIST_GSEAGEN_BY] >>
263  t.type >>
265  // bx by ichan t.type cc;
266  }
267 
268  if ( tag == mc_keys::track_primary_t )
269  {
270  ii >> t.type; // nucleus id (in pdg format or not?)
271  }
272 
273  if ( ii.fail() )
274  {
275  ostream& out = Exception::getOstream();
276  out << "Error reading trk ";
277  t.print(out);
278  throw Exception(static_cast<ostringstream&>(out).str());
279  }
280 
281  return !ii.fail();
282 }
void setusr(const std::string &key, double value)
Set user data item with given key.
Definition: AAObject.hh:95
const char *const energy_lost_in_can
Definition: io_ascii.hh:43
static const int W2LIST_GSEAGEN_BX
Bjorken x.
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:17
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:108
const char *const neutrino_t
Definition: io_ascii.hh:28
Vec dir
track direction
Definition: Trk.hh:16
std::string comment
use as you like
Definition: Trk.hh:32
is
Definition: JDAQCHSM.chsm:167
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:18
void clearusr()
Clear user data.
Definition: AAObject.hh:139
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
double len
length, if applicable [m]
Definition: Trk.hh:20
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:22
int id
track identifier
Definition: Trk.hh:14
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_BY
Bjorken y.
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:15
const char *const track_in_t
Definition: io_ascii.hh:25
General exception.
Definition: Exception.hh:13
void print(std::ostream &out=std::cout) const
Print track.
Definition: Trk.hh:175
const char *const track_primary_t
Definition: io_ascii.hh:29
static std::ostream & getOstream()
Get output stream for conversion of exception.
Definition: Exception.hh:63
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
bool write ( const Trk t,
const Evt evt,
std::ostream &  os,
std::string  tag = mc_keys::track_in_t 
)
inline

Write track to a stream.

Parameters
ttrack
osoutput stream
tagtag
Returns
true if correctly read; else false

Definition at line 292 of file io_ascii.hh.

293 {
294  using namespace std;
295 
296  int type = t.type;
297 
298  if ( tag == mc_keys::auto_t )
299  {
300  tag = t.comment;
301  }
302 
303  os << tag << ' ' << t.id << ' ' << t.pos << ' ' << t.dir << ' ' << t.E << ' ' << t.t;
304 
305  if ( tag == mc_keys::track_in_t)
306  {
307  os << ' ' << geant3_code(type) << ' ' << t.len;
308 
310  {
311  os << ' ' << t.getusr( mc_usr_keys::energy_lost_in_can );
312  }
313  os << endl;
314  }
315 
316  else if (tag == mc_keys::track_primary_t)
317  {
318  os << ' ' << t.type << endl;
319  }
320 
321 
322  else if ( tag == mc_keys::neutrino_t )
323  {
324  double bx(0),by(0);
325  int ichan(0), cc(0);
326 
327  if ( evt.w2list.size() > W2LIST_GSEAGEN_CC ) {
328  bx = evt.w2list[W2LIST_GSEAGEN_BX];
329  by = evt.w2list[W2LIST_GSEAGEN_BY];
330  ichan = evt.w2list[W2LIST_GSEAGEN_ICHAN];
331  cc = evt.w2list[W2LIST_GSEAGEN_CC];
332  }
333 
334  os << ' ' << bx
335  << ' ' << by
336  << ' ' << ichan
337  << ' ' << t.type
338  << ' ' << cc
339  << endl;
340  }
341 
342  else
343  os << endl;
344 
345  return !os.fail();
346 }
const char *const energy_lost_in_can
Definition: io_ascii.hh:43
static const int W2LIST_GSEAGEN_BX
Bjorken x.
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:17
const char *const neutrino_t
Definition: io_ascii.hh:28
Vec dir
track direction
Definition: Trk.hh:16
std::string comment
use as you like
Definition: Trk.hh:32
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:18
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:122
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
double len
length, if applicable [m]
Definition: Trk.hh:20
double getusr(const std::string &key) const
Get user data item with given key.
Definition: AAObject.hh:72
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:22
int id
track identifier
Definition: Trk.hh:14
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_BY
Bjorken y.
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:15
const char *const track_in_t
Definition: io_ascii.hh:25
bool haveusr(const std::string &key) const
Check availability of user data of the item with given key.
Definition: AAObject.hh:42
const char *const track_primary_t
Definition: io_ascii.hh:29
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
const char *const auto_t
Definition: io_ascii.hh:20
std::vector<double> read_line_to_vector ( std::istream &  is)
inline

Read data.

Parameters
isinput stream
Returns
data

Definition at line 355 of file io_ascii.hh.

356 {
357  using namespace std;
358 
360 
361  string ss;
362  getline(is, ss);
363  istringstream il(ss);
364  for ( double x; il >> x ; ) r.push_back( x );
365 
366  return r;
367 }
data_type r[M+1]
Definition: JPolint.hh:709
is
Definition: JDAQCHSM.chsm:167
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
template<typename T >
void push_front ( std::vector< T > &  vec,
T value 
)
inline

Put value in front of data.

Parameters
vecdata
valuevalue

Definition at line 377 of file io_ascii.hh.

378 {
379  vec.insert( vec.begin(), value );
380 }
bool read ( Evt evt,
std::istream &  is,
bool  skip_hits = false 
)
inline

Read event from a stream.

Parameters
evtevent
isinput stream
skip_hitsoption to skip reading of hits
Returns
true if correctly read; else false

Definition at line 391 of file io_ascii.hh.

392 {
393  using namespace std;
394 
395  string w;
396 
397  // find next start_event
398 
399  while ( w != mc_keys::start_event_t && is.good() ) is >> w;
400 
401  int mc_event_type; // dummy - this is always 1 in all files.
402  is >> evt.mc_id >> mc_event_type;
403 
404  Trk trk_nu, trk_primary;
405  bool have_trk_nu(false), have_trk_primary(false);
406 
407 
408  evt.mc_trks.clear();
409  evt.hits.clear();
410  evt.mc_hits.clear();
411 
412  string w_old;
413 
414  while ( is )
415  {
416  static Hit h;
417  static Trk t;
418 
419  is >> w;
420 
421  if (skip_hits && ( w == mc_keys::hit_t || w == mc_keys::hit_raw_t) )
422  {
423  is.ignore( 1000, '\n' );
424  continue;
425  }
426 
427  if ( w == mc_keys::hit_t )
428  {
429  read( h, is, true );
430  evt.mc_hits.push_back( h );
431  }
432  else if ( w == mc_keys::hit_raw_t )
433  {
434  read( h, is, false);
435  evt.hits.push_back( h );
436  }
437  else if ( w == mc_keys::track_in_t )
438  {
439  read( t, evt, is , w);
440  evt.mc_trks.push_back( t );
441  }
442  else if ( w == mc_keys::track_t )
443  {
444  read( t, evt, is );
445  evt.trks.push_back( t );
446  }
447  else if ( w == mc_keys::neutrino_t)
448  {
449  read( trk_nu ,evt, is, w );
450  have_trk_nu = true;
451  }
452  else if ( w == mc_keys::track_primary_t)
453  {
454  read( trk_primary, evt, is, w );
455  have_trk_primary = true;
456  }
457  // else if ( w == mc_keys::primarylepton_t)
458  // {
459  // read( trk_primary_lepton, is, w);
460  // have_trk_primary_lepton = true;
461  // }
462  else if ( w == mc_keys::weights_t)
463  {
464  evt.w = read_line_to_vector( is );
465  }
466  else if ( w == mc_keys::w2list_t)
467  {
468  auto v = read_line_to_vector( is );
469  evt.w2list.resize( std::max( evt.w2list.size(), v.size()));
470  std::copy( v.begin(), v.end() , evt.w2list.begin() );
471  }
472  else if ( w == mc_keys::w3list_t)
473  {
474  evt.w3list = read_line_to_vector( is );
475  }
476  else if ( w == mc_keys::hourangle_t )
477  {
478  double ha;
479  is >> ha;
480  evt.setusr(mc_usr_keys::hourangle, ha );
481  }
482 
483 
484  else if ( w == mc_keys::center_on_can_t)
485  {
486  // in corsika files, there is the (undocumented?) center_on_can tag,
487  // which denoets the projection of the primary on the can. The direction
488  // of the center_on_can 'track' is by defintion the direction of the
489  // primary. We record the position in the usr data.
490 
492  if ( v.size() > 3 )
493  {
497  }
498  }
499 
500  else if ( w == mc_keys::muon_decay_t)
501  {
502  // in km3sim files, there are additional tags, including this one
504  if ( v.size() > 4 )
505  {
506  evt.setusr(mc_usr_keys::muon_decay_x, v[2] );
507  evt.setusr(mc_usr_keys::muon_decay_y, v[3] );
508  evt.setusr(mc_usr_keys::muon_decay_z, v[4] );
509  }
510  }
511 
512 
513  else if ( w == mc_keys::end_event_t)
514  {
515  // finalize the mc_tracks -- as best we can.
516 
517  // If there is both a primary, and a neutrino, then the primary
518  // will go second (mc_trks[1]) with id=-1 and the neutrino will
519  // be mc_trks[0] with id=0. Unless they are same particle (identical
520  // pos,dir,E); in that case the primary is skipped.
521  // The primarylepton tag is not stored as a seperate Trk.
522 
523  if ( have_trk_primary && have_trk_nu )
524  {
525  bool same = trk_nu.pos == trk_primary.pos &&
526  trk_nu.dir == trk_primary.dir &&
527  trk_nu.E == trk_primary.E;
528 
529  if (!same)
530  {
531  trk_primary.id = -1;
532  push_front( evt.mc_trks, trk_primary);
533  }
534 
535  trk_nu.id = 0;
536  push_front( evt.mc_trks, trk_nu);
537  }
538 
539  else if ( have_trk_primary )
540  {
541  trk_primary.id = 0;
542  push_front( evt.mc_trks, trk_primary);
543  }
544 
545  else if ( have_trk_nu )
546  {
547  trk_nu.id = 0;
548  push_front( evt.mc_trks, trk_nu);
549  }
550 
551  return true;
552  }
553  else
554  {
555  is.ignore( 1000, '\n' );
556  }
557  w_old = w;
558  }
559 
560  if (!is.eof())
561  {
562  THROW(Exception, "Error while reading ascii event" << w << ' ' << evt.id);
563  }
564 
565  return false;
566 }
void setusr(const std::string &key, double value)
Set user data item with given key.
Definition: AAObject.hh:95
data_type w[N+1][M+1]
Definition: JPolint.hh:708
const char *const w2list_t
Definition: io_ascii.hh:32
const char *const center_on_can_y
Definition: io_ascii.hh:52
const char *const weights_t
Definition: io_ascii.hh:31
const char *const muon_decay_x
Definition: io_ascii.hh:47
const char *const neutrino_t
Definition: io_ascii.hh:28
const char *const center_on_can_z
Definition: io_ascii.hh:53
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
const char *const w3list_t
Definition: io_ascii.hh:33
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
const char *const muon_decay_t
Definition: io_ascii.hh:36
const char *const muon_decay_y
Definition: io_ascii.hh:48
is
Definition: JDAQCHSM.chsm:167
const char *const hourangle
Definition: io_ascii.hh:54
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:23
const char *const hourangle_t
Definition: io_ascii.hh:34
void push_front(std::vector< T > &vec, T &value)
Put value in front of data.
Definition: io_ascii.hh:377
const char *const center_on_can_t
Definition: io_ascii.hh:35
const char *const center_on_can_x
Definition: io_ascii.hh:51
const char *const track_in_t
Definition: io_ascii.hh:25
Definition: Hit.hh:8
const char *const track_t
Definition: io_ascii.hh:26
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:36
General exception.
Definition: Exception.hh:13
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:44
const char *const muon_decay_z
Definition: io_ascii.hh:49
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:153
const char *const hit_t
Definition: io_ascii.hh:23
int id
offline event identifier
Definition: Evt.hh:21
const char *const track_primary_t
Definition: io_ascii.hh:29
const char *const end_event_t
Definition: io_ascii.hh:37
std::vector< double > read_line_to_vector(std::istream &is)
Read data.
Definition: io_ascii.hh:355
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
data_type v[N+1][M+1]
Definition: JPolint.hh:707
const char *const hit_raw_t
Definition: io_ascii.hh:24
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:12
const char *const start_event_t
Definition: io_ascii.hh:22
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:45
std::vector< double > w3list
MC: atmospheric flux information.
Definition: Evt.hh:41
bool write ( const Evt evt,
std::ostream &  os 
)
inline

Write event to a stream.

Parameters
evtevent
osoutput stream
Returns
true if correctly read; else false

Definition at line 576 of file io_ascii.hh.

577 {
578  using namespace std;
579 
580  os << mc_keys::start_event_t << ' ' << evt.mc_id << ' ' << 1 << endl;
581 
582  for ( auto& trk : evt.mc_trks ) write ( trk, evt, os, mc_keys::auto_t );
583  for ( auto& trk : evt.trks ) write ( trk, evt, os, mc_keys::track_fit_t );
584  for ( auto& hit : evt.mc_hits ) write ( hit, os, mc_keys::hit_t);
585  for ( auto& hit : evt.hits ) write ( hit, os, mc_keys::hit_raw_t);
586 
587  os << mc_keys::weights_t; for (auto& w : evt.w ) os << ' ' << w; os << endl;
588  os << mc_keys::w2list_t; for (auto& w : evt.w2list ) os << ' ' << w; os << endl;
589  os << mc_keys::w3list_t; for (auto& w : evt.w3list ) os << ' ' << w; os << endl;
590  os << mc_keys::end_event_t << endl;
591 
592  return true;
593 }
data_type w[N+1][M+1]
Definition: JPolint.hh:708
const char *const w2list_t
Definition: io_ascii.hh:32
const char *const weights_t
Definition: io_ascii.hh:31
const char *const w3list_t
Definition: io_ascii.hh:33
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
const char *const track_fit_t
Definition: io_ascii.hh:27
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:23
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:36
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
Definition: io_ascii.hh:152
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:44
const char *const hit_t
Definition: io_ascii.hh:23
const char *const end_event_t
Definition: io_ascii.hh:37
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
const char *const hit_raw_t
Definition: io_ascii.hh:24
const char *const start_event_t
Definition: io_ascii.hh:22
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:45
std::vector< double > w3list
MC: atmospheric flux information.
Definition: Evt.hh:41
const char *const auto_t
Definition: io_ascii.hh:20
bool read ( Head hdr,
std::istream &  is 
)
inline

Read header from a stream.

The stream may be positioned at any point before the tag mc_keys::start_run_t, which marks the beginning of the header. Information before the header (if any) is disgarded.

Parameters
hdrheader
isinput stream
Returns
true if correctly read; else false

Definition at line 608 of file io_ascii.hh.

609 {
610  using namespace std;
611 
612  string line;
613 
614  bool start = false;
615 
616  while (getline( is, line ))
617  {
619  {
620  break;
621  }
622 
624  {
625  start = true;
626  }
627 
629  {
630  THROW(Exception, "Unexpected tag " << mc_keys::start_event_t << " found while reading header at " << line << " (could mean the evt file has no header)");
631  }
632 
633  if (!start) continue;
634 
635  vector<string> v = splitstring( line, ':' );
636  if (v.size() < 2 )
637  {
638  THROW(Exception, "Invalid line found when reading header at " << line);
639  continue;
640  }
641 
642  // make sure key is unique
643  string key = v[0];
644  for (int i = 1; hdr.find(key) != hdr.end() ; i++)
645  {
646  key = v[0] + "_" + to_string(i);
647  }
648 
649  hdr[key] = io_stringutil::trim(v[1]);
650  }
651 
652  if (!start)
653  {
654  THROW(Exception, "Reading of MC header terminated before finding a start_run: tag. Please check your file");
655  }
656 
657  return start;
658 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
is
Definition: JDAQCHSM.chsm:167
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
bool startswith(const std::string &a, const std::string &b)
Check if string starts with given text.
Definition: io_ascii.hh:67
General exception.
Definition: Exception.hh:13
std::string to_string(const T &value)
Convert value to string.
const char *const end_event_t
Definition: io_ascii.hh:37
const char *const start_run_t
Definition: io_ascii.hh:21
std::string trim(const std::string &s)
Remove leading and trailing white spaces.
Definition: io_ascii.hh:79
data_type v[N+1][M+1]
Definition: JPolint.hh:707
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:45
const char *const start_event_t
Definition: io_ascii.hh:22
bool write ( const Head hdr,
std::ostream &  os 
)
inline

Write header to a stream.

Parameters
hdrheader
osoutput stream
Returns
true if correctly written; else false

Definition at line 668 of file io_ascii.hh.

669 {
670  hdr.print(os);
671  return true;
672 }
void print(std::ostream &out=std::cout) const
Print header.
Definition: Head.hh:221