CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes
mkfit::DataFile Struct Reference

#include <Event.h>

Public Types

enum  ExtraSection {
  ES_SimTrackStates = 0x1, ES_Seeds = 0x2, ES_CmsswTracks = 0x4, ES_HitIterMasks = 0x8,
  ES_BeamSpot = 0x10
}
 

Public Member Functions

int advancePosToNextEvent (FILE *fp)
 
void close ()
 
void CloseWrite (int n_written)
 
bool hasBeamSpot () const
 
bool hasCmsswTracks () const
 
bool hasHitIterMasks () const
 
bool hasSeeds () const
 
bool hasSimTrackStates () const
 
int openRead (const std::string &fname, int expected_n_layers)
 
void openWrite (const std::string &fname, int n_layers, int n_ev, int extra_sections=0)
 
void rewind ()
 
void skipNEvents (int n_to_skip)
 

Public Attributes

FILE * f_fp = 0
 
DataFileHeader f_header
 
std::mutex f_next_ev_mutex
 
long f_pos = sizeof(DataFileHeader)
 

Detailed Description

Definition at line 101 of file Event.h.

Member Enumeration Documentation

◆ ExtraSection

Enumerator
ES_SimTrackStates 
ES_Seeds 
ES_CmsswTracks 
ES_HitIterMasks 
ES_BeamSpot 

Definition at line 102 of file Event.h.

Member Function Documentation

◆ advancePosToNextEvent()

int mkfit::DataFile::advancePosToNextEvent ( FILE *  fp)

Definition at line 1016 of file Event.cc.

References f_next_ev_mutex, f_pos, personalPlayback::fp, and mkfit::Config::loopOverFile.

Referenced by mkfit::Event::read_in().

1016  {
1017  int evsize;
1018 
1019  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1020 
1021  fseek(fp, f_pos, SEEK_SET);
1022  fread(&evsize, sizeof(int), 1, fp);
1023  if (Config::loopOverFile) {
1024  // File ended, rewind back to beginning
1025  if (feof(fp) != 0) {
1026  f_pos = sizeof(DataFileHeader);
1027  fseek(fp, f_pos, SEEK_SET);
1028  fread(&evsize, sizeof(int), 1, fp);
1029  }
1030  }
1031 
1032  f_pos += evsize;
1033 
1034  return evsize;
1035  }
std::mutex f_next_ev_mutex
Definition: Event.h:115
long f_pos
Definition: Event.h:111

◆ close()

void mkfit::DataFile::close ( void  )

Definition at line 1049 of file Event.cc.

References f_fp, and f_header.

Referenced by CloseWrite(), esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), and test_standard().

1049  {
1050  fclose(f_fp);
1051  f_fp = 0;
1052  f_header = DataFileHeader();
1053  }
DataFileHeader f_header
Definition: Event.h:113
FILE * f_fp
Definition: Event.h:110

◆ CloseWrite()

void mkfit::DataFile::CloseWrite ( int  n_written)

Definition at line 1055 of file Event.cc.

References close(), f_fp, f_header, and mkfit::DataFileHeader::f_n_events.

Referenced by main().

1055  {
1056  if (f_header.f_n_events != n_written) {
1057  fseek(f_fp, 0, SEEK_SET);
1058  f_header.f_n_events = n_written;
1059  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
1060  }
1061  close();
1062  }
DataFileHeader f_header
Definition: Event.h:113
void close()
Definition: Event.cc:1049
FILE * f_fp
Definition: Event.h:110

◆ hasBeamSpot()

bool mkfit::DataFile::hasBeamSpot ( ) const
inline

◆ hasCmsswTracks()

bool mkfit::DataFile::hasCmsswTracks ( ) const
inline

◆ hasHitIterMasks()

bool mkfit::DataFile::hasHitIterMasks ( ) const
inline

◆ hasSeeds()

bool mkfit::DataFile::hasSeeds ( ) const
inline

◆ hasSimTrackStates()

bool mkfit::DataFile::hasSimTrackStates ( ) const
inline

◆ openRead()

int mkfit::DataFile::openRead ( const std::string &  fname,
int  expected_n_layers 
)

Definition at line 922 of file Event.cc.

References cms::cuda::assert(), mkfit::cmsswSeeds, ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), ES_CmsswTracks, ES_Seeds, ES_SimTrackStates, beamvalidation::exit(), mkfit::DataFileHeader::f_extra_sections, mkfit::DataFileHeader::f_format_version, f_fp, f_header, mkfit::DataFileHeader::f_magic, mkfit::DataFileHeader::f_n_events, mkfit::DataFileHeader::f_n_layers, mkfit::DataFileHeader::f_sizeof_hit, mkfit::DataFileHeader::f_sizeof_hot, mkfit::DataFileHeader::f_sizeof_track, alignmentValidation::fname, hasCmsswTracks(), hasSeeds(), mkfit::Config::readCmsswTracks, mkfit::Config::seedInput, and submitPVResolutionJobs::stderr.

Referenced by mkfit::Shell::Shell(), and test_standard().

922  {
923  constexpr int min_ver = 7;
924  constexpr int max_ver = 7;
925 
926  f_fp = fopen(fname.c_str(), "r");
927  assert(f_fp != 0 && "Opening of input file failed.");
928 
929  fread(&f_header, sizeof(DataFileHeader), 1, f_fp);
930 
931  if (f_header.f_magic != 0xBEEF) {
932  fprintf(stderr, "Incompatible input file (wrong magick).\n");
933  exit(1);
934  }
935  if (f_header.f_format_version < min_ver || f_header.f_format_version > max_ver) {
936  fprintf(stderr,
937  "Unsupported file version %d. Supported versions are from %d to %d.\n",
939  min_ver,
940  max_ver);
941  exit(1);
942  }
943  if (f_header.f_sizeof_track != sizeof(Track)) {
944  fprintf(stderr,
945  "sizeof(Track) on file (%d) different from current value (%d).\n",
947  (int)sizeof(Track));
948  exit(1);
949  }
950  if (f_header.f_sizeof_hit != sizeof(Hit)) {
951  fprintf(stderr,
952  "sizeof(Hit) on file (%d) different from current value (%d).\n",
954  (int)sizeof(Hit));
955  exit(1);
956  }
957  if (f_header.f_sizeof_hot != sizeof(HitOnTrack)) {
958  fprintf(stderr,
959  "sizeof(HitOnTrack) on file (%d) different from current value (%d).\n",
961  (int)sizeof(HitOnTrack));
962  exit(1);
963  }
964  if (f_header.f_n_layers != expected_n_layers) {
965  fprintf(stderr,
966  "Number of layers on file (%d) is different from current TrackerInfo (%d).\n",
968  expected_n_layers);
969  exit(1);
970  }
971 
972  printf("Opened file '%s', format version %d, n_layers %d, n_events %d\n",
973  fname.c_str(),
978  printf(" Extra sections:");
980  printf(" SimTrackStates");
982  printf(" Seeds");
984  printf(" CmsswTracks");
985  printf("\n");
986  }
987 
988  if (Config::seedInput == cmsswSeeds && !hasSeeds()) {
989  fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n");
990  exit(1);
991  }
992 
994  fprintf(stderr, "Reading of CmsswTracks requested but data not available on file.\n");
995  exit(1);
996  }
997 
998  return f_header.f_n_events;
999  }
bool hasCmsswTracks() const
Definition: Event.h:121
DataFileHeader f_header
Definition: Event.h:113
assert(be >=bs)
FILE * f_fp
Definition: Event.h:110
string fname
main script
bool hasSeeds() const
Definition: Event.h:120
def exit(msg="")

◆ openWrite()

void mkfit::DataFile::openWrite ( const std::string &  fname,
int  n_layers,
int  n_ev,
int  extra_sections = 0 
)

Definition at line 1001 of file Event.cc.

References mkfit::DataFileHeader::f_extra_sections, f_fp, f_header, mkfit::DataFileHeader::f_n_events, mkfit::DataFileHeader::f_n_layers, and alignmentValidation::fname.

Referenced by main().

1001  {
1002  f_fp = fopen(fname.c_str(), "w");
1003  f_header.f_n_layers = n_layers;
1004  f_header.f_n_events = n_ev;
1005  f_header.f_extra_sections = extra_sections;
1006 
1007  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
1008  }
DataFileHeader f_header
Definition: Event.h:113
FILE * f_fp
Definition: Event.h:110
string fname
main script

◆ rewind()

void mkfit::DataFile::rewind ( )

Definition at line 1010 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

Referenced by mkfit::Shell::GoToEvent().

1010  {
1011  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1012  f_pos = sizeof(DataFileHeader);
1013  fseek(f_fp, f_pos, SEEK_SET);
1014  }
std::mutex f_next_ev_mutex
Definition: Event.h:115
FILE * f_fp
Definition: Event.h:110
long f_pos
Definition: Event.h:111

◆ skipNEvents()

void mkfit::DataFile::skipNEvents ( int  n_to_skip)

Definition at line 1037 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

Referenced by mkfit::Shell::GoToEvent(), and test_standard().

1037  {
1038  int evsize;
1039 
1040  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1041 
1042  while (n_to_skip-- > 0) {
1043  fseek(f_fp, f_pos, SEEK_SET);
1044  fread(&evsize, sizeof(int), 1, f_fp);
1045  f_pos += evsize;
1046  }
1047  }
std::mutex f_next_ev_mutex
Definition: Event.h:115
FILE * f_fp
Definition: Event.h:110
long f_pos
Definition: Event.h:111

Member Data Documentation

◆ f_fp

FILE* mkfit::DataFile::f_fp = 0

◆ f_header

DataFileHeader mkfit::DataFile::f_header

◆ f_next_ev_mutex

std::mutex mkfit::DataFile::f_next_ev_mutex

Definition at line 115 of file Event.h.

Referenced by advancePosToNextEvent(), rewind(), and skipNEvents().

◆ f_pos

long mkfit::DataFile::f_pos = sizeof(DataFileHeader)

Definition at line 111 of file Event.h.

Referenced by advancePosToNextEvent(), rewind(), and skipNEvents().