#include #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; void make_groups( vector& group_starts , vector& group_length, short * sizes, int len_sizes, int roi); long get_event_size( vector& gs, vector& gl, short * sizes); 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= -1*(1< gs; vector gl; make_groups( gs , gl, sizes, event_size-1, event_size); long cevts = get_event_size( gs,gl, sizes); cout << cevts << endl; cout << "number of groups:" << gs.size() << endl; // write the length of the event out.write( (char*) &cevts, sizeof(cevts) ); // write the event to disk out.write( (char*)&first_word, sizeof(first_word)); unsigned short header; for (int g=0; g= size) // diff entry fits in one byte { buffer[Bs[i]] |= dat <<(bs[i]+1-size); } else // entry is distributed over two bytes { buffer[Bs[i]] |= dat>>(size - bs[i]+1); buffer[Bs[i-1]] |= dat<<(8-size - bs[i]+1); } } delete[] bs; delete[] Bs; if (g<50) { int tellp = out.tellp(); // printf("start_addres: 0x%8X\n", tellp); } out.write( (char*)buffer, group_size); delete[] buffer; } return 0; /* // 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& group_starts , vector& group_length, short * sizes, int len_sizes, int roi) { short * diff_sizes = new short[len_sizes-1]; for (int i=0; i gs; vector gl; gs.push_back(0); for (int i=0; i& gs, vector& gl, short * sizes) { long bits; // eventsize in bytes long evts = 2; // the first word // gs and gl have equal length for (int i=0; i