MFMReaGenericFrame.cc 9.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 MFMReaGenericFrame.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 "MFMReaGenericFrame.h"

//_______________________________________________________________________________

19 20 21 22 23 24 25 26
MFMReaGenericFrame::MFMReaGenericFrame(){

	fStatus1 = NULL;
	fStatus2 = NULL;
	fTypeTNS = NULL;
	fEnergy  = NULL;
	fTime    = NULL;
	fNumberOfBoards =0;
27
	fInitTabValuesDone = false;
28 29 30 31
 }
//_______________________________________________________________________________ 
MFMReaGenericFrame::~MFMReaGenericFrame(){
   
32 33
   int card=0;
   if (fInitTabValuesDone==false)return;
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
   for (card=0;card<fNumberOfBoards;card++){
	if (fStatus1[card]!=NULL)  delete[] fStatus1[card]; 
	if (fStatus2[card]!=NULL)  delete[] fStatus2[card]; 
	if (fTypeTNS[card]!=NULL)  delete[] fTypeTNS[card]; 
	if (fEnergy[card] !=NULL)  delete[] fEnergy[card]; 
	if (fTime[card]   !=NULL)  delete[] fTime[card]; 
   	}
   if (fStatus1!=NULL)  delete[] fStatus1; 
   if (fStatus2!=NULL)  delete[] fStatus2; 
   if (fTypeTNS!=NULL)  delete[] fTypeTNS; 
   if (fEnergy !=NULL)  delete[] fEnergy; 
   if (fTime   !=NULL)  delete[] fTime; 
 }
//_______________________________________________________________________________

49 50 51 52 53 54 55 56 57 58
void MFMReaGenericFrame::SetStatus(int i, uint16_t status) {
	if (i < 0 and i > REA_GENERIC_NB_STATUS)
		cout << "MFMReaGenericFrame::ReaGenericSetStatus Error of status index\n";
	if (i == 0)
		((MFM_ReaGeneric_frame*) pHeader)->Data.Status1 = status;
	if (i == 1)
		((MFM_ReaGeneric_frame*) pHeader)->Data.Status2 = status;
}
//_______________________________________________________________________________

59
uint16_t MFMReaGenericFrame::GetStatus(int i)const {
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
	/// Set Status (0,1 or 2)
	uint16_t status;
	if (i < 0 and i > REA_GENERIC_NB_STATUS) {
		cout << "MFMReaGenericFrame::ExGetStatus Error of status index\n";
		return 0;
	} else {
		if (i == 0)
			status = (((MFM_ReaGeneric_frame*) pHeader)->Data.Status1);
		if (i == 1)
			status = (((MFM_ReaGeneric_frame*) pHeader)->Data.Status2);
	}
	if (fLocalIsBigEndian != fFrameIsBigEndian)
		SwapInt16(&status);
	return status;
}
//_______________________________________________________________________________

void MFMReaGenericFrame::SetTypeTns(enum ReaTnsType type) {
	/// Set TypeTns
	((MFM_ReaGeneric_frame*) pHeader)->Data.Type_Tns= type;
}
//_______________________________________________________________________________

83
enum ReaTnsType MFMReaGenericFrame::GetTypeTns()const {
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
	/// Get TypeTns
	uint16_t  type;
	type = (((MFM_ReaGeneric_frame*) pHeader)->Data.Type_Tns);
	if (fLocalIsBigEndian != fFrameIsBigEndian)
		SwapInt16(&type);
	return (enum ReaTnsType)type;
}
//_______________________________________________________________________________

void MFMReaGenericFrame::SetEnergy(uint16_t energy) {
	/// Set Energy
	((MFM_ReaGeneric_frame*) pHeader)->Data.Energy = energy;
}
//_______________________________________________________________________________

99
uint16_t MFMReaGenericFrame::GetEnergy() const{
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	/// Get Energy
	uint16_t energy;
	energy = (((MFM_ReaGeneric_frame*) pHeader)->Data.Energy);
	if (fLocalIsBigEndian != fFrameIsBigEndian)
		SwapInt16(&energy);
	return energy;
}
//_______________________________________________________________________________

void MFMReaGenericFrame::SetTime(uint16_t time) {
	/// Set Time
	((MFM_ReaGeneric_frame*) pHeader)->Data.Time= time;
}
//_______________________________________________________________________________

115
uint16_t MFMReaGenericFrame::GetTime() const{
116 117 118 119 120 121 122 123 124
	/// Get Time
	uint16_t time;
	time = (((MFM_ReaGeneric_frame*) pHeader)->Data.Time);
	if (fLocalIsBigEndian != fFrameIsBigEndian)
		SwapInt16(&time);
	return time;
}

//_______________________________________________________________________________
LEGEARD Luc's avatar
LEGEARD Luc committed
125
void MFMReaGenericFrame::FillDataWithRamdomValue(uint64_t timestamp,
126 127 128 129
		uint32_t eventnumber) {

	/// Fill all data of frame with random values to do test
	/// And report time stamp and event number
LEGEARD Luc's avatar
LEGEARD Luc committed
130
	MFMNumExoFrame::FillDataWithRamdomValue(timestamp,eventnumber);
131 132 133 134 135 136 137
	int value = random();
	uint16_t uivalue = (uint16_t) (4294967296 * value / RAND_MAX);
	SetTypeTns(REA_GENERIC_TIME_TYPE);
	SetEnergy(uivalue);
	SetTime(uivalue+1);
}
//_______________________________________________________________________________
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
void MFMReaGenericFrame::InitStat() {
	MFMNumExoFrame::InitStat();
	int channel;
	for ( channel=0; channel< NUMEXO_NB_CHANNELS ; channel ++){
		fSumEnergy[channel]=0;
		fSumStatus[channel][0]=0;
		fSumStatus[channel][1]=0;
		fSumTypeTNS[channel]=0;
		fSumTime[channel]=0;
		}

}
//_______________________________________________________________________________
void MFMReaGenericFrame::FillStat() {
	MFMNumExoFrame::FillStat();
	int channel,board;
	uint32_t eventnumber = GetEventNumber();
	static uint32_t eventnumberold = 0;
	if (eventnumber != 0) {
		if (eventnumber - eventnumberold < 0)
			IncrementNegativJump();
		if (eventnumber - eventnumberold != 1)
			IncrementNoContiJump();
		eventnumberold=eventnumber;
	}
	channel = GetTGCristalId();
  	board   = GetBoardId();
	fSumTime[channel]   += GetTime();
	fSumEnergy[channel] += GetEnergy();
	fSumStatus[channel][0] += GetStatus(0);
	fSumStatus[channel][1] += GetStatus(1);
	fSumTypeTNS[channel]   += GetTypeTns();
	if (fEnergy)  SetTabValues();

}
//_______________________________________________________________________________
string MFMReaGenericFrame::GetStat(string info)const {

	string display("");
	stringstream ss("");
	ss << MFMNumExoFrame::GetStat(info);
	int i, j;
	int total = 0;
	int channel;
	
	ss << "Sum of all values of events for each of "<< NUMEXO_NB_CHANNELS <<" channels (if no null): \n";
	for ( channel=0; channel< NUMEXO_NB_CHANNELS ; channel ++){
		if (fSumEnergy [channel]>0)  ss << "Sum of Energy  ["<<channel<<"] = "<< fSumEnergy [channel]<<"\n"; 
		if (fSumTime [channel]>0)    ss << "Sum of Time    ["<<channel<<"] = "<< fSumTime[channel]<<"\n"; 
		if (fSumTypeTNS [channel]>0) ss << "Sum of TypeTNS ["<<channel<<"] = "<< fSumTypeTNS[channel]<<"\n"; 
		if (fSumStatus[channel][0]>0)ss << "Sum of Status0 ["<<channel<<"] = "<< fSumStatus[channel][0]<<"\n"; 
		if (fSumStatus[channel][1])  ss << "Sum of Status1 ["<<channel<<"] = "<< fSumStatus[channel][1]<<"\n"; 
		}
	display = ss.str();
	return display;
}

//_______________________________________________________________________________
void  MFMReaGenericFrame::InitTabValues(uint16_t *listofboards,int numberofboards){
  // method to init tab  for analyse and use to fill TTree 
198
  
199 200
  int board =0, channel=0;
  fNumberOfBoards = numberofboards;
201
  fInitTabValuesDone = true;
202
  for(board =0; board< NUMEXO_MAX_NUMB_BOARDS ;board ++) {
203 204
  	fConvertNoBoardIndex[board] = 0;
  	fConvertIndexNoBoard[board] = 0;
205 206 207 208 209 210 211 212 213 214 215 216 217 218
  	}
  if (fEnergy  == NULL) fEnergy  = new uint16_t*[fNumberOfBoards];
  if (fTime    == NULL) fTime    = new uint16_t*[fNumberOfBoards]; 
  if (fTypeTNS == NULL) fTypeTNS = new uint16_t*[fNumberOfBoards];
  
  if (fStatus1 == NULL) fStatus1 = new uint16_t*[fNumberOfBoards];
  if (fStatus2 == NULL) fStatus2 = new uint16_t*[fNumberOfBoards]; 
  for (board=0 ; board< numberofboards; board++){	
  	fConvertNoBoardIndex[listofboards[board]] = board ;
  	fConvertIndexNoBoard[board] = listofboards[board] ;
  	fEnergy[board]  = new uint16_t[NUMEXO_NB_CHANNELS];
	fTime[board]    = new uint16_t[NUMEXO_NB_CHANNELS];
	fTypeTNS[board] = new uint16_t[NUMEXO_NB_CHANNELS];
	fStatus1[board] = new uint16_t[NUMEXO_NB_CHANNELS];
219
	fStatus2[board] = new uint16_t[NUMEXO_NB_CHANNELS]; 	
220 221 222 223 224
	}
   ResetTabValues();
}
//_______________________________________________________________________________
void   MFMReaGenericFrame::ResetTabValues(){ 	
225 226
 
 if (fInitTabValuesDone==false)return;
227 228 229 230

int board =0, channel=0;
  fTabValueEventNumber=0;
  fTabValueTimeStamp=0;
231 232 233
  fChannel =0;
  fBoardNumber=0;
  fBoardIndex=0;
234

235 236
  for (board=0 ; board< fNumberOfBoards; board++){	
	for (channel=0 ; channel< NUMEXO_NB_CHANNELS; channel++){
237 238 239 240 241
		fEnergy[board][channel]   = 0;
		fTime[board][channel] 	  = 0;    
		fTypeTNS[board][channel]  = 0; 
		fStatus1[board][channel]  = 0;
		fStatus2[board][channel]  = 0;
242 243 244 245 246 247
	}
  }
}
//_______________________________________________________________________________
void   MFMReaGenericFrame::SetTabValues(){ 
	// method to set values of tabs  for analyse and use to fill TTree 
248 249
	fChannel       = GetTGCristalId();
  	fBoardNumber   = GetBoardId();
250 251
  	fTabValueEventNumber = GetEventNumber();
  	fTabValueTimeStamp   = GetTimeStamp();
252 253 254 255 256 257 258 259 260 261 262 263 264
  	fBoardIndex          = fConvertNoBoardIndex[fBoardNumber];
 if (fInitTabValuesDone==false)return;  	
  	if ((fNumberOfBoards>fBoardIndex)and ( fNumberOfBoards >fChannel)){
  		fEnergy[fBoardIndex][fChannel]  = GetEnergy();
		fTime[fBoardIndex][fChannel]    = GetTime();
		fTypeTNS[fBoardIndex][fChannel] = GetTypeTns();
		fStatus1[fBoardIndex][fChannel] = GetStatus(0);
		fStatus2[fBoardIndex][fChannel] = GetStatus(1);
	} else { 
	   cout << "Warning , index of  card or No Channel to big \n";
	   cout <<dec <<" BoardIndex   = "<<fBoardIndex << "  <->   NumberOfBoards = "<<fNumberOfBoards<<"\n";
  	   cout       <<" ChannelIndex = "<<fChannel << " <->  NUMEXO_NB_CHANNELS = "<<NUMEXO_NB_CHANNELS<<"\n";
	}		
265 266 267
}
//_______________________________________________________________________________	

268 269 270 271
string MFMReaGenericFrame::GetDumpData(char mode, bool nozero) const {
	// Dump parameter Label and parameter value of the current event.
	// if enter parameter is true (default value), all zero parameter of event aren't dumped
	// mode = 'd' for decimal, 'b' for binary, 'h' for hexa, 'o' for octal
272

273 274 275 276 277 278 279 280 281 282
	stringstream ss;
	string display("");

	int i, j, maxbin, presentation = 0, max_presentation = 5;
	char tempo[255];
	char Bin[255];
	char Bin2[255];
	int reste;
	char one = '1', zero = '0';
	int DecNumber = 0;
283

284 285 286 287 288 289 290 291 292 293 294
	if (mode == 'b')
		max_presentation = 3;
	if (GetEventNumber() == 0xFFFFFFFF) {
		ss << "No Event , so no event dump. Get a new event frame";
	} else {
		ss << "  E = "<<GetEnergy()<<"  T = "<< GetTime() ;
	}
	display = ss.str();
	return display;
}
//_______________________________________________________________________________
295