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 100 of file Event.h.

Member Enumeration Documentation

◆ ExtraSection

Enumerator
ES_SimTrackStates 
ES_Seeds 
ES_CmsswTracks 
ES_HitIterMasks 
ES_BeamSpot 

Definition at line 101 of file Event.h.

Member Function Documentation

◆ advancePosToNextEvent()

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

Definition at line 1020 of file Event.cc.

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

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

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

◆ close()

void mkfit::DataFile::close ( void  )

Definition at line 1053 of file Event.cc.

References f_fp, and f_header.

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

1053  {
1054  fclose(f_fp);
1055  f_fp = 0;
1056  f_header = DataFileHeader();
1057  }
DataFileHeader f_header
Definition: Event.h:112
FILE * f_fp
Definition: Event.h:109

◆ CloseWrite()

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

Definition at line 1059 of file Event.cc.

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

Referenced by main().

1059  {
1060  if (f_header.f_n_events != n_written) {
1061  fseek(f_fp, 0, SEEK_SET);
1062  f_header.f_n_events = n_written;
1063  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
1064  }
1065  close();
1066  }
DataFileHeader f_header
Definition: Event.h:112
void close()
Definition: Event.cc:1053
FILE * f_fp
Definition: Event.h:109

◆ 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 926 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().

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

1005  {
1006  f_fp = fopen(fname.c_str(), "w");
1007  f_header.f_n_layers = n_layers;
1008  f_header.f_n_events = n_ev;
1009  f_header.f_extra_sections = extra_sections;
1010 
1011  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
1012  }
DataFileHeader f_header
Definition: Event.h:112
FILE * f_fp
Definition: Event.h:109
string fname
main script

◆ rewind()

void mkfit::DataFile::rewind ( )

Definition at line 1014 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

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

1014  {
1015  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1016  f_pos = sizeof(DataFileHeader);
1017  fseek(f_fp, f_pos, SEEK_SET);
1018  }
std::mutex f_next_ev_mutex
Definition: Event.h:114
FILE * f_fp
Definition: Event.h:109
long f_pos
Definition: Event.h:110

◆ skipNEvents()

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

Definition at line 1041 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

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

1041  {
1042  int evsize;
1043 
1044  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1045 
1046  while (n_to_skip-- > 0) {
1047  fseek(f_fp, f_pos, SEEK_SET);
1048  fread(&evsize, sizeof(int), 1, f_fp);
1049  f_pos += evsize;
1050  }
1051  }
std::mutex f_next_ev_mutex
Definition: Event.h:114
FILE * f_fp
Definition: Event.h:109
long f_pos
Definition: Event.h:110

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 114 of file Event.h.

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

◆ f_pos

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

Definition at line 110 of file Event.h.

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