Changeset 11496 for trunk


Ignore:
Timestamp:
07/20/11 18:49:32 (13 years ago)
Author:
tbretz
Message:
Optimized ToFits according to the result of the optimization of the MFits reader.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Converter.cc

    r11482 r11496  
    875875   const char *charSrc  = static_cast<const char*>(src);
    876876
    877    for (Converter::FormatList::const_iterator i=fList.begin(); i!=fList.end(); i++)
     877   // We skip the last element 'v'
     878   for (Converter::FormatList::const_iterator i=fList.begin(); i!=fList.end()-1; i++)
    878879   {
    879        if (charDest-size>dest/* || charSrc-size>src*/)
     880       /*
     881        // For speed reasons we don't do a check in the loop
     882       if (charDest-size>dest || charSrc-size>src)
    880883       {
    881884           ostringstream err;
     
    883886           throw runtime_error(err.str());
    884887       }
    885 
     888       */
     889
     890       // Skip strings (must be the last, so we could just skip it)
    886891       const char type = i->first.first->name()[0];
    887        if (type=='v')
    888            break;
    889 
    890892       if (type=='S')
    891893       {
    892894           charSrc += strlen(charSrc)+1;
    893895           continue;
    894 
    895            // copy string until termination
    896            // while (*charSrc)
    897            //     *charDest++ = *charSrc++;
    898            //
    899            // *charDest++ = *charSrc++;
    900896       }
    901 
    902        // string types
    903        if (string("bsilfdxc").find_first_of(type)==string::npos)
    904            throw runtime_error(string("Type '")+type+"' not supported converting to FITS.");
    905897
    906898       const int s = i->first.second;      // size of element
    907899       const int n = i->second.first;      // number of elements
    908900
    909        // for all elements of this column
    910        for (int j=0; j<n; j++)
     901       // Check if there are types with unknown sizes
     902       if (s==0 || n==0)
     903           throw runtime_error(string("Type '")+type+"' not supported converting to FITS.");
     904
     905       // Let the compiler do some optimization
     906       switch (s)
    911907       {
    912            reverse_copy(charSrc,  charSrc+s, charDest);
    913 
    914            charSrc  += s;
    915            charDest += s;
     908       case 1: memcpy(charDest, charSrc, s*n); charSrc+=s*n; charDest+=s*n; break;
     909       case 2: for (int j=0; j<n; j++) { reverse_copy(charSrc, charSrc+2, charDest); charSrc+=2; charDest+=2; } break;
     910       case 4: for (int j=0; j<n; j++) { reverse_copy(charSrc, charSrc+4, charDest); charSrc+=4; charDest+=4; } break;
     911       case 8: for (int j=0; j<n; j++) { reverse_copy(charSrc, charSrc+8, charDest); charSrc+=8; charDest+=8; } break;
    916912       }
    917913   }
     
    920916   {
    921917       ostringstream err;
    922        err << "Data block size (" << size << ") doesn't fit format description [fmt=" << fFormat << "]";
     918       err << "ToFits - Data block size (" << size << ") doesn't fit format description [fmt=" << fFormat << "]";
    923919       throw runtime_error(err.str());
    924920   }
Note: See TracChangeset for help on using the changeset viewer.