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 1013 of file Event.cc.

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

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

1013  {
1014  int evsize;
1015 
1016  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1017 
1018  fseek(fp, f_pos, SEEK_SET);
1019  fread(&evsize, sizeof(int), 1, fp);
1020  if (Config::loopOverFile) {
1021  // File ended, rewind back to beginning
1022  if (feof(fp) != 0) {
1023  f_pos = sizeof(DataFileHeader);
1024  fseek(fp, f_pos, SEEK_SET);
1025  fread(&evsize, sizeof(int), 1, fp);
1026  }
1027  }
1028 
1029  f_pos += evsize;
1030 
1031  return evsize;
1032  }
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 1046 of file Event.cc.

References f_fp, and f_header.

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

1046  {
1047  fclose(f_fp);
1048  f_fp = 0;
1049  f_header = DataFileHeader();
1050  }
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 1052 of file Event.cc.

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

Referenced by main().

1052  {
1053  if (f_header.f_n_events != n_written) {
1054  fseek(f_fp, 0, SEEK_SET);
1055  f_header.f_n_events = n_written;
1056  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
1057  }
1058  close();
1059  }
DataFileHeader f_header
Definition: Event.h:112
void close()
Definition: Event.cc:1046
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 919 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().

919  {
920  constexpr int min_ver = 7;
921  constexpr int max_ver = 7;
922 
923  f_fp = fopen(fname.c_str(), "r");
924  assert(f_fp != 0 && "Opening of input file failed.");
925 
926  fread(&f_header, sizeof(DataFileHeader), 1, f_fp);
927 
928  if (f_header.f_magic != 0xBEEF) {
929  fprintf(stderr, "Incompatible input file (wrong magick).\n");
930  exit(1);
931  }
932  if (f_header.f_format_version < min_ver || f_header.f_format_version > max_ver) {
933  fprintf(stderr,
934  "Unsupported file version %d. Supported versions are from %d to %d.\n",
936  min_ver,
937  max_ver);
938  exit(1);
939  }
940  if (f_header.f_sizeof_track != sizeof(Track)) {
941  fprintf(stderr,
942  "sizeof(Track) on file (%d) different from current value (%d).\n",
944  (int)sizeof(Track));
945  exit(1);
946  }
947  if (f_header.f_sizeof_hit != sizeof(Hit)) {
948  fprintf(stderr,
949  "sizeof(Hit) on file (%d) different from current value (%d).\n",
951  (int)sizeof(Hit));
952  exit(1);
953  }
954  if (f_header.f_sizeof_hot != sizeof(HitOnTrack)) {
955  fprintf(stderr,
956  "sizeof(HitOnTrack) on file (%d) different from current value (%d).\n",
958  (int)sizeof(HitOnTrack));
959  exit(1);
960  }
961  if (f_header.f_n_layers != expected_n_layers) {
962  fprintf(stderr,
963  "Number of layers on file (%d) is different from current TrackerInfo (%d).\n",
965  expected_n_layers);
966  exit(1);
967  }
968 
969  printf("Opened file '%s', format version %d, n_layers %d, n_events %d\n",
970  fname.c_str(),
975  printf(" Extra sections:");
977  printf(" SimTrackStates");
979  printf(" Seeds");
981  printf(" CmsswTracks");
982  printf("\n");
983  }
984 
985  if (Config::seedInput == cmsswSeeds && !hasSeeds()) {
986  fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n");
987  exit(1);
988  }
989 
991  fprintf(stderr, "Reading of CmsswTracks requested but data not available on file.\n");
992  exit(1);
993  }
994 
995  return f_header.f_n_events;
996  }
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 998 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().

998  {
999  f_fp = fopen(fname.c_str(), "w");
1000  f_header.f_n_layers = n_layers;
1001  f_header.f_n_events = n_ev;
1002  f_header.f_extra_sections = extra_sections;
1003 
1004  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
1005  }
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 1007 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

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

1007  {
1008  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1009  f_pos = sizeof(DataFileHeader);
1010  fseek(f_fp, f_pos, SEEK_SET);
1011  }
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 1034 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

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

1034  {
1035  int evsize;
1036 
1037  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
1038 
1039  while (n_to_skip-- > 0) {
1040  fseek(f_fp, f_pos, SEEK_SET);
1041  fread(&evsize, sizeof(int), 1, f_fp);
1042  f_pos += evsize;
1043  }
1044  }
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().