Changeset 14268
- Timestamp:
- 07/16/12 17:45:10 (12 years ago)
- Location:
- fact/tools/pyscripts/sandbox/dneise/fact_compress/c++
- Files:
-
- 11 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/sandbox/dneise/fact_compress/c++/compare.cpp
r14229 r14268 3 3 #include <iostream> 4 4 #include <fstream> 5 #include <stdint.h> 6 #include <stdio.h> 5 7 using namespace std; 6 8 … … 10 12 char c1,c2; 11 13 12 int main ( ) {14 int main (int argc, char * argv[]) { 13 15 14 ifstream in1 ( "a.fits", ios::in|ios::binary);15 ifstream in2 ( "bla.bin", ios::in|ios::binary);16 ifstream in1 ( argv[1], ios::in|ios::binary); 17 ifstream in2 ( argv[2], ios::in|ios::binary); 16 18 17 19 if (in1.is_open() && in2.is_open()) … … 22 24 end = in1.tellg(); 23 25 in1.seekg (0, ios::beg); 24 cout << "a.fitssize:" << end-begin << endl;26 cout << argv[1] <<" size:" << end-begin << endl; 25 27 26 28 begin = in2.tellg(); … … 28 30 end = in2.tellg(); 29 31 in2.seekg (0, ios::beg); 30 cout << "bla.binsize:" << end-begin << endl;32 cout << argv[2] <<" size:" << end-begin << endl; 31 33 32 34 while ( in1.good() && in2.good() ) … … 37 39 { 38 40 cout << "difference found @ adress:" << hex << in1.tellg() << "\t" << in2.tellg() << endl; 39 cout << "in1:" << hex << int(c1) << endl; 40 cout << "in2:" << hex << int(c2) << endl; 41 printf ("%30s \t: 0x%X \n", argv[1] ,uint8_t(c1) ); 42 printf ("%30s \t: 0x%X \n", argv[2] ,uint8_t(c2) ); 43 break; 41 44 } 42 45 } -
fact/tools/pyscripts/sandbox/dneise/fact_compress/c++/readfits.cpp
r14259 r14268 1 2 // reading a complete binary file3 1 #include <iostream> 4 2 #include <fstream> 5 3 #include <vector> 4 #include <string.h> 6 5 7 6 // I will use the fits class by TB for reading the interesting data from the files 7 8 #include "izstream.h" 9 8 10 #define HAVE_ZLIB 9 #include "fits "11 #include "fits.h" 10 12 11 13 using namespace std; … … 15 17 16 18 int main (int argc, char * argv[]) { 17 19 20 18 21 if (argc < 3) 19 22 { … … 45 48 fits * calib =new fits(calib_file_name); 46 49 calib->PrintKeys(); 47 calib->PrintColums(); 48 offset_mV = new float[] 49 50 // I need the offset calibration constants from the calibration files 51 // they are stored as floats at a known position inside the calibration file... 52 long position_of_calibration_constants = 0x1000; 53 // The calibration constants are stored in units of pseudo-mV. 54 // but I need them in ADC units 55 // I will first read offset_mV from the file, then multiply (or divide) 56 // with the conversion factor 2000/4096.; 57 // then I will convert it to shorts. 58 // From that point on I will only use the shorts in *offset*, so I can 59 // free the memory for *offset_mV* already. 50 calib->PrintColumns(); 51 60 52 int size_of_offset = 1440*1024; 61 int size_of_offset_memblock = 1440*1024*sizeof(float);62 53 float * offset_mV = new float[size_of_offset]; 63 54 short * offset = new short[size_of_offset]; 64 char * memblock = new char[size_of_offset_memblock]; 65 66 ifstream calib (calib_file_name, ios::in|ios::binary); 67 if ( !calib.is_open() ) 68 { 69 cerr << "Could not open Calibration File:" << calib_file_name << ".. ABORT." << endl; 70 return 1; 71 } 72 else // file was opened, I can go on... 73 { 74 calib.seekg(position_of_calibration_constants, ios::beg); 75 calib.read(memblock, size_of_offset_memblock); 76 offset_mV = (float*)memblock; 77 for (int i=0; i<size_of_offset; i++) 78 { 79 // -0.5 is for rounding correctly negative integers. 80 // in all cases where it worked, the offset should be negative for FACT. 81 offset[i] = short(offset_mV / 2000. * 4096 - 0.5); 82 } 83 } 55 calib->SetPtrAddress("BaselineMean",offset_mV, size_of_offset); 56 57 calib->GetNextRow(); 58 for (int i =0 ; i<size_of_offset; i++) 59 { 60 offset[i] = short(offset_mV[i] / 2000. * 4096 - 0.5); 61 } 62 cout << endl; 84 63 delete[] offset_mV; 85 delete [] memblock;86 calib .close();64 delete calib; 65 calib = NULL; 87 66 //========================================================================= 88 67 // END OF CALIBRATION CONSTANTS … … 90 69 91 70 92 ifstream data (data_file_name, ios::in|ios::binary);71 ifstream datafile (data_file_name, ios::in|ios::binary); 93 72 ofstream out (out_file_name, ios::out|ios::binary|ios::trunc); 94 if (data .is_open() && out.is_open())73 if (datafile.is_open() && out.is_open()) 95 74 { 96 75 // create our own header … … 101 80 const int ascii_header_size = 0x2d00; 102 81 char * memblock = new char [ascii_header_size]; 103 data .read(memblock, ascii_header_size);82 datafile.read(memblock, ascii_header_size); 104 83 out.write(memblock, ascii_header_size); 105 84 delete[] memblock; 106 85 107 86 for ( int event_id = 0 ; event_id < 1000; event_id++) 108 //while ( data .good() )87 //while ( datafile.good() ) 109 88 { 110 89 // copy binary header to new file 111 90 const int bin_header_size = 3390; 112 91 char * memblock = new char [bin_header_size]; 113 data .read(memblock, bin_header_size);92 datafile.read(memblock, bin_header_size); 114 93 out.write(memblock, bin_header_size); 115 94 delete[] memblock; … … 125 104 unsigned char * sizes = new unsigned char [diff_size]; 126 105 127 data .read(memblock, data_size*sizeof(short) );106 datafile.read(memblock, data_size*sizeof(short) ); 128 107 129 108 for ( int i = 0; i<diff_size; i++) … … 195 174 for (int j = 0; j<group_sizes[i]; j++) 196 175 { 197 out.write( ( short*)&(diffs[diff_index++]), 2);176 out.write( (char*)&(diffs[diff_index++]), 2); 198 177 } 199 178 } … … 208 187 } 209 188 cout << "finished with 1000 events." << endl; 210 long after_address = data .tellg();211 data .seekg (0, ios::end);212 long end = data .tellg();213 data .seekg (after_address, ios::beg);189 long after_address = datafile.tellg(); 190 datafile.seekg (0, ios::end); 191 long end = datafile.tellg(); 192 datafile.seekg (after_address, ios::beg); 214 193 215 194 cout << "between last event and end:" << end - after_address << endl; … … 217 196 const int rest_size = end-after_address; 218 197 char * memblock2 = new char [rest_size]; 219 data .read(memblock2, rest_size);198 datafile.read(memblock2, rest_size); 220 199 cout << "first char in memblock: " << int(memblock2[0]) << endl; 221 200 char lastchar = memblock2[0]; … … 233 212 234 213 235 data .close();214 datafile.close(); 236 215 out.close(); 237 216 } //end of if file open
Note:
See TracChangeset
for help on using the changeset viewer.