Changeset 14268 for fact


Ignore:
Timestamp:
07/16/12 17:45:10 (12 years ago)
Author:
neise
Message:
evolving
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  
    33#include <iostream>
    44#include <fstream>
     5#include <stdint.h>
     6#include <stdio.h>
    57using namespace std;
    68
     
    1012char c1,c2;
    1113
    12 int main () {
     14int main (int argc, char * argv[]) {
    1315   
    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);
    1618   
    1719    if (in1.is_open() && in2.is_open())
     
    2224        end = in1.tellg();
    2325        in1.seekg (0, ios::beg);
    24         cout << "a.fits size:" << end-begin << endl;
     26        cout << argv[1] <<" size:" << end-begin << endl;
    2527       
    2628        begin = in2.tellg();
     
    2830        end = in2.tellg();
    2931        in2.seekg (0, ios::beg);
    30         cout << "bla.bin size:" << end-begin << endl;
     32        cout << argv[2] <<" size:" << end-begin << endl;
    3133       
    3234        while ( in1.good() && in2.good() )
     
    3739            {
    3840                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;
    4144            }
    4245        }
  • fact/tools/pyscripts/sandbox/dneise/fact_compress/c++/readfits.cpp

    r14259 r14268  
    1 
    2 // reading a complete binary file
    31#include <iostream>
    42#include <fstream>
    53#include <vector>
     4#include <string.h>
    65
    76// I will use the fits class by TB for reading the interesting data from the files
     7
     8#include "izstream.h"
     9
    810#define HAVE_ZLIB
    9 #include "fits"
     11#include "fits.h"
    1012
    1113using namespace std;
     
    1517
    1618int main (int argc, char * argv[]) {
    17    
     19
     20
    1821    if (argc < 3)
    1922    {
     
    4548    fits * calib =new fits(calib_file_name);
    4649    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
    6052    int size_of_offset = 1440*1024;
    61     int size_of_offset_memblock = 1440*1024*sizeof(float);
    6253    float * offset_mV = new float[size_of_offset];
    6354    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;
    8463    delete[] offset_mV;
    85     delete[] memblock;
    86     calib.close();
     64    delete calib;
     65    calib = NULL;
    8766    //=========================================================================
    8867    // END OF                CALIBRATION CONSTANTS
     
    9069   
    9170   
    92     ifstream data (data_file_name, ios::in|ios::binary);
     71    ifstream datafile (data_file_name, ios::in|ios::binary);
    9372    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())
    9574    {
    9675        // create our own header
     
    10180        const int ascii_header_size = 0x2d00;
    10281        char * memblock = new char [ascii_header_size];
    103         data.read(memblock, ascii_header_size);
     82        datafile.read(memblock, ascii_header_size);
    10483        out.write(memblock, ascii_header_size);
    10584        delete[] memblock;
    10685       
    10786        for ( int event_id = 0 ; event_id < 1000; event_id++)
    108         //while ( data.good() )
     87        //while ( datafile.good() )
    10988        {
    11089            // copy binary header to new file
    11190            const int bin_header_size = 3390;
    11291            char * memblock = new char [bin_header_size];
    113             data.read(memblock, bin_header_size);
     92            datafile.read(memblock, bin_header_size);
    11493            out.write(memblock, bin_header_size);
    11594            delete[] memblock;
     
    125104                unsigned char * sizes = new unsigned char [diff_size];
    126105               
    127                 data.read(memblock, data_size*sizeof(short) );
     106                datafile.read(memblock, data_size*sizeof(short) );
    128107               
    129108                for ( int i = 0; i<diff_size; i++)
     
    195174                        for (int j = 0; j<group_sizes[i]; j++)
    196175                        {
    197                             out.write( (short*)&(diffs[diff_index++]), 2);
     176                            out.write( (char*)&(diffs[diff_index++]), 2);
    198177                        }
    199178                    }
     
    208187        }
    209188        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);
    214193       
    215194        cout << "between last event and end:" << end - after_address << endl;
     
    217196        const int rest_size = end-after_address;
    218197        char * memblock2 = new char [rest_size];
    219         data.read(memblock2, rest_size);
     198        datafile.read(memblock2, rest_size);
    220199        cout << "first char in memblock: " << int(memblock2[0]) << endl;
    221200        char lastchar = memblock2[0];
     
    233212       
    234213       
    235         data.close();
     214        datafile.close();
    236215        out.close();
    237216  } //end of if file open
Note: See TracChangeset for help on using the changeset viewer.