32 #define SMALLEST_CHUNK_SIZE 20 33 #define NO_HEADER_SIZE 8192 34 #define OPTIMAL_CHUNK_SIZE 8187 36 #define HEAD 1145128264 37 #define DATA 1096040772 38 #define SCAL 1279345491 39 #define DEAD 1145128260 42 #define ENDFILE 541478725 43 #define ENDBUFF 0xFFFFFFFF 45 #define LDF_DATA_LENGTH 8193 // Maximum length of an ldf style DATA buffer. 52 void set_char_array(
const std::string &input_,
char *arr_,
const unsigned int &size_){
53 size_t size_to_copy = size_;
54 if(size_ > input_.size()){ size_to_copy = input_.size(); }
55 for(
unsigned int i = 0; i < size_; i++){
56 if(i < size_to_copy){ arr_[i] = input_[i]; }
57 else{ arr_[i] =
' '; }
89 unsigned int check_bufftype;
90 file_->read((
char*)&check_bufftype, 4);
108 unsigned int buffer_len = 100;
110 while(buffer_len % 4 != 0){ buffer_len++; }
142 for(
unsigned int i = 0; i < input_.size(); i++){
150 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
152 unsigned int len_of_title = strlen(
run_title);
153 unsigned int padding_bytes = 0;
154 while((len_of_title + padding_bytes) % 4 != 0){
157 unsigned int total_title_len = len_of_title + padding_bytes;
159 if(
debug_mode){ std::cout <<
"debug: writing " << 100 + total_title_len <<
" byte HEAD buffer\n"; }
162 file_->write((
char*)&
run_num, 4);
169 file_->write((
char*)&total_title_len, 4);
173 for(
unsigned int i = 0; i < padding_bytes; i++){
174 file_->write(&padding, 1);
177 file_->write((
char*)&
buffend, 4);
184 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
186 unsigned int check_bufftype;
187 file_->read((
char*)&check_bufftype, 4);
189 if(
debug_mode){ std::cout <<
"debug: not a valid HEAD buffer\n"; }
190 file_->seekg(-4, file_->cur);
194 unsigned int end_buff_check;
195 unsigned int len_of_title;
196 file_->read((
char*)&
run_num, 4);
203 file_->read((
char*)&len_of_title, 4);
209 file_->read((
char*)&end_buff_check, 4);
212 if(
debug_mode){ std::cout <<
"debug: buffer not terminated properly\n"; }
233 std::cout <<
" 'HEAD' buffer-\n";
234 std::cout <<
" Facility: " << std::string(
facility) <<
"\n";
235 std::cout <<
" Format: " << std::string(
format) <<
"\n";
236 std::cout <<
" Start: " << std::string(
start_date) <<
"\n";
237 std::cout <<
" Stop: " << std::string(
end_date) <<
"\n";
238 std::cout <<
" Title: " << std::string(
run_title) <<
"\n";
239 std::cout <<
" Run number: " <<
run_num <<
"\n";
241 std::cout <<
" ACQ time: " <<
run_time <<
" seconds\n";
246 std::cout << std::string(
facility) << delimiter_;
247 std::cout << std::string(
format) << delimiter_;
248 std::cout << std::string(
start_date) << delimiter_;
249 std::cout << std::string(
end_date) << delimiter_;
250 std::cout << std::string(
run_title) << delimiter_;
251 std::cout <<
run_num << delimiter_;
263 if(!file_ || !file_->is_open() || !file_->good() || nWords_ == 0){
return false; }
265 if(
debug_mode){ std::cout <<
"debug: writing spill of " << nWords_ <<
" words\n"; }
268 file_->write((
char*)&nWords_, 4);
269 file_->write(data_, 4*nWords_);
271 file_->write((
char*)&
buffend, 4);
277 bool PLD_data::Read(std::ifstream *file_,
char *data_,
unsigned int &nBytes,
unsigned int max_bytes_,
bool dry_run_mode){
278 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
280 unsigned int check_bufftype;
281 file_->read((
char*)&check_bufftype, 4);
283 if(
debug_mode){ std::cout <<
"debug: not a valid DATA buffer\n"; }
285 unsigned int countw = 0;
287 file_->read((
char*)&check_bufftype, 4);
289 if(
debug_mode){ std::cout <<
"debug: encountered physical end-of-file before start of spill!\n"; }
295 if(
debug_mode){ std::cout <<
"debug: read an extra " << countw <<
" words to get to first DATA buffer!\n"; }
298 file_->read((
char*)&nBytes, 4);
301 if(
debug_mode){ std::cout <<
"debug: reading spill of " << nBytes <<
" bytes\n"; }
303 if(nBytes > max_bytes_){
304 if(
debug_mode){ std::cout <<
"debug: spill size is greater than size of data array!\n"; }
308 unsigned int end_buff_check;
309 if(!dry_run_mode){ file_->read(data_, nBytes); }
310 else{ file_->seekg(nBytes, std::ios::cur); }
311 file_->read((
char*)&end_buff_check, 4);
314 if(
debug_mode){ std::cout <<
"debug: buffer not terminated properly\n"; }
331 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
338 file_->write((
char*)&
zero, 4);
339 file_->write((
char*)
unknown, 8);
340 file_->write((
char*)&
run_num, 4);
341 file_->write((
char*)&
unknown[2], 4);
345 file_->write((
char*)&
zero, 4);
353 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
355 unsigned int check_bufftype, check_buffsize;
356 file_->read((
char*)&check_bufftype, 4);
357 file_->read((
char*)&check_buffsize, 4);
359 if(
debug_mode){ std::cout <<
"debug: not a valid DIR buffer\n"; }
360 file_->seekg(-8, file_->cur);
366 file_->read((
char*)
unknown, 8);
367 file_->read((
char*)&
run_num, 4);
368 file_->seekg((
buffsize*4 - 20), file_->cur);
384 std::cout <<
" 'DIR ' buffer-\n";
385 std::cout <<
" Run number: " <<
run_num <<
"\n";
391 std::cout <<
run_num << delimiter_;
405 local = localtime(&temp_time);
407 int month = local->tm_mon+1;
408 int day = local->tm_mday;
409 int year = local->tm_year;
410 int hour = local->tm_hour;
411 int minute = local->tm_min;
414 std::stringstream stream;
415 (month<10) ? stream <<
"0" << month <<
"/" : stream << month <<
"/";
416 (day<10) ? stream <<
"0" << day <<
"/" : stream << day <<
"/";
417 (year<110) ? stream <<
"0" << year-100 <<
" " : stream << year-100 <<
" ";
419 (hour<10) ? stream <<
"0" << hour <<
":" : stream << hour <<
":";
420 (minute<10) ? stream <<
"0" << minute <<
" " : stream << minute <<
" ";
424 std::string dtime_str = stream.str();
425 if(dtime_str.size() > 16){
return false; }
426 for(
unsigned int i = 0; i < 16; i++){
427 if(i >= dtime_str.size()){
date[i] =
' '; }
428 else{
date[i] = dtime_str[i]; }
435 for(
unsigned int i = 0; i < 80; i++){
436 if(i >= input_.size()){
run_title[i] =
' '; }
447 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
456 file_->write(
type, 16);
457 file_->write(
date, 16);
459 file_->write((
char*)&
run_num, 4);
463 for(
unsigned int i = 0; i < 116; i++){ temp[i] = 0x0; }
464 file_->write(temp, 116);
468 file_->write((
char*)&
buffend, 4);
476 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
478 unsigned int check_bufftype, check_buffsize;
479 file_->read((
char*)&check_bufftype, 4);
480 file_->read((
char*)&check_buffsize, 4);
482 if(
debug_mode){ std::cout <<
"debug: not a valid HEAD buffer\n"; }
483 file_->seekg(-8, file_->cur);
489 file_->read(
type, 16);
type[16] =
'\0';
490 file_->read(
date, 16);
date[16] =
'\0';
492 file_->read((
char*)&
run_num, 4);
509 std::cout <<
" 'HEAD' buffer-\n";
510 std::cout <<
" Facility: " << std::string(
facility) <<
"\n";
511 std::cout <<
" Format: " << std::string(
format) <<
"\n";
512 std::cout <<
" Type: " << std::string(
type) <<
"\n";
513 std::cout <<
" Date: " << std::string(
date) <<
"\n";
514 std::cout <<
" Title: " << std::string(
run_title) <<
"\n";
515 std::cout <<
" Run number: " <<
run_num <<
"\n";
520 std::cout << std::string(
facility) << delimiter_;
521 std::cout << std::string(
format) << delimiter_;
522 std::cout << std::string(
type) << delimiter_;
523 std::cout << std::string(
date) << delimiter_;
524 std::cout << std::string(
run_title) << delimiter_;
530 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
532 if(
debug_mode){ std::cout <<
"debug: writing 2 word DATA header\n"; }
542 if(!f_ || !f_->good() || f_->eof()){
return false; }
565 curr_buffer = buffer1;
566 next_buffer = buffer2;
570 curr_buffer = buffer2;
571 next_buffer = buffer1;
581 buff_head = curr_buffer[buff_pos++];
582 buff_size = curr_buffer[buff_pos++];
584 if(!f_->good()){
return false; }
585 else if(f_->eof()){ retval = 2; }
601 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
607 file_->write((
char*)&
buffend, 4);
616 bool DATA_buffer::Write(std::ofstream *file_,
char *data_,
unsigned int nWords_,
int &buffs_written){
617 if(!file_ || !file_->is_open() || !file_->good() || !data_ || nWords_ == 0){
618 if(
debug_mode){ std::cout <<
"debug: !file_ || !file_->is_open() || !data_ || nWords_ == 0\n"; }
629 unsigned int spillpos = 0;
630 unsigned int chunkPayload;
633 unsigned int chunkSizeB;
634 unsigned int totalNumChunks = 0;
635 unsigned int currentNumChunk = 0;
637 char *arrptr = data_;
640 while(spillpos < nWords_){
647 chunkPayload = nWords_ - spillpos;
649 spillpos += chunkPayload;
650 oldBuffPos += chunkPayload + 4;
665 while(spillpos < nWords_){
675 chunkPayload = nWords_ - spillpos;
677 spillpos += chunkPayload;
678 chunkSizeB = 4*(chunkPayload + 3);
681 std::cout <<
"debug: writing " << 1+chunkSizeB/4 <<
" word spill chunk " << currentNumChunk <<
" of " << totalNumChunks <<
".\n";
683 file_->write((
char*)&chunkSizeB, 4);
684 file_->write((
char*)&totalNumChunks, 4);
685 file_->write((
char*)¤tNumChunk, 4);
686 file_->write((
char*)arrptr, 4*chunkPayload);
687 file_->write((
char*)&
buffend, 4);
691 buff_pos += chunkPayload + 4;
692 arrptr += 4*chunkPayload;
695 std::cout <<
"WARNING: Current ldf buffer overfilled by " << buff_pos -
LDF_DATA_LENGTH <<
" words!\n";
697 if(buff_pos >= LDF_DATA_LENGTH){
714 std::cout <<
"debug: writing final spill chunk " << currentNumChunk <<
" of " << 1+
end_spill_size/4 <<
" words.\n";
717 file_->write((
char*)&totalNumChunks, 4);
718 file_->write((
char*)¤tNumChunk, 4);
721 file_->write((
char*)&
buffend, 4);
730 bool DATA_buffer::Read(std::ifstream *file_,
char *data_,
unsigned int &nBytes,
unsigned int max_bytes_,
bool &full_spill,
bool &bad_spill,
bool dry_run_mode){
731 if(!file_ || !file_->is_open() || !file_->good()){
738 bool first_chunk =
true;
739 unsigned int this_chunk_sizeB;
740 unsigned int total_num_chunks = 0;
741 unsigned int current_chunk_num = 0;
742 unsigned int prev_chunk_num;
743 unsigned int prev_num_chunks;
748 if(
debug_mode){ std::cout <<
"debug: failed to read from input data file\n"; }
754 prev_chunk_num = current_chunk_num;
755 prev_num_chunks = total_num_chunks;
761 if(
debug_mode){ std::cout <<
"debug: scanning spill chunk " << current_chunk_num <<
" of " << total_num_chunks <<
"\n"; }
765 if(current_chunk_num != 0){
766 if(
debug_mode){ std::cout <<
"debug: starting read in middle of spill (chunk " << current_chunk_num <<
" of " << total_num_chunks <<
")\n"; }
773 else{ full_spill =
true; }
776 else if(total_num_chunks != prev_num_chunks){
777 if(
debug_mode){ std::cout <<
"debug: skipped to new spill with " << total_num_chunks <<
" spill chunks without reading footer of old spill\n"; }
788 else if(current_chunk_num != prev_chunk_num + 1){
790 if(current_chunk_num == prev_chunk_num + 2){ std::cout <<
"debug: missing single spill chunk (" << prev_chunk_num+1 <<
")\n"; }
791 else{ std::cout <<
"debug: missing multiple spill chunks (" << prev_chunk_num+1 <<
" to " << current_chunk_num-1 <<
")\n"; }
806 if(current_chunk_num == total_num_chunks - 1){
808 if(
debug_mode){ std::cout <<
"debug: spill footer (chunk " << current_chunk_num <<
" of " << total_num_chunks <<
") has size " << this_chunk_sizeB <<
" != 5\n"; }
820 if(full_spill){ std::cout <<
"debug: finished scanning spill of " << nBytes <<
" bytes\n"; }
821 else{ std::cout <<
"debug: finished scanning spill fragment of " << nBytes <<
" bytes\n"; }
834 unsigned int copied_bytes;
835 if(this_chunk_sizeB <= 12){
836 if(
debug_mode){ std::cout <<
"debug: invalid number of bytes in chunk " << current_chunk_num+1 <<
" of " << total_num_chunks <<
", " << this_chunk_sizeB <<
" B!\n"; }
848 copied_bytes = this_chunk_sizeB - 12;
850 nBytes += copied_bytes;
856 if(
debug_mode){ std::cout <<
"debug: encountered double EOF buffer marking end of file\n"; }
860 if(
debug_mode){ std::cout <<
"debug: encountered EOF buffer marking end of run\n"; }
871 std::cout <<
"debug: encountered non DATA type buffer 0x" << std::hex <<
buff_head << std::dec <<
"\n";
872 std::cout <<
"debug: skipping entire remaining " <<
buff_size <<
" buffer words!\n";
903 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
913 file_->write((
char*)&
buffend, 4);
921 if(!file_ || !file_->is_open() || !file_->good()){
return false; }
923 unsigned int check_bufftype, check_buffsize;
924 file_->read((
char*)&check_bufftype, 4);
925 file_->read((
char*)&check_buffsize, 4);
927 if(
debug_mode){ std::cout <<
"debug: not a valid EOF buffer\n"; }
928 file_->seekg(-8, file_->cur);
932 file_->seekg((
buffsize*4), file_->cur);
939 std::stringstream stream; stream << current_file_num;
940 std::string run_num_str = stream.str();
943 if(current_file_num == 0){ output = fname_prefix; }
944 else if(current_file_num < 10){ output = fname_prefix +
"_0" + run_num_str; }
945 else{ output = fname_prefix +
"_" + run_num_str; }
947 if(output_format == 0){ output +=
".ldf"; }
948 else if(output_format == 1){ output +=
".pld"; }
949 else{ output +=
".root"; }
955 unsigned int depth = (int)directories.size();
958 std::string formatted_filename =
"";
959 unsigned int index = 0;
960 while(index < current_filename.size()){
961 if(current_filename[index] ==
'.'){
962 if(current_filename[index+1] ==
'.'){
963 if(depth > 0){ depth--; }
965 output = current_filename;
970 else if(current_filename[index+1] ==
'/'){
974 formatted_filename += current_filename[index];
979 formatted_filename += current_filename[index];
986 for(
unsigned int i = 0; i < depth; i++){
987 output += directories.at(i) +
"/";
989 output += formatted_filename;
991 else{ output = formatted_filename; }
1001 if(!output_file.is_open() || !output_file.good()){
return false; }
1004 if(total_buffers_ == -1){
1005 unsigned int size = output_file.tellp();
1006 output_file.seekp(12);
1011 output_file.write((
char*)&total_num_buffer, 4);
1014 std::cout <<
"debug: file size is " << size <<
" bytes (" << size/4 <<
" 4 byte words)\n";
1015 std::cout <<
"debug: file contains " << total_num_buffer <<
" buffers of " <<
ACTUAL_BUFF_SIZE <<
" words\n";
1016 if(overflow != 0){ std::cout <<
"debug: file has an overflow of " << overflow <<
" 4 byte words!\n"; }
1017 std::cout <<
"debug: set .ldf directory buffer number to " << total_num_buffer << std::endl;
1021 output_file.close();
1026 output_file.write((
char*)&total_buffers_, 4);
1027 if(
debug_mode){ std::cout <<
"debug: set .ldf directory buffer number to " << total_buffers_ << std::endl; }
1030 output_file.close();
1037 current_file_num = 0;
1040 fname_prefix =
"poll_data";
1041 current_filename =
"unknown";
1042 current_full_filename =
"unknown";
1048 current_directory = std::string(getcwd(ch_cwd, 1024));
1051 std::string temp =
"";
1052 for(
unsigned int i = 0; i < current_directory.size(); i++){
1053 if(current_directory[i] ==
'/'){
1055 directories.push_back(temp);
1059 else{ temp += current_directory[i]; }
1062 if(temp !=
""){ directories.push_back(temp); }
1064 current_depth = directories.size();
1075 fname_prefix = filename_;
1082 pldData.SetDebugMode(debug_);
1083 dirBuff.SetDebugMode(debug_);
1084 headBuff.SetDebugMode(debug_);
1085 dataBuff.SetDebugMode(debug_);
1086 eofBuff.SetDebugMode(debug_);
1092 output_format = format_;
1100 fname_prefix = filename_;
1101 current_file_num = 0;
1106 if(!data_ || nWords_ == 0){
return -1; }
1108 if(!output_file.is_open() || !output_file.good()){
return -1; }
1110 if(nWords_ > max_spill_size){ max_spill_size = nWords_; }
1114 if(output_format == 0){
1115 if(!dataBuff.Write(&output_file, data_, nWords_, buffs_written)){
return -1; }
1117 else if(output_format == 1){
1118 if(!pldData.Write(&output_file, data_, nWords_)){
return -1; }
1122 if(
debug_mode){ std::cout <<
"debug: invalid output format for PollOutputFile::Write!\n"; }
1127 return buffs_written;
1134 if(!cli_){
return -1; }
1136 unsigned int end_packet =
ENDBUFF;
1138 std::streampos file_size = output_file.tellp();
1144 char size_of_int =
sizeof(int);
1145 char size_of_spos =
sizeof(std::streampos);
1147 char *packet = NULL;
1149 if(!output_file.is_open() || !output_file.good()){
1156 bytes = 2 + 2 *
sizeof(int);
1157 packet =
new char[bytes];
1159 unsigned int index = 0;
1160 memcpy(&packet[index], (
char *)&size_of_int, 1); index += 1;
1161 memcpy(&packet[index], (
char *)&size_of_spos, 1); index += 1;
1162 memcpy(&packet[index], (
char *)&bytes,
sizeof(
int)); index +=
sizeof(int);
1163 memcpy(&packet[index], (
char *)&end_packet,
sizeof(
int)); index +=
sizeof(int);
1177 bytes = (2 + 4 *
sizeof(int)) +
sizeof(std::streampos) + current_full_filename.size();
1178 packet =
new char[bytes];
1179 const char *str = current_full_filename.c_str();
1181 unsigned int index = 0;
1182 memcpy(&packet[index], (
char *)&size_of_int, 1); index += 1;
1183 memcpy(&packet[index], (
char *)&size_of_spos, 1); index += 1;
1184 memcpy(&packet[index], (
char *)&bytes,
sizeof(
int)); index +=
sizeof(int);
1185 memcpy(&packet[index], (
char *)str, (
unsigned int)current_full_filename.size()); index += current_full_filename.size();
1186 memcpy(&packet[index], (
char *)&file_size,
sizeof(std::streampos)); index +=
sizeof(std::streampos);
1187 memcpy(&packet[index], (
char *)&number_spills,
sizeof(
int)); index +=
sizeof(int);
1188 memcpy(&packet[index], (
char *)&buff_size,
sizeof(
int)); index +=
sizeof(int);
1189 memcpy(&packet[index], (
char *)&end_packet,
sizeof(
int));
1205 std::string filename = GetNextFileName(run_num_,prefix,output_directory,continueRun);
1206 output_file.open(filename.c_str(), std::ios::binary);
1207 if(!output_file.is_open() || !output_file.good()){
1208 output_file.close();
1212 current_filename = filename;
1213 get_full_filename(current_full_filename);
1215 if(output_format == 0){
1216 dirBuff.SetRunNumber(run_num_);
1217 dirBuff.Write(&output_file);
1219 headBuff.SetTitle(title_);
1220 headBuff.SetDateTime();
1221 headBuff.SetRunNumber(run_num_);
1222 headBuff.Write(&output_file);
1224 else if(output_format == 1){
1230 unsigned int temp = 0;
1232 output_file.write((
char*)&temp, 4);
1235 output_file.write((
char*)&temp, 4);
1238 if(
debug_mode){ std::cout <<
"debug: invalid output format for PollOutputFile::OpenNewFile!\n"; }
1247 std::stringstream filename;
1248 filename << output_directory << prefix <<
"_" << std::setfill(
'0') << std::setw(3) << run_num_;
1250 if(output_format == 0){ filename <<
".ldf"; }
1251 else if(output_format == 1){ filename <<
".pld"; }
1253 std::ifstream dummy_file(filename.str().c_str());
1254 unsigned int suffix = 0;
1255 while (dummy_file.is_open()) {
1259 if(continueRun){ filename << output_directory << prefix <<
"_" << std::setfill(
'0') << std::setw(3) << run_num_ <<
"-" << ++suffix; }
1260 else{ filename << output_directory << prefix <<
"_" << std::setfill(
'0') << std::setw(3) << ++run_num_; }
1262 if(output_format == 0){ filename <<
".ldf"; }
1263 else if(output_format == 1){ filename <<
".pld"; }
1265 dummy_file.open(filename.str().c_str());
1268 return filename.str();
1272 if(output_format == 0)
return dirBuff.GetRunNumber();
1274 else if(
debug_mode) std::cout <<
"debug: invalid output format for PollOutputFile::GetRunNumber!\n";
1280 if(!output_file.is_open() || !output_file.good()){
return; }
1282 if(output_format == 0){
1283 dataBuff.Close(&output_file);
1285 eofBuff.Write(&output_file);
1286 eofBuff.Write(&output_file);
1290 else if(output_format == 1){
1292 output_file.write((
char*)&temp, 4);
1295 output_file.write((
char*)&temp, 4);
1298 output_file.seekp(0);
1302 output_file.close();
1304 else if(
debug_mode){ std::cout <<
"debug: invalid output format for PollOutputFile::CloseFile!\n"; }
virtual void Reset()
Set initial values.
unsigned int good_chunks
Total size of ldf buffer (in 4 byte words).
virtual bool Write(std::ofstream *file_)
0x20464F45 "EOF "
PLD_data()
Default constructor.
virtual bool Read(std::ifstream *file_)
Returns only false if not overloaded.
std::string get_filename()
Get the formatted filename of the current file.
virtual bool Read(std::ifstream *file_)
Read an EOF buffer from a file. Return false if buffer has the wrong header and return true otherwise...
void SetFilenamePrefix(std::string filename_)
Set the output filename prefix.
virtual bool Write(std::ofstream *file_)
Returns only false if not overloaded.
bool SetDateTime()
Set the date and time of the ldf file.
const unsigned int pacman_word1
The size of the end of spill "event" (5 words).
Provides network connectivity for poll2.
DIR_buffer()
Default constructor.
virtual bool Write(std::ofstream *file_)
unsigned int buff_head
The total number of ldf buffers read from file.
virtual void Reset()
Set initial values.
unsigned int buff_size
The ldf buffer header ID.
int Write(char *data_, unsigned int nWords_)
Write nWords_ of data to the file.
void initialize()
Initialize the output file with initial parameters.
void PrintDelimited(const char &delimiter_='\t')
Print dir buffer information in a delimited list.
unsigned int buff_pos
Count of the number of missing spill chunks which were dropped.
bool get_full_filename(std::string &output)
Get the full path of the current file.
unsigned int total_buff_size
void Print()
Print dir buffer information.
bool SetTitle(std::string input_)
Set the title of the ldf file.
unsigned int GetRunNumber()
virtual void Reset()
Set initial values.
DATA_buffer()
Default constructor.
void Print()
Print header information.
virtual bool Write(std::ofstream *file_, char *data_, unsigned int nWords_, int &buffs_written)
Write a data spill to file.
std::string GetNextFileName(unsigned int &run_num_, std::string prefix, std::string output_dir, bool continueRun=false)
Return the filename of the next output file.
virtual bool Read(std::ifstream *file_, char *data_, unsigned int &nBytes_, unsigned int max_bytes_, bool &full_spill, bool &bad_spill, bool dry_run_mode=false)
Read a data spill from a file.
bool read_next_buffer(std::ifstream *f_, bool force_=false)
virtual bool Write(std::ofstream *file_, char *data_, unsigned int nWords_)
0x41544144 "DATA"
unsigned int missing_chunks
Count of the number of good spill chunks which were read.
HEAD_buffer()
Default constructor.
void SetDebugMode(bool debug_=true)
bool Close(std::ofstream *file_)
0x41544144 "DATA"
void PrintDelimited(const char &delimiter_='\t')
Print header information in a delimited list.
PollOutputFile()
Default constructor.
unsigned int bcount
Pointer to the next ldf buffer.
virtual void Reset()
Does nothing if not overloaded.
virtual bool Read(std::ifstream *file_, char *data_, unsigned int &nBytes, unsigned int max_bytes_, bool dry_run_mode=false)
Read a data spill from a file.
bool is_hribf_buffer(const unsigned int &input_)
Return true if the input word corresponds to the header of a ldf style buffer.
int SendMessage(char *message_, size_t length_)
void set_char_array(const std::string &input_, char *arr_, const unsigned int &size_)
End of spill vsn. The scan code searches for these words.
unsigned int buffer1[ACTUAL_BUFF_SIZE]
The error code for the read method.
BufferType(unsigned int bufftype_, unsigned int buffsize_, unsigned int buffend_=0xFFFFFFFF)
Generic BufferType constructor.
void SetDebugMode(bool debug_=true)
Toggle debug mode.
void CloseFile(float total_run_time_=0.0)
Write the footer and close the file.
const unsigned int end_spill_size
int SendPacket(Client *cli_)
unsigned int * next_buffer
Pointer to the current ldf buffer.
virtual bool Read(std::ifstream *file_)
Read a DIR buffer from a file. Return false if buffer has the wrong header and return true otherwise...
bool SetFileFormat(unsigned int format_)
Set the output file format.
bool open_(std::ofstream *file_)
The actual position in the current ldf buffer.
virtual bool Read(std::ifstream *file_)
Read a HEAD buffer from a file. Return false if buffer has the wrong header and return true otherwise...
bool ReadHeader(std::ifstream *file_)
Return true if the first word of the current buffer is equal to this buffer type. ...
const unsigned int pacman_word2
Words to signify the end of a spill. The scan code searches for these words.
virtual bool Write(std::ofstream *file_)
bool OpenNewFile(std::string title_, unsigned int &run_num_, std::string prefix, std::string output_dir="./", bool continueRun=false)
Close the current file, if one is open, and open a new file for data output.
Handles poll2 output data files.
bool overwrite_dir(int total_buffers_=-1)
virtual void Reset()
Set initial values.
unsigned int * curr_buffer
Container for a second ldf buffer.
unsigned int buffer2[ACTUAL_BUFF_SIZE]
Container for a ldf buffer.