MIDAS
Loading...
Searching...
No Matches
HsFileSchema Class Reference
Inheritance diagram for HsFileSchema:
Collaboration diagram for HsFileSchema:

Public Member Functions

 HsFileSchema ()
 
 ~HsFileSchema ()
 
void remove_inactive_columns ()
 
void print (bool print_tags=true) const
 
int flush_buffers ()
 
int close ()
 
int write_event (const time_t t, const char *data, const size_t data_size)
 
int read_last_written (const time_t timestamp, const int debug, time_t *last_written)
 
int read_data (const time_t start_time, const time_t end_time, const int num_var, const std::vector< int > &var_schema_index, const int var_index[], const int debug, std::vector< time_t > &last_time, MidasHistoryBufferInterface *buffer[])
 
- Public Member Functions inherited from HsSchema
 HsSchema ()
 
virtual ~HsSchema ()
 
virtual int match_event_var (const char *event_name, const char *var_name, const int var_index)
 

Public Attributes

std::string fFileName
 
size_t fRecordSize = 0
 
off64_t fDataOffset = 0
 
size_t fLastSize = 0
 
int fWriterFd = -1
 
size_t fRecordBufferSize = 0
 
char * fRecordBuffer = NULL
 
off64_t fFileSizeInitial = 0
 
off64_t fFileSize = 0
 
- Public Attributes inherited from HsSchema
std::string fEventName
 
time_t fTimeFrom = 0
 
time_t fTimeTo = 0
 
std::vector< HsSchemaEntryfVariables
 
std::vector< int > fOffsets
 
size_t fNumBytes = 0
 
int fCountWriteUndersize = 0
 
int fCountWriteOversize = 0
 
size_t fWriteMaxSize = 0
 
size_t fWriteMinSize = 0
 
bool fDisabled = true
 

Detailed Description

Definition at line 757 of file history_schema.cxx.

Constructor & Destructor Documentation

◆ HsFileSchema()

HsFileSchema::HsFileSchema ( )
inline

Definition at line 775 of file history_schema.cxx.

776 {
777 // empty
778 }

◆ ~HsFileSchema()

HsFileSchema::~HsFileSchema ( )
inline

Definition at line 780 of file history_schema.cxx.

781 {
782 //printf("HsFileSchema::dtor %p!\n", this);
783 close();
784 fRecordSize = 0;
785 fDataOffset = 0;
786 fLastSize = 0;
787 fWriterFd = -1;
788 if (fRecordBuffer) {
789 free(fRecordBuffer);
790 fRecordBuffer = NULL;
791 }
793 }
Here is the call graph for this function:

Member Function Documentation

◆ close()

int HsFileSchema::close ( )
virtual

Implements HsSchema.

Definition at line 2606 of file history_schema.cxx.

2607{
2608 if (fWriterFd >= 0) {
2610 fWriterFd = -1;
2611 }
2612 return HS_SUCCESS;
2613}
#define HS_SUCCESS
Definition midas.h:728
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flush_buffers()

int HsFileSchema::flush_buffers ( )
inlinevirtual

Implements HsSchema.

Definition at line 797 of file history_schema.cxx.

797{ return HS_SUCCESS; };

◆ print()

void HsFileSchema::print ( bool  print_tags = true) const
virtual

Reimplemented from HsSchema.

Definition at line 838 of file history_schema.cxx.

839{
840 size_t nv = this->fVariables.size();
841 printf("event [%s], file_name [%s], time %s..%s, %zu variables, %zu bytes, dat_offset %jd, record_size %zu\n", this->fEventName.c_str(), this->fFileName.c_str(), TimeToString(this->fTimeFrom).c_str(), TimeToString(this->fTimeTo).c_str(), nv, fNumBytes, (intmax_t)fDataOffset, fRecordSize);
842 if (print_tags) {
843 for (size_t j=0; j<nv; j++)
844 printf(" %zu: name [%s], type [%s] tid %d, n_data %d, n_bytes %d, offset %d\n", j, this->fVariables[j].name.c_str(), rpc_tid_name(this->fVariables[j].type), this->fVariables[j].type, this->fVariables[j].n_data, this->fVariables[j].n_bytes, this->fOffsets[j]);
845 }
846}
std::vector< int > fOffsets
std::vector< HsSchemaEntry > fVariables
std::string fEventName
const char * rpc_tid_name(INT id)
Definition midas.cxx:11895
static std::string TimeToString(time_t t)
INT type
Definition mana.cxx:269
#define name(x)
Definition midas_macro.h:24
INT j
Definition odbhist.cxx:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_data()

int HsFileSchema::read_data ( const time_t  start_time,
const time_t  end_time,
const int  num_var,
const std::vector< int > &  var_schema_index,
const int  var_index[],
const int  debug,
std::vector< time_t > &  last_time,
MidasHistoryBufferInterface buffer[] 
)
virtual

Implements HsSchema.

Definition at line 2877 of file history_schema.cxx.

2883{
2884 HsFileSchema* s = this;
2885
2886 if (debug)
2887 printf("FileHistory::read_data: file %s, schema time %s..%s, read time %s..%s, %d vars\n", s->fFileName.c_str(), TimeToString(s->fTimeFrom).c_str(), TimeToString(s->fTimeTo).c_str(), TimeToString(start_time).c_str(), TimeToString(end_time).c_str(), num_var);
2888
2889 //if (1) {
2890 // printf("Last time: ");
2891 // for (int i=0; i<num_var; i++) {
2892 // printf(" %s", TimeToString(last_time[i]).c_str());
2893 // }
2894 // printf("\n");
2895 //}
2896
2897 if (debug) {
2898 printf("FileHistory::read_data: file %s map", s->fFileName.c_str());
2899 for (size_t i=0; i<var_schema_index.size(); i++) {
2900 printf(" %2d", var_schema_index[i]);
2901 }
2902 printf("\n");
2903 }
2904
2905 int fd = ::open(s->fFileName.c_str(), O_RDONLY);
2906 if (fd < 0) {
2907 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', open() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2908 return HS_FILE_ERROR;
2909 }
2910
2911 off64_t file_size = ::lseek64(fd, 0, SEEK_END);
2912
2913 if (file_size < 0) {
2914 cm_msg(MERROR, "FileHistory::read_data", "Cannot read file size of \'%s\', lseek64(SEEK_END) errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2915 ::close(fd);
2916 return HS_FILE_ERROR;
2917 }
2918
2919 if (file_size < s->fDataOffset) {
2920 // empty file
2921 ::close(fd);
2922 return HS_SUCCESS;
2923 }
2924
2925 off64_t nrec = (file_size - s->fDataOffset)/s->fRecordSize;
2926
2927 //printf("read_data: nrec %jd, file_size %jd, offset %jd, record size %zu\n", (intmax_t)nrec, (intmax_t)file_size, s->fDataOffset, s->fRecordSize);
2928
2929 if (nrec < 0)
2930 nrec = 0;
2931
2932 if (nrec < 1) {
2933 ::close(fd);
2934 return HS_SUCCESS;
2935 }
2936
2937 off64_t iunused = 0;
2938 time_t tunused = 0;
2939 off64_t irec = 0;
2940 time_t trec = 0;
2941 time_t tstart = 0;
2942 time_t tend = 0;
2943
2944 int istatus = FindTime(s->fFileName.c_str(), fd, s->fDataOffset, s->fRecordSize, nrec, start_time, &iunused, &tunused, &irec, &trec, &tstart, &tend, 0*debug);
2945
2946 if (istatus != HS_SUCCESS) {
2947 ::close(fd);
2948 return HS_FILE_ERROR;
2949 }
2950
2951 if (debug) {
2952 printf("FindTime %d, nrec %jd, (%jd, %s) (%jd, %s), tstart %s, tend %s, want %s\n", istatus, (intmax_t)nrec, (intmax_t)iunused, TimeToString(tunused).c_str(), (intmax_t)irec, TimeToString(trec).c_str(), TimeToString(tstart).c_str(), TimeToString(tend).c_str(), TimeToString(start_time).c_str());
2953 }
2954
2955 if (irec < 0 || irec >= nrec) {
2956 // all data in this file is older than start_time
2957
2958 ::close(fd);
2959
2960 if (debug)
2961 printf("FileHistory::read: file %s, schema time %s..%s, read time %s..%s, file time %s..%s, data in this file is too old\n", s->fFileName.c_str(), TimeToString(s->fTimeFrom).c_str(), TimeToString(s->fTimeTo).c_str(), TimeToString(start_time).c_str(), TimeToString(end_time).c_str(), TimeToString(tstart).c_str(), TimeToString(tend).c_str());
2962
2963 return HS_SUCCESS;
2964 }
2965
2966 if (tstart < s->fTimeFrom) {
2967 // data starts before time declared in schema
2968
2969 ::close(fd);
2970
2971 cm_msg(MERROR, "FileHistory::read_data", "Bad history file \'%s\': timestamp of first data %s is before schema start time %s", s->fFileName.c_str(), TimeToString(tstart).c_str(), TimeToString(s->fTimeFrom).c_str());
2972
2973 return HS_FILE_ERROR;
2974 }
2975
2976 if (tend && s->fTimeTo && tend > s->fTimeTo) {
2977 // data ends after time declared in schema (overlaps with next file)
2978
2979 ::close(fd);
2980
2981 cm_msg(MERROR, "FileHistory::read_data", "Bad history file \'%s\': timestamp of last data %s is after schema end time %s", s->fFileName.c_str(), TimeToString(tend).c_str(), TimeToString(s->fTimeTo).c_str());
2982
2983 return HS_FILE_ERROR;
2984 }
2985
2986 for (int i=0; i<num_var; i++) {
2987 int si = var_schema_index[i];
2988 if (si < 0)
2989 continue;
2990
2991 if (trec < last_time[i]) { // protect against duplicate and non-monotonous data
2992 ::close(fd);
2993
2994 cm_msg(MERROR, "FileHistory::read_data", "Internal history error at file \'%s\': variable %d data timestamp %s is before last timestamp %s", s->fFileName.c_str(), i, TimeToString(trec).c_str(), TimeToString(last_time[i]).c_str());
2995
2996 return HS_FILE_ERROR;
2997 }
2998 }
2999
3000 int count = 0;
3001
3002 off64_t fpos = s->fDataOffset + irec*s->fRecordSize;
3003
3004 off64_t xpos = ::lseek64(fd, fpos, SEEK_SET);
3005
3006 //printf("read_data: lseek64() returned %jd, irec %jd, offset %jd, record size %zu, fpos %jd\n", xpos, irec, s->fDataOffset, s->fRecordSize, fpos);
3007
3008 if (xpos < 0) {
3009 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', lseek64(%jd) errno %d (%s)", s->fFileName.c_str(), (intmax_t)fpos, errno, strerror(errno));
3010 ::close(fd);
3011 return HS_FILE_ERROR;
3012 }
3013
3014 char* buf = new char[s->fRecordSize];
3015
3016 off64_t prec = irec;
3017
3018 while (1) {
3019 ssize_t rd = ::read(fd, buf, s->fRecordSize);
3020
3021 if (rd < 0) {
3022 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', read() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
3023 break;
3024 }
3025
3026 if (rd == 0) {
3027 // EOF
3028 break;
3029 }
3030
3031 if ((size_t)rd != s->fRecordSize) {
3032 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', short read() returned %zd instead of %zu bytes", s->fFileName.c_str(), rd, s->fRecordSize);
3033 break;
3034 }
3035
3036 prec++;
3037
3038 bool past_end_of_last_file = (s->fTimeTo == 0) && (prec > nrec);
3039
3040 time_t t = *(DWORD*)buf;
3041
3042 if (debug > 1)
3043 printf("FileHistory::read: file %s, schema time %s..%s, read time %s..%s, row time %s\n", s->fFileName.c_str(), TimeToString(s->fTimeFrom).c_str(), TimeToString(s->fTimeTo).c_str(), TimeToString(start_time).c_str(), TimeToString(end_time).c_str(), TimeToString(t).c_str());
3044
3045 if (t < trec) {
3046 delete[] buf;
3047 ::close(fd);
3048 cm_msg(MERROR, "FileHistory::read_data", "Bad history file \'%s\': record %jd timestamp %s is before start time %s", s->fFileName.c_str(), (intmax_t)(irec + count), TimeToString(t).c_str(), TimeToString(trec).c_str());
3049 return HS_FILE_ERROR;
3050 }
3051
3052 if (tend && (t > tend) && !past_end_of_last_file) {
3053 delete[] buf;
3054 ::close(fd);
3055 cm_msg(MERROR, "FileHistory::read_data", "Bad history file \'%s\': record %jd timestamp %s is after last timestamp %s", s->fFileName.c_str(), (intmax_t)(irec + count), TimeToString(t).c_str(), TimeToString(tend).c_str());
3056 return HS_FILE_ERROR;
3057 }
3058
3059 if (t > end_time)
3060 break;
3061
3062 char* data = buf + 4;
3063
3064 for (int i=0; i<num_var; i++) {
3065 int si = var_schema_index[i];
3066 if (si < 0)
3067 continue;
3068
3069 if (t < last_time[i]) { // protect against duplicate and non-monotonous data
3070 delete[] buf;
3071 ::close(fd);
3072
3073 cm_msg(MERROR, "FileHistory::read_data", "Bad history file \'%s\': record %jd timestamp %s is before timestamp %s of variable %d", s->fFileName.c_str(), (intmax_t)(irec + count), TimeToString(t).c_str(), TimeToString(last_time[i]).c_str(), i);
3074
3075 return HS_FILE_ERROR;
3076 }
3077
3078 double v = 0;
3079 void* ptr = data + s->fOffsets[si];
3080
3081 int ii = var_index[i];
3082 assert(ii >= 0);
3083 assert(ii < s->fVariables[si].n_data);
3084
3085 switch (s->fVariables[si].type) {
3086 default:
3087 // unknown data type
3088 v = 0;
3089 break;
3090 case TID_BYTE:
3091 v = ((unsigned char*)ptr)[ii];
3092 break;
3093 case TID_SBYTE:
3094 v = ((signed char *)ptr)[ii];
3095 break;
3096 case TID_CHAR:
3097 v = ((char*)ptr)[ii];
3098 break;
3099 case TID_WORD:
3100 v = ((unsigned short *)ptr)[ii];
3101 break;
3102 case TID_SHORT:
3103 v = ((signed short *)ptr)[ii];
3104 break;
3105 case TID_DWORD:
3106 v = ((unsigned int *)ptr)[ii];
3107 break;
3108 case TID_INT:
3109 v = ((int *)ptr)[ii];
3110 break;
3111 case TID_BOOL:
3112 v = ((unsigned int *)ptr)[ii];
3113 break;
3114 case TID_FLOAT:
3115 v = ((float*)ptr)[ii];
3116 break;
3117 case TID_DOUBLE:
3118 v = ((double*)ptr)[ii];
3119 break;
3120 }
3121
3122 buffer[i]->Add(t, v);
3123 last_time[i] = t;
3124 }
3125 count++;
3126 }
3127
3128 delete[] buf;
3129
3130 ::close(fd);
3131
3132 if (debug) {
3133 printf("FileHistory::read_data: file %s map", s->fFileName.c_str());
3134 for (size_t i=0; i<var_schema_index.size(); i++) {
3135 printf(" %2d", var_schema_index[i]);
3136 }
3137 printf(" read %d rows\n", count);
3138 }
3139
3140 if (debug)
3141 printf("FileHistory::read: file %s, schema time %s..%s, read time %s..%s, %d vars, read %d rows\n", s->fFileName.c_str(), TimeToString(s->fTimeFrom).c_str(), TimeToString(s->fTimeTo).c_str(), TimeToString(start_time).c_str(), TimeToString(end_time).c_str(), num_var, count);
3142
3143 return HS_SUCCESS;
3144}
std::string fFileName
virtual void Add(time_t time, double value)=0
#define HS_FILE_ERROR
Definition midas.h:729
unsigned int DWORD
Definition mcstd.h:51
#define TID_DOUBLE
Definition midas.h:343
#define TID_SBYTE
Definition midas.h:329
#define TID_BOOL
Definition midas.h:340
#define TID_SHORT
Definition midas.h:334
#define TID_WORD
Definition midas.h:332
#define TID_BYTE
Definition midas.h:327
#define MERROR
Definition midas.h:559
#define TID_CHAR
Definition midas.h:331
#define TID_INT
Definition midas.h:338
#define TID_FLOAT
Definition midas.h:341
#define TID_DWORD
Definition midas.h:336
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:931
static int FindTime(const char *file_name, int fd, off64_t offset, size_t recsize, off64_t nrec, time_t timestamp, off64_t *i1p, time_t *t1p, off64_t *i2p, time_t *t2p, time_t *tstart, time_t *tend, int debug)
DWORD last_time
Definition mana.cxx:3070
void * data
Definition mana.cxx:268
BOOL debug
debug printouts
Definition mana.cxx:254
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
#define read(n, a, f)
Here is the call graph for this function:

◆ read_last_written()

int HsFileSchema::read_last_written ( const time_t  timestamp,
const int  debug,
time_t *  last_written 
)
virtual

Implements HsSchema.

Definition at line 2781 of file history_schema.cxx.

2784{
2785 int status;
2786 HsFileSchema* s = this;
2787
2788 if (debug)
2789 printf("FileHistory::read_last_written: file %s, schema time %s..%s, timestamp %s\n", s->fFileName.c_str(), TimeToString(s->fTimeFrom).c_str(), TimeToString(s->fTimeTo).c_str(), TimeToString(timestamp).c_str());
2790
2791 int fd = open(s->fFileName.c_str(), O_RDONLY);
2792 if (fd < 0) {
2793 cm_msg(MERROR, "FileHistory::read_last_written", "Cannot read \'%s\', open() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2794 return HS_FILE_ERROR;
2795 }
2796
2797 off64_t file_size = ::lseek64(fd, 0, SEEK_END);
2798
2799 if (file_size < 0) {
2800 cm_msg(MERROR, "FileHistory::read_last_written", "Cannot read file size of \'%s\', lseek64(SEEK_END) errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2801 return HS_FILE_ERROR;
2802 }
2803
2804 if (file_size < s->fDataOffset) {
2805 // empty file
2806 ::close(fd);
2807 if (last_written)
2808 *last_written = 0;
2809 return HS_SUCCESS;
2810 }
2811
2812 off64_t nrec = (file_size - s->fDataOffset)/s->fRecordSize;
2813
2814 //printf("read_last_written: nrec %jd, file_size %jd, offset %jd, record size %zu\n", (intmax_t)nrec, (intmax_t)file_size, s->fDataOffset, s->fRecordSize);
2815
2816 if (nrec < 0)
2817 nrec = 0;
2818
2819 if (nrec < 1) {
2820 ::close(fd);
2821 if (last_written)
2822 *last_written = 0;
2823 return HS_SUCCESS;
2824 }
2825
2826 time_t lw = 0;
2827
2828 // read last record to check if desired time is inside or outside of the file
2829
2830 if (1) {
2831 char* buf = new char[s->fRecordSize];
2832
2833 status = ReadRecord(s->fFileName.c_str(), fd, s->fDataOffset, s->fRecordSize, nrec - 1, buf);
2834 if (status != HS_SUCCESS) {
2835 delete[] buf;
2836 ::close(fd);
2837 return HS_FILE_ERROR;
2838 }
2839
2840 lw = *(DWORD*)buf;
2841
2842 delete[] buf;
2843 }
2844
2845 if (lw >= timestamp) {
2846 off64_t irec = 0;
2847 time_t trec = 0;
2848 off64_t iunused = 0;
2849 time_t tunused = 0;
2850 time_t tstart = 0; // not used
2851 time_t tend = 0; // not used
2852
2853 status = FindTime(s->fFileName.c_str(), fd, s->fDataOffset, s->fRecordSize, nrec, timestamp, &irec, &trec, &iunused, &tunused, &tstart, &tend, 0*debug);
2854 if (status != HS_SUCCESS) {
2855 ::close(fd);
2856 return HS_FILE_ERROR;
2857 }
2858
2859 assert(trec < timestamp);
2860
2861 lw = trec;
2862 }
2863
2864 if (last_written)
2865 *last_written = lw;
2866
2867 if (debug)
2868 printf("FileHistory::read_last_written: file %s, schema time %s..%s, timestamp %s, last_written %s\n", s->fFileName.c_str(), TimeToString(s->fTimeFrom).c_str(), TimeToString(s->fTimeTo).c_str(), TimeToString(timestamp).c_str(), TimeToString(lw).c_str());
2869
2870 assert(lw < timestamp);
2871
2872 ::close(fd);
2873
2874 return HS_SUCCESS;
2875}
static int ReadRecord(const char *file_name, int fd, off64_t offset, size_t recsize, off64_t irec, char *rec)
DWORD status
Definition odbhist.cxx:39
Here is the call graph for this function:

◆ remove_inactive_columns()

void HsFileSchema::remove_inactive_columns ( )
inlinevirtual

Implements HsSchema.

Definition at line 795 of file history_schema.cxx.

795{ /* empty */ };

◆ write_event()

int HsFileSchema::write_event ( const time_t  t,
const char *  data,
const size_t  data_size 
)
virtual

Implements HsSchema.

Definition at line 2483 of file history_schema.cxx.

2484{
2485 HsFileSchema* s = this;
2486
2487 assert(s->fVariables.size() == s->fOffsets.size());
2488
2489 if (s->fWriterFd < 0) {
2490 s->fWriterFd = open(s->fFileName.c_str(), O_RDWR);
2491 if (s->fWriterFd < 0) {
2492 cm_msg(MERROR, "FileHistory::write_event", "Cannot write to \'%s\', open() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2493 return HS_FILE_ERROR;
2494 }
2495
2496 //static_assert((sizeof(int)==3),"here!");
2497 //static_assert((sizeof(off64_t)==7),"here!");
2498 //static_assert((sizeof(size_t)==3),"here!");
2499 //static_assert((sizeof(intmax_t)==3),"here!");
2500
2501 //off64_t zzz = 1;
2502 //off64_t xxx = zzz<<60;
2503 //int yyy = xxx;
2504 //printf("%d", yyy);
2505
2506 off64_t file_size = ::lseek64(s->fWriterFd, 0, SEEK_END);
2507
2508 if (file_size < 0) {
2509 cm_msg(MERROR, "FileHistory::write_event", "Cannot read file size of \'%s\', lseek64(SEEK_END) errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2510 return HS_FILE_ERROR;
2511 }
2512
2513 off64_t nrec = 0;
2514
2515 if (file_size >= s->fDataOffset) {
2516 nrec = (file_size - s->fDataOffset)/s->fRecordSize;
2517 }
2518
2519 if (nrec < 0)
2520 nrec = 0;
2521
2522 off64_t data_end = s->fDataOffset + nrec*s->fRecordSize;
2523
2524 //printf("write_event: file_size %jd, nrec %jd, data_end %jd\n", (intmax_t)file_size, (intmax_t)nrec, (intmax_t)data_end);
2525
2526 if (data_end != file_size) {
2527 if (nrec > 0)
2528 cm_msg(MERROR, "FileHistory::write_event", "File \'%s\' may be truncated, data offset %jd, record size %zu, file size: %jd, should be %jd, making it so", s->fFileName.c_str(), (intmax_t)s->fDataOffset, s->fRecordSize, (intmax_t)file_size, (intmax_t)data_end);
2529
2530 off64_t status64 = ::lseek64(s->fWriterFd, data_end, SEEK_SET);
2531
2532 if (status64 < 0) {
2533 cm_msg(MERROR, "FileHistory::write_event", "Cannot seek \'%s\' to offset %jd, lseek64() errno %d (%s)", s->fFileName.c_str(), (intmax_t)data_end, errno, strerror(errno));
2534 return HS_FILE_ERROR;
2535 }
2536
2537 int status = ::ftruncate64(s->fWriterFd, data_end);
2538
2539 if (status < 0) {
2540 cm_msg(MERROR, "FileHistory::write_event", "Cannot truncate \'%s\' to size %jd, ftruncate64() errno %d (%s)", s->fFileName.c_str(), (intmax_t)data_end, errno, strerror(errno));
2541 return HS_FILE_ERROR;
2542 }
2543 }
2544
2545 s->fFileSizeInitial = data_end;
2546 s->fFileSize = data_end;
2547 }
2548
2549 size_t expected_size = s->fRecordSize - 4;
2550
2551 // sanity check: record_size and n_bytes are computed from the byte counts in the file header
2552 assert(expected_size == s->fNumBytes);
2553
2554 if (s->fLastSize == 0)
2555 s->fLastSize = expected_size;
2556
2557 if (data_size != s->fLastSize) {
2558 cm_msg(MERROR, "FileHistory::write_event", "Event \'%s\' data size mismatch, expected %zu bytes, got %zu bytes, previously %zu bytes", s->fEventName.c_str(), expected_size, data_size, s->fLastSize);
2559 //printf("schema:\n");
2560 //s->print();
2561
2562 if (data_size < expected_size)
2563 return HS_FILE_ERROR;
2564
2565 // truncate for now
2566 // data_size = expected_size;
2567 s->fLastSize = data_size;
2568 }
2569
2570 size_t size = 4 + expected_size;
2571
2572 if (size != s->fRecordBufferSize) {
2573 s->fRecordBuffer = (char*)realloc(s->fRecordBuffer, size);
2574 assert(s->fRecordBuffer != NULL);
2575 s->fRecordBufferSize = size;
2576 }
2577
2578 memcpy(s->fRecordBuffer, &t, 4);
2579 memcpy(s->fRecordBuffer+4, data, expected_size);
2580
2581 ssize_t wr = write(s->fWriterFd, s->fRecordBuffer, size);
2582 if ((size_t)wr != size) {
2583 cm_msg(MERROR, "FileHistory::write_event", "Cannot write to \'%s\', write(%zu) returned %zd, errno %d (%s)", s->fFileName.c_str(), size, wr, errno, strerror(errno));
2584 return HS_FILE_ERROR;
2585 }
2586
2587 s->fFileSize += size;
2588
2589#if 0
2590 status = write(s->fWriterFd, &t, 4);
2591 if (status != 4) {
2592 cm_msg(MERROR, "FileHistory::write_event", "Cannot write to \'%s\', write(timestamp) errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2593 return HS_FILE_ERROR;
2594 }
2595
2596 status = write(s->fWriterFd, data, expected_size);
2597 if (status != expected_size) {
2598 cm_msg(MERROR, "FileHistory::write_event", "Cannot write to \'%s\', write(%d) errno %d (%s)", s->fFileName.c_str(), data_size, errno, strerror(errno));
2599 return HS_FILE_ERROR;
2600 }
2601#endif
2602
2603 return HS_SUCCESS;
2604}
off64_t fFileSizeInitial
#define write(n, a, f, d)
Here is the call graph for this function:

Member Data Documentation

◆ fDataOffset

off64_t HsFileSchema::fDataOffset = 0

Definition at line 763 of file history_schema.cxx.

◆ fFileName

std::string HsFileSchema::fFileName

Definition at line 761 of file history_schema.cxx.

◆ fFileSize

off64_t HsFileSchema::fFileSize = 0

Definition at line 771 of file history_schema.cxx.

◆ fFileSizeInitial

off64_t HsFileSchema::fFileSizeInitial = 0

Definition at line 770 of file history_schema.cxx.

◆ fLastSize

size_t HsFileSchema::fLastSize = 0

Definition at line 764 of file history_schema.cxx.

◆ fRecordBuffer

char* HsFileSchema::fRecordBuffer = NULL

Definition at line 767 of file history_schema.cxx.

◆ fRecordBufferSize

size_t HsFileSchema::fRecordBufferSize = 0

Definition at line 766 of file history_schema.cxx.

◆ fRecordSize

size_t HsFileSchema::fRecordSize = 0

Definition at line 762 of file history_schema.cxx.

◆ fWriterFd

int HsFileSchema::fWriterFd = -1

Definition at line 765 of file history_schema.cxx.


The documentation for this class was generated from the following file: