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
 
charfRecordBuffer = 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< intfOffsets
 
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 734 of file history_schema.cxx.

Constructor & Destructor Documentation

◆ HsFileSchema()

HsFileSchema::HsFileSchema ( )
inline

Definition at line 752 of file history_schema.cxx.

753 {
754 // empty
755 }

◆ ~HsFileSchema()

HsFileSchema::~HsFileSchema ( )
inline

Definition at line 757 of file history_schema.cxx.

758 {
759 //printf("HsFileSchema::dtor %p!\n", this);
760 close();
761 fRecordSize = 0;
762 fDataOffset = 0;
763 fLastSize = 0;
764 fWriterFd = -1;
765 if (fRecordBuffer) {
766 free(fRecordBuffer);
768 }
770 }
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

Member Function Documentation

◆ close()

int HsFileSchema::close ( )
virtual

Implements HsSchema.

Definition at line 2583 of file history_schema.cxx.

2584{
2585 if (fWriterFd >= 0) {
2587 fWriterFd = -1;
2588 }
2589 return HS_SUCCESS;
2590}
#define HS_SUCCESS
Definition midas.h:727
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 774 of file history_schema.cxx.

774{ return HS_SUCCESS; };

◆ print()

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

Reimplemented from HsSchema.

Definition at line 815 of file history_schema.cxx.

816{
817 size_t nv = this->fVariables.size();
818 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);
819 if (print_tags) {
820 for (size_t j=0; j<nv; j++)
821 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]);
822 }
823}
std::vector< int > fOffsets
std::vector< HsSchemaEntry > fVariables
std::string fEventName
const char * rpc_tid_name(INT id)
Definition midas.cxx:11772
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 2854 of file history_schema.cxx.

2860{
2861 HsFileSchema* s = this;
2862
2863 if (debug)
2864 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);
2865
2866 //if (1) {
2867 // printf("Last time: ");
2868 // for (int i=0; i<num_var; i++) {
2869 // printf(" %s", TimeToString(last_time[i]).c_str());
2870 // }
2871 // printf("\n");
2872 //}
2873
2874 if (debug) {
2875 printf("FileHistory::read_data: file %s map", s->fFileName.c_str());
2876 for (size_t i=0; i<var_schema_index.size(); i++) {
2877 printf(" %2d", var_schema_index[i]);
2878 }
2879 printf("\n");
2880 }
2881
2882 int fd = ::open(s->fFileName.c_str(), O_RDONLY);
2883 if (fd < 0) {
2884 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', open() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2885 return HS_FILE_ERROR;
2886 }
2887
2888 off64_t file_size = ::lseek64(fd, 0, SEEK_END);
2889
2890 if (file_size < 0) {
2891 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));
2892 ::close(fd);
2893 return HS_FILE_ERROR;
2894 }
2895
2897 // empty file
2898 ::close(fd);
2899 return HS_SUCCESS;
2900 }
2901
2902 off64_t nrec = (file_size - s->fDataOffset)/s->fRecordSize;
2903
2904 //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);
2905
2906 if (nrec < 0)
2907 nrec = 0;
2908
2909 if (nrec < 1) {
2910 ::close(fd);
2911 return HS_SUCCESS;
2912 }
2913
2914 off64_t iunused = 0;
2915 time_t tunused = 0;
2916 off64_t irec = 0;
2917 time_t trec = 0;
2918 time_t tstart = 0;
2919 time_t tend = 0;
2920
2921 int istatus = FindTime(s->fFileName.c_str(), fd, s->fDataOffset, s->fRecordSize, nrec, start_time, &iunused, &tunused, &irec, &trec, &tstart, &tend, 0*debug);
2922
2923 if (istatus != HS_SUCCESS) {
2924 ::close(fd);
2925 return HS_FILE_ERROR;
2926 }
2927
2928 if (debug) {
2929 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());
2930 }
2931
2932 if (irec < 0 || irec >= nrec) {
2933 // all data in this file is older than start_time
2934
2935 ::close(fd);
2936
2937 if (debug)
2938 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());
2939
2940 return HS_SUCCESS;
2941 }
2942
2944 // data starts before time declared in schema
2945
2946 ::close(fd);
2947
2948 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());
2949
2950 return HS_FILE_ERROR;
2951 }
2952
2953 if (tend && s->fTimeTo && tend > s->fTimeTo) {
2954 // data ends after time declared in schema (overlaps with next file)
2955
2956 ::close(fd);
2957
2958 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());
2959
2960 return HS_FILE_ERROR;
2961 }
2962
2963 for (int i=0; i<num_var; i++) {
2964 int si = var_schema_index[i];
2965 if (si < 0)
2966 continue;
2967
2968 if (trec < last_time[i]) { // protect against duplicate and non-monotonous data
2969 ::close(fd);
2970
2971 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());
2972
2973 return HS_FILE_ERROR;
2974 }
2975 }
2976
2977 int count = 0;
2978
2980
2982
2983 //printf("read_data: lseek64() returned %jd, irec %jd, offset %jd, record size %zu, fpos %jd\n", xpos, irec, s->fDataOffset, s->fRecordSize, fpos);
2984
2985 if (xpos < 0) {
2986 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', lseek64(%jd) errno %d (%s)", s->fFileName.c_str(), (intmax_t)fpos, errno, strerror(errno));
2987 ::close(fd);
2988 return HS_FILE_ERROR;
2989 }
2990
2991 char* buf = new char[s->fRecordSize];
2992
2993 off64_t prec = irec;
2994
2995 while (1) {
2996 ssize_t rd = ::read(fd, buf, s->fRecordSize);
2997
2998 if (rd < 0) {
2999 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', read() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
3000 break;
3001 }
3002
3003 if (rd == 0) {
3004 // EOF
3005 break;
3006 }
3007
3008 if ((size_t)rd != s->fRecordSize) {
3009 cm_msg(MERROR, "FileHistory::read_data", "Cannot read \'%s\', short read() returned %zd instead of %zu bytes", s->fFileName.c_str(), rd, s->fRecordSize);
3010 break;
3011 }
3012
3013 prec++;
3014
3015 bool past_end_of_last_file = (s->fTimeTo == 0) && (prec > nrec);
3016
3017 time_t t = *(DWORD*)buf;
3018
3019 if (debug > 1)
3020 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());
3021
3022 if (t < trec) {
3023 delete[] buf;
3024 ::close(fd);
3025 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());
3026 return HS_FILE_ERROR;
3027 }
3028
3029 if (tend && (t > tend) && !past_end_of_last_file) {
3030 delete[] buf;
3031 ::close(fd);
3032 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());
3033 return HS_FILE_ERROR;
3034 }
3035
3036 if (t > end_time)
3037 break;
3038
3039 char* data = buf + 4;
3040
3041 for (int i=0; i<num_var; i++) {
3042 int si = var_schema_index[i];
3043 if (si < 0)
3044 continue;
3045
3046 if (t < last_time[i]) { // protect against duplicate and non-monotonous data
3047 delete[] buf;
3048 ::close(fd);
3049
3050 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);
3051
3052 return HS_FILE_ERROR;
3053 }
3054
3055 double v = 0;
3056 void* ptr = data + s->fOffsets[si];
3057
3058 int ii = var_index[i];
3059 assert(ii >= 0);
3060 assert(ii < s->fVariables[si].n_data);
3061
3062 switch (s->fVariables[si].type) {
3063 default:
3064 // unknown data type
3065 v = 0;
3066 break;
3067 case TID_BYTE:
3068 v = ((unsigned char*)ptr)[ii];
3069 break;
3070 case TID_SBYTE:
3071 v = ((signed char *)ptr)[ii];
3072 break;
3073 case TID_CHAR:
3074 v = ((char*)ptr)[ii];
3075 break;
3076 case TID_WORD:
3077 v = ((unsigned short *)ptr)[ii];
3078 break;
3079 case TID_SHORT:
3080 v = ((signed short *)ptr)[ii];
3081 break;
3082 case TID_DWORD:
3083 v = ((unsigned int *)ptr)[ii];
3084 break;
3085 case TID_INT:
3086 v = ((int *)ptr)[ii];
3087 break;
3088 case TID_BOOL:
3089 v = ((unsigned int *)ptr)[ii];
3090 break;
3091 case TID_FLOAT:
3092 v = ((float*)ptr)[ii];
3093 break;
3094 case TID_DOUBLE:
3095 v = ((double*)ptr)[ii];
3096 break;
3097 }
3098
3099 buffer[i]->Add(t, v);
3100 last_time[i] = t;
3101 }
3102 count++;
3103 }
3104
3105 delete[] buf;
3106
3107 ::close(fd);
3108
3109 if (debug) {
3110 printf("FileHistory::read_data: file %s map", s->fFileName.c_str());
3111 for (size_t i=0; i<var_schema_index.size(); i++) {
3112 printf(" %2d", var_schema_index[i]);
3113 }
3114 printf(" read %d rows\n", count);
3115 }
3116
3117 if (debug)
3118 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);
3119
3120 return HS_SUCCESS;
3121}
std::string fFileName
virtual void Add(time_t time, double value)=0
#define HS_FILE_ERROR
Definition midas.h:728
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:915
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 2758 of file history_schema.cxx.

2761{
2762 int status;
2763 HsFileSchema* s = this;
2764
2765 if (debug)
2766 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());
2767
2768 int fd = open(s->fFileName.c_str(), O_RDONLY);
2769 if (fd < 0) {
2770 cm_msg(MERROR, "FileHistory::read_last_written", "Cannot read \'%s\', open() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2771 return HS_FILE_ERROR;
2772 }
2773
2774 off64_t file_size = ::lseek64(fd, 0, SEEK_END);
2775
2776 if (file_size < 0) {
2777 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));
2778 return HS_FILE_ERROR;
2779 }
2780
2782 // empty file
2783 ::close(fd);
2784 if (last_written)
2785 *last_written = 0;
2786 return HS_SUCCESS;
2787 }
2788
2789 off64_t nrec = (file_size - s->fDataOffset)/s->fRecordSize;
2790
2791 //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);
2792
2793 if (nrec < 0)
2794 nrec = 0;
2795
2796 if (nrec < 1) {
2797 ::close(fd);
2798 if (last_written)
2799 *last_written = 0;
2800 return HS_SUCCESS;
2801 }
2802
2803 time_t lw = 0;
2804
2805 // read last record to check if desired time is inside or outside of the file
2806
2807 if (1) {
2808 char* buf = new char[s->fRecordSize];
2809
2810 status = ReadRecord(s->fFileName.c_str(), fd, s->fDataOffset, s->fRecordSize, nrec - 1, buf);
2811 if (status != HS_SUCCESS) {
2812 delete[] buf;
2813 ::close(fd);
2814 return HS_FILE_ERROR;
2815 }
2816
2817 lw = *(DWORD*)buf;
2818
2819 delete[] buf;
2820 }
2821
2822 if (lw >= timestamp) {
2823 off64_t irec = 0;
2824 time_t trec = 0;
2825 off64_t iunused = 0;
2826 time_t tunused = 0;
2827 time_t tstart = 0; // not used
2828 time_t tend = 0; // not used
2829
2830 status = FindTime(s->fFileName.c_str(), fd, s->fDataOffset, s->fRecordSize, nrec, timestamp, &irec, &trec, &iunused, &tunused, &tstart, &tend, 0*debug);
2831 if (status != HS_SUCCESS) {
2832 ::close(fd);
2833 return HS_FILE_ERROR;
2834 }
2835
2836 assert(trec < timestamp);
2837
2838 lw = trec;
2839 }
2840
2841 if (last_written)
2842 *last_written = lw;
2843
2844 if (debug)
2845 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());
2846
2847 assert(lw < timestamp);
2848
2849 ::close(fd);
2850
2851 return HS_SUCCESS;
2852}
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 772 of file history_schema.cxx.

772{ /* 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 2460 of file history_schema.cxx.

2461{
2462 HsFileSchema* s = this;
2463
2464 assert(s->fVariables.size() == s->fOffsets.size());
2465
2466 if (s->fWriterFd < 0) {
2467 s->fWriterFd = open(s->fFileName.c_str(), O_RDWR);
2468 if (s->fWriterFd < 0) {
2469 cm_msg(MERROR, "FileHistory::write_event", "Cannot write to \'%s\', open() errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2470 return HS_FILE_ERROR;
2471 }
2472
2473 //static_assert((sizeof(int)==3),"here!");
2474 //static_assert((sizeof(off64_t)==7),"here!");
2475 //static_assert((sizeof(size_t)==3),"here!");
2476 //static_assert((sizeof(intmax_t)==3),"here!");
2477
2478 //off64_t zzz = 1;
2479 //off64_t xxx = zzz<<60;
2480 //int yyy = xxx;
2481 //printf("%d", yyy);
2482
2483 off64_t file_size = ::lseek64(s->fWriterFd, 0, SEEK_END);
2484
2485 if (file_size < 0) {
2486 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));
2487 return HS_FILE_ERROR;
2488 }
2489
2490 off64_t nrec = 0;
2491
2492 if (file_size >= s->fDataOffset) {
2493 nrec = (file_size - s->fDataOffset)/s->fRecordSize;
2494 }
2495
2496 if (nrec < 0)
2497 nrec = 0;
2498
2500
2501 //printf("write_event: file_size %jd, nrec %jd, data_end %jd\n", (intmax_t)file_size, (intmax_t)nrec, (intmax_t)data_end);
2502
2503 if (data_end != file_size) {
2504 if (nrec > 0)
2505 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);
2506
2508
2509 if (status64 < 0) {
2510 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));
2511 return HS_FILE_ERROR;
2512 }
2513
2515
2516 if (status < 0) {
2517 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));
2518 return HS_FILE_ERROR;
2519 }
2520 }
2521
2523 s->fFileSize = data_end;
2524 }
2525
2526 size_t expected_size = s->fRecordSize - 4;
2527
2528 // sanity check: record_size and n_bytes are computed from the byte counts in the file header
2529 assert(expected_size == s->fNumBytes);
2530
2531 if (s->fLastSize == 0)
2533
2534 if (data_size != s->fLastSize) {
2535 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);
2536 //printf("schema:\n");
2537 //s->print();
2538
2539 if (data_size < expected_size)
2540 return HS_FILE_ERROR;
2541
2542 // truncate for now
2543 // data_size = expected_size;
2544 s->fLastSize = data_size;
2545 }
2546
2547 size_t size = 4 + expected_size;
2548
2549 if (size != s->fRecordBufferSize) {
2550 s->fRecordBuffer = (char*)realloc(s->fRecordBuffer, size);
2551 assert(s->fRecordBuffer != NULL);
2552 s->fRecordBufferSize = size;
2553 }
2554
2555 memcpy(s->fRecordBuffer, &t, 4);
2557
2558 ssize_t wr = write(s->fWriterFd, s->fRecordBuffer, size);
2559 if ((size_t)wr != size) {
2560 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));
2561 return HS_FILE_ERROR;
2562 }
2563
2564 s->fFileSize += size;
2565
2566#if 0
2567 status = write(s->fWriterFd, &t, 4);
2568 if (status != 4) {
2569 cm_msg(MERROR, "FileHistory::write_event", "Cannot write to \'%s\', write(timestamp) errno %d (%s)", s->fFileName.c_str(), errno, strerror(errno));
2570 return HS_FILE_ERROR;
2571 }
2572
2574 if (status != expected_size) {
2575 cm_msg(MERROR, "FileHistory::write_event", "Cannot write to \'%s\', write(%d) errno %d (%s)", s->fFileName.c_str(), data_size, errno, strerror(errno));
2576 return HS_FILE_ERROR;
2577 }
2578#endif
2579
2580 return HS_SUCCESS;
2581}
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 740 of file history_schema.cxx.

◆ fFileName

std::string HsFileSchema::fFileName

Definition at line 738 of file history_schema.cxx.

◆ fFileSize

off64_t HsFileSchema::fFileSize = 0

Definition at line 748 of file history_schema.cxx.

◆ fFileSizeInitial

off64_t HsFileSchema::fFileSizeInitial = 0

Definition at line 747 of file history_schema.cxx.

◆ fLastSize

size_t HsFileSchema::fLastSize = 0

Definition at line 741 of file history_schema.cxx.

◆ fRecordBuffer

char* HsFileSchema::fRecordBuffer = NULL

Definition at line 744 of file history_schema.cxx.

◆ fRecordBufferSize

size_t HsFileSchema::fRecordBufferSize = 0

Definition at line 743 of file history_schema.cxx.

◆ fRecordSize

size_t HsFileSchema::fRecordSize = 0

Definition at line 739 of file history_schema.cxx.

◆ fWriterFd

int HsFileSchema::fWriterFd = -1

Definition at line 742 of file history_schema.cxx.


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