• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

beamtime/tof-tdctest/go4/GET4V10/TGet4v1Event.h (r4864/r4862)

Go to the documentation of this file.
00001 #ifndef TGET4EVENT_H
00002 #define TGET4EVENT_H
00003 
00004 #include "TGo4EventElement.h"
00005 #include "TGo4CompositeEvent.h"
00006 #include <vector>
00007 
00008 /*
00009  * Put all definitions here and use them in processor,
00010  * since they are necessary for data structure of event
00011  */
00012 
00013 #include "roc/Message.h"
00014 
00015 namespace get4v10 {
00016 
00017    enum SysMessageTypes {
00018       SYSMSG_GET4V1_32BIT_0  = 240,     // Get4 V1.0, 32bit mode, Raw messages chip 0 link 1
00019       SYSMSG_GET4V1_32BIT_1  = 241,     // Get4 V1.0, 32bit mode, Raw messages chip 1 link 1
00020       SYSMSG_GET4V1_32BIT_2  = 242,     // Get4 V1.0, 32bit mode, Raw messages chip 2 link 1
00021       SYSMSG_GET4V1_32BIT_3  = 243,     // Get4 V1.0, 32bit mode, Raw messages chip 3 link 1
00022       SYSMSG_GET4V1_32BIT_4  = 244,     // Get4 V1.0, 32bit mode, Raw messages chip 4 link 1
00023       SYSMSG_GET4V1_32BIT_5  = 245,     // Get4 V1.0, 32bit mode, Raw messages chip 5 link 1
00024       SYSMSG_GET4V1_32BIT_6  = 246,     // Get4 V1.0, 32bit mode, Raw messages chip 6 link 1
00025       SYSMSG_GET4V1_32BIT_7  = 247,     // Get4 V1.0, 32bit mode, Raw messages chip 7 link 1
00026       SYSMSG_GET4V1_32BIT_8  = 248,     // Get4 V1.0, 32bit mode, Raw messages chip 0 link 2
00027       SYSMSG_GET4V1_32BIT_9  = 249,     // Get4 V1.0, 32bit mode, Raw messages chip 1 link 2
00028       SYSMSG_GET4V1_32BIT_10 = 250,     // Get4 V1.0, 32bit mode, Raw messages chip 2 link 2
00029       SYSMSG_GET4V1_32BIT_11 = 251,     // Get4 V1.0, 32bit mode, Raw messages chip 3 link 2
00030       SYSMSG_GET4V1_32BIT_12 = 252,     // Get4 V1.0, 32bit mode, Raw messages chip 4 link 2
00031       SYSMSG_GET4V1_32BIT_13 = 253,     // Get4 V1.0, 32bit mode, Raw messages chip 5 link 2
00032       SYSMSG_GET4V1_32BIT_14 = 254,     // Get4 V1.0, 32bit mode, Raw messages chip 6 link 2
00033       SYSMSG_GET4V1_32BIT_15 = 255,     // Get4 V1.0, 32bit mode, Raw messages chip 7 link 2
00034    };
00035 }
00036 /*************************************/
00037 
00039 // number of maximum connected ROCs
00040 #define MAX_ROC           15
00041 
00042 #define MAX_AUX 4
00043 
00044 #define MAX_SYNC 2
00045 
00046 // maximum number of GET4 chips in a full setup
00047 #define MAX_GET4          32
00048 // maximum number of GET4 chips, connected to a single ROC
00049 #define MAX_GET4_PER_ROC  16
00050 
00051 #define NB_CHAN_GET4           4
00052 
00053 #define GET4_PRINT             6   // ROC messages
00054 
00055 //#define GET4_EPOCH_CYCLE_SIZE 0x007FFFFF
00056 //#define GET4_EPOCH_CYCLE_SIZE 0x00FFFFFF
00057 #define GET4_EPOCH_CYCLE_SIZE 0xFFFFFFFFuLL
00058 //#define MAIN_EPOCH_CYCLE_SIZE 0x000FFFFF
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  * Extended message container. Keeps original ROC message, but adds full timestamp and
00078  * optionally corrected adc valules.
00079  * Note that extended messages inside the vector will be sorted after full timestamp
00080  * by the TRocProc::FinalizeEvent
00081  *
00082  * TODO: Recalculation of full time when setting RocEpoch and/or RocCycle !!!
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       // copy constructor, used by vector to copy content
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       /* this is used for timesorting the messages in the filled vectors */
00124       /*
00125       bool operator<(const TGet4v1MessageExtended &rhs) const
00126          { return (fuFulltime < rhs.fuFulltime); }
00127          */
00128       /* Move to double version to insure GET4 messages ordering */
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          if( roc::MSG_GET4 == fxMessage.getMessageType() )
00225             fuFulltime = fxMessage.getMsgFullTime( uRocEpoch );
00226          else if(roc::MSG_SYS == fxMessage.getMessageType() &&
00227                  roc::SYSMSG_GET4_EVENT == fxMessage.getSysMesType() )
00228             fuFulltime = fxMessage.FullTimeStamp2(uRocEpoch, (fxMessage.getField(23,12)<<7) )
00229                          / 20 + 512;
00230 */
00231          return kTRUE;
00232       }
00233 
00234       Bool_t SetRocEpoch( UInt_t rocEpochIn)
00235       {
00236          uRocEpoch        = rocEpochIn;
00237          /*
00238          if( roc::MSG_GET4 == fxMessage.getMessageType() )
00239             fuFulltime = fxMessage.getMsgFullTime( uRocEpoch );
00240          else if(roc::MSG_SYS == fxMessage.getMessageType() &&
00241                  roc::SYSMSG_GET4_EVENT == fxMessage.getSysMesType() )
00242             fuFulltime = fxMessage.FullTimeStamp2(uRocEpoch, (fxMessage.getField(23,12)<<7) )
00243                          / 20 + 512;
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       // All Get4 v1.0 24 bit messages
00269       inline void SetGet4Number( UChar_t ucGet4Index) { fxMessage.setGet4Number(ucGet4Index); }
00270       inline void SetEpoch2ChipNumber(UChar_t ucGet4Index) { fxMessage.setEpoch2ChipNumber(ucGet4Index); }
00271 
00272       // Get4 v1,0 32bits message function (later  general?)
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          // type 0 => Epoch message
00291       inline UInt_t  getGet4V10R32EpochNumber() const { return getFieldBE(fxMessage, 17,24); }
00292       inline Bool_t  getGet4V10R32SyncFlag()    const { return getBitBE(fxMessage, 16); }
00293          // type 1 => Slow control
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          // type 2 => Error message
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          // type 3 => Hit Data
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       /* original roc message*/
00317       roc::Message fxMessage;
00318 
00319       /* full time stamp without correction*/
00320       ULong64_t fuFulltime;
00321       Double_t  fdFullTime;
00322 
00323       /* corrected time difference to trigger time of master ROC
00324        * float range should be sufficient here*/
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       // copy constructor, used by vector to copy content for sorting
00367       Get4v1Hit(const Get4v1Hit& src) :
00368          fTimeMessage(src.fTimeMessage), fbTimeSet(src.fbTimeSet),
00369          fTotMessage(src.fTotMessage), fbTotSet(src.fbTotSet),
00370          fdTot(src.fdTot) {};
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       // copy constructor
00396       Get4v1Tdc(const Get4v1Tdc& src);
00397       // Assignment operator
00398       Get4v1Tdc & operator=(const Get4v1Tdc& src);
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       /* last time of trigger signal (defined by parameter)
00418        * can be sync or aux message, depending on TGet4Parameter::triggerSignal setup*/
00419       Double_t fdTriggerFullTime[MAX_ROC];
00420 
00421       // Event number of the corresponding MBS event
00422       UInt_t   fuMbsEventNumber;
00423       // Index of the real event inside MBS event
00424       UInt_t   fuEventNbInsideMbsEvt;
00425       // Total event number
00426       UInt_t   fuGlobalEventNumber;
00427 
00428       // Flag indicating that this real event is the one synchronized to MBS
00429       Bool_t   fbMbsSyncedEvent;
00430       // Event Nmber from the sync message
00431       UInt_t   fuSyncEventNumber;
00432 
00433       // Flag indicating that this real event was made after finding coincidence in data
00434       Bool_t   fbDataTriggered;
00435       // Index of the Data trigger making this event
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       /* Evaluate global corrected time stamp from trigger difference times
00454        * as stored for each extended message*/
00455       ULong64_t CalcGlobalTime(Double_t deltaTrigger);
00456 
00457       /* last time of trigger signal from configured "master" ROC
00458        * can be sync or aux message, depending on TGet4Parameter::triggerSignal setup
00459        * This is also time reference for global timestamp
00460        * This may be kept over several events, so we dont need a Clear method!*/
00461       ULong64_t fLastGlobalTriggerTm;
00462 
00463       ULong64_t fMbsEventNumber;
00464 
00465       std::vector<Get4v1Event> fEvents;
00466 
00467       /* Method returning the number of hits for a specific event/TDC/channel combination
00468        * Effectively hides the internal classes structure for Detector classes */
00469       UInt_t GetHitsNumber( UInt_t uEvent, UInt_t uGet4ChipBoard, UInt_t uGet4Channel )
00470          { return ( (fEvents[uEvent]).fGet4Boards[ uGet4ChipBoard ] ).fHits[ uGet4Channel ].size(); };
00471 
00472       /* Method returning the Time information for a specific event/TDC/channel/hit
00473        * combination
00474        * Effectively hides the internal classes structure for Detector classes */
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 

Generated on Tue Dec 10 2013 04:52:19 for ROCsoft by  doxygen 1.7.1