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

Member Enumeration Documentation

◆ ExtraSection

Enumerator
ES_SimTrackStates 
ES_Seeds 
ES_CmsswTracks 
ES_HitIterMasks 
ES_BeamSpot 

Definition at line 88 of file Event.h.

Member Function Documentation

◆ advancePosToNextEvent()

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

Definition at line 939 of file Event.cc.

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

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

939  {
940  int evsize;
941 
942  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
943 
944  fseek(fp, f_pos, SEEK_SET);
945  fread(&evsize, sizeof(int), 1, fp);
946  if (Config::loopOverFile) {
947  // File ended, rewind back to beginning
948  if (feof(fp) != 0) {
949  f_pos = sizeof(DataFileHeader);
950  fseek(fp, f_pos, SEEK_SET);
951  fread(&evsize, sizeof(int), 1, fp);
952  }
953  }
954 
955  f_pos += evsize;
956 
957  return evsize;
958  }
std::mutex f_next_ev_mutex
Definition: Event.h:101
long f_pos
Definition: Event.h:97

◆ close()

void mkfit::DataFile::close ( void  )

Definition at line 972 of file Event.cc.

References f_fp, and f_header.

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

972  {
973  fclose(f_fp);
974  f_fp = 0;
975  f_header = DataFileHeader();
976  }
DataFileHeader f_header
Definition: Event.h:99
FILE * f_fp
Definition: Event.h:96

◆ CloseWrite()

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

Definition at line 978 of file Event.cc.

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

Referenced by main().

978  {
979  if (f_header.f_n_events != n_written) {
980  fseek(f_fp, 0, SEEK_SET);
981  f_header.f_n_events = n_written;
982  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
983  }
984  close();
985  }
DataFileHeader f_header
Definition: Event.h:99
void close()
Definition: Event.cc:972
FILE * f_fp
Definition: Event.h:96

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

References cms::cuda::assert(), mkfit::cmsswSeeds, 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 test_standard().

851  {
852  constexpr int min_ver = 4;
853  constexpr int max_ver = 6;
854 
855  f_fp = fopen(fname.c_str(), "r");
856  assert(f_fp != 0 && "Opening of input file failed.");
857 
858  fread(&f_header, sizeof(DataFileHeader), 1, f_fp);
859 
860  if (f_header.f_magic != 0xBEEF) {
861  fprintf(stderr, "Incompatible input file (wrong magick).\n");
862  exit(1);
863  }
864  if (f_header.f_format_version < min_ver || f_header.f_format_version > max_ver) {
865  fprintf(stderr,
866  "Unsupported file version %d. Supported versions are from %d to %d.\n",
868  min_ver,
869  max_ver);
870  exit(1);
871  }
872  if (f_header.f_sizeof_track != sizeof(Track)) {
873  fprintf(stderr,
874  "sizeof(Track) on file (%d) different from current value (%d).\n",
876  (int)sizeof(Track));
877  exit(1);
878  }
879  if (f_header.f_sizeof_hit != sizeof(Hit)) {
880  fprintf(stderr,
881  "sizeof(Hit) on file (%d) different from current value (%d).\n",
883  (int)sizeof(Hit));
884  exit(1);
885  }
886  if (f_header.f_sizeof_hot != sizeof(HitOnTrack)) {
887  fprintf(stderr,
888  "sizeof(HitOnTrack) on file (%d) different from current value (%d).\n",
890  (int)sizeof(HitOnTrack));
891  exit(1);
892  }
893  if (f_header.f_n_layers != expected_n_layers) {
894  fprintf(stderr,
895  "Number of layers on file (%d) is different from current TrackerInfo (%d).\n",
897  expected_n_layers);
898  exit(1);
899  }
900 
901  printf("Opened file '%s', format version %d, n_layers %d, n_events %d\n",
902  fname.c_str(),
907  printf(" Extra sections:");
909  printf(" SimTrackStates");
911  printf(" Seeds");
913  printf(" CmsswTracks");
914  printf("\n");
915  }
916 
917  if (Config::seedInput == cmsswSeeds && !hasSeeds()) {
918  fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n");
919  exit(1);
920  }
921 
923  fprintf(stderr, "Reading of CmsswTracks requested but data not available on file.\n");
924  exit(1);
925  }
926 
927  return f_header.f_n_events;
928  }
bool hasCmsswTracks() const
Definition: Event.h:107
DataFileHeader f_header
Definition: Event.h:99
assert(be >=bs)
FILE * f_fp
Definition: Event.h:96
string fname
main script
bool hasSeeds() const
Definition: Event.h:106
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 930 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().

930  {
931  f_fp = fopen(fname.c_str(), "w");
932  f_header.f_n_layers = n_layers;
933  f_header.f_n_events = n_ev;
934  f_header.f_extra_sections = extra_sections;
935 
936  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
937  }
DataFileHeader f_header
Definition: Event.h:99
FILE * f_fp
Definition: Event.h:96
string fname
main script

◆ skipNEvents()

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

Definition at line 960 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

Referenced by test_standard().

960  {
961  int evsize;
962 
963  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
964 
965  while (n_to_skip-- > 0) {
966  fseek(f_fp, f_pos, SEEK_SET);
967  fread(&evsize, sizeof(int), 1, f_fp);
968  f_pos += evsize;
969  }
970  }
std::mutex f_next_ev_mutex
Definition: Event.h:101
FILE * f_fp
Definition: Event.h:96
long f_pos
Definition: Event.h:97

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

Referenced by advancePosToNextEvent(), and skipNEvents().

◆ f_pos

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

Definition at line 97 of file Event.h.

Referenced by advancePosToNextEvent(), and skipNEvents().