Ignore:
Timestamp:
07/23/10 10:48:12 (14 years ago)
Author:
rohlfs
Message:
can read also EventIO files
Location:
trunk/MagicSoft/Mars/msim
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/msim/MPhotonData.cc

    r9348 r9616  
    245245// --------------------------------------------------------------------------
    246246//
     247// Set the data member according to the 8 floats read from a eventio-file.
     248// This function MUST reset all data-members, no matter whether these are
     249// contained in the input stream.
     250//
     251// Currently we exchange x and y and set y=-y to convert Corsikas coordinate
     252// system into our own.
     253//
     254Int_t MPhotonData::FillEventIO(Float_t f[8])
     255{
     256    fPosX             =  f[1]; // xpos relative to telescope [cm]
     257    fPosY             = -f[0]; // ypos relative to telescope [cm]
     258    fCosU             =  f[3]; // cos to x
     259    fCosV             = -f[2]; // cos to y
     260    fTime             =  f[4]; // a relative arival time [ns]
     261    fProductionHeight =  f[5]; // altitude of emission [cm]
     262    fNumPhotons       =  f[6]; // photons in this bunch
     263    fWavelength       =  f[7]; // so far always zeor = unspec. [nm]
     264
     265
     266    // Now reset all data members which are not in the stream
     267    fPrimary    = MMcEvtBasic::kUNDEFINED;
     268    fTag        = -1;
     269    fWeight     =  1;
     270
     271    return kTRUE;
     272}
     273
     274// --------------------------------------------------------------------------
     275//
    247276// Read seven floats from the stream and call FillCorsika for them.
    248277//
  • trunk/MagicSoft/Mars/msim/MPhotonData.h

    r9370 r9616  
    133133
    134134    Int_t FillCorsika(Float_t f[7]);
     135    Int_t FillEventIO(Float_t f[7]);
    135136    Int_t FillRfl(Float_t f[8]);
    136137
  • trunk/MagicSoft/Mars/msim/MPhotonEvent.cc

    r9349 r9616  
    121121
    122122#include "MPhotonData.h"
     123#include "MCorsikaFormat.h"
    123124
    124125ClassImp(MPhotonEvent);
     
    452453// Read the Event section from the file
    453454//
    454 Int_t MPhotonEvent::ReadCorsikaEvt(istream &fin)
     455Int_t MPhotonEvent::ReadCorsikaEvt(MCorsikaFormat * fInFormat)
    455456{
    456457    Int_t n = 0;
     
    482483    // 1.06GB/ 3s   CPU
    483484    // 1.06GB/22s   REAL
     485    Bool_t readError = kFALSE;
     486    Float_t * buffer;
     487
     488    if ( fInFormat->IsEventioFormat() )
     489        {
     490        while (fInFormat->GetNextEvent(&buffer, readError))
     491            {
     492
     493            const Int_t rc = Add(n).FillEventIO(buffer);
     494            switch (rc)
     495            {
     496            case kCONTINUE:  continue;        // No data in this bunch... skip it.
     497            case kERROR:     return kERROR;   // Error occured
     498            //case kFALSE:     return kFALSE;   // End of stream
     499            }
     500
     501            // This is a photon we would like to keep later.
     502            // Increase the counter by one
     503            n++;
     504            }
     505        }
     506    else
     507        {
     508        while (fInFormat->GetNextEvent(&buffer, readError))
     509            {
     510
     511            const Int_t rc = Add(n).FillCorsika(buffer);
     512            switch (rc)
     513            {
     514            case kCONTINUE:  continue;        // No data in this bunch... skip it.
     515            case kERROR:     return kERROR;   // Error occured
     516            //case kFALSE:     return kFALSE;   // End of stream
     517            }
     518
     519            // This is a photon we would like to keep later.
     520            // Increase the counter by one
     521            n++;
     522            }
     523        }
     524     if (readError)      return kFALSE;
     525
     526/*
    484527
    485528    while (1)
    486529    {
    487         // Stprage for one block
    488         char c[273*4];
    489 
    490         // Read the first four byte to check whether the next block
    491         // doen't belong to the event anymore
    492         fin.read(c, 4);
    493         if (!fin)
     530        Float_t buffer[273];
     531        Float_t * ptr = buffer;
     532
     533
     534        if (!fInFormat->ReadData(273, buffer))
    494535            return kFALSE;
    495536
    496         // Check if the event is finished
    497         if (!memcmp(c, "EVTE", 4))
     537        if (!memcmp(ptr, "EVTE", 4))
     538            {
     539
     540            fInFormat->UnreadLastData();
    498541            break;
    499 
    500         // Now read the rest of the data
    501         fin.read(c+4, 272*4);
    502 
    503         Float_t *ptr = reinterpret_cast<Float_t*>(c);
     542            }
     543
    504544        Float_t *end = ptr + 273;
    505545
     
    525565        }
    526566    }
     567
     568*/
     569    Resize(n);
     570    fData.UnSort();
     571
     572    SetReadyToSave();
     573
     574    //*fLog << all << "Number of photon bunches: " << fData.GetEntriesFast() << endl;
     575    return kTRUE;
     576
     577}
     578
     579Int_t MPhotonEvent::ReadCorsikaEvt(istream &fin)
     580{
     581    Int_t n = 0;
     582
     583    // --- old I/O ---
     584    // Read only + Reflector (no absorption)
     585    // Muons:   1.06GB/115s =  9.2MB/s (100kEvs)
     586    // Gammas:  1.57GB/275s =  5.7MB/s (  1kEvs)
     587
     588    // Read only:
     589    // Gammas:  1.57GB/158s =  9.9MB/s (  1kEvs)
     590    // Muons:   1.06GB/ 77s = 13.8MB/s (100kEvs)
     591
     592    // --- new I/O ---
     593    // Read only (don't allocate storage space):
     594    // Gammas:  1.57GB/143s = 11.0MB/s (  1kEvs)
     595    // Muons:   1.06GB/ 77s = 13.8MB/s (100kEvs)
     596
     597    // Read only in blocks (with storage allocation):
     598    // Gammas:  1.57GB/28s  =  56MB/s (  1kEvs)
     599    // Muons:   1.06GB/5.2s = 204MB/s (100kEvs)
     600
     601    // Read only in blocks (without storage allocation):
     602    // similar to just copy
     603
     604    // Copy with cp
     605    // 1.57GB/ 5s   CPU
     606    // 1.57GB/28s   REAL
     607    // 1.06GB/ 3s   CPU
     608    // 1.06GB/22s   REAL
     609
     610    while (1)
     611    {
     612        // Stprage for one block
     613        char c[273*4];
     614
     615        // Read the first four byte to check whether the next block
     616        // doen't belong to the event anymore
     617        fin.read(c, 4);
     618        if (!fin)
     619            return kFALSE;
     620
     621        // Check if the event is finished
     622        if (!memcmp(c, "EVTE", 4))
     623            break;
     624
     625        // Now read the rest of the data
     626        fin.read(c+4, 272*4);
     627
     628        Float_t *ptr = reinterpret_cast<Float_t*>(c);
     629        Float_t *end = ptr + 273;
     630
     631        // Loop over all sub-blocks (photons) in the block and if
     632        // they contain valid data add them to the array
     633        while (ptr<end)
     634        {
     635            // Get/Add the n-th entry from the array and
     636            // fill it with the current 7 floats
     637            const Int_t rc = Add(n).FillCorsika(ptr);
     638            ptr += 7;
     639
     640            switch (rc)
     641            {
     642            case kCONTINUE:  continue;        // No data in this bunch... skip it.
     643            case kERROR:     return kERROR;   // Error occured
     644            //case kFALSE:     return kFALSE;   // End of stream
     645            }
     646
     647            // This is a photon we would like to keep later.
     648            // Increase the counter by one
     649            n++;
     650        }
     651    }
    527652/*
    528653    while (1)
  • trunk/MagicSoft/Mars/msim/MPhotonEvent.h

    r9349 r9616  
    1616class MPhotonData;
    1717class MCorsikaRunHeader;
     18class MCorsikaFormat;
    1819
    1920class MPhotonEvent : public MParContainer
     
    5253
    5354    // I/O
     55    Int_t ReadCorsikaEvt(MCorsikaFormat * fInFormat);
    5456    Int_t ReadCorsikaEvt(istream &fin);
    5557    Int_t ReadRflEvt(istream &fin);
Note: See TracChangeset for help on using the changeset viewer.