00001 #ifndef TGET4EVENT_H
00002 #define TGET4EVENT_H
00003
00004 #include "TGo4EventElement.h"
00005 #include "TGo4CompositeEvent.h"
00006 #include <vector>
00007
00008
00009
00010
00011
00012
00013 #include "roc/Message.h"
00014
00015 namespace get4v10 {
00016
00017 enum SysMessageTypes {
00018 SYSMSG_GET4V1_32BIT_0 = 240,
00019 SYSMSG_GET4V1_32BIT_1 = 241,
00020 SYSMSG_GET4V1_32BIT_2 = 242,
00021 SYSMSG_GET4V1_32BIT_3 = 243,
00022 SYSMSG_GET4V1_32BIT_4 = 244,
00023 SYSMSG_GET4V1_32BIT_5 = 245,
00024 SYSMSG_GET4V1_32BIT_6 = 246,
00025 SYSMSG_GET4V1_32BIT_7 = 247,
00026 SYSMSG_GET4V1_32BIT_8 = 248,
00027 SYSMSG_GET4V1_32BIT_9 = 249,
00028 SYSMSG_GET4V1_32BIT_10 = 250,
00029 SYSMSG_GET4V1_32BIT_11 = 251,
00030 SYSMSG_GET4V1_32BIT_12 = 252,
00031 SYSMSG_GET4V1_32BIT_13 = 253,
00032 SYSMSG_GET4V1_32BIT_14 = 254,
00033 SYSMSG_GET4V1_32BIT_15 = 255,
00034 };
00035 }
00036
00037
00039
00040 #define MAX_ROC 15
00041
00042 #define MAX_AUX 4
00043
00044 #define MAX_SYNC 2
00045
00046
00047 #define MAX_GET4 32
00048
00049 #define MAX_GET4_PER_ROC 16
00050
00051 #define NB_CHAN_GET4 4
00052
00053 #define GET4_PRINT 6 // ROC messages
00054
00055
00056
00057 #define GET4_EPOCH_CYCLE_SIZE 0xFFFFFFFFuLL
00058
00059 #define MAIN_EPOCH_CYCLE_SIZE 0xFFFFFFFFuLL
00060
00061 #define GET4_SYNC_CYCLE_SIZE 25 // Epochs ( nb-1 unsynchronized, 1 synchronized)
00062 #define MAIN_CLK_SYNC_SIZE 40 // Epochs ( nb-1 unsynchronized, 1 synchronized)
00063
00064 #define NB_SYNC_JUMP_RESET 2
00065
00066 #define NB_BIN_GET4_FTS 128 // bins ( = 2^NB_BITS_FTS)
00067
00068 #define GET4_BIN_SIZE_IN_PS 50
00069 #define GET4_EPOCH_IN_BINS 524288
00070 #define GET4_EPOCH_IN_PS 26214400
00071 #define GET4_CYCLE_IN_EPOCHS 1048576
00072
00073
00074 #include <stdint.h>
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 class TGet4v1MessageExtended : public TObject
00085 {
00086 public:
00087
00088 TGet4v1MessageExtended(const roc::Message& msg, ULong64_t fulltime=0 ) :
00089 TObject(),
00090 fxMessage(msg),
00091 fuFulltime(fulltime),
00092 fdFullTime((Double_t)fulltime),
00093 ffTriggerDeltaT(0),
00094 fbIs32Bit(kFALSE),
00095 uRocEpoch( 0 ),
00096 uRocEpochCycle( 0 ),
00097 fbIsEmpty(kFALSE)
00098 {
00099 }
00100
00101 TGet4v1MessageExtended() :
00102 TObject(),
00103 fxMessage(),
00104 fuFulltime(0),
00105 fdFullTime(0),
00106 ffTriggerDeltaT(0),
00107 fbIs32Bit(kFALSE),
00108 uRocEpoch( 0 ),
00109 uRocEpochCycle( 0 ),
00110 fbIsEmpty(kFALSE)
00111 {
00112 }
00113
00114 virtual ~TGet4v1MessageExtended(){}
00115
00116
00117 TGet4v1MessageExtended(const TGet4v1MessageExtended& src) : TObject(),
00118 fxMessage(src.fxMessage), fuFulltime(src.fuFulltime), fdFullTime(src.fdFullTime),
00119 ffTriggerDeltaT(src.ffTriggerDeltaT), fbIs32Bit(src.fbIs32Bit),
00120 uRocEpoch(src.uRocEpoch), uRocEpochCycle(src.uRocEpochCycle),
00121 fbIsEmpty(src.fbIsEmpty){}
00122
00123
00124
00125
00126
00127
00128
00129 bool operator<(const TGet4v1MessageExtended &rhs) const
00130 { return (fdFullTime < rhs.fdFullTime); }
00131
00132 void Clear()
00133 {
00134 fxMessage = roc::Message();
00135 fuFulltime = 0;
00136 fdFullTime = 0;
00137 ffTriggerDeltaT = 0;
00138 fbIs32Bit = kFALSE;
00139 uRocEpoch = 0;
00140 uRocEpochCycle = 0;
00141 SetEmptyFlag();
00142 }
00143
00144 void SetRocMessage(const roc::Message & source)
00145 {
00146 fxMessage=source;
00147 }
00148
00149 const roc::Message& GetRocMessage() const
00150 {
00151 return fxMessage;
00152 }
00153
00154 UChar_t GetMessageType() const
00155 {
00156 return fxMessage.getMessageType();
00157 }
00158 UChar_t GetSysMesType() const
00159 {
00160 return fxMessage.getSysMesType();
00161 }
00162
00163 void SetFullTime(ULong64_t ts)
00164 {
00165 fuFulltime=ts;
00166 fdFullTime = (Double_t) ts;
00167 }
00168 void SetFullTimeD(Double_t ts)
00169 {
00170 fdFullTime = ts;
00171 fuFulltime = (ULong64_t)ts;
00172 }
00173 ULong64_t GetFullTime() const
00174 {
00175 return fuFulltime;
00176 }
00177 Double_t GetFullTimeD() const
00178 {
00179 return fdFullTime;
00180 }
00181
00182 uint16_t GetRocNumber() const
00183 {
00184 return fxMessage.getRocNumber();
00185 }
00186
00187 uint8_t GetGet4Number() const
00188 {
00189 return fxMessage.getGet4Number();
00190 }
00191
00192 uint8_t GetGet4ChNum() const
00193 {
00194 return fxMessage.getGet4ChNum();
00195 }
00196
00197 uint32_t GetGet4Ts() const
00198 {
00199 return fxMessage.getGet4Ts();
00200 }
00201
00202 Bool_t IsRisingGet4Edge() const
00203 {
00204 return fxMessage.getGet4Edge();
00205 }
00206
00207 void SetTriggerDeltaT(float dt)
00208 {
00209 ffTriggerDeltaT=dt;
00210 }
00211
00212 float GetTriggerDeltaT() const
00213 {
00214 return ffTriggerDeltaT;
00215 }
00216
00217 Bool_t SetGet4MessageFull( const roc::Message & DataMessIn, UInt_t rocEpochIn,
00218 UInt_t rocCycleIn)
00219 {
00220 fxMessage = DataMessIn;
00221 uRocEpoch = rocEpochIn;
00222 uRocEpochCycle = rocCycleIn;
00223
00224
00225
00226
00227
00228
00229
00230
00231 return kTRUE;
00232 }
00233
00234 Bool_t SetRocEpoch( UInt_t rocEpochIn)
00235 {
00236 uRocEpoch = rocEpochIn;
00237
00238
00239
00240
00241
00242
00243
00244
00245 return kTRUE;
00246 }
00247 Bool_t SetRocCycle( UInt_t rocCycleIn)
00248 {
00249 uRocEpochCycle = rocCycleIn;
00250 return kTRUE;
00251 }
00252
00253 UInt_t GetRocEpoch() const
00254 {
00255 return uRocEpoch;
00256 }
00257 UInt_t GetRocCycle() const
00258 {
00259 return uRocEpochCycle;
00260 }
00261
00262 Bool_t RocOrder( const TGet4v1MessageExtended &messageToCompare )const;
00263 Double_t RocSpacing( const TGet4v1MessageExtended &messageToCompare) const;
00264
00265 void Print( unsigned kind = roc::msg_print_Human ) const;
00266 void Print32Bit( unsigned kind = roc::msg_print_Human ) const;
00267
00268
00269 inline void SetGet4Number( UChar_t ucGet4Index) { fxMessage.setGet4Number(ucGet4Index); }
00270 inline void SetEpoch2ChipNumber(UChar_t ucGet4Index) { fxMessage.setEpoch2ChipNumber(ucGet4Index); }
00271
00272
00273 inline UInt_t getFieldBE(roc::Message rawMessage, UInt_t shift, UInt_t len) const
00274 { return (dataBE(rawMessage) >> shift) & ((((UInt_t)1) << len) - 1); }
00275 inline UChar_t getBitBE(roc::Message rawMessage, UInt_t shift) const
00276 { return (dataBE(rawMessage) >> shift) & 1; }
00277 inline ULong64_t dataBE( roc::Message rawMessage) const
00278 { return (((ULong64_t)rawMessage.getField(0, 8) &0x00000000000000FF)<<56)+
00279 ( ((ULong64_t)rawMessage.getField(0, 16) &0x000000000000FF00)<<40)+
00280 ( ((ULong64_t)rawMessage.getField(0, 24) &0x0000000000FF0000)<<24)+
00281 ( ( ((ULong64_t)rawMessage.getField( 8, 24) <<8 ) &0x00000000FF000000)<< 8)+
00282 ( ( ((ULong64_t)rawMessage.getField(16, 24)) << 8)&0x00000000FF000000)+
00283 ( ((ULong64_t)rawMessage.getField(24, 24) )&0x0000000000FF0000)+
00284 ( ((ULong64_t)rawMessage.getField(40, 16) )&0x000000000000FF00)+
00285 ( ((ULong64_t)rawMessage.getField(56, 8) )&0x00000000000000FF);
00286 }
00287
00288 inline UChar_t getGet4V10R32ChipId() const { return ( (fxMessage.getSysMesType() )&0xF ); }
00289 inline UChar_t getGet4V10R32MessageType() const { return getFieldBE(fxMessage, 46, 2); }
00290
00291 inline UInt_t getGet4V10R32EpochNumber() const { return getFieldBE(fxMessage, 17,24); }
00292 inline Bool_t getGet4V10R32SyncFlag() const { return getBitBE(fxMessage, 16); }
00293
00294 inline UInt_t getGet4V10R32SlData() const { return getFieldBE(fxMessage, 16,24); }
00295 inline UChar_t getGet4V10R32SlType() const { return getFieldBE(fxMessage, 40, 2); }
00296 inline Bool_t getGet4V10R32SlEdge() const { return getBitBE(fxMessage, 42); }
00297 inline UChar_t getGet4V10R32SlChan() const { return getFieldBE(fxMessage, 43, 2); }
00298
00299 inline UChar_t getGet4V10R32ErrorData() const { return getFieldBE(fxMessage, 16, 7); }
00300 inline UChar_t getGet4V10R32ErrorChan() const { return getFieldBE(fxMessage, 42, 2); }
00301 inline Bool_t getGet4V10R32ErrorEdge() const { return getBitBE(fxMessage, 44); }
00302
00303 inline UChar_t getGet4V10R32HitTot() const { return getFieldBE(fxMessage, 16, 8); }
00304 inline UChar_t getGet4V10R32HitFt() const { return getFieldBE(fxMessage, 24, 7); }
00305 inline UInt_t getGet4V10R32HitTs() const { return getFieldBE(fxMessage, 31,12); }
00306 inline UInt_t getGet4V10R32HitTimeBin()const { return getFieldBE(fxMessage, 24,19); }
00307 inline UChar_t getGet4V10R32HitChan() const { return getFieldBE(fxMessage, 43, 2); }
00308 inline Bool_t getGet4V10R32HitDllFlag() const { return getBitBE(fxMessage, 45); }
00309
00310 void Set32BitFlag(){ fbIs32Bit = kTRUE; };
00311 Bool_t Is32Bit(){ return fbIs32Bit; };
00312 void SetEmptyFlag(){ fbIsEmpty = kTRUE; };
00313 Bool_t IsEmpty(){ return fbIsEmpty; };
00314 protected:
00315
00316
00317 roc::Message fxMessage;
00318
00319
00320 ULong64_t fuFulltime;
00321 Double_t fdFullTime;
00322
00323
00324
00325 float ffTriggerDeltaT;
00326
00327 Bool_t fbIs32Bit;
00328 UInt_t uRocEpoch;
00329 UInt_t uRocEpochCycle;
00330
00331 Bool_t fbIsEmpty;
00332
00333 ClassDef(TGet4v1MessageExtended,1)
00334 };
00335
00336 class Get4v1Hit : public TObject {
00337 public:
00338 Get4v1Hit() : TObject() { Clear(); }
00339 void Clear(Option_t *t="");
00340 void SetFullHit24Bits( TGet4v1MessageExtended& mesTime, TGet4v1MessageExtended& mesTot);
00341 void SetFullHit32Bits( TGet4v1MessageExtended& mesHit, Double_t d32bTotRange = 25500.0 );
00342 void SetTime24Bits( TGet4v1MessageExtended& mesTime );
00343 void SetTot24Bits( TGet4v1MessageExtended& mesTot );
00344
00345 TGet4v1MessageExtended GetTimeMessage() { return fTimeMessage; };
00346 TGet4v1MessageExtended GetTotMessage() { return fTotMessage; };
00347
00348 UChar_t GetChan(){ return (kTRUE == fbIs32Bit? fTimeMessage.getGet4V10R32HitChan() : fTimeMessage.GetGet4ChNum()); };
00349 ULong_t GetHitFullTime(){ return fTimeMessage.GetFullTime(); };
00350 Double_t GetHitFullTimeD(){ return fTimeMessage.GetFullTimeD();};
00351 UInt_t GetHitEpoch(){ return fTimeMessage.GetRocEpoch(); };
00352 UInt_t GetHitCycle(){ return fTimeMessage.GetRocCycle(); };
00353
00354 Double_t GetHitTime();
00355 Double_t GetTot(){ return fdTot; };
00356 Int_t GetHitLeadingFTS();
00357 Int_t GetHitTrailingFTS();
00358 Double_t GetTimeDiff( Get4v1Hit& hitToCompare );
00359
00360 Bool_t IsTimeSet(){ return fbTimeSet;};
00361 Bool_t IsTotSet(){ return fbTotSet;};
00362 Bool_t IsComplete(){ return fbTimeSet && fbTotSet;};
00363 Bool_t Is32Bit(){ return fbIs32Bit; };
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 protected:
00374 Bool_t fbIs32Bit;
00375 void CalculateTot( Double_t d32bTotRange = 25500.0 );
00376
00377 TGet4v1MessageExtended fTimeMessage;
00378 Bool_t fbTimeSet;
00379 TGet4v1MessageExtended fTotMessage;
00380 Bool_t fbTotSet;
00381 Double_t fdTot;
00382
00383 ClassDef(Get4v1Hit,1)
00384 };
00385
00386 class Get4v1Tdc : public TObject {
00387 public:
00388 Get4v1Tdc() : TObject() { Clear(); }
00389 ~Get4v1Tdc();
00390 void Clear(Option_t *t="");
00391 UInt_t Size();
00392
00393 std::vector<Get4v1Hit> fHits[NB_CHAN_GET4];
00394
00395
00396
00397
00398
00399
00400 ClassDef(Get4v1Tdc,1)
00401 };
00402
00403 class Get4v1Event : public TObject {
00404 public:
00405 Get4v1Event() : TObject() { Clear(); }
00406 ~Get4v1Event();
00407 void Clear(Option_t *t="");
00408 UInt_t Size();
00409 Bool_t IsEmpty();
00410 Bool_t HasTrigger();
00411 Bool_t IsMbsSynced(){ return fbMbsSyncedEvent;};
00412
00413 Get4v1Tdc fGet4Boards[MAX_GET4];
00414
00415 std::vector<TGet4v1MessageExtended> fPureRocMessages[MAX_ROC];
00416
00417
00418
00419 Double_t fdTriggerFullTime[MAX_ROC];
00420
00421
00422 UInt_t fuMbsEventNumber;
00423
00424 UInt_t fuEventNbInsideMbsEvt;
00425
00426 UInt_t fuGlobalEventNumber;
00427
00428
00429 Bool_t fbMbsSyncedEvent;
00430
00431 UInt_t fuSyncEventNumber;
00432
00433
00434 Bool_t fbDataTriggered;
00435
00436 UInt_t fuTriggerIndex;
00437
00438 ClassDef(Get4v1Event,1)
00439 };
00440
00441 class TGet4v1Event : public TGo4EventElement {
00442 public:
00443 TGet4v1Event();
00444 TGet4v1Event(const char* name, Short_t id=0);
00445 virtual ~TGet4v1Event();
00446
00448 virtual void Clear(Option_t *t="");
00449
00451 double GetEventTime() const { return fLastGlobalTriggerTm*1e-9; };
00452
00453
00454
00455 ULong64_t CalcGlobalTime(Double_t deltaTrigger);
00456
00457
00458
00459
00460
00461 ULong64_t fLastGlobalTriggerTm;
00462
00463 ULong64_t fMbsEventNumber;
00464
00465 std::vector<Get4v1Event> fEvents;
00466
00467
00468
00469 UInt_t GetHitsNumber( UInt_t uEvent, UInt_t uGet4ChipBoard, UInt_t uGet4Channel )
00470 { return ( (fEvents[uEvent]).fGet4Boards[ uGet4ChipBoard ] ).fHits[ uGet4Channel ].size(); };
00471
00472
00473
00474
00475 Double_t GetHitTime( UInt_t uEvent, UInt_t uGet4ChipBoard, UInt_t uGet4Channel, UInt_t uHit = 0)
00476 { return ( ( (fEvents[uEvent]).fGet4Boards[ uGet4ChipBoard ] ).fHits[ uGet4Channel ] )[uHit].GetHitTime(); };
00477 Double_t GetHitTot( UInt_t uEvent, UInt_t uGet4ChipBoard, UInt_t uGet4Channel, UInt_t uHit = 0)
00478 { return ( ( (fEvents[uEvent]).fGet4Boards[ uGet4ChipBoard ] ).fHits[ uGet4Channel ] )[uHit].GetTot(); };
00479
00480 ClassDef(TGet4v1Event,1)
00481 };
00482 #endif //TGET4V1EVENT_H
00483
00484
00485