Ignore:
Timestamp:
11/25/02 09:12:47 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mfileio
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfileio/MCT1ReadAscii.cc

    r1583 r1668  
    127127    const char *name = file->GetName();
    128128
    129     fIn = new ifstream(gSystem->ExpandPathName(name));
     129    const char *expname = gSystem->ExpandPathName(name);
     130    fIn = new ifstream(expname);
     131    delete [] expname;
    130132
    131133    const Bool_t noexist = !(*fIn);
  • trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc

    r1666 r1668  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
    19 !   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
     18!   Author(s): Thomas Bretz 11/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    2019!
    21 !   Copyright: MAGIC Software Development, 2000-2001
     20!   Copyright: MAGIC Software Development, 2000-2002
    2221!
    2322!
     
    2928//
    3029// Reads a output file of the CT1 preproc.
     30//
     31// Implements usage of a selector (see MRead) Use such a filter to skip
     32// events before reading! But never use a filter which needs read data
     33// as input...
    3134//
    3235//  Input Containers:
     
    5861#include "MLogManip.h"
    5962
     63#include "MTime.h"
     64#include "MFilter.h"
     65
    6066#include "MParList.h"
    6167#include "MCerPhotEvt.h"
     
    112118void MCT1ReadPreProc::AddFile(const char *txt)
    113119{
    114     const TString fname = gSystem->ExpandPathName(txt);
     120    const char *name = gSystem->ExpandPathName(txt);
     121    TString fname(name);
     122    delete [] name;
    115123
    116124    if (!CheckHeader(fname))
     
    502510    // open the file which is the first one in the chain
    503511    //
    504     const TString name  = file->GetName();
    505     const TString fname = gSystem->ExpandPathName(name);
     512    const TString name = file->GetName();
     513
     514    const char *expname = gSystem->ExpandPathName(name);
     515    const TString fname(expname);
     516    delete [] expname;
    506517
    507518    //
     
    648659
    649660    //
     661    //  look for the time class in the plist
     662    //
     663    fTime = (MTime*)pList->FindCreateObj("MTime");
     664    if (!fTime)
     665        return kFALSE;
     666
     667    //
    650668    //  look for the pedestal class in the plist
    651669    //
     
    685703    fNumRuns       = 0;
    686704
    687     return kTRUE;
     705    return GetSelector() ? GetSelector()->CallPreProcess(pList) : kTRUE;
    688706}
    689707
     
    695713void MCT1ReadPreProc::ProcessEvent(const struct eventrecord &event)
    696714{
     715    //  int   isecs_since_midday; // seconds passed since midday before sunset (JD of run start)
     716    //  int   isecfrac_200ns;     // fractional part of isecs_since_midday
     717    fTime->SetTime(event.isecfrac_200ns, event.isecs_since_midday);
     718    fTime->SetReadyToSave();
     719
    697720    /*
    698721     --- USEFULL? NEEDED? ---
    699      int   isecs_since_midday; // seconds passed since midday before sunset (JD of run start)
    700      int   isecfrac_200ns;     // fractional part of isecs_since_midday
    701722     short snot_ok_flags;      // the bits in these two bytes are flags for additional information on the event: Everything OK =: all Bits = 0
    702723
     
    862883            return kFALSE;
    863884
     885    //
     886    // Check for a selector. If one is given and returns kFALSE
     887    // skip this event.
     888    //
     889    if (GetSelector())
     890    {
     891        //
     892        // Make sure selector is processed
     893        //
     894        if (!GetSelector()->CallProcess())
     895        {
     896            *fLog << err << dbginf << "Processing Selector failed." << endl;
     897            return kFALSE;
     898        }
     899
     900        //
     901        // Skip Event
     902        //
     903        if (!GetSelector()->IsExpressionTrue())
     904        {
     905            fIn->seekg(sizeof(struct eventrecord), ios::cur);
     906
     907            fNumEvents++;
     908            fNumEventsInRun++;
     909
     910            return kCONTINUE;
     911        }
     912    }
     913
    864914    // event data to be read from the file
    865915    struct eventrecord event;
     
    890940    }
    891941
    892     return kTRUE;
    893 }
     942    return GetSelector() ? GetSelector()->CallPostProcess() : kTRUE;
     943}
  • trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h

    r1664 r1668  
    77
    88class TList;
     9class MTime;
    910class MMcEvt;
    1011class MMcTrig;
     
    2728    MCerPhotEvt  *fNphot;   // the data container for all data.
    2829    MPedestalCam *fPedest;  // ct1 pedestals
     30    MTime        *fTime;    // event time
    2931    MMcEvt       *fMcEvt;   // monte carlo data container for MC files
    3032    MMcTrig      *fMcTrig;  // mc data container for trigger information
     
    5254    void   ProcessEvent(const struct eventrecord &event);
    5355
     56    Bool_t PreProcess(MParList *pList);
     57    Bool_t Process();
     58    Bool_t PostProcess();
     59
    5460public:
    5561    MCT1ReadPreProc(const char *filename=NULL,
     
    6167    void AddFile(const char *fname);
    6268
    63     Bool_t PreProcess(MParList *pList);
    64     Bool_t Process();
    65     Bool_t PostProcess();
    66 
    6769    UInt_t GetEntries() { return fEntries; }
    6870
  • trunk/MagicSoft/Mars/mfileio/MRead.cc

    r1600 r1668  
    2929// Base class for all reading tasks                                        //
    3030//                                                                         //
     31// You can set a selector. Depending on the impelementation in the derived //
     32// class it can be used to skip events, if the filter return kFALSE.       //
     33// Make sure that the selector (filter) doesn't need information which     //
     34// doesn't exist before reading an event!                                  //
     35//                                                                         //
    3136/////////////////////////////////////////////////////////////////////////////
    3237#include "MRead.h"
  • trunk/MagicSoft/Mars/mfileio/MRead.h

    r1600 r1668  
    66#endif
    77
     8class MFilter;
     9
    810class MRead : public MTask
    911{
     12private:
     13    MFilter *fSelector;
     14
    1015public:
     16    MRead() : fSelector(NULL) {}
    1117
    1218    virtual UInt_t GetEntries() = 0;
     19
     20    void SetSelector(MFilter *f) { fSelector = f; }
     21    MFilter *GetSelector() { return fSelector; }
    1322
    1423    ClassDef(MRead, 0)  // Base class for a reading task
  • trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc

    r1667 r1668  
    9898//  chains -1 is returned, otherwise the number of files which were added.
    9999//
    100 Int_t MReadMarsFile::AddFile(const char *fname)
     100Int_t MReadMarsFile::AddFile(const char *fname, Int_t entries)
    101101{
    102102    //
     
    107107    //
    108108    Int_t n1 = fRun->AddFile(fname);
    109     Int_t n2 = MReadTree::AddFile(fname);
     109    Int_t n2 = MReadTree::AddFile(fname, entries);
    110110
    111111    return n1 != n2 ? -1 : n1;
  • trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h

    r1664 r1668  
    2424    ~MReadMarsFile();
    2525
    26     Int_t AddFile(const char *fname);
     26    Int_t AddFile(const char *fname, Int_t entries=-1);
    2727
    2828    ClassDef(MReadMarsFile, 1)  // Reads a tree from file(s) and the information from the 'RunHeader'-tree
  • trunk/MagicSoft/Mars/mfileio/MReadTree.cc

    r1664 r1668  
    191191//  AddFile returns the number of files added to the chain.
    192192//
    193 Int_t MReadTree::AddFile(const char *fname)
    194 {
     193//  For more information see TChain::Add
     194//
     195Int_t MReadTree::AddFile(const char *fname, Int_t entries)
     196{
     197#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,01)
     198    //
     199    // This is a workaround to get rid of crashed if the file doesn't
     200    // exist due to non initialized TFile::fProcessIDs
     201    //
     202    //  (Code taken from TFile::TFile
     203    //
     204    const char *name;
     205
     206    TString newname;
     207
     208    if ((name = gSystem->ExpandPathName(fname)))
     209    {
     210        newname = name;
     211        delete [] name;
     212    }
     213
     214    if (newname.IsNull())
     215    {
     216        *fLog << err << dbginf << "Error expanding path " << fname << "." << endl;
     217        return 0;
     218    }
     219
     220    if (gSystem->AccessPathName(newname, kFileExists))
     221    {
     222        *fLog << err << "ERROR - File '" << fname << "' does not exist." << endl;
     223        return 0;
     224    }
     225
     226    fname = newname.Data();
     227#endif
     228
    195229    //
    196230    // FIXME! A check is missing whether the file already exists or not.
    197231    //
    198     //
    199     // returns the number of file which were added
    200     //
    201 
    202     const Int_t numfiles = fChain->Add(fname);
     232    const Int_t numfiles = fChain->Add(fname, entries);
    203233
    204234    if (numfiles>0)
     
    208238}
    209239
     240/*
     241 // --------------------------------------------------------------------------
     242 //
     243 //
     244 Int_t MReadTree::AddFile(const TChainElement &obj)
     245 {
     246     return AddFile(obj.GetTitle(), obj.GetEntries());
     247 }
     248*/
     249
    210250// --------------------------------------------------------------------------
    211251//
     
    216256Int_t MReadTree::AddFiles(const MReadTree &read)
    217257{
    218     Int_t rc = 0;
    219 
    220     TIter Next(read.fChain->GetListOfFiles());
    221     TObject *obj = NULL;
    222     while ((obj=Next()))
    223         rc += AddFile(obj->GetTitle());
     258    const Int_t rc = fChain->Add(read.fChain);
    224259
    225260    if (rc>0)
    226261        SetBit(kChainWasChanged);
     262
     263    /*
     264     Int_t rc = 0;
     265
     266     TIter Next(read.fChain->GetListOfFiles());
     267     TObject *obj = NULL;
     268     while ((obj=Next()))
     269         rc += AddFile(*(TChainElement*)obj);
     270    */
    227271
    228272    return rc;
     
    241285        return;
    242286
    243     *fLog << inf << GetDescriptor() << ": Branch choosing method enabled (only enabled branches are read)." << endl;
     287    *fLog << inf << GetDescriptor() << ": Branch choosing enabled (only enabled branches are read)." << endl;
    244288    fChain->SetBranchStatus("*", kFALSE);
    245289    fBranchChoosing = kTRUE;
     
    255299void MReadTree::EnableBranch(const char *name)
    256300{
     301    if (fChain->GetListOfFiles()->GetEntries()==0)
     302    {
     303        *fLog << err << "Chain contains no file... Branch '";
     304        *fLog << name << "' ignored." << endl;
     305        return;
     306    }
     307
    257308    EnableBranchChoosing();
    258309
     
    449500//  root environment) the branch is skipped and an error message is printed
    450501//  out.
     502//  If a selector is specified it is preprocessed after the
     503//  MReadTree::PreProcess
    451504//
    452505Bool_t MReadTree::PreProcess(MParList *pList)
     
    576629    fChain->SetNotify(this);
    577630
    578     return kTRUE;
     631    return GetSelector() ? GetSelector()->CallPreProcess(pList) : kTRUE;
    579632}
    580633
     
    626679//  (Remark: The position can also be set by some member functions
    627680//  If the end of the file is reached the Eventloop is stopped.
     681//  In case an event selector is given its value is checked before
     682//  reading the event. If it returns kAFLSE the event is skipped.
    628683//
    629684#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
     
    658713#endif
    659714
    660     Bool_t rc = fChain->GetEntry(fNumEntry++) != 0;
     715    if (GetSelector())
     716    {
     717        //
     718        // Make sure selector is processed
     719        //
     720        if (!GetSelector()->CallProcess())
     721        {
     722            *fLog << err << dbginf << "Processing Selector failed." << endl;
     723            return kFALSE;
     724        }
     725
     726        //
     727        // Skip Event
     728        //
     729        if (!GetSelector()->IsExpressionTrue())
     730        {
     731            fNumEntry++;
     732            return kCONTINUE;
     733        }
     734    }
     735
     736    const Bool_t rc = fChain->GetEntry(fNumEntry++) != 0;
    661737
    662738    if (rc)
     
    664740
    665741    return rc;
     742}
     743
     744// --------------------------------------------------------------------------
     745//
     746//  If a selector is given the selector is post processed
     747//
     748Bool_t MReadTree::PostProcess()
     749{
     750    return GetSelector() ? GetSelector()->CallPostProcess() : kTRUE;
    666751}
    667752
  • trunk/MagicSoft/Mars/mfileio/MReadTree.h

    r1600 r1668  
    6464    virtual void   Print(Option_t *opt="") const;
    6565
    66     virtual Int_t  AddFile(const char *fname);
     66    virtual Int_t  AddFile(const char *fname, Int_t entries=-1);
    6767    virtual Int_t  AddFiles(const MReadTree &read);
    6868
    6969    virtual Bool_t PreProcess(MParList *pList);
    7070    virtual Bool_t Process();
     71    virtual Bool_t PostProcess();
    7172
    7273    virtual Bool_t Notify();
Note: See TracChangeset for help on using the changeset viewer.