Ignore:
Timestamp:
05/28/13 13:45:31 (11 years ago)
Author:
tbretz
Message:
Added more kRequest enums; moved the request form the run-ctrl (where it would be executed immediately) to the evt-ctrl; moved the definition and handling of the memory here - there is no need for a shared_ptr for fEvent; keep a history of the start-cells for step removal in the calibration; added a pointer to a valid header.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/EventBuilder.h

    r16108 r16380  
    33
    44#include "FAD.h"
     5
     6#include <array>
     7#include <forward_list>
    58
    69/* global variables;
     
    3235enum CloseRequest_t
    3336{
    34     kRequestNone = 0,
    35     kRequestManual = 1,
    36     kRequestTimeout = 2,
    37     kRequestConnectionChange = 4,
    38     kRequestEventCheckFailed = 8
     37    kRequestNone             =    0,
     38    kRequestManual           = 1<<1,
     39    kRequestTimeout          = 1<<2,
     40    kRequestConnectionChange = 1<<3,
     41    kRequestEventCheckFailed = 1<<4,
     42    kRequestMaxEvtsReached   = 1<<5,
     43    kRequestMaxTimeReached   = 1<<6
    3944};
    4045
     
    5863
    5964    FileStatus_t fileStat;
    60     int closeRequest;
    6165
    6266    std::shared_ptr<DrsCalibration> calib;
     67    std::list<std::array<int16_t,1440>> prevStart; // History for start cells of previous events (for step calibration)
    6368
    64     RUN_CTRL2() : runId(-1), lastTime(0), lastEvt(0), maxEvt(1<<31), fileStat(kFileNotYetOpen), closeRequest(kRequestNone)
     69    RUN_CTRL2() : runId(-1), lastTime(0), lastEvt(0), maxEvt(1<<31), fileStat(kFileNotYetOpen)
    6570    {
    6671        // runId   = -1;
     
    7479};
    7580
     81#define MAX_HEAD_MEM (NBOARDS * sizeof(PEVNT_HEADER))
     82#define MAX_TOT_MEM (sizeof(EVENT) + (NPIX+NTMARK)*1024*2 + MAX_HEAD_MEM)
     83
     84namespace Memory
     85{
     86    extern uint64_t inuse;
     87    extern uint64_t allocated;
     88
     89    extern uint64_t max_inuse;
     90
     91    extern std::mutex mtx;
     92
     93    extern std::forward_list<void*> memory;
     94
     95    extern void *malloc();
     96    extern void  free(void *mem);
     97};
     98
    7699struct EVT_CTRL2
    77100{
    78     int64_t   runNum;
    79     uint32_t  evNum;
     101    uint32_t  runNum;  // header->runnumber;
     102    uint32_t  evNum;   // header->fad_evt_counter
    80103
    81     uint32_t  trgNum;
    82     uint32_t  trgTyp;
     104    uint32_t  trgNum;  // header->trigger_id
     105    uint32_t  trgTyp;  // header->trigger_type
    83106    uint32_t  fadLen;
    84107
    85     uint32_t  nBoard;
     108    uint16_t  nBoard;
    86109    int16_t   board[NBOARDS];
    87110
     
    92115    uint8_t   Errors[4];
    93116
    94     std::shared_ptr<PEVNT_HEADER> FADhead;
    95     EVENT *fEvent;
     117    PEVNT_HEADER *FADhead; // Pointer to the whole allocated memory
     118    EVENT        *fEvent;  // Pointer to the event data itself
     119    PEVNT_HEADER *header;  // Pointer to a valid header within FADhead
     120
     121    bool reportMem;        // initMemory has reported no memory once (set outside of class)
     122    int closeRequest;
    96123
    97124    std::shared_ptr<RUN_CTRL2> runCtrl;
    98125
    99     EVT_CTRL2(std::shared_ptr<RUN_CTRL2> run=std::shared_ptr<RUN_CTRL2>()) : runNum(-1), runCtrl(run)
     126    // Be carefull with this constructor... writeEvt can seg fault
     127    // it gets an empty runCtrl
     128    EVT_CTRL2() : nBoard(0), FADhead(0), header(0), reportMem(false), closeRequest(kRequestNone)
    100129    {
    101         Errors[0] = 0;
    102         Errors[1] = 0;
    103         Errors[2] = 0;
    104         Errors[3] = 0;
     130        //flag all boards as unused
     131        std::fill(board, board+NBOARDS, -1);
     132    }
     133    /*
     134    EVT_CTRL2(CloseRequest_t req) : nBoard(0), FADhead(0), header(0), reportMem(false), closeRequest(req), runCtrl(new RUN_CTRL2)
     135    {
     136        //flag all boards as unused
     137        std::fill(board, board+NBOARDS, -1);
     138        }*/
    105139
     140    EVT_CTRL2(int req, const std::shared_ptr<RUN_CTRL2> &run) : nBoard(0), FADhead(0), header(0), reportMem(false), closeRequest(req), runCtrl(run)
     141    {
    106142        //flag all boards as unused
    107         nBoard = 0;
    108         for (int b=0; b<NBOARDS; b++)
    109             board[b] = -1;
     143        std::fill(board, board+NBOARDS, -1);
     144    }
     145    ~EVT_CTRL2()
     146    {
     147        Memory::free(FADhead);
    110148    }
    111149
     
    119157        rh.RunUsec = time.tv_usec;
    120158
    121         memcpy(rh.FADhead, FADhead.get(), NBOARDS*sizeof(PEVNT_HEADER));
     159        memcpy(rh.FADhead, FADhead, NBOARDS*sizeof(PEVNT_HEADER));
    122160
    123161        return rh;
    124162    }
    125163
    126     void initEvent(const std::shared_ptr<PEVNT_HEADER> &mem)
     164    bool valid() const { return header; }
     165
     166    bool initMemory()
    127167    {
    128         FADhead = mem;
    129         fEvent  = reinterpret_cast<EVENT*>(mem.get()+NBOARDS);
     168        // We have a valid entry, but no memory has yet been allocated
     169        if (FADhead)
     170            return true;
     171
     172        FADhead = (PEVNT_HEADER*)Memory::malloc();
     173        if (!FADhead)
     174            return false;
     175
     176        fEvent = reinterpret_cast<EVENT*>(FADhead+NBOARDS);
    130177
    131178        memset(fEvent->Adc_Data, 0, (NPIX+NTMARK)*2*nRoi);
    132179
    133         //flag all pixels as unused
    134         for (int k = 0; k < NPIX; k++)
    135             fEvent->StartPix[k] = -1;
     180        //flag all pixels as unused, flag all TMark as unused
     181        std::fill(fEvent->StartPix, fEvent->StartPix+NPIX,   -1);
     182        std::fill(fEvent->StartTM,  fEvent->StartTM +NTMARK, -1);
    136183
    137         //flag all TMark as unused
    138         for (int k = 0; k < NTMARK; k++)
    139             fEvent->StartTM[k] = -1;
    140 
    141         fEvent->NumBoards   = 0;
    142184        fEvent->SoftTrig    = 0;
    143         fEvent->PCTime      = time.tv_sec;
    144         fEvent->PCUsec      = time.tv_usec;
    145185        fEvent->Roi         = nRoi;
    146186        fEvent->RoiTM       = nRoiTM;
     
    148188        fEvent->TriggerNum  = trgNum;
    149189        fEvent->TriggerType = trgTyp;
     190
     191        return true;
    150192    }
    151193};
Note: See TracChangeset for help on using the changeset viewer.