ROOT logo
#ifndef HMDCSTOREEVENTS_H
#define HMDCSTOREEVENTS_H

#include "TObject.h"
#include "hgeomvector.h"
#include "hseqarr.h"

class HMdcEvntListCells;
class HMdcClus;

class HMdcStoreWires : public TObject {
  protected:
    HSeqArr      nDTPerEvent; // array of indexis of events
    HSeqArrIter* iterEvents;  // pointer to iterator of events
    HSeqArr      mdcWireAddr; // array of addresses of fired wires
    HSeqArrIter* iterWires;   // pointer to iterator of wires in event
    
    UInt_t       maxMemSize;  // upper limit for memory
    
    UInt_t       nEvents;     // number of events in array (for filling only)  
    UShort_t     nDrTimes;    // number of wires in current event (for filling)
    
    UShort_t     nDrTmPerEv;  // number of wires in current event (for reading)
    UInt_t       nRdEvents;   // number of read events  (for reading)
    UShort_t     nRdDrTimes;  // number of read wires  (for reading)

  public:
    HMdcStoreWires(void);
    ~HMdcStoreWires(void);
    void setMaxMemSize(UInt_t mSize); // mSize - in Mb!
    virtual UInt_t getMemSize(void) const;
    Bool_t testMemSize(void) const;
    
    // Storing functions:
    void addWireAddr(Int_t s, Int_t m, Int_t l, Int_t c);
    void setEndEvent(void);
    
    // Getting functions:
    virtual void resetIter(void);
    Bool_t getNextEvent(void);
    Bool_t getNextWireAddr(Int_t& s, Int_t& m, Int_t& l, Int_t& c);
    inline static UShort_t packAddress(Int_t s, Int_t m, Int_t l, Int_t c);
    inline static void unpackAddress(UShort_t& addr, Int_t& s, Int_t& m, 
        Int_t& l, Int_t& c);
    
    // Storing and getting events:
    void addEvent(const HMdcEvntListCells& event);
    Bool_t getNextEvent(HMdcEvntListCells& event);
  protected:
    
  ClassDef(HMdcStoreWires,0)
};

inline UShort_t HMdcStoreWires::packAddress(Int_t s,Int_t m,Int_t l,Int_t c) {
  return UShort_t((( ((s&7)<<5) + ((m&3)<<3) + (l&7) ) <<8) + (c&255));
}

inline void HMdcStoreWires::unpackAddress(UShort_t& addr, Int_t& s, 
    Int_t& m, Int_t& l, Int_t& c) {
  s=(Int_t)((addr>>13)&7);  // 13=5+8
  m=(Int_t)((addr>>11)&3);  // 11=3+8
  l=(Int_t)((addr>>8)&7);
  c=(Int_t)(addr&255);
}

//----------------------------------------------

class HMdcStoreEvents : public TObject {
  protected:
    HSeqArr      nDTPerEvent; // array of indexis of events
    HSeqArrIter* iterEvents;  // pointer to iterator of events
    HSeqArr      mdcCells;    // array of addresses & dr.times of fired wires
    HSeqArrIter* iterWires;   // pointer to iterator of wires in event
    
    UInt_t       maxMemSize;  // upper limit for memory
    
    UInt_t       nEvents;     // number of events in array (for filling only)  
    UShort_t     nDrTimes;    // number of wires in current event (for filling)
    
    UShort_t     nDrTmPerEv;  // number of wires in current event (for reading)
    UInt_t       nRdEvents;   // number of read events  (for reading)
    UShort_t     nRdDrTimes;  // number of read wires  (for reading)

  public:
    HMdcStoreEvents(void);
    ~HMdcStoreEvents(void);
    void setMaxMemSize(UInt_t mSize); // mSize - in Mb!
    virtual UInt_t getMemSize(void) const;
    Bool_t testMemSize(void) const;
    
    // Storing functions:
    void addWire(Int_t s,Int_t m,Int_t l,Int_t c,Float_t tm, Bool_t flag=kTRUE);
    void setEndEvent(void);
    
    // Getting functions:
    virtual void resetIter(void);
    Bool_t getNextEvent(void);
    Bool_t getNextCell(Int_t& s, Int_t& m, Int_t& l, Int_t& c, Float_t& tm);
    Bool_t getNextCell(Int_t& s, Int_t& m, Int_t& l, Int_t& c, Float_t& tm,
        Bool_t& flag);
    Bool_t getNextCell(Int_t& s, Int_t& m, Int_t& l, Int_t& c, Float_t& tm,
        Bool_t& flag,UInt_t** addr);
    inline static UInt_t packCell(Int_t s, Int_t m, Int_t l, Int_t c, 
        Float_t tm, Bool_t flag=kTRUE);
    inline static Bool_t unpackCell(UInt_t& addr, Int_t& s, Int_t& m, 
        Int_t& l, Int_t& c, Float_t& tm);
    static void unsetFlag(UInt_t& addr) {addr &= 0xFFFEFFFF;}
    static void setFlag(UInt_t& addr)   {addr |=    0x10000;} // 0x10000=1<<16;
    
    // Storing and getting events:
    void   addEvent(const HMdcEvntListCells& event);
    Bool_t getNextEvent(HMdcEvntListCells& event,Bool_t checkFlag=kFALSE);
  protected:
    
  ClassDef(HMdcStoreEvents,0)
};

inline UInt_t HMdcStoreEvents::packCell(Int_t s,Int_t m,Int_t l,Int_t c,
    Float_t tm,Bool_t flag) {
  UInt_t sign = tm>0 ? 0 : 0x4000;       // 0x4000 = 1<<14
  if(sign) tm = -tm;
  UInt_t dt   = UInt_t(tm*10. + 0.5);
  if(dt > 0x3FFF) dt=0x3FFF;
  dt = (dt|sign)<<17;
  if(flag) setFlag(dt);
  return UInt_t((( ((s&7)<<5) + ((m&3)<<3) + (l&7) ) <<8) + (c&0xFF)) +dt;
}

inline Bool_t HMdcStoreEvents::unpackCell(UInt_t& addr, Int_t& s, 
    Int_t& m, Int_t& l, Int_t& c, Float_t& tm) {
  // return user flag
  s  = (Int_t)((addr>>13)&7);               // 13=5+8
  m  = (Int_t)((addr>>11)&3);               // 11=3+8
  l  = (Int_t)((addr>>8)&7);
  c  = (Int_t)(addr&0xFF);
  tm = ((addr>>17)&0x3FFF)*0.1;
  if(addr&0x80000000) tm = -tm;             // negative dr.time.
  return (addr&0x10000) > 0;                // 0x10000=1<<16
}

//----------------------------------------------

class HMdcStoreTracks : public TObject {
  protected:
    HSeqArr      address;      // keep sector and mod.for x1,y1 (mod1)
                               // and mod.for x2,y2 (mod2) and flag
                               // if mod1=mod2 - x1,y1 - layer 1, x2,y2 - layer 6
    HSeqArr      trackPos;     // array of cluster positions
    HSeqArr      nTracksEvent; // array of numbers of tracks per event
    HSeqArrIter* iterAddress;  // pointer to iterator of track address
    HSeqArrIter* iterTrackPos; // pointer to iterator of clusters positions
    HSeqArrIter* iterNTrckEv;  // pointer to iterator of num.of clusters/event
    UChar_t      flagAddress;  // trackFlag and address for current track
    Float_t      x1,y1;        // current cluster parameters:
    Float_t      x2,y2;        // two points in coor.sys. mdc's
    UShort_t     nEventTracks; // num. tracks in one event (<=32767)
    UShort_t     nReadTracks;  // counter of the read tracks in this event
    Bool_t       eventFlag;    // event flag
    Bool_t       arrayEnd;     // end of array flag
  public:
    HMdcStoreTracks(void);
    ~HMdcStoreTracks(void);
    virtual UInt_t getMemSize(void) const;
    
    // Storing functions:
    Bool_t setEndTrack(void);
    void setEndEvent(Bool_t flag=kTRUE);
    void setTrackPar(UChar_t s, UChar_t m1, Float_t xf, Float_t yf,
        UChar_t m2, Float_t xl, Float_t yl, UChar_t flag=1);
    
    // Getting functions:
    virtual void resetIter(void);  // must be called ones per clusters loop
    Bool_t nextEvent(void);
    Bool_t nextTrack(void);
    
    Bool_t  getEventFlag(void)            {return eventFlag;}
    Bool_t  getTrackFlag(void)            {return (flagAddress&128) > 0;}
    UChar_t getSector(void)               {return flagAddress&7;}
    UChar_t getMod1(void)                 {return (flagAddress>>3)&3;}
    UChar_t getMod2(void)                 {return (flagAddress>>5)&3;}
    Int_t   getNumEventTracks(void) const {return nEventTracks;}
    Float_t getX1(void) const             {return x1;}
    Float_t getY1(void) const             {return y1;}
    Float_t getZ1(void) const             {return 0.;}
    Float_t getX2(void) const             {return x2;}
    Float_t getY2(void) const             {return y2;}
    Float_t getZ2(void) const             {return 0.;}
    void getTrackPar(Float_t& xf,Float_t& yf, Float_t& xl,Float_t& yl) const;
    void getPoint1(HGeomVector& p1) const {p1.setXYZ(x1,y1,0.);}
    void getPoint2(HGeomVector& p2) const {p2.setXYZ(x2,y2,0.);}
    void getPoints(HGeomVector& p1,HGeomVector& p2) const {
        getPoint1(p1); getPoint2(p2);}

    // Use this function at the reading data only!!!    
    void resetEventIter(void);   // for reading the same event again
    Bool_t resetTrackPar(Float_t xt,Float_t yt,Float_t xp,Float_t yp);
    Bool_t resetTrackFlag(Bool_t flag);
    Bool_t resetEventFlag(Bool_t flag);
    Bool_t isEnd(void) {return arrayEnd;}
    
  protected:
    void clear();
    Bool_t getTrackPar(void);
      
  ClassDef(HMdcStoreTracks,0)  // storage of track parameters
};

//----------------------------------------------

class HMdcStoreClusters : public HMdcStoreTracks {
  protected:
    HMdcStoreEvents wires;        // storage of cluster(track) wires
  
    UInt_t* wiresListPack[1200];  // list of packed wires for current cluster
    Int_t   numWires;
  public:
    HMdcStoreClusters(void) {}
    ~HMdcStoreClusters(void) {}
    virtual UInt_t getMemSize(void) const;
    
    // Storing functions:
    void setEndCluster(void);
    
    // Getting functions:
    virtual void resetIter(void);  // must be called ones per clusters loop
    Bool_t getNextCluster(void);
    Bool_t getNextCell(Int_t& s, Int_t& m, Int_t& l, Int_t& c, Float_t& tm) {
        return wires.getNextCell(s,m,l,c,tm);}
    Bool_t getNextCell(Int_t& s, Int_t& m, Int_t& l, Int_t& c, Float_t& tm,
        Bool_t& flag) {
        return wires.getNextCell(s,m,l,c,tm,flag);}
    
    // Storing and getting clusters:
    void addClustWires(const HMdcEvntListCells& event, 
        const HMdcClus* cl);                        // store wires list only
    void addClustWires(const HMdcEvntListCells& event,
        const HMdcClus* cl1, const HMdcClus* cl2);  // store wires list only
    Bool_t getNextCluster(HMdcEvntListCells& event,Bool_t checkFlag=kFALSE);
    Bool_t unsetFlag(Int_t si,Int_t mi,Int_t li,Int_t ci);
    Bool_t setFlag(Int_t si,Int_t mi,Int_t li,Int_t ci);
    
  protected:
      
  ClassDef(HMdcStoreClusters,0)  // storage of track param. and wires
};

#endif  /*!HMDCSTOREEVENTS_H*/
 hmdcstoreevents.h:1
 hmdcstoreevents.h:2
 hmdcstoreevents.h:3
 hmdcstoreevents.h:4
 hmdcstoreevents.h:5
 hmdcstoreevents.h:6
 hmdcstoreevents.h:7
 hmdcstoreevents.h:8
 hmdcstoreevents.h:9
 hmdcstoreevents.h:10
 hmdcstoreevents.h:11
 hmdcstoreevents.h:12
 hmdcstoreevents.h:13
 hmdcstoreevents.h:14
 hmdcstoreevents.h:15
 hmdcstoreevents.h:16
 hmdcstoreevents.h:17
 hmdcstoreevents.h:18
 hmdcstoreevents.h:19
 hmdcstoreevents.h:20
 hmdcstoreevents.h:21
 hmdcstoreevents.h:22
 hmdcstoreevents.h:23
 hmdcstoreevents.h:24
 hmdcstoreevents.h:25
 hmdcstoreevents.h:26
 hmdcstoreevents.h:27
 hmdcstoreevents.h:28
 hmdcstoreevents.h:29
 hmdcstoreevents.h:30
 hmdcstoreevents.h:31
 hmdcstoreevents.h:32
 hmdcstoreevents.h:33
 hmdcstoreevents.h:34
 hmdcstoreevents.h:35
 hmdcstoreevents.h:36
 hmdcstoreevents.h:37
 hmdcstoreevents.h:38
 hmdcstoreevents.h:39
 hmdcstoreevents.h:40
 hmdcstoreevents.h:41
 hmdcstoreevents.h:42
 hmdcstoreevents.h:43
 hmdcstoreevents.h:44
 hmdcstoreevents.h:45
 hmdcstoreevents.h:46
 hmdcstoreevents.h:47
 hmdcstoreevents.h:48
 hmdcstoreevents.h:49
 hmdcstoreevents.h:50
 hmdcstoreevents.h:51
 hmdcstoreevents.h:52
 hmdcstoreevents.h:53
 hmdcstoreevents.h:54
 hmdcstoreevents.h:55
 hmdcstoreevents.h:56
 hmdcstoreevents.h:57
 hmdcstoreevents.h:58
 hmdcstoreevents.h:59
 hmdcstoreevents.h:60
 hmdcstoreevents.h:61
 hmdcstoreevents.h:62
 hmdcstoreevents.h:63
 hmdcstoreevents.h:64
 hmdcstoreevents.h:65
 hmdcstoreevents.h:66
 hmdcstoreevents.h:67
 hmdcstoreevents.h:68
 hmdcstoreevents.h:69
 hmdcstoreevents.h:70
 hmdcstoreevents.h:71
 hmdcstoreevents.h:72
 hmdcstoreevents.h:73
 hmdcstoreevents.h:74
 hmdcstoreevents.h:75
 hmdcstoreevents.h:76
 hmdcstoreevents.h:77
 hmdcstoreevents.h:78
 hmdcstoreevents.h:79
 hmdcstoreevents.h:80
 hmdcstoreevents.h:81
 hmdcstoreevents.h:82
 hmdcstoreevents.h:83
 hmdcstoreevents.h:84
 hmdcstoreevents.h:85
 hmdcstoreevents.h:86
 hmdcstoreevents.h:87
 hmdcstoreevents.h:88
 hmdcstoreevents.h:89
 hmdcstoreevents.h:90
 hmdcstoreevents.h:91
 hmdcstoreevents.h:92
 hmdcstoreevents.h:93
 hmdcstoreevents.h:94
 hmdcstoreevents.h:95
 hmdcstoreevents.h:96
 hmdcstoreevents.h:97
 hmdcstoreevents.h:98
 hmdcstoreevents.h:99
 hmdcstoreevents.h:100
 hmdcstoreevents.h:101
 hmdcstoreevents.h:102
 hmdcstoreevents.h:103
 hmdcstoreevents.h:104
 hmdcstoreevents.h:105
 hmdcstoreevents.h:106
 hmdcstoreevents.h:107
 hmdcstoreevents.h:108
 hmdcstoreevents.h:109
 hmdcstoreevents.h:110
 hmdcstoreevents.h:111
 hmdcstoreevents.h:112
 hmdcstoreevents.h:113
 hmdcstoreevents.h:114
 hmdcstoreevents.h:115
 hmdcstoreevents.h:116
 hmdcstoreevents.h:117
 hmdcstoreevents.h:118
 hmdcstoreevents.h:119
 hmdcstoreevents.h:120
 hmdcstoreevents.h:121
 hmdcstoreevents.h:122
 hmdcstoreevents.h:123
 hmdcstoreevents.h:124
 hmdcstoreevents.h:125
 hmdcstoreevents.h:126
 hmdcstoreevents.h:127
 hmdcstoreevents.h:128
 hmdcstoreevents.h:129
 hmdcstoreevents.h:130
 hmdcstoreevents.h:131
 hmdcstoreevents.h:132
 hmdcstoreevents.h:133
 hmdcstoreevents.h:134
 hmdcstoreevents.h:135
 hmdcstoreevents.h:136
 hmdcstoreevents.h:137
 hmdcstoreevents.h:138
 hmdcstoreevents.h:139
 hmdcstoreevents.h:140
 hmdcstoreevents.h:141
 hmdcstoreevents.h:142
 hmdcstoreevents.h:143
 hmdcstoreevents.h:144
 hmdcstoreevents.h:145
 hmdcstoreevents.h:146
 hmdcstoreevents.h:147
 hmdcstoreevents.h:148
 hmdcstoreevents.h:149
 hmdcstoreevents.h:150
 hmdcstoreevents.h:151
 hmdcstoreevents.h:152
 hmdcstoreevents.h:153
 hmdcstoreevents.h:154
 hmdcstoreevents.h:155
 hmdcstoreevents.h:156
 hmdcstoreevents.h:157
 hmdcstoreevents.h:158
 hmdcstoreevents.h:159
 hmdcstoreevents.h:160
 hmdcstoreevents.h:161
 hmdcstoreevents.h:162
 hmdcstoreevents.h:163
 hmdcstoreevents.h:164
 hmdcstoreevents.h:165
 hmdcstoreevents.h:166
 hmdcstoreevents.h:167
 hmdcstoreevents.h:168
 hmdcstoreevents.h:169
 hmdcstoreevents.h:170
 hmdcstoreevents.h:171
 hmdcstoreevents.h:172
 hmdcstoreevents.h:173
 hmdcstoreevents.h:174
 hmdcstoreevents.h:175
 hmdcstoreevents.h:176
 hmdcstoreevents.h:177
 hmdcstoreevents.h:178
 hmdcstoreevents.h:179
 hmdcstoreevents.h:180
 hmdcstoreevents.h:181
 hmdcstoreevents.h:182
 hmdcstoreevents.h:183
 hmdcstoreevents.h:184
 hmdcstoreevents.h:185
 hmdcstoreevents.h:186
 hmdcstoreevents.h:187
 hmdcstoreevents.h:188
 hmdcstoreevents.h:189
 hmdcstoreevents.h:190
 hmdcstoreevents.h:191
 hmdcstoreevents.h:192
 hmdcstoreevents.h:193
 hmdcstoreevents.h:194
 hmdcstoreevents.h:195
 hmdcstoreevents.h:196
 hmdcstoreevents.h:197
 hmdcstoreevents.h:198
 hmdcstoreevents.h:199
 hmdcstoreevents.h:200
 hmdcstoreevents.h:201
 hmdcstoreevents.h:202
 hmdcstoreevents.h:203
 hmdcstoreevents.h:204
 hmdcstoreevents.h:205
 hmdcstoreevents.h:206
 hmdcstoreevents.h:207
 hmdcstoreevents.h:208
 hmdcstoreevents.h:209
 hmdcstoreevents.h:210
 hmdcstoreevents.h:211
 hmdcstoreevents.h:212
 hmdcstoreevents.h:213
 hmdcstoreevents.h:214
 hmdcstoreevents.h:215
 hmdcstoreevents.h:216
 hmdcstoreevents.h:217
 hmdcstoreevents.h:218
 hmdcstoreevents.h:219
 hmdcstoreevents.h:220
 hmdcstoreevents.h:221
 hmdcstoreevents.h:222
 hmdcstoreevents.h:223
 hmdcstoreevents.h:224
 hmdcstoreevents.h:225
 hmdcstoreevents.h:226
 hmdcstoreevents.h:227
 hmdcstoreevents.h:228
 hmdcstoreevents.h:229
 hmdcstoreevents.h:230
 hmdcstoreevents.h:231
 hmdcstoreevents.h:232
 hmdcstoreevents.h:233
 hmdcstoreevents.h:234
 hmdcstoreevents.h:235
 hmdcstoreevents.h:236
 hmdcstoreevents.h:237
 hmdcstoreevents.h:238
 hmdcstoreevents.h:239
 hmdcstoreevents.h:240
 hmdcstoreevents.h:241
 hmdcstoreevents.h:242
 hmdcstoreevents.h:243
 hmdcstoreevents.h:244
 hmdcstoreevents.h:245
 hmdcstoreevents.h:246
 hmdcstoreevents.h:247