Changeset 18037


Ignore:
Timestamp:
12/15/14 09:36:20 (10 years ago)
Author:
Jens Buss
Message:
merged Trunk to Branch MarsResidualTimeSpread
Location:
branches/MarsResidualTimeSpread
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/MarsResidualTimeSpread/mbase/MEnv.cc

    r9345 r18037  
    5151#include "MEnv.h"
    5252
     53#include <fstream>
     54#include <exception>
     55
    5356#include <Gtypes.h>
    5457#include <TObjString.h>
     
    97100
    98101    SetRcName(fname);
     102   
     103    if (!IsTEnvCompliant(name)){
     104        throw "This file can't be correctly parsed by TEnv";
     105        return;
     106    }
    99107
    100108    // No file found
     
    189197
    190198    return 0;
     199}
     200
     201//---------------------------------------------------------------------------
     202//
     203// Check if the input file is compatible to the way TEnv parses a resource file.
     204//
     205// Returns true in case everything is file and
     206//         false in case there is a problem with the file.
     207//
     208// Background:
     209//      This check has been introduced as a workaround for a ROOT feature.
     210//      TEnv will not see the last line in a text file, when this last line
     211//      does not end with a \n.
     212//
     213//      In addition we check for the occurence of \r, since some editors would
     214//      place \r instead of \n (unlike windows that uses \n\r), which would
     215//      also result in problems.
     216//      FIXME: So currently we also complain about "\n\r" and "\r\n" as well as
     217//      "\r  \t   \n" or "\n      \t\t\t\r", which would in fact not be a problem at
     218//      all.
     219Bool_t MEnv::IsTEnvCompliant(const char *fname)
     220{
     221    ifstream ifs(fname);
     222    bool printable_char_since_last_lf = false;
     223    char c;
     224    while (ifs.good()){
     225        ifs.get(c);
     226
     227        if (c==13){
     228            gLog << err << "Menv::IsTEnvCompliant - file:" << fname
     229                << " contains \\r this might lead to parsing errors. "
     230                <<"Please exchange \\r by \\n everywhere in that file."
     231                << endl;
     232            return false;
     233        }
     234        if (c=='\n'){
     235            printable_char_since_last_lf = false;
     236        }
     237        if (isgraph(c)){
     238            printable_char_since_last_lf = true;
     239        }
     240    }
     241    if (printable_char_since_last_lf){
     242        gLog << err << "Menv::IsTEnvCompliant - file:" << fname
     243            << " must have \\n at the end of the file. "
     244            <<"Please make sure this is the case."
     245            << endl;
     246        return false;
     247    }
     248    return true;
    191249}
    192250
  • branches/MarsResidualTimeSpread/mbase/MEnv.h

    r9518 r18037  
    2727    TString Compile(TString str, const char *post) const;
    2828    Int_t   ReadInclude();
     29    Bool_t  IsTEnvCompliant(const char *fname);
    2930
    3031public:
  • branches/MarsResidualTimeSpread/mcore/factofits.h

    r17304 r18037  
    224224            c.SetStr(  "RAWSUM",   "         0",    "Checksum of raw little endian data");
    225225            c.SetFloat("ZRATIO",   0,               "Compression ratio");
     226
    226227            c.SetInt(  "ZSHRINK",  1,               "Catalog shrink factor");
    227228            c.End();
     
    280281            //update relevant keywords
    281282            c.SetFloat("ZRATIO", (float)(1024*1440*2)/(float)(compressed_size));
    282             c.SetInt("PCOUNT", compressed_size + catalog_size);
     283            c.SetInt("PCOUNT", compressed_size);// + catalog_size);
     284
     285
     286//cout << "DEBUG: compressed_size=" << compressed_size << " " << compressed_size%2880 << " " << catalog_size << endl;
     287
    283288
    284289#if GCC_VERSION < 40603
     
    302307            return good();
    303308        }
     309
    304310        ///Apply the drs offset calibration (overload of super-method)
    305311        virtual void DrsOffsetCalibrate(char* target_location)
Note: See TracChangeset for help on using the changeset viewer.