00001 #include "RawBeamPosData.h" 00002 00003 #include <cstring> 00004 #include <iostream> 00005 using namespace std; 00006 00007 ClassImp(RawBeamPosData) 00008 00009 RawBeamPosData::RawBeamPosData() 00010 { 00011 fData.SetData(0); 00012 } 00013 00014 RawBeamPosData::RawBeamPosData(const RawBeamData& data) 00015 { 00016 this->SetData(data); 00017 } 00018 00019 RawBeamPosData::~RawBeamPosData() 00020 { 00021 fData.SetData(0); 00022 } 00023 00024 RawBeamData& RawBeamPosData::GetData() 00025 { 00026 return fData; 00027 } 00028 bool RawBeamPosData::SetData(const RawBeamData& data) 00029 { 00030 fData = data; 00031 00032 if (!fData.GetData()) return false; 00033 00034 // Sanity checks 00035 const size_t bpm_data_size = 216; 00036 const size_t siz = fData.GetDataLength(); 00037 if (siz != bpm_data_size) { 00038 cerr << "Not right size: 216 != " << siz << endl; 00039 fData.SetData(0); 00040 return false; 00041 } 00042 00043 return true; 00044 } 00045 00046 bool RawBeamPosData::IsValid() 00047 { 00048 return fData.GetData() != 0; 00049 } 00050 00051 00052 // This stuff is from RBPM.java from Jim Patrick @ FNAL 00053 00054 /* 00055 Example of reading and displaying Recycler BPM display buffer. 00056 The data comes from the front-end as an array of 32 bit words. 00057 The control system converts ("scales") 00058 this into an array of 216 doubles by the transformation: 00059 readings[i] = (double) ((float)raw[i]) 00060 (This transformation is specified in the definition 00061 of the device in the device database). 00062 In order to interpret the data properly, it 00063 is necessary to invert this transformation. 00064 Furthermore, the data is not simply an array of 00065 int, but a structure that contains some floats 00066 as well. 00067 */ 00068 00069 static const int N_BPM_PER_HOUSE = 48; 00070 00071 // Offsets defining elements of the structure 00072 00073 static const int GLOBAL_STATUS = 0; 00074 // Timestamp block (2 words) 00075 static const int GPSTIMESTAMP_OFFSET = 1; 00076 static const int ENABLE = 3; 00077 static const int MEASURE_TYPE = 4; 00078 static const int MEASURE_MODE = 5; 00079 static const int BEAM_TYPE = 6; 00080 static const int BEAM_MEAS = 7; 00081 static const int ARM_EVENT = 8; 00082 static const int TRIG_EVENT = 9; 00083 static const int PRETRIG_ENABLE = 10; 00084 static const int TRIG_DELAY = 11; 00085 static const int BUCKET_DELAY = 12; 00086 static const int INTENSITY_THRESHOLD = 13; 00087 static const int TIMEOUT = 14; 00088 static const int CALIBRATION_SPEC = 15; 00089 static const int MDAT_DELAY = 16; 00090 00091 static const int EVENT_INDEX = 17; 00092 static const int DATA_TYPE = 18; 00093 static const int BEGIN_TURN = 19; 00094 static const int NUM_TURNS = 20; 00095 static const int CHANNEL = 21; 00096 static const int N_POSITION = 22; 00097 static const int POSITION = 23; 00098 static const int N_INTENSITY = POSITION + N_BPM_PER_HOUSE; 00099 static const int INTENSITY = N_INTENSITY + 1; 00100 static const int N_POSITION_RMS = INTENSITY + N_BPM_PER_HOUSE; 00101 static const int POSITION_RMS = N_POSITION_RMS + 1; 00102 static const int N_INTENSITY_RMS = POSITION_RMS + N_BPM_PER_HOUSE; 00103 static const int INTENSITY_RMS = N_INTENSITY_RMS + 1; 00104 static const int N_STATUS = INTENSITY_RMS + N_BPM_PER_HOUSE; 00105 static const int STATUSES = N_STATUS + 1; 00106 00107 // A lot of other stuff to ignore for now 00108 00109 int RawBeamPosData::VmeSeconds() 00110 { 00111 const double* data = fData.GetData(); 00112 float f = (float)data[GPSTIMESTAMP_OFFSET]; 00113 int i; 00114 memcpy(&i,&f,sizeof(int)); 00115 return i; 00116 } 00117 00118 int RawBeamPosData::VmeNanoseconds() 00119 { 00120 const double* data = fData.GetData(); 00121 float f = (float)data[GPSTIMESTAMP_OFFSET+1]; 00122 int i; 00123 memcpy(&i,&f,sizeof(int)); 00124 return i; 00125 } 00126 00127 /* 00128 Enable 00129 MeasureType 00130 MeasureMode 00131 BeamType 00132 BeamMeas 00133 ArmEvent 00134 TrigEvent 00135 PretrigEnable 00136 TriggerDelay 00137 BucketDelay 00138 IntensityThreshold 00139 Timeout 00140 CalibrationSpec 00141 MDATDelay 00142 EventIndex 00143 DataType 00144 BeginTurn 00145 NumberTurns 00146 Channel 00147 Positions 00148 Intensities 00149 PositionsRMS 00150 IntensitiesRMS 00151 Statuses 00152 */
1.3.9.1