#include #include #include #include // I will use the fits class by TB for reading the interesting data from the files #include "izstream.h" #define HAVE_ZLIB #include "fits.h" #include "helper.hxx" using namespace std; ifstream::pos_type size; char * memblock; int main (int argc, char * argv[]) { char * data_file_name = "20120712_004.fits"; char * calib_file_name ="20120712_003.drs.fits.gz"; char * out_file_name = NULL; out_file_name = new char[strlen(data_file_name)+4]; strcpy(out_file_name, data_file_name); strcpy(out_file_name+strlen(data_file_name),".fc"); out_file_name[strlen(data_file_name)+3] = 0; //========================================================================= // CALIBRATION CONSTANTS //========================================================================= fits * calib =new fits(calib_file_name); calib->PrintKeys(); calib->PrintColumns(); int size_of_offset = 1440*1024; float * offset_mV = new float[size_of_offset]; short * offset = new short[size_of_offset]; calib->SetPtrAddress("BaselineMean",offset_mV, size_of_offset); calib->GetNextRow(); for (int i =0 ; iPrintKeys(); datafits->PrintColumns(); int nevents = (int)datafits->GetNumRows(); int roi = (int)datafits->GetInt("NROI"); int npixel = (int)datafits->GetInt("NPIX"); int event_size = npixel * roi; short *event = new short[event_size]; short *sc = new short[npixel]; datafits->SetPtrAddress("Data",event, event_size ); datafits->SetPtrAddress("StartCellData",sc, npixel ); short first_word; short *diffs = new short[event_size-1]; short *sizes = new short[event_size-1]; //========================================================================= // DATA FILE - with ISTREAM //========================================================================= ifstream datafile (data_file_name, ios::in|ios::binary); ofstream out (out_file_name, ios::out|ios::binary|ios::trunc); helper h(&datafile, &out); if (datafile.is_open() && out.is_open()) { // create our own header // out.write( "FACT_COMPRESS ", 80); // out.write( "END. ", 80); h.copy_ascii_header(); for ( int event_id = 0 ; event_id < nevents; event_id++) { h.copy_event_header(); printf("last event header @: 0x%10X \n", h.event_header_start); // jump over npixel * roi * shorts datafile.seekg( datafile.tellg() + long(npixel * roi * sizeof(short)) , ios::beg); // since the data is stored big-endian in the FITS file, I can't memcopy it .. // have to use the methods of the fits-class datafits->GetNextRow(); // perform a little DRS calibration for ( int pix=0; pix= -8 && diffs[i] <= 7) sizes[i] = 4; else if (diffs[i] >= -16 && diffs[i] <= 15) sizes[i] = 5; else if (diffs[i] >= -32 && diffs[i] <= 31) sizes[i] = 6; else if (diffs[i] >= -128 && diffs[i] <= 127) sizes[i] = 8; else if (diffs[i] >= -256 && diffs[i] <=255) sizes[i] = 9; else if (diffs[i] >= -512 && diffs[i] <= 511) sizes[i] = 10; else if (diffs[i] >= -1024 && diffs[i] <= 1023) sizes[i] = 11; else if (diffs[i] >= -2048 && diffs[i] <= 2047) sizes[i] = 12; else sizes[i] = 16; /* if (diffs[i] >= -128 && diffs[i] <= 127) sizes[i] = 8; else sizes[i] = 16; */ } short last_size = 77; long long cevts = sizeof(first_word)*8; vector< vector > groups; for (int i=0; i dummy; groups.push_back( dummy ); last_size = sizes[i]; } groups.back().push_back(i); } // calc compressed event size cevts = sizeof(first_word)*8; for (int i=0; i group_sizes; vector groups; for (int i=0 ; i < diff_size; i++) { if (sizes[i] != last_size) { group_sizes.push_back( counter ); groups.push_back( last_size ); last_size = sizes[i]; } counter++; } groups.push_back( last_size ); group_sizes.push_back( counter ); // measure how large the stuff, is int cs =0; // for all groups write header and group short header = 0; int diff_index = 0; for ( int i = 0 ; i < (int)groups.size() ; i++) { // write header if (groups[i] == 8) { header = short(group_sizes[i]); } else { header = 0x8000 | short(group_sizes[i] ); } cs += sizeof(short); // write group if (groups[i] == 8) { for (int j = 0; j