MFMParisFrame.cc 4.37 KB
Newer Older
LEGEARD Luc's avatar
LEGEARD Luc committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
/*
  MFMParisFrame.cc
  Copyright Acquisition group, GANIL Caen, France
*/

#include <iostream>
#include <cmath>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <stdlib.h>
using namespace std;

#include "MFMParisFrame.h"

//_______________________________________________________________________________
MFMParisFrame::MFMParisFrame(int unitBlock_size, int dataSource,
			     int frameType, int revision, int frameSize, int headerSize) {
  /// Constructor for a PARIS frame . the header is filled with unitblock_size, data source , frame type , revision , frame, size and header size value
  SetPointers();
}

//_______________________________________________________________________________
MFMParisFrame::MFMParisFrame() {
  /// Constructor for a empty PARIS frame

}
//_______________________________________________________________________________
MFMParisFrame::~MFMParisFrame() {
  /// destructor of PARIS frame
}

//_______________________________________________________________________________
void MFMParisFrame::SetQShort(uint16_t energy) {
  /// Set Energy
  (((MFM_paris_frame*) pHeader)->Data.QShort) = energy;
}

//_______________________________________________________________________________
uint16_t MFMParisFrame::GetQShort()const {
  /// GetEnergy
  uint16_t energy;
  energy=(((MFM_paris_frame*) pHeader)->Data.QShort);
  if (fLocalIsBigEndian != fFrameIsBigEndian)
    SwapInt16(&energy);
  return energy;
}

//_______________________________________________________________________________
void MFMParisFrame::SetQLong(uint16_t energy) {
  /// Set Energy
  (((MFM_paris_frame*) pHeader)->Data.QLong) = energy;
}

//_______________________________________________________________________________
uint16_t MFMParisFrame::GetQLong() const{
  /// GetEnergy
  uint16_t energy;
  energy=(((MFM_paris_frame*) pHeader)->Data.QLong);
  if (fLocalIsBigEndian != fFrameIsBigEndian)
    SwapInt16(&energy);
  return energy;
}

//_______________________________________________________________________________

void MFMParisFrame::SetCfd(float cfd) {
  /// Set Top in frame
  (((MFM_paris_frame*) pHeader)->Data.Cfd) = cfd;
}
//_______________________________________________________________________________

float MFMParisFrame::GetCfd()const {
  /// computer and return  Top value from frame
  float cfd;
  cfd = ((((MFM_paris_frame*) pHeader)->Data.Cfd) + random()/RAND_MAX -0.5 )/ 1000.;

  return cfd;
}


//_______________________________________________________________________________
void MFMParisFrame::FillDataWithRamdomValue(uint64_t timestamp,
					 uint32_t eventnumber) {

  /// Fill all data of frame with random values to do test
  /// And report time stamp and event number
  float maxuint16 = pow(2,16);
  float maxuint32 = pow(2,32);
  float value = random();

  uint16_t uivalue16 = (uint16_t) (maxuint16 * (float)(value / RAND_MAX));
  uint32_t uivalue32 = (uint32_t) (maxuint32 * (float)(value / RAND_MAX));


  SetQShort(uivalue16);
  SetQLong (uivalue16);
  SetCfd   (uivalue32 +0.5);

  SetEventNumber(eventnumber);
  SetTimeStamp(timestamp);
  MFMNumExoFrame::FillDataWithRamdomValue(timestamp,eventnumber);
  SetFrameType (MFM_PARIS_FRAME_TYPE);
}

//_______________________________________________________________________________

string MFMParisFrame::GetHeaderDisplay(char* infotext)const{
  std::stringstream ss;
  std::string display("");
  
  ss << MFMNumExoFrame::GetHeaderDisplay(infotext);
  ss << std::endl;
  ss << " qShort = " << GetQShort() ;
  ss << " qLong = " << GetQLong() << " CFD = " << GetCfd() << " [ns]";
  ss << std::endl;
  ss << " Flags = " << std::hex << ((MFM_paris_frame*) pHeader)->Data.Flags << std::dec ; 
  ss << "   PLL unlock " << ((GetPLL()) ? "true" : "false");
  ss << "   PUR " << ((GetPUR()) ? "true" : "false");
  ss << "   OVR " << ((GetOVR()) ? "true" : "false");
  
  display = ss.str();
  return display; 
}

//_______________________________________________________________________________
bool MFMParisFrame::GetPLL()const {
  return ((((MFM_paris_frame*) pHeader)->Data.Flags)&0x20)>>5;
}
//_______________________________________________________________________________
bool MFMParisFrame::GetPUR()const{
  return ((((MFM_paris_frame*) pHeader)->Data.Flags)&0x10)>>4;
}
//_______________________________________________________________________________
bool MFMParisFrame::GetOVR()const{
  return ((((MFM_paris_frame*) pHeader)->Data.Flags)&0x8)>>3;
}