Ignore:
Timestamp:
11/13/02 17:03:19 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mfileio
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h

    r1574 r1600  
    66
    77#pragma link C++ class MChain+;
     8#pragma link C++ class MRead+;
    89#pragma link C++ class MReadTree+;
    910#pragma link C++ class MReadMarsFile+;
  • trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc

    r1599 r1600  
    4242//
    4343/////////////////////////////////////////////////////////////////////////////
    44 
    4544#include "MCT1ReadPreProc.h"
    4645
     
    8180//
    8281MCT1ReadPreProc::MCT1ReadPreProc(const char *fname, const char *name,
    83                                  const char *title) : fIn(NULL)
    84 {
    85     fName  = name  ? name  : "MCT1ReadPreProc";
     82                                 const char *title) : fIn(NULL), fEntries(0)
     83{
     84    fName  = name  ? name  : "MRead";
    8685    fTitle = title ? title : "Task to loop over events in CT1 ascii file";
    8786
     
    113112void MCT1ReadPreProc::AddFile(const char *txt)
    114113{
    115     TNamed *name = new TNamed(txt, "");
    116     fFileNames->AddLast(name);
     114    ifstream *store = fIn;
     115
     116    fIn = new ifstream(gSystem->ExpandPathName(txt));
     117
     118    if (!(*fIn))
     119    {
     120        *fLog << warn << "Cannot open file '" << txt << "'... ignored." << endl;
     121        fIn = store;
     122        return;
     123    }
     124
     125    fEntries += GetNumEvents();
     126
     127    delete fIn;
     128
     129    fIn = store;
     130
     131    fFileNames->AddLast(new TNamed(txt, ""));
    117132}
    118133
     
    123138// data members
    124139//
    125 void MCT1ReadPreProc::ProcessHeader(const struct outputpars &outpars)
    126 {
    127     fNumPixels = outpars.inumpixels; // number of pixels in the camera
    128 
    129     if (fNumPixels>iMAXNUMPIX || fNumPixels==0)
    130         fNumPixels=iMAXNUMPIX;
     140void MCT1ReadPreProc::ProcessRunHeader(const struct outputpars &outpars)
     141{
     142    if (outpars.inumpixels != iMAXNUMPIX)
     143        *fLog << warn << "WARNING! File doesn't contain " << iMAXNUMPIX << " Pixels... maybe corrupt." << endl;
     144
     145    fNumEventsInRun = 0;
    131146
    132147    //
     
    166181    *fLog << "Source:    RA=" << outpars.dsourcera_hours << "h  DEC=";
    167182    *fLog << outpars.dsourcedec_deg << "deg" << endl;
    168 
    169     *fLog << "Pixels:    " << fNumPixels << endl;
    170183
    171184    //int     inummuonpixels;   // number of pixels in the muon shield
     
    262275
    263276    // FIXME? Is x-y echanged between Mars CT1 geometry and CT1 definition?
    264     fSrcPos->SetXY(outpars.fypointcorr_deg/fGeom->GetConvMm2Deg(),
    265                    outpars.fxpointcorr_deg/fGeom->GetConvMm2Deg());
     277    fSrcPos->SetXY(-outpars.fypointcorr_deg/fGeom->GetConvMm2Deg(),
     278                   -outpars.fxpointcorr_deg/fGeom->GetConvMm2Deg());
     279    fSrcPos->SetReadyToSave();
    266280
    267281    /*
     
    342356
    343357    fIsMcFile = outpars.bmontecarlo==TRUE;
     358
     359    fPedest->SetReadyToSave();
    344360}
    345361
     
    348364// Read CT1 PreProc File Header:
    349365//
    350 Bool_t MCT1ReadPreProc::ReadHeader()
     366Bool_t MCT1ReadPreProc::ReadRunHeader()
    351367{
    352368    char cheadertitle[iHEADERTITLELENGTH];
     
    381397    fIn->read((Byte_t*)&outpars, sizeof(struct outputpars));
    382398
    383     ProcessHeader(outpars);
     399    ProcessRunHeader(outpars);
    384400
    385401    return kTRUE;
    386402}
    387403
    388 Bool_t MCT1ReadPreProc::ReadFooter()
     404Bool_t MCT1ReadPreProc::ReadRunFooter()
    389405{
    390406    char cheadertitle[iHEADERTITLELENGTH];
     
    400416
    401417    if (!s.BeginsWith(m(0,p)))
    402         return kFALSE;
     418    {
     419        fIn->seekg(-iHEADERTITLELENGTH, ios::cur);
     420        return kFALSE;
     421    }
    403422
    404423    *fLog << inf << cheadertitle << flush;
     
    423442     */
    424443
     444    fNumFilterEvts += filterres.ifilter_passed_evts;
     445    fNumRuns++;
     446
     447    *fLog << inf << "Read " << fNumEventsInRun << " events from run." << endl;
     448
     449    if (fNumEventsInRun!=(UInt_t)filterres.ifilter_passed_evts)
     450    {
     451        *fLog << warn << "WARNING! Number of events in run doesn't match number of read events." << endl;
     452        *fLog << "         File might be corrupt." << endl;
     453    }
     454
    425455    return kTRUE;
    426456}
     
    468498    *fLog << inf << "-----------------------------------------------------------------------" << endl;
    469499
    470     //*fLog << "File contains " << GetNumEvents() << " events." << endl;
    471 
    472     Bool_t rc = ReadHeader();
     500    *fLog << "File contains " << GetNumEvents() << " events." << endl;
     501
     502    // WORKAROUND for not working seekg(0) in GetNumEvents
     503    fIn->close();
     504    fIn->open(gSystem->ExpandPathName(name));
     505
     506    Bool_t rc = ReadRunHeader();
    473507
    474508    if (!rc)
    475         *fLog << warn << "Unable to read header... skipping file." << endl;
     509        *fLog << warn << "Unable to read first run header... skipping file." << endl;
    476510
    477511    return rc;
     
    480514Int_t MCT1ReadPreProc::GetNumEvents()
    481515{
    482     Int_t n = 0;
     516    *fLog << inf << "Scanning file for size" << flush;
     517
     518    const TString m(cEND_EVENTS_TEMPLATE);
     519    const Int_t p = m.First('%');
     520    const TString test = m(0, p);
     521
     522    Int_t nevts = 0;
     523    Int_t nruns = 0;
    483524
    484525    while (!fIn->eof())
    485526    {
    486         if (fIn->get()!=cEND_EVENTS_TEMPLATE[0])
    487             continue;
    488 
    489         char cheadertitle[iHEADERTITLELENGTH];
    490         fIn->read(cheadertitle, iHEADERTITLELENGTH-1);
    491 
    492         TString s = cheadertitle;
    493         TString m = cEND_EVENTS_TEMPLATE;
    494         Int_t p = m.First('%');
    495 
    496         if (!s.BeginsWith(m(1,p-1)))
    497             continue;
    498 
    499         int num;
    500 
    501         sscanf(cheadertitle, &cEND_EVENTS_TEMPLATE[1], &num);
    502 
    503         n += num;
    504     }
    505 
    506     fIn->seekg(0);
    507 
    508     return n;
     527        fIn->seekg(iHEADERTITLELENGTH, ios::cur);
     528        fIn->seekg(sizeof(struct outputpars), ios::cur);
     529
     530        while (1)
     531        {
     532            if (fIn->peek()==cEND_EVENTS_TEMPLATE[0])
     533            {
     534                char cheadertitle[iHEADERTITLELENGTH];
     535                fIn->read(cheadertitle, iHEADERTITLELENGTH);
     536
     537                const TString s = cheadertitle;
     538                if (s.BeginsWith(test))
     539                {
     540                    fIn->seekg(sizeof(struct filterresults), ios::cur);
     541                    nruns++;
     542                    break;
     543                }
     544
     545                fIn->seekg(-iHEADERTITLELENGTH, ios::cur);
     546            }
     547
     548            fIn->seekg(sizeof(struct eventrecord), ios::cur);
     549            if (fIn->eof())
     550                break;
     551            nevts++;
     552        }
     553        *fLog << "." << flush;
     554    }
     555
     556    *fLog << "done." << endl;
     557    *fLog << "Found " << nevts << " events in " << nruns << " runs." << endl;
     558
     559    return nevts;
    509560}
    510561
     
    542593    //  look for the source position in the camera
    543594    //
    544     fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
     595    fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", "Source");
    545596    if (!fSrcPos)
    546597        return kFALSE;
     
    566617    if (!fMcTrig)
    567618        return kFALSE;
     619
     620    fNumFilterEvts = 0;
     621    fNumRuns       = 0;
    568622
    569623    return kTRUE;
     
    582636     int   isecfrac_200ns;     // fractional part of isecs_since_midday
    583637     short snot_ok_flags;      // the bits in these two bytes are flags for additional information on the event: Everything OK =: all Bits = 0
    584      int   ipreproc_alt_arcs;  // "should be" alt according to preproc (arcseconds)
    585      int   ipreproc_az_arcs;   // "should be" az according to preproc (arcseconds)
    586638
    587639     // for ALT-AZ mount telescopes: rotation angle of the field of
     
    602654     float fhourangle;
    603655     */
    604     /*
    605      *fLog << event.isecs_since_midday << "s ";
    606      *fLog << event.ipreproc_alt_arcs << "s ";
    607      *fLog << event.ipreproc_az_arcs << "s ";
    608      *fLog << event.ifieldrot_arcs << "s ";
    609      *fLog << event.fhourangle << endl;
    610      */
    611656
    612657    //
     
    614659    // too the list with it's id, number of photons and error
    615660    //
    616     fNphot->InitSize(fNumPixels);
     661    fNphot->InitSize(iMAXNUMPIX);
    617662
    618663    // number of photoelectrons measured in each pixel only the
    619664    // actual number of pixels (outputpars.inumpixels) is written out
    620665    // short spixsig_10thphot[iMAXNUMPIX];
    621     for (Int_t i=0; i<fNumPixels; i++)
    622     {
    623         if (event.spixsig_10thphot[i]>0)
    624             fNphot->AddPixel(i, 0.1*event.spixsig_10thphot[i],
    625                              (*fPedest)[i].GetMeanRms());
    626     }
     666    for (Int_t i=0; i<iMAXNUMPIX; i++)
     667    {
     668        if (event.spixsig_10thphot[i]==0)
     669            continue;
     670
     671        fNphot->AddPixel(i, 0.1*event.spixsig_10thphot[i],
     672                         (*fPedest)[i].GetMeanRms());
     673    }
     674    fNphot->SetReadyToSave();
     675
     676    // int ipreproc_alt_arcs; // "should be" alt according to preproc (arcseconds)
     677    // int ipreproc_az_arcs;  // "should be" az according to preproc (arcseconds)
    627678
    628679    fMcEvt->SetTheta(TMath::Pi()*(0.5-1./180*event.ialt_arcs/3600));   // altitude (arcseconds)
    629680    fMcEvt->SetPhi(TMath::Pi()/180*event.iaz_arcs/3600);               // azimuth (arcseconds)
     681
     682    fMcEvt->SetReadyToSave();
    630683
    631684    if (!fIsMcFile)
     
    636689    fMcEvt->SetImpact(event.imcimpact_m*100);    // simulated impact
    637690
    638     fMcTrig->SetFirstLevel(event.imctriggerflag); // MC data from Dorota get a triggerflag: 1 means triggered, 0 not. */
     691    fMcTrig->SetFirstLevel(event.imctriggerflag);    // MC data from Dorota get a triggerflag: 1 means triggered, 0 not. */
     692    fMcTrig->SetReadyToSave();
    639693
    640694    //float fmcsize_phel;   // Simulated SIZE
     
    655709
    656710    //
    657     // If the first character isn't the first of the footer it must be
    658     // an event
    659     //
    660     if (fIn->peek()!=cEND_EVENTS_TEMPLATE[0])
    661         return kTRUE;
    662 
    663     //
    664     // Remember the current position if the first character faked a
    665     // footer
    666     //
    667     const Int_t pos = fIn->tellg();
    668 
    669     //
    670     // Try reading the footer. If it isn't succefull jump back...
    671     // must be an event
    672     //
    673     if (!ReadFooter())
    674     {
    675         fIn->seekg(pos, ios::beg);
    676         return kTRUE;
    677     }
    678 
    679     *fLog << inf << "Footer found." << endl;
    680 
    681     //
    682     // No after reading the footer check if we reached the end of the file
    683     //
    684     if (fIn->eof())
    685     {
    686         *fLog << "End of file." << endl;
    687         return kFALSE;
    688     }
    689 
    690     //
    691     // If the eof isn't reached a new header must follow. Check for it.
    692     //
    693     if (fIn->peek()!=cTITLE_TEMPLATE[0])
    694     {
    695         *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl;
    696         return kFALSE;
    697     }
    698 
    699     *fLog << "-----------------------------------------------------------------------" << endl;
    700     if (ReadHeader())
    701         return kTRUE;
    702 
    703     *fLog << inf << "Error reading run header in file... skipping rest of file." << endl;
    704     return kFALSE;
     711    // Because we can have 0-event runs in the file we loop as often
     712    // as we don't find a new footer-header combination.
     713    //
     714    while (1)
     715    {
     716        //
     717        // If the first character isn't the first of the footer it must be
     718        // an event
     719        //
     720        if (fIn->peek()!=cEND_EVENTS_TEMPLATE[0])
     721            return kTRUE;
     722
     723        //
     724        // Try reading the footer. If it isn't succefull...
     725        // must be an event
     726        //
     727        if (!ReadRunFooter())
     728            return kTRUE;
     729
     730        *fLog << inf << "Footer found." << endl;
     731
     732        //
     733        // No after reading the footer check if we reached the end of the file
     734        //
     735        if (fIn->eof())
     736        {
     737            *fLog << "End of file." << endl;
     738            return kFALSE;
     739        }
     740
     741        //
     742        // If the eof isn't reached a new header must follow. Check for it.
     743        //
     744        if (fIn->peek()!=cTITLE_TEMPLATE[0])
     745        {
     746            *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl;
     747            return kFALSE;
     748        }
     749
     750        *fLog << "-----------------------------------------------------------------------" << endl;
     751        if (!ReadRunHeader())
     752            return kTRUE;
     753    }
    705754}
    706755
     
    726775    struct eventrecord event;
    727776
    728     const int size1 = sizeof(event)-sizeof(event.spixsig_10thphot);
    729     const int size2 = sizeof(event.spixsig_10thphot[0])*fNumPixels;
    730 
    731     // read the eventrecord with the recorded number of stored pixels
    732     fIn->read((Byte_t*)&event, size1+size2);
    733 
    734     if (fIn->eof())
    735         return kFALSE;
     777    // read the eventrecord from the file
     778    fIn->read((Byte_t*)&event, sizeof(struct eventrecord));
    736779
    737780    ProcessEvent(event);
    738781
    739     fNumEvent++;
     782    fNumEvents++;
     783    fNumEventsInRun++;
    740784
    741785    return kTRUE;
    742786}
    743787
     788Bool_t MCT1ReadPreProc::PostProcess()
     789{
     790    *fLog << all;
     791    *fLog << "Number events passed the filter: " << fNumFilterEvts << endl;
     792    *fLog << "Number of Events read from file: " << fNumEvents << endl;
     793    *fLog << "Number of Runs read from file:   " << fNumRuns << endl;
     794
     795    if (fNumEvents!=fNumFilterEvts)
     796    {
     797        *fLog << warn << "WARNING! Number of events in file doesn't match number of read events..." << endl;
     798        *fLog << "         File might be corrupt." << endl;
     799    }
     800
     801    return kTRUE;
     802}
  • trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h

    r1583 r1600  
    22#define MARS_MCT1ReadPreProc
    33
    4 #ifndef MARS_MTask
    5 #include "MTask.h"
     4#ifndef MARS_MRead
     5#include "MRead.h"
    66#endif
    77
     
    1818struct eventrecord;
    1919
    20 class MCT1ReadPreProc : public MTask
     20class MCT1ReadPreProc : public MRead
    2121{
    2222private:
    23     ifstream     *fIn;          // the inputfile
    24     MGeomCam     *fGeom;        // camera geometry
    25     MCerPhotEvt  *fNphot;       // the data container for all data.
    26     MPedestalCam *fPedest;      // ct1 pedestals
    27     MMcEvt       *fMcEvt;       // monte carlo data container for MC files
    28     MMcTrig      *fMcTrig;      // mc data container for trigger information
    29     MSrcPosCam   *fSrcPos;      // source position in the camera
    30     TList        *fFileNames;   // Array which stores the \0-terminated filenames
    31     MBlindPixels *fBlinds;      // Array holding blind pixels
     23    ifstream *fIn;          // the inputfile
     24    TList    *fFileNames;   // Array which stores the \0-terminated filenames
    3225
    33     Int_t fNumPixels;
    34     Bool_t fIsMcFile;
     26    MGeomCam     *fGeom;    // camera geometry
     27    MCerPhotEvt  *fNphot;   // the data container for all data.
     28    MPedestalCam *fPedest;  // ct1 pedestals
     29    MMcEvt       *fMcEvt;   // monte carlo data container for MC files
     30    MMcTrig      *fMcTrig;  // mc data container for trigger information
     31    MSrcPosCam   *fSrcPos;  // source position in the camera
     32    MBlindPixels *fBlinds;  // Array holding blind pixels
    3533
    36     UInt_t fNumEvents;
    37     UInt_t fNumEvent;
     34    Bool_t fIsMcFile;       // Flag whether current run is a MC run
     35
     36    UInt_t fNumEvents;      // number of events counted in all runs in all files
     37    UInt_t fNumEventsInRun; // number of events in the counted in th ecurrent run
     38    UInt_t fNumRuns;        // number of processed runs of all files
     39    UInt_t fEntries;        // entries of all files succesfully added
     40    UInt_t fNumFilterEvts;  // number of events mentioned in the runs footers
    3841
    3942    Bool_t OpenNextFile();
     
    4245
    4346    void   ReadPedestals();
    44     Bool_t ReadHeader();
    45     Bool_t ReadFooter();
     47    Bool_t ReadRunHeader();
     48    Bool_t ReadRunFooter();
    4649    Bool_t CheckFilePosition();
    47     void   ProcessHeader(const struct outputpars &outpars);
     50    void   ProcessRunHeader(const struct outputpars &outpars);
    4851    void   ProcessEvent(const struct eventrecord &event);
    4952
    5053public:
    5154    MCT1ReadPreProc(const char *filename=NULL,
    52                   const char *name=NULL,
    53                   const char *title=NULL);
     55                    const char *name=NULL,
     56                    const char *title=NULL);
    5457
    5558    ~MCT1ReadPreProc();
     
    5962    Bool_t PreProcess(MParList *pList);
    6063    Bool_t Process();
     64    Bool_t PostProcess();
     65
     66    UInt_t GetEntries() { return fEntries; }
    6167
    6268    ClassDef(MCT1ReadPreProc, 0)        // Reads the CT1 data file
  • trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc

    r1583 r1600  
    5454MReadMarsFile::MReadMarsFile() : fRun(NULL)
    5555{
    56     fName  = "MReadMarsFile";
     56    fName  = "MRead";
    5757    fTitle = "Task to loop over all events in a tree of a Mars file.";
    5858}
     
    6767    : MReadTree(tname, fname)
    6868{
    69     fName  = name  ? name  : "MReadMarsFile";
     69    fName  = name  ? name  : "MRead";
    7070    fTitle = title ? title : "Task to loop over all events in a tree of a Mars file.";
    7171
  • trunk/MagicSoft/Mars/mfileio/MReadTree.cc

    r1583 r1600  
    5555#include <TFile.h>           // TFile::GetName
    5656#include <TSystem.h>         // gSystem->ExpandPath
    57 #include <TGProgressBar.h>
     57//#include <TGProgressBar.h>
    5858#include <TChainElement.h>
    5959#include <TOrdCollection.h>
     
    7575//
    7676MReadTree::MReadTree()
    77     : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE), fProgress(NULL)
    78 {
    79     fName  = "MReadTree";
     77    : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE)
     78{
     79    fName  = "MRead";
    8080    fTitle = "Task to loop over all events in one single tree";
    8181
     
    9999MReadTree::MReadTree(const char *tname, const char *fname,
    100100                     const char *name, const char *title)
    101     : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE), fProgress(NULL)
    102 {
    103     fName  = name  ? name  : "MReadTree";
     101    : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE)
     102{
     103    fName  = name  ? name  : "MRead";
    104104    fTitle = title ? title : "Task to loop over all events in one single tree";
    105105
     
    415415    if (TestBit(kChainWasChanged))
    416416    {
     417        *fLog << inf << "Scanning chain... " << flush;
    417418        fNumEntries = (UInt_t)fChain->GetEntries();
     419        *fLog << fNumEntries << " events found." << endl;
    418420        ResetBit(kChainWasChanged);
    419421    }
     
    566568
    567569    //
    568     // If a progress bar is given set its range.
    569     //
    570     if (fProgress)
    571         fProgress->SetRange(0, fNumEntries);
    572 
    573     //
    574570    // Now we can start notifying. Reset tree makes sure, that TChain thinks
    575571    // that the correct file is not yet initialized and reinitilizes it
  • trunk/MagicSoft/Mars/mfileio/MReadTree.h

    r1572 r1600  
    22#define MARS_MReadTree
    33
    4 #ifndef MARS_MTask
    5 #include "MTask.h"
     4#ifndef MARS_MRead
     5#include "MRead.h"
    66#endif
    77
    88class MChain;
    99class TBranch;
    10 class TGProgressBar;
    1110
    12 class MReadTree : public MTask
     11class MReadTree : public MRead
    1312{
    1413private:
     
    2726
    2827private:
    29     TGProgressBar  *fProgress; //! Possible display of status
    30 
    3128    void SetBranchStatus(const TList *list, Bool_t status);
    3229    void SetBranchStatus(TObject *branch, Bool_t status);
     
    5047    void   EnableBranch(const char *name);
    5148    void   VetoBranch(const char *name);
    52 
    53     void   SetProgressBar(TGProgressBar *bar) { fProgress = bar; }
    5449
    5550    Bool_t GetEvent();
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc

    r1583 r1600  
    130130    // - Branches are automatically deleted by the tree destructor
    131131    //
     132
     133    *fLog << inf << "Output File closed and deleted." << endl;
    132134}
    133135
  • trunk/MagicSoft/Mars/mfileio/Makefile

    r1574 r1600  
    3232
    3333SRCFILES = MChain.cc \
     34           MRead.cc \
    3435           MReadTree.cc \
    3536           MReadMarsFile.cc \
Note: See TracChangeset for help on using the changeset viewer.