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

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

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

946  {
947  int evsize;
948 
949  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
950 
951  fseek(fp, f_pos, SEEK_SET);
952  fread(&evsize, sizeof(int), 1, fp);
953  if (Config::loopOverFile) {
954  // File ended, rewind back to beginning
955  if (feof(fp) != 0) {
956  f_pos = sizeof(DataFileHeader);
957  fseek(fp, f_pos, SEEK_SET);
958  fread(&evsize, sizeof(int), 1, fp);
959  }
960  }
961 
962  f_pos += evsize;
963 
964  return evsize;
965  }
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 979 of file Event.cc.

References f_fp, and f_header.

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

979  {
980  fclose(f_fp);
981  f_fp = 0;
982  f_header = DataFileHeader();
983  }
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 985 of file Event.cc.

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

Referenced by main().

985  {
986  if (f_header.f_n_events != n_written) {
987  fseek(f_fp, 0, SEEK_SET);
988  f_header.f_n_events = n_written;
989  fwrite(&f_header, sizeof(DataFileHeader), 1, f_fp);
990  }
991  close();
992  }
DataFileHeader f_header
Definition: Event.h:99
void close()
Definition: Event.cc:979
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 852 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 mkfit::Shell::Shell(), and test_standard().

852  {
853  constexpr int min_ver = 7;
854  constexpr int max_ver = 7;
855 
856  f_fp = fopen(fname.c_str(), "r");
857  assert(f_fp != 0 && "Opening of input file failed.");
858 
859  fread(&f_header, sizeof(DataFileHeader), 1, f_fp);
860 
861  if (f_header.f_magic != 0xBEEF) {
862  fprintf(stderr, "Incompatible input file (wrong magick).\n");
863  exit(1);
864  }
865  if (f_header.f_format_version < min_ver || f_header.f_format_version > max_ver) {
866  fprintf(stderr,
867  "Unsupported file version %d. Supported versions are from %d to %d.\n",
869  min_ver,
870  max_ver);
871  exit(1);
872  }
873  if (f_header.f_sizeof_track != sizeof(Track)) {
874  fprintf(stderr,
875  "sizeof(Track) on file (%d) different from current value (%d).\n",
877  (int)sizeof(Track));
878  exit(1);
879  }
880  if (f_header.f_sizeof_hit != sizeof(Hit)) {
881  fprintf(stderr,
882  "sizeof(Hit) on file (%d) different from current value (%d).\n",
884  (int)sizeof(Hit));
885  exit(1);
886  }
887  if (f_header.f_sizeof_hot != sizeof(HitOnTrack)) {
888  fprintf(stderr,
889  "sizeof(HitOnTrack) on file (%d) different from current value (%d).\n",
891  (int)sizeof(HitOnTrack));
892  exit(1);
893  }
894  if (f_header.f_n_layers != expected_n_layers) {
895  fprintf(stderr,
896  "Number of layers on file (%d) is different from current TrackerInfo (%d).\n",
898  expected_n_layers);
899  exit(1);
900  }
901 
902  printf("Opened file '%s', format version %d, n_layers %d, n_events %d\n",
903  fname.c_str(),
908  printf(" Extra sections:");
910  printf(" SimTrackStates");
912  printf(" Seeds");
914  printf(" CmsswTracks");
915  printf("\n");
916  }
917 
918  if (Config::seedInput == cmsswSeeds && !hasSeeds()) {
919  fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n");
920  exit(1);
921  }
922 
924  fprintf(stderr, "Reading of CmsswTracks requested but data not available on file.\n");
925  exit(1);
926  }
927 
928  return f_header.f_n_events;
929  }
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 931 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().

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

◆ rewind()

void mkfit::DataFile::rewind ( )

Definition at line 940 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

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

940  {
941  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
942  f_pos = sizeof(DataFileHeader);
943  fseek(f_fp, f_pos, SEEK_SET);
944  }
std::mutex f_next_ev_mutex
Definition: Event.h:101
FILE * f_fp
Definition: Event.h:96
long f_pos
Definition: Event.h:97

◆ skipNEvents()

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

Definition at line 967 of file Event.cc.

References f_fp, f_next_ev_mutex, and f_pos.

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

967  {
968  int evsize;
969 
970  std::lock_guard<std::mutex> readlock(f_next_ev_mutex);
971 
972  while (n_to_skip-- > 0) {
973  fseek(f_fp, f_pos, SEEK_SET);
974  fread(&evsize, sizeof(int), 1, f_fp);
975  f_pos += evsize;
976  }
977  }
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(), rewind(), and skipNEvents().

◆ f_pos

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

Definition at line 97 of file Event.h.

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