Changeset 3800 for trunk


Ignore:
Timestamp:
04/22/04 19:40:02 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r3799 r3800  
    2525
    2626
     27
    2728 2004/04/22: Thomas Bretz
    2829
    2930   * mhist/MHCamera.[h,cc]:
    3031     - implemented SetUsed
     32
     33   * merpp.cc:
     34     - added "-ff" and interleave mode - both not execcively tested yet
     35
     36   * mhbase/MFillH.cc:
     37     - added a missing 'endl'
     38
     39   * mraw/MRawCrateData.[h,cc], mraw/MRawEvtData.[h,cc],
     40     mraw/MRawEvtHeader.[h,cc]
     41     - added SkipEvt (the number of skipped bytes is untested)
     42
     43   * mraw/MRawEvtHeader.[h,cc]
     44     - return kCONTINUE if time is invalid
     45
     46   * mraw/MRawFileRead.[h,cc]:
     47     - implemented AddFile feature - first draft!
     48     - added feature to skip events
     49
     50   * mraw/MRawFileWrite.h:
     51     - changed default compression level corresponding to merpp to 2
     52
     53   * mraw/MRawRead.[h,cc]:
     54     - added fForceMode flag to be able to suppress event errors
    3155
    3256
  • trunk/MagicSoft/Mars/merpp.cc

    r3487 r3800  
    7272    gLog << "     -a, --no-colors                  Do not use Ansii color codes" << endl;
    7373    gLog << "     -f                               Force overwrite of an existing file" << endl;
     74    gLog << "     -ff                              Force merpp to ignore broken events <raw data only>" << endl;
     75    gLog << "     --interleave=#                   Process only each i-th event [default=1]  <raw data only>" << endl;
    7476    gLog << "     --sql=mysql://user:password@url  Insert run into database <raw data only>" << endl;
    7577    gLog << "     --start=yyyy-mm-dd/hh:mm:ss.mmm  Start event time for merpping report files" << endl;
     
    117119        gLog.SetNoColors();
    118120
    119     const Int_t kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
     121    const Int_t kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 2;
    120122    Bool_t kUpdate = arg.HasOnlyAndRemove("--update") || arg.HasOnlyAndRemove("-u");
     123    const Bool_t kInterleave = arg.HasOption("--interleave=") ? arg.GetIntAndRemove("--interleave=") : 1;
    121124    const Bool_t kForce = arg.HasOnlyAndRemove("-f");
     125    const Bool_t kForceProc = arg.HasOnlyAndRemove("-ff");
    122126
    123127    gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
     
    307311    {
    308312        read  = new MRawFileRead(kNamein);
     313        static_cast<MRawFileRead*>(read)->SetInterleave(kInterleave);
     314        static_cast<MRawFileRead*>(read)->SetForceMode(kForceProc);
    309315        write = new MRawFileWrite(kNameout, option, "Magic root-file", kComprlvl);
    310316    }
  • trunk/MagicSoft/Mars/mhbase/MFillH.cc

    r3790 r3800  
    461461        *fLog << (TestBit(kCanSkip) ? warn : err);
    462462        *fLog << (TestBit(kCanSkip) ? "WARNING" : "ERROR");
    463         *fLog << " Calling SetupFill for " << fH->GetDescriptor() << "...";
    464         *fLog << (TestBit(kCanSkip) ? "skipped." : "aborting.");
     463        *fLog << " - Calling SetupFill for " << fH->GetDescriptor() << "...";
     464        *fLog << (TestBit(kCanSkip) ? "skipped." : "aborting.") << endl;
    465465
    466466        return TestBit(kCanSkip) ? kSKIP : kFALSE;
  • trunk/MagicSoft/Mars/mraw/MRawCrateData.cc

    r3183 r3800  
    6363}
    6464
     65void MRawCrateData::SkipEvt(istream &fin, UShort_t ver)
     66{
     67    fin.seekg(ver>1?11:10);
     68}
     69
    6570// --------------------------------------------------------------------------
    6671//
  • trunk/MagicSoft/Mars/mraw/MRawCrateData.h

    r2645 r3800  
    2929
    3030    void ReadEvt(istream& fin, UShort_t ver);
     31    void SkipEvt(istream& fin, UShort_t ver);
    3132
    3233    ClassDef(MRawCrateData, 2) //Container to store the Raw CRATE DATA
  • trunk/MagicSoft/Mars/mraw/MRawEvtData.cc

    r3183 r3800  
    523523}
    524524
     525// --------------------------------------------------------------------------
     526//
     527// Make sure, that you skip the whole event. This function only skips a part
     528// of the event - see MRawRead::SkipEvent
     529//
     530void MRawEvtData::SkipEvt(istream &fin)
     531{
     532    const UShort_t nlo  = fRunHeader->GetNumSamplesLoGain();
     533    const UShort_t nhi  = fRunHeader->GetNumSamplesHiGain();
     534    const UShort_t npic = fRunHeader->GetNumPixInCrate();
     535
     536    fin.seekg((nhi+nlo)*npic, ios::cur);
     537}
     538
    525539Bool_t MRawEvtData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
    526540{
  • trunk/MagicSoft/Mars/mraw/MRawEvtData.h

    r2958 r3800  
    7171
    7272    void ReadEvt(istream &fin);
     73    void SkipEvt(istream &fin);
    7374
    7475    Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
  • trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc

    r3497 r3800  
    310310        if (!DecodeTime(abstime))
    311311        {
    312             *fLog << err << "ERROR - Event time in event header invalid... abort." << endl;
    313             return kFALSE;
     312            *fLog << warn << "WARNING - Event time in event header invalid... abort." << endl;
     313            return kCONTINUE;
    314314        }
    315315
     
    331331
    332332    return !fin.eof();
     333}
     334
     335void MRawEvtHeader::SkipEvt(istream &fin, UShort_t ver)
     336{
     337    fin.seekg(36+fPixLoGainOn->GetSize(), ios::cur);
    333338}
    334339
  • trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h

    r3483 r3800  
    6666
    6767    int ReadEvt(istream& fin, UShort_t ver);
     68    void SkipEvt(istream& fin, UShort_t ver);
    6869
    6970    ClassDef(MRawEvtHeader, 1) // Parameter Conatiner for raw EVENT HEADER
  • trunk/MagicSoft/Mars/mraw/MRawFileRead.cc

    r3568 r3800  
    2424
    2525//////////////////////////////////////////////////////////////////////////////
    26 //                                                                          //
    27 //  MRawFileRead                                                            //
    28 //                                                                          //
    29 //  This tasks reads the raw binary file like specified in the TDAS???      //
    30 //  and writes the data in the corresponding containers which are           //
    31 //  either retrieved from the parameter list or created and added.          //
    32 //                                                                          //
    33 //  Input Containers:                                                       //
    34 //   -/-                                                                    //
    35 //                                                                          //
    36 //  Output Containers:                                                      //
    37 //   MRawRunHeader, MRawEvtHeader, MRawEvtData, MRawCrateArray, MRawEvtTime //
    38 //                                                                          //
     26//
     27//  MRawFileRead
     28//
     29//  This tasks reads the raw binary file like specified in the TDAS???
     30//  and writes the data in the corresponding containers which are
     31//  either retrieved from the parameter list or created and added.
     32//
     33//  Use SetInterleave() if you don't want to read all events, eg
     34//    SetInterleave(5) reads only each 5th event.
     35//
     36//  Input Containers:
     37//   -/-
     38//
     39//  Output Containers:
     40//   MRawRunHeader, MRawEvtHeader, MRawEvtData, MRawCrateArray, MRawEvtTime
     41//
    3942//////////////////////////////////////////////////////////////////////////////
    4043#include "MRawFileRead.h"
     
    4346#include <fstream>
    4447
     48#include <TSystem.h>
     49
    4550#include "MLog.h"
    4651#include "MLogManip.h"
     
    4853#include "MTime.h"
    4954#include "MParList.h"
     55
    5056#include "MRawRunHeader.h"
    5157#include "MRawEvtHeader.h"
     
    95101//
    96102MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
    97     : fFileName(fname), fIn(NULL)
     103    : fFileNames(NULL), fNumFile(0), fIn(NULL), fParList(NULL), fInterleave(1)
    98104{
    99105    fName  = name  ? name  : "MRawFileRead";
    100106    fTitle = title ? title : "Read task to read DAQ binary files";
    101107
    102     fIn = new ifstream;
     108    fFileNames = new TList;
     109    fFileNames->SetOwner();
     110
     111    AddFile(fname);
    103112}
    104113
     
    109118MRawFileRead::~MRawFileRead()
    110119{
    111     delete fIn;
     120    delete fFileNames;
     121    if (fIn)
     122        delete fIn;
     123}
     124
     125// --------------------------------------------------------------------------
     126//
     127// Add a new file to a list of files to be processed, Returns the number
     128// of files added. (We can enhance this with a existance chack and
     129// wildcard support)
     130//
     131Int_t MRawFileRead::AddFile(const char *fname)
     132{
     133    TNamed *name = new TNamed(fname, "");
     134    fFileNames->AddLast(name);
     135    return 1;
     136
     137}
     138
     139// --------------------------------------------------------------------------
     140//
     141// This opens the next file in the list and deletes its name from the list.
     142//
     143Bool_t MRawFileRead::OpenNextFile()
     144{
     145    //
     146    // open the input stream and check if it is really open (file exists?)
     147    //
     148    if (fIn)
     149        delete fIn;
     150    fIn = NULL;
     151
     152    //
     153    // Check for the existance of a next file to read
     154    //
     155    TObject *file = fFileNames->At(fNumFile);
     156    if (!file)
     157        return kFALSE;
     158
     159    //
     160    // open the file which is the first one in the chain
     161    //
     162    const char *name = file->GetName();
     163
     164    const char *expname = gSystem->ExpandPathName(name);
     165    fIn = new ifstream(expname);
     166
     167    const Bool_t noexist = !(*fIn);
     168    if (noexist)
     169    {
     170        *fLog << err << "Cannot open file " << expname << ": ";
     171        *fLog << strerror(errno) << endl;
     172    }
     173    else
     174        *fLog << inf << "Open file: '" << name << "'" << endl;
     175
     176    delete [] expname;
     177
     178    if (noexist)
     179        return kFALSE;
     180
     181    fNumFile++;
     182
     183    //
     184    // Read RUN HEADER (see specification) from input stream
     185    //
     186    if (!fRawRunHeader->ReadEvt(*fIn))
     187        return kFALSE;
     188
     189    if (!(*fIn))
     190    {
     191        *fLog << err << "Error: Accessing file '" << name << "'" << endl;
     192        return kFALSE;
     193    }
     194
     195    //
     196    // Print Run Header
     197    //
     198    fRawRunHeader->Print();
     199    *fRawEvtTime = fRawRunHeader->GetRunStart();
     200
     201    fNumEvents += fRawRunHeader->GetNumEvents();
     202
     203    //
     204    // Give the run header information to the 'sub-classes'
     205    // Run header must be valid!
     206    //
     207    fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
     208    fRawEvtData  ->Init(fRawRunHeader, fRawCrateArray);
     209
     210    //
     211    // Search for MTaskList
     212    //
     213    MTask *tlist = (MTask*)fParList->FindObject("MTaskList");
     214    if (!tlist)
     215    {
     216        *fLog << err << dbginf << "MTaskList not found... abort." << endl;
     217        return kFALSE;
     218    }
     219
     220    //
     221    // A new file has been opened and new headers have been read.
     222    //  --> ReInit tasklist
     223    //
     224    return tlist->ReInit(fParList);
     225}
     226
     227// --------------------------------------------------------------------------
     228//
     229// Return file name of current file.
     230//
     231const TString MRawFileRead::GetFileName() const
     232{
     233    const TObject *file = fFileNames->At(fNumFile-1);
     234    return file ? file->GetName() : "";
     235}
     236
     237// --------------------------------------------------------------------------
     238//
     239// Restart with the first file
     240//
     241Bool_t MRawFileRead::Rewind()
     242{
     243    fNumFile=0;
     244    fNumEvents=0;
     245    return OpenNextFile();
    112246}
    113247
     
    130264Int_t MRawFileRead::PreProcess(MParList *pList)
    131265{
     266    fParList = pList;
     267
    132268    //
    133269    // open the input stream
     
    135271    // successfull
    136272    //
    137     fIn->open(fFileName);
    138     if (!(*fIn))
    139     {
    140         *fLog << err << "Cannot open file " << fFileName << ": ";
    141         *fLog << strerror(errno) << endl;
    142         return kFALSE;
    143     }
    144 
    145273    if (!MRawRead::PreProcess(pList))
    146274        return kFALSE;
    147275
    148276    //
    149     // Read RUN HEADER (see specification) from input stream
    150     //
    151     if (!fRawRunHeader->ReadEvt(*fIn))
    152         return kFALSE;
    153 
    154     if (!(*fIn))
    155     {
    156         *fLog << err << "Error: Accessing file '" << fFileName << "'" << endl;
    157         return kFALSE;
    158     }
    159     //if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
    160     //    return kFALSE;
    161 
    162     fRawRunHeader->Print();
    163 
    164     *fRawEvtTime = fRawRunHeader->GetRunStart();
    165 
    166     //
    167     // Give the run header information to the 'sub-classes'
    168     // Run header must be valid!
    169     //
    170     fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
    171     fRawEvtData  ->Init(fRawRunHeader, fRawCrateArray);
     277    // Now open next (first) file
     278    //
     279    if (!Rewind())
     280        return kFALSE;
    172281
    173282    return kTRUE;
     
    184293Int_t MRawFileRead::Process()
    185294{
    186     return ReadEvent(*fIn);
     295    while (1)
     296    {
     297        //
     298        // skip events if requested
     299        //
     300        if (fInterleave>1 && GetNumExecutions()%fInterleave>0 && fIn->peek()!=EOF)
     301        {
     302            SkipEvent(*fIn);
     303            return kCONTINUE;
     304        }
     305
     306        //
     307        // Read a single event from file
     308        //
     309        const Bool_t rc = ReadEvent(*fIn);
     310        if (rc!=kFALSE)
     311            return rc;
     312
     313        //
     314        // If an event could not be read from file try to open new file
     315        //
     316        if (!OpenNextFile())
     317            return kFALSE;
     318    }
     319    return kTRUE;
    187320}
    188321
     
    195328Int_t MRawFileRead::PostProcess()
    196329{
    197     fIn->close();
    198 
    199330    //
    200331    // Sanity check for the number of events
    201332    //
    202     if (fRawRunHeader->GetNumEvents()==GetNumExecutions()-1 || GetNumExecutions()==0)
     333    if (fNumEvents==GetNumExecutions()-1 || GetNumExecutions()==0)
    203334        return kTRUE;
    204335
    205336    *fLog << warn << dec;
    206337    *fLog << "Warning - number of read events (" << GetNumExecutions()-1;
    207     *fLog << ") doesn't match number in run header (";
    208     *fLog << fRawRunHeader->GetNumEvents() << ")." << endl;
     338    *fLog << ") doesn't match number in run header(s) (";
     339    *fLog << fNumEvents << ")." << endl;
    209340
    210341    return kTRUE;
  • trunk/MagicSoft/Mars/mraw/MRawFileRead.h

    r3328 r3800  
    66#endif
    77
     8class TList;
     9class MTaskList;
     10
    811class MRawFileRead : public MRawRead
    912{
    1013private:
    11     TString   fFileName;
    12     ifstream *fIn;        //! buffered input stream (file to read from)
     14    TList     *fFileNames; // list of file names
     15    UInt_t     fNumFile;   //! number of next file
     16    UInt_t     fNumEvents; //! input stream (file to read from)
     17
     18    ifstream  *fIn;        //! input stream (file to read from)
     19
     20    MParList  *fParList;   //! tasklist to call ReInit from
     21
     22    UInt_t     fInterleave;
     23
     24    Bool_t OpenNextFile();
    1325
    1426    Int_t PreProcess(MParList *pList);
     
    2032    ~MRawFileRead();
    2133
    22     const TString &GetFileName() const { return fFileName; }
     34    void SetInterleave(UInt_t i) { fInterleave = i; }
     35
     36    const TString GetFileName() const;
     37
     38    Int_t  AddFile(const char *fname);
     39    Bool_t Rewind();
    2340
    2441    ClassDef(MRawFileRead, 0)   // Task to read the raw data binary file
  • trunk/MagicSoft/Mars/mraw/MRawFileWrite.h

    r2556 r3800  
    3737                  const Option_t *opt="RECREATE",
    3838                  const char *ftitle="Untitled",
    39                   const Int_t comp=1,
     39                  const Int_t comp=2,
    4040                  const char *name=NULL, const char *title=NULL);
    4141    ~MRawFileWrite();
  • trunk/MagicSoft/Mars/mraw/MRawRead.cc

    r3183 r3800  
    6666//
    6767MRawRead::MRawRead(const char *name, const char *title)
     68    : fForceMode(kFALSE)
    6869{
    6970    fName  = name  ? name  : "MRawRead";
     
    161162
    162163    //
    163     //  Read in the next EVENT HEADER (see specification),
     164    // Read in the next EVENT HEADER (see specification),
    164165    // if there is no next event anymore stop eventloop
    165166    //
    166     if (!fRawEvtHeader->ReadEvt(fin, ver))
    167         return kFALSE;
     167    const Bool_t rc = fRawEvtHeader->ReadEvt(fin, ver);
     168    if (rc==kCONTINUE && fForceMode==kFALSE)
     169    {
     170        *fLog << err << "Problem found reading the event header... abort." << endl;
     171        return kFALSE;
     172    }
    168173
    169174    //
     
    203208        CreateFakeTime();
    204209
    205     // FIXME: For all other runs we should enhance the precision
    206     //        of the time-stamp by using the FADCClockTick
     210    if (rc==kCONTINUE && fForceMode==kTRUE)
     211        return kCONTINUE;
    207212
    208213    return kTRUE;
    209214}
     215
     216void MRawRead::SkipEvent(istream &fin)
     217{
     218    //
     219    //  Get file format version
     220    //
     221    const UShort_t ver = fRawRunHeader->GetFormatVersion();
     222    fRawEvtHeader->SkipEvt(fin, ver);
     223
     224    const UShort_t nc = fRawRunHeader->GetNumCrates();
     225    for (int i=0; i<nc; i++)
     226    {
     227        fRawCrateArray->GetEntry(i)->SkipEvt(fin, ver);
     228        fRawEvtData->SkipEvt(fin);
     229    }
     230}
  • trunk/MagicSoft/Mars/mraw/MRawRead.h

    r2728 r3800  
    2222    MTime          *fRawEvtTime;    // raw evt time information container to fill from file
    2323
     24    Bool_t          fForceMode;     // Force mode skipping defect events
     25
    2426    void CreateFakeTime() const;
    2527
    2628    Bool_t ReadEvent(istream &fin);
     29    void   SkipEvent(istream &fin);
    2730    Int_t  PreProcess(MParList *pList);
    2831
     
    3336    MRawRead(const char *name=NULL, const char *title=NULL);
    3437
     38    void SetForceMode(Bool_t b=kTRUE) { fForceMode = b; }
     39
    3540    ClassDef(MRawRead, 0)       // Task to read the raw data binary file
    3641};
Note: See TracChangeset for help on using the changeset viewer.