Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
io_ascii.hh File Reference
#include <string>
#include <istream>
#include <ostream>
#include <sstream>
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "km3net-dataformat/offline/Trk.hh"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Exception.hh"
#include "km3net-dataformat/definitions/w2list_gseagen.hh"
#include "km3net-dataformat/definitions/trkmembers.hh"
#include "TDatabasePDG.h"

Go to the source code of this file.

Namespaces

namespace  mc_keys
 
namespace  mc_usr_keys
 
namespace  io_stringutil
 

Functions

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

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::track_bundle_t = "track_bundle:"
 
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::eventtime_t = "eventtime:"
 
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

◆ pdg_code()

int pdg_code ( int geant3_code)
inline

Convert Geant3 to PDG particle type.

Parameters
geant3_codeGeant3 code
Returns
PDG code

Definition at line 111 of file io_ascii.hh.

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

◆ geant3_code()

int geant3_code ( int pdg_code)
inline

Convert PDG to Geant3 particle type.

Parameters
pdg_codePDG code
Returns
Geant3 code

Definition at line 125 of file io_ascii.hh.

126{
127 if (pdg_code == -1 ) return -1;
128 if (pdg_code == +311 ) return geant3_code( 130 ); // K0 -> K0long
129 if (pdg_code == -311 ) return geant3_code( 130 ); // K0bar -> K0long
130
131 return TDatabasePDG::Instance()->ConvertPdgToGeant3( pdg_code );
132}

◆ read() [1/4]

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 142 of file io_ascii.hh.

143{
144 is >> v.x >> v.y >> v.z;
145 return !is.fail();
146}
double z
Definition Vec.hh:14
double x
Definition Vec.hh:14
double y
Definition Vec.hh:14

◆ write() [1/4]

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 155 of file io_ascii.hh.

156{
157 os << v.x << ' ' << v.y << ' ' << v.z;
158 return !os.fail();
159}

◆ read() [2/4]

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 169 of file io_ascii.hh.

170{
171 h.dom_id = 0; // need a proper det file to
172 h.channel_id = 0; // set these.
173
174 is >> h.id >> h.pmt_id >> h.a >> h.t;
175 if ( !read_mc )
176 {
177 return !is.fail();
178 }
179 else
180 {
181 is >> h.type >> h.origin;
182 }
183
184 // at this point, an additional pure_a and pure_t may be present,
185 // but we do not read them.
186
187 return !is.fail();
188}
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 origin
track id of the track that created this hit (mc only)
Definition Hit.hh:29
double a
hit amplitude (in p.e.)
Definition Hit.hh:24
int id
Definition Hit.hh:11
int type
particle type or parametrisation used for hit (mc only)
Definition Hit.hh:28
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
Definition Hit.hh:15
double t
hit time (from tdc+calibration or MC truth)
Definition Hit.hh:23

◆ write() [2/4]

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 199 of file io_ascii.hh.

200{
201 int om_id = h.pmt_id; // todo: deal with this better.
202
203 os << tag << ' ' << h.id << ' ' << om_id << ' ' << h.a << ' ' << h.t;
204 if ( tag != mc_keys::hit_raw_t ) {
205 os << ' ' << h.type << ' ' << h.origin; // not writing pure_a and pure_t
206 }
207 os << std::endl;
208 return !os.fail();
209}
const char *const hit_raw_t
Definition io_ascii.hh:25

◆ read_line_to_vector()

std::vector< double > read_line_to_vector ( std::istream & is)
inline

Read data.

Parameters
isinput stream
Returns
data

Definition at line 218 of file io_ascii.hh.

219{
220 using namespace std;
221
223
224 string ss;
225 getline(is, ss);
226 istringstream il(ss);
227 for ( double x; il >> x ; ) r.push_back( x );
228
229 return r;
230}
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478

◆ push_front()

template<typename T >
void push_front ( std::vector< T > & vec,
const T & value )
inline

Put value in front of data.

Parameters
vecdata
valuevalue

Definition at line 240 of file io_ascii.hh.

241{
242 vec.insert( vec.begin(), value );
243}

◆ read() [3/4]

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 254 of file io_ascii.hh.

255{
256 using namespace std;
257
258 string w;
259
260 // find next start_event
261
262 while ( w != mc_keys::start_event_t && is.good() ) is >> w;
263
264 int mc_event_type; // dummy - this is always 1 in all files.
265 is >> evt.mc_id >> mc_event_type;
266
267 Trk trk_nu, trk_primary;
268 bool have_trk_nu(false), have_trk_primary(false);
269
270
271 evt.mc_trks.clear();
272 evt.hits.clear();
273 evt.mc_hits.clear();
274
275 string w_old;
276
277 while ( is )
278 {
279 static Hit h;
280 static Trk t;
281
282 is >> w;
283
284 if (skip_hits && ( w == mc_keys::hit_t || w == mc_keys::hit_raw_t)) {
285 is.ignore( 1000, '\n' );
286 continue;
287 }
288
289 if ( w == mc_keys::hit_t ) {
290
291 read( h, is, true );
292 evt.mc_hits.push_back( h );
293
294 } else if ( w == mc_keys::hit_raw_t ) {
295
296 read( h, is, false);
297 evt.hits.push_back( h );
298
299 } else if ( w == mc_keys::track_in_t ||
300 w == mc_keys::track_t ||
301 w == mc_keys::neutrino_t ||
304
305 t.id = 0;
306 t.len = 0.0;
307 t.clearusr();
308 t.comment = w;
309
310 string line;
311 getline( is, line );
312 istringstream ii(line);
313
314 if ( w != mc_keys::track_bundle_t ) {
315 ii >> t.id;
316 } else {
317 ii >> t.len;
318 }
319
320 ii >> t.pos >> t.dir >> t.E;
321
322 if (!ii.fail()) {
323
324 if ( w == mc_keys::track_in_t) {
325
327
328 ii >> t.t >> t.type;
329
330 if (!ii.fail()) {
331
332 t.type = pdg_code( t.type );
333
334 ii >> t.len;
335
336 if ( ii.fail() ) { // missing length is not an error
337 evt.mc_trks.push_back( t );
338 continue;
339 }
340
341 double eloss = 0;
342 ii >> eloss;
343
344 if ( ii.fail() ) { // missing eloss is not an error
345 evt.mc_trks.push_back( t );
346 continue;
347 }
348
350
351 evt.mc_trks.push_back( t );
352 }
353
354 } else if ( w == mc_keys::track_t ) {
355
356 ii >> t.t;
357
358 evt.trks.push_back( t );
359
360 } else if ( w == mc_keys::neutrino_t ) {
361
363
364 // the last item we will read is W2LIST_GSEAGEN_CC, make enough space;
365 if (evt.w2list.size() < W2LIST_GSEAGEN_CC+1 ) evt.w2list.resize(W2LIST_GSEAGEN_CC+1);
366
367 ii >> t.t >>
371 t.type >>
373
374 trk_nu = t;
375 have_trk_nu = true;
376
377 } else if ( w == mc_keys::track_primary_t ) {
378
380
381 ii >> t.t >> trk_primary.type; // nucleus id (in pdg format or not?)
382
383 trk_primary = t;
384 have_trk_primary = true;
385
386 } else if ( w == mc_keys::track_bundle_t ) {
387
390
391 evt.mc_trks.push_back( t );
392
393 } else {
394
395 ostream& out = Exception::getOstream();
396 out << "Unknown tag " << w << " for trk ";
397 t.print(out);
398 throw Exception(static_cast<ostringstream&>(out).str());
399 }
400 }
401
402 if ( ii.fail() ) {
403 ostream& out = Exception::getOstream();
404 out << "Error reading trk ";
405 t.print(out);
406 throw Exception(static_cast<ostringstream&>(out).str());
407 }
408
409 } else if ( w == mc_keys::weights_t) {
410
411 evt.w = read_line_to_vector( is );
412
413 } else if ( w == mc_keys::w2list_t) {
414
415 auto v = read_line_to_vector( is );
416 evt.w2list.resize( std::max( evt.w2list.size(), v.size()));
417 std::copy( v.begin(), v.end() , evt.w2list.begin() );
418
419 } else if ( w == mc_keys::w3list_t) {
420
421 evt.w3list = read_line_to_vector( is );
422
423 } else if ( w == mc_keys::hourangle_t ) {
424
425 double ha;
426 is >> ha;
428
429 } else if ( w == mc_keys::center_on_can_t) {
430
431 // in corsika files, there is the (undocumented?) center_on_can tag,
432 // which denoets the projection of the primary on the can. The direction
433 // of the center_on_can 'track' is by defintion the direction of the
434 // primary. We record the position in the usr data.
435
437
438 if ( v.size() > 3 ) {
442 }
443
444 } else if ( w == mc_keys::eventtime_t ) {
445
446 unsigned nsec, n16ns_ticks;
447 is >> nsec >> n16ns_ticks;
448 evt.mc_event_time.SetSec( nsec );
449 evt.mc_event_time.SetNanoSec( n16ns_ticks * 16 );
450
451 } else if ( w == mc_keys::muon_decay_t) {
452
453 // in km3sim files, there are additional tags, including this one
455 if ( v.size() > 4 )
456 {
460 }
461
462 } else if ( w == mc_keys::end_event_t) {
463
464 // finalize the mc_tracks -- as best we can.
465
466 // If there is both a primary, and a neutrino, then the primary
467 // will go second (mc_trks[1]) with id=-1 and the neutrino will
468 // be mc_trks[0] with id=0. Unless they are same particle (identical
469 // pos,dir,E); in that case the primary is skipped.
470 // The primarylepton tag is not stored as a seperate Trk.
471
472 if ( have_trk_primary && have_trk_nu ) {
473
474 bool same = trk_nu.pos == trk_primary.pos &&
475 trk_nu.dir == trk_primary.dir &&
476 trk_nu.E == trk_primary.E;
477
478 if (!same) {
479 trk_primary.id = -1;
480 push_front( evt.mc_trks, trk_primary);
481 }
482
483 trk_nu.id = 0;
484 push_front( evt.mc_trks, trk_nu);
485
486 } else if ( have_trk_primary ) {
487
488 trk_primary.id = 0;
489 push_front( evt.mc_trks, trk_primary);
490
491 } else if ( have_trk_nu ) {
492
493 trk_nu.id = 0;
494 push_front( evt.mc_trks, trk_nu);
495 }
496
497 return true;
498
499 } else {
500 is.ignore( 1000, '\n' );
501 }
502
503 w_old = w;
504 }
505
506 if (!is.eof()) {
507 THROW(Exception, "Error while reading ascii event" << w << ' ' << evt.id);
508 }
509
510 return false;
511}
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General exception.
Definition Exception.hh:13
static std::ostream & getOstream()
Get output stream for conversion of exception.
Definition Exception.hh:63
void push_front(std::vector< T > &vec, const T &value)
Put value in front of data.
Definition io_ascii.hh:240
std::vector< double > read_line_to_vector(std::istream &is)
Read data.
Definition io_ascii.hh:218
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
Definition io_ascii.hh:142
const char *const w3list_t
Definition io_ascii.hh:35
const char *const neutrino_t
Definition io_ascii.hh:29
const char *const weights_t
Definition io_ascii.hh:33
const char *const center_on_can_t
Definition io_ascii.hh:38
const char *const eventtime_t
Definition io_ascii.hh:37
const char *const track_in_t
Definition io_ascii.hh:26
const char *const track_t
Definition io_ascii.hh:27
const char *const muon_decay_t
Definition io_ascii.hh:39
const char *const start_event_t
Definition io_ascii.hh:23
const char *const hit_t
Definition io_ascii.hh:24
const char *const hourangle_t
Definition io_ascii.hh:36
const char *const track_bundle_t
Definition io_ascii.hh:31
const char *const end_event_t
Definition io_ascii.hh:40
const char *const w2list_t
Definition io_ascii.hh:34
const char *const track_primary_t
Definition io_ascii.hh:30
const char *const center_on_can_y
Definition io_ascii.hh:55
const char *const muon_decay_y
Definition io_ascii.hh:51
const char *const energy_lost_in_can
Definition io_ascii.hh:46
const char *const center_on_can_x
Definition io_ascii.hh:54
const char *const muon_decay_z
Definition io_ascii.hh:52
const char *const muon_decay_x
Definition io_ascii.hh:50
const char *const hourangle
Definition io_ascii.hh:57
const char *const center_on_can_z
Definition io_ascii.hh:56
void clearusr()
Clear user data.
Definition AAObject.hh:139
void setusr(const std::string &key, double value)
Set user data item with given key.
Definition AAObject.hh:95
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions)
Definition Evt.hh:42
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition Evt.hh:24
std::vector< Hit > hits
list of hits
Definition Evt.hh:38
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition Evt.hh:48
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition Evt.hh:49
int id
offline event identifier
Definition Evt.hh:22
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
Definition Evt.hh:46
std::vector< double > w3list
MC: atmospheric flux information.
Definition Evt.hh:44
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list or km3net-dataformat/definitions)
Definition Evt.hh:43
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition Evt.hh:39
Definition Hit.hh:10
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
void print(std::ostream &out=std::cout) const
Print track.
Definition Trk.hh:182
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition Trk.hh:28
int type
MC: particle type in PDG encoding.
Definition Trk.hh:24
int id
track identifier
Definition Trk.hh:16
Vec dir
track direction
Definition Trk.hh:18
std::string comment
use as you like
Definition Trk.hh:35
double E
Energy [GeV] (either MC truth or reconstructed)
Definition Trk.hh:20
double t
track time [ns] (when the particle is at pos )
Definition Trk.hh:19
double len
length, if applicable [m]
Definition Trk.hh:22
Vec pos
postion [m] of the track at time t
Definition Trk.hh:17
static const int PDG_MUONBUNDLE
muon bundle reached the can level (mupage)
Definition trkmembers.hh:38
static const int TRK_ST_FINALSTATE
for MC: the particle must be processed by detector simulation ('track_in' tag in evt files)....
Definition trkmembers.hh:15
static const int TRK_ST_MUONBUNDLE
initial state muon bundle (mupage)
Definition trkmembers.hh:18
static const int TRK_ST_PRIMARYCOSMIC
initial state cosmic ray ('track_primary' tag in evt files from corant).
Definition trkmembers.hh:17
static const int TRK_ST_PRIMARYNEUTRINO
initial state neutrino ('neutrino' tag in evt files from gseagen and genhen).
Definition trkmembers.hh:16
static const int W2LIST_GSEAGEN_BX
Bjorken x.
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
static const int W2LIST_GSEAGEN_BY
Bjorken y.

◆ write() [3/4]

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 521 of file io_ascii.hh.

522{
523 using namespace std;
524
525 // set precision to 12 digits.
526 const int precision = 12;
527 auto old_flags = os.flags();
528 auto old_precision = os.precision( precision );
529 os.unsetf( std::ios_base::scientific | std::ios_base::fixed ); // default behaviour
530
531 os << mc_keys::start_event_t << ' ' << evt.mc_id << ' ' << 1 << endl;
532
533 for ( auto& trk : evt.mc_trks ) {
534
535 const std::string& tag = trk.comment;
536
537 os << tag << ' '
538 << (tag != mc_keys::track_bundle_t ? trk.id : trk.len) << ' '
539 << trk.pos << ' '
540 << trk.dir << ' '
541 << trk.E;
542
543 if ( tag == mc_keys::track_in_t ) {
544
545 os << ' ' << trk.t << ' ' << geant3_code(trk.type) << ' ' << trk.len;
546
547 if ( trk.haveusr( mc_usr_keys::energy_lost_in_can ) ) {
548 os << ' ' << trk.getusr( mc_usr_keys::energy_lost_in_can );
549 }
550
551 os << endl;
552
553 } else if ( tag == mc_keys::track_primary_t ) {
554
555 os << ' ' << trk.t << ' ' << trk.type << endl;
556
557 } else if ( tag == mc_keys::neutrino_t ) {
558
559 double bx(0), by(0);
560 int ichan(0), cc(0);
561
562 if ( evt.w2list.size() > W2LIST_GSEAGEN_CC ) {
563 bx = evt.w2list[W2LIST_GSEAGEN_BX];
564 by = evt.w2list[W2LIST_GSEAGEN_BY];
565 ichan = evt.w2list[W2LIST_GSEAGEN_ICHAN];
566 cc = evt.w2list[W2LIST_GSEAGEN_CC];
567 }
568
569 os << ' ' << trk.t
570 << ' ' << bx
571 << ' ' << by
572 << ' ' << ichan
573 << ' ' << trk.type
574 << ' ' << cc
575 << endl;
576
577 } else {
578
579 os << endl;
580 }
581 }
582
583 for ( auto& trk : evt.trks ) {
584 os << mc_keys::track_fit_t << ' ' << trk.id << ' ' << trk.pos << ' ' << trk.dir << ' ' << trk.E << ' ' << trk.t << endl;
585 }
586
587 for ( auto& hit : evt.mc_hits ) write ( hit, os, mc_keys::hit_t);
588 for ( auto& hit : evt.hits ) write ( hit, os, mc_keys::hit_raw_t);
589
590 os << mc_keys::weights_t; for (auto& w : evt.w ) os << ' ' << w; os << endl;
591 os << mc_keys::w2list_t; for (auto& w : evt.w2list ) os << ' ' << w; os << endl;
592 os << mc_keys::w3list_t; for (auto& w : evt.w3list ) os << ' ' << w; os << endl;
593
594 os << mc_keys::eventtime_t << evt.mc_event_time.GetSec() << " "
595 << evt.mc_event_time.GetNanoSec() / 16 << endl;
596
597 os << mc_keys::end_event_t << endl;
598
599 // restore os to how we found it.
600 os.flags( old_flags );
601 os.precision( old_precision );
602
603 return true;
604}
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
Definition io_ascii.hh:155
const char *const track_fit_t
Definition io_ascii.hh:28

◆ read() [4/4]

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 619 of file io_ascii.hh.

620{
621 using namespace std;
622
623 string line;
624
625 bool start = false;
626
627 while (getline( is, line ))
628 {
630 {
631 break;
632 }
633
635 {
636 start = true;
637 }
638
640 {
641 THROW(Exception, "Unexpected tag " << mc_keys::start_event_t << " found while reading header at " << line << " (could mean the evt file has no header)");
642 }
643
644 if (!start) continue;
645
646 vector<string> v = splitstring( line, ':' );
647 if (v.size() < 2 )
648 {
649 std::cout << "Warning: line with empty tag found when reading header" << endl;
650 std::cout << " "<< line << endl;
651 std::cout << " will be skipped" << endl;
652 continue;
653 }
654
655 // the following with unsure key in the map is unique by adding _1 _2 etc.
657
658 }
659
660 if (!start)
661 {
662 THROW(Exception, "Reading of MC header terminated before finding a start_run: tag. Please check your file");
663 }
664
665 return start;
666}
std::vector< std::string > splitstring(const std::string &str, char delim=' ')
Split string at delimiter.
Definition Head.hh:43
bool startswith(const std::string &a, const std::string &b)
Check if string starts with given text.
Definition io_ascii.hh:70
std::string trim(const std::string &s)
Remove leading and trailing white spaces.
Definition io_ascii.hh:82
const char *const start_run_t
Definition io_ascii.hh:22
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
Definition Head.hh:176

◆ write() [4/4]

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 676 of file io_ascii.hh.

677{
678 hdr.print(os);
679 return true;
680}
void print(std::ostream &out=std::cout) const
Print header.
Definition Head.hh:298