[MAJOR CHANGE] change ClassData, Timestamp, energy, etc, be dynamically allocated, NOT TESTED, compiled not problem
This commit is contained in:
parent
c38f4ae401
commit
14c2ceab6c
|
@ -6,10 +6,10 @@ class FSUReader{
|
|||
|
||||
public:
|
||||
FSUReader();
|
||||
FSUReader(std::string fileName, bool verbose = true);
|
||||
FSUReader(std::string fileName, uShort dataSize = 100, bool verbose = true);
|
||||
~FSUReader();
|
||||
|
||||
void OpenFile(std::string fileName, bool verbose = true);
|
||||
void OpenFile(std::string fileName, uShort dataSize, bool verbose = true);
|
||||
bool isOpen() const{return inFile == nullptr ? false : true;}
|
||||
|
||||
void ScanNumBlock(bool verbose = true, uShort saveData = 0);
|
||||
|
@ -30,10 +30,14 @@ class FSUReader{
|
|||
int GetChMask() const{return chMask;}
|
||||
unsigned long GetFileByteSize() const {return inFileSize;}
|
||||
|
||||
void ClearHitListandCount() { hit.clear(); numHit = 0;}
|
||||
void ClearHitList() { hit.clear();}
|
||||
Hit GetHit(int id) const {return hit[id];}
|
||||
unsigned long GetHitCount() const{ return numHit;}
|
||||
ulong GetHitListLength() const {return hit.size();}
|
||||
|
||||
void ClearHitCount() {numHit = 0;}
|
||||
ulong GetHitCount() const{ return numHit;}
|
||||
std::vector<Hit> GetHitVector() const {return hit;}
|
||||
void SortHit();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -85,11 +89,11 @@ inline FSUReader::FSUReader(){
|
|||
|
||||
}
|
||||
|
||||
inline FSUReader::FSUReader(std::string fileName, bool verbose){
|
||||
OpenFile(fileName, verbose);
|
||||
inline FSUReader::FSUReader(std::string fileName, uShort dataSize, bool verbose){
|
||||
OpenFile(fileName, dataSize, verbose);
|
||||
}
|
||||
|
||||
inline void FSUReader::OpenFile(std::string fileName, bool verbose){
|
||||
inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, bool verbose){
|
||||
|
||||
inFile = fopen(fileName.c_str(), "r");
|
||||
|
||||
|
@ -155,7 +159,7 @@ inline void FSUReader::OpenFile(std::string fileName, bool verbose){
|
|||
|
||||
numCh = DPPType == DPPType::DPP_QDC_CODE ? 64 : 16;
|
||||
|
||||
data = new Data(numCh);
|
||||
data = new Data(numCh, dataSize);
|
||||
data->tick2ns = tick2ns;
|
||||
data->boardSN = sn;
|
||||
data->DPPType = DPPType;
|
||||
|
@ -217,7 +221,7 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose, uShort saveData){
|
|||
int stop = data->DataIndex[ch];
|
||||
|
||||
for( int i = start; i <= stop; i++ ){
|
||||
i = i % MaxNData;
|
||||
i = i % data->GetDataSize();
|
||||
|
||||
temp.sn = sn;
|
||||
temp.ch = ch;
|
||||
|
@ -257,6 +261,12 @@ inline int FSUReader::ReadBlock(unsigned int ID, int verbose){
|
|||
|
||||
}
|
||||
|
||||
inline void FSUReader::SortHit(){
|
||||
std::sort(hit.begin(), hit.end(), [](const Hit& a, const Hit& b) {
|
||||
return a.timestamp < b.timestamp;
|
||||
});
|
||||
}
|
||||
|
||||
inline void FSUReader::ScanNumBlock(bool verbose, uShort saveData){
|
||||
if( feof(inFile) ) return;
|
||||
|
||||
|
@ -290,9 +300,7 @@ inline void FSUReader::ScanNumBlock(bool verbose, uShort saveData){
|
|||
|
||||
if(saveData) {
|
||||
if( verbose) printf("\nQuick Sort hit array according to time...");
|
||||
std::sort(hit.begin(), hit.end(), [](const Hit& a, const Hit& b) {
|
||||
return a.timestamp < b.timestamp;
|
||||
});
|
||||
SortHit();
|
||||
if( verbose) printf(".......done.\n");
|
||||
}
|
||||
|
||||
|
|
163
ClassData.h
163
ClassData.h
|
@ -16,7 +16,8 @@
|
|||
|
||||
#include "macro.h"
|
||||
|
||||
#define MaxNData 10000 /// store 10k events per channels
|
||||
//#define MaxNData 10000 /// store 10k events per channels
|
||||
#define DefaultDataSize 10000
|
||||
|
||||
enum DPPType{
|
||||
DPP_PHA_CODE = 0x8B,
|
||||
|
@ -51,26 +52,42 @@ class Data{
|
|||
int LoopIndex[MaxNChannels]; /// number of loop in the circular memory
|
||||
int DataIndex[MaxNChannels];
|
||||
|
||||
unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit
|
||||
unsigned short fineTime [MaxNChannels][MaxNData]; /// 10 bits, in unit of tick2ns / 1000 = ps
|
||||
unsigned short Energy [MaxNChannels][MaxNData]; /// 15 bit
|
||||
unsigned short Energy2 [MaxNChannels][MaxNData]; /// 15 bit, in PSD, Energy = Qshort, Energy2 = Qlong
|
||||
bool PileUp [MaxNChannels][MaxNData]; /// pile up flag
|
||||
//unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit
|
||||
// unsigned short fineTime [MaxNChannels][MaxNData]; /// 10 bits, in unit of tick2ns / 1000 = ps
|
||||
// unsigned short Energy [MaxNChannels][MaxNData]; /// 15 bit
|
||||
// unsigned short Energy2 [MaxNChannels][MaxNData]; /// 15 bit, in PSD, Energy = Qshort, Energy2 = Qlong
|
||||
// bool PileUp [MaxNChannels][MaxNData]; /// pile up flag
|
||||
|
||||
std::vector<short> Waveform1 [MaxNChannels][MaxNData]; // used at least 14 MB
|
||||
std::vector<short> Waveform2 [MaxNChannels][MaxNData];
|
||||
std::vector<bool> DigiWaveform1[MaxNChannels][MaxNData];
|
||||
std::vector<bool> DigiWaveform2[MaxNChannels][MaxNData];
|
||||
std::vector<bool> DigiWaveform3[MaxNChannels][MaxNData];
|
||||
std::vector<bool> DigiWaveform4[MaxNChannels][MaxNData];
|
||||
// std::vector<short> Waveform1 [MaxNChannels][MaxNData]; // used at least 14 MB
|
||||
// std::vector<short> Waveform2 [MaxNChannels][MaxNData];
|
||||
// std::vector<bool> DigiWaveform1[MaxNChannels][MaxNData];
|
||||
// std::vector<bool> DigiWaveform2[MaxNChannels][MaxNData];
|
||||
// std::vector<bool> DigiWaveform3[MaxNChannels][MaxNData];
|
||||
// std::vector<bool> DigiWaveform4[MaxNChannels][MaxNData];
|
||||
|
||||
uShort GetDataSize() const {return dataSize;}
|
||||
ullong ** Timestamp; /// 47 bit
|
||||
uShort ** fineTime; /// 10 bits, in unit of tick2ns / 1000 = ps
|
||||
uShort ** Energy ; /// 15 bit
|
||||
uShort ** Energy2 ; /// 15 bit, in PSD, Energy = Qshort, Energy2 = Qlong
|
||||
bool ** PileUp ; /// pile up flag
|
||||
|
||||
std::vector<short> ** Waveform1 ; // used at least 14 MB
|
||||
std::vector<short> ** Waveform2 ;
|
||||
std::vector<bool> ** DigiWaveform1;
|
||||
std::vector<bool> ** DigiWaveform2;
|
||||
std::vector<bool> ** DigiWaveform3;
|
||||
std::vector<bool> ** DigiWaveform4;
|
||||
|
||||
public:
|
||||
Data(unsigned short numCh);
|
||||
Data(unsigned short numCh, uShort dataSize = DefaultDataSize);
|
||||
~Data();
|
||||
|
||||
void Allocate80MBMemory();
|
||||
void AllocateMemory(uint32_t size);
|
||||
|
||||
void AllocateDataSize(uShort dataSize);
|
||||
void ClearDataPointer();
|
||||
void ClearData();
|
||||
void ClearTriggerRate();
|
||||
void ClearBuffer();
|
||||
|
@ -102,6 +119,8 @@ class Data{
|
|||
const unsigned short numInputCh;
|
||||
unsigned int nw;
|
||||
|
||||
uShort dataSize;
|
||||
|
||||
///for temperary
|
||||
std::vector<short> tempWaveform1;
|
||||
std::vector<short> tempWaveform2;
|
||||
|
@ -128,13 +147,16 @@ class Data{
|
|||
|
||||
//==========================================
|
||||
|
||||
inline Data::Data(unsigned short numCh): numInputCh(numCh){
|
||||
inline Data::Data(unsigned short numCh, uShort dataSize): numInputCh(numCh){
|
||||
tick2ns = 2.0;
|
||||
boardSN = 0;
|
||||
DPPType = DPPType::DPP_PHA_CODE;
|
||||
DPPTypeStr = "";
|
||||
IsNotRollOverFakeAgg = false;
|
||||
buffer = NULL;
|
||||
|
||||
AllocateDataSize(dataSize);
|
||||
|
||||
for ( int i = 0; i < MaxNChannels; i++) TotNumNonPileUpEvents[i] = 0;
|
||||
ClearData();
|
||||
ClearTriggerRate();
|
||||
|
@ -146,10 +168,85 @@ inline Data::Data(unsigned short numCh): numInputCh(numCh){
|
|||
outFile = nullptr;
|
||||
outFileSize = 0; // should be max at 2 GB
|
||||
FinishedOutFilesSize = 0; // sum of files size.
|
||||
|
||||
}
|
||||
|
||||
inline Data::~Data(){
|
||||
if( buffer != NULL ) delete buffer;
|
||||
|
||||
ClearDataPointer();
|
||||
}
|
||||
|
||||
inline void Data::AllocateDataSize(uShort dataSize){
|
||||
|
||||
printf("Data::%s, size: %u\n", __func__, dataSize);
|
||||
|
||||
this->dataSize = dataSize;
|
||||
|
||||
Timestamp = new ullong * [numInputCh];
|
||||
fineTime = new uShort * [numInputCh];
|
||||
Energy = new uShort * [numInputCh];
|
||||
Energy2 = new uShort * [numInputCh];
|
||||
PileUp = new bool * [numInputCh];
|
||||
|
||||
Waveform1 = new std::vector<short> * [numInputCh];
|
||||
Waveform2 = new std::vector<short> * [numInputCh];
|
||||
DigiWaveform1 = new std::vector<bool> * [numInputCh];
|
||||
DigiWaveform2 = new std::vector<bool> * [numInputCh];
|
||||
DigiWaveform3 = new std::vector<bool> * [numInputCh];
|
||||
DigiWaveform4 = new std::vector<bool> * [numInputCh];
|
||||
|
||||
for(int ch = 0; ch < numInputCh; ch++){
|
||||
Timestamp[ch] = new ullong[dataSize];
|
||||
fineTime[ch] = new uShort[dataSize];
|
||||
Energy[ch] = new uShort[dataSize];
|
||||
Energy2[ch] = new uShort[dataSize];
|
||||
PileUp[ch] = new bool[dataSize];
|
||||
|
||||
Waveform1[ch] = new std::vector<short> [dataSize];
|
||||
Waveform2[ch] = new std::vector<short> [dataSize];
|
||||
DigiWaveform1[ch] = new std::vector<bool> [dataSize];
|
||||
DigiWaveform2[ch] = new std::vector<bool> [dataSize];
|
||||
DigiWaveform3[ch] = new std::vector<bool> [dataSize];
|
||||
DigiWaveform4[ch] = new std::vector<bool> [dataSize];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void Data::ClearDataPointer(){
|
||||
|
||||
printf("Data::%s\n", __func__);
|
||||
|
||||
for(int ch = 0; ch < numInputCh; ch++){
|
||||
delete [] Timestamp[ch] ;
|
||||
delete [] fineTime[ch];
|
||||
delete [] Energy[ch];
|
||||
delete [] Energy2[ch];
|
||||
delete [] PileUp[ch];
|
||||
|
||||
delete [] Waveform1[ch];
|
||||
delete [] Waveform2[ch];
|
||||
delete [] DigiWaveform1[ch];
|
||||
delete [] DigiWaveform2[ch];
|
||||
delete [] DigiWaveform3[ch];
|
||||
delete [] DigiWaveform4[ch];
|
||||
}
|
||||
|
||||
delete [] Timestamp;
|
||||
delete [] fineTime;
|
||||
delete [] Energy;
|
||||
delete [] Energy2;
|
||||
delete [] PileUp;
|
||||
|
||||
delete [] Waveform1;
|
||||
delete [] Waveform2;
|
||||
delete [] DigiWaveform1;
|
||||
delete [] DigiWaveform2;
|
||||
delete [] DigiWaveform3;
|
||||
delete [] DigiWaveform4;
|
||||
|
||||
dataSize = 0;
|
||||
|
||||
}
|
||||
|
||||
inline void Data::AllocateMemory(uint32_t size){
|
||||
|
@ -179,7 +276,7 @@ inline void Data::ClearData(){
|
|||
for( int ch = 0 ; ch < MaxNChannels; ch++){
|
||||
LoopIndex[ch] = 0;
|
||||
DataIndex[ch] = -1;
|
||||
for( int j = 0; j < MaxNData; j++){
|
||||
for( int j = 0; j < dataSize; j++){
|
||||
Timestamp[ch][j] = 0;
|
||||
fineTime[ch][j] = 0;
|
||||
Energy[ch][j] = 0;
|
||||
|
@ -326,12 +423,12 @@ inline void Data::PrintAllData(bool tableMode, unsigned int maxRowDisplay) const
|
|||
printf("%4s|", "");
|
||||
for( int ch = 0; ch < numInputCh; ch++){
|
||||
if( LoopIndex[ch] > 0 ) {
|
||||
MaxEntry = MaxNData-1;
|
||||
MaxEntry = dataSize-1;
|
||||
}else{
|
||||
if( DataIndex[ch] > MaxEntry ) MaxEntry = DataIndex[ch];
|
||||
}
|
||||
if( DataIndex[ch] < 0 ) continue;
|
||||
printf(" %5s-%02d,%2d,%-6d |", "ch", ch, LoopIndex[ch], DataIndex[ch]);
|
||||
printf(" %5s-%02d,%2d,%-6d |", "ch", ch, LoopIndex[ch], DataIndex[ch]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
@ -340,7 +437,7 @@ inline void Data::PrintAllData(bool tableMode, unsigned int maxRowDisplay) const
|
|||
printf("%4d|", entry );
|
||||
for( int ch = 0; ch < numInputCh; ch++){
|
||||
if( DataIndex[ch] < 0 ) continue;
|
||||
printf(" %5d,%12lld |", Energy[ch][entry], Timestamp[ch][entry]);
|
||||
printf(" %5d,%17lld |", Energy[ch][entry], Timestamp[ch][entry]);
|
||||
}
|
||||
printf("\n");
|
||||
entry ++;
|
||||
|
@ -352,9 +449,9 @@ inline void Data::PrintAllData(bool tableMode, unsigned int maxRowDisplay) const
|
|||
for( int ch = 0; ch < numInputCh ; ch++){
|
||||
if( DataIndex[ch] < 0 ) continue;
|
||||
printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]);
|
||||
for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){
|
||||
if( DPPType == DPPType::DPP_PHA_CODE || DPPType == DPPType::DPP_QDC_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
if( DPPType == DPPType::DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? dataSize : DataIndex[ch]) ; ev++){
|
||||
if( DPPType == DPPType::DPP_PHA_CODE || DPPType == DPPType::DPP_QDC_CODE ) printf("%4d, %5u, %18llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
if( DPPType == DPPType::DPP_PSD_CODE ) printf("%4d, %5u, %5u, %18llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
if( maxRowDisplay > 0 && (unsigned int) ev > maxRowDisplay ) break;
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +462,7 @@ inline void Data::PrintChData(unsigned short ch, unsigned int maxRowDisplay) con
|
|||
|
||||
if( DataIndex[ch] < 0 ) printf("no data in ch-%d\n", ch);
|
||||
printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]);
|
||||
for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){
|
||||
for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? dataSize : DataIndex[ch]) ; ev++){
|
||||
if( DPPType == DPPType::DPP_PHA_CODE || DPPType == DPPType::DPP_QDC_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
if( DPPType == DPPType::DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
if( maxRowDisplay > 0 && (unsigned int) ev > maxRowDisplay ) break;
|
||||
|
@ -482,7 +579,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
if( NumEventsDecoded[ch] > 4 ){
|
||||
|
||||
int indexStart = DataIndex[ch] - NumEventsDecoded[ch] + 1;
|
||||
if( indexStart < 0 ) indexStart += MaxNData;
|
||||
if( indexStart < 0 ) indexStart += dataSize;
|
||||
|
||||
unsigned long long dTime = Timestamp[ch][DataIndex[ch]] - Timestamp[ch][indexStart];
|
||||
double sec = dTime * tick2ns / 1e9;
|
||||
|
@ -499,11 +596,11 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
|
||||
calIndexes[ch][1] = DataIndex[ch];
|
||||
calIndexes[ch][0] = DataIndex[ch] - nEvent + 1;
|
||||
if (calIndexes[ch][0] < 0 ) calIndexes[ch][0] += MaxNData;
|
||||
if (calIndexes[ch][0] < 0 ) calIndexes[ch][0] += dataSize;
|
||||
|
||||
// std::vector<unsigned long long> tList ;
|
||||
// for( int i = 0; i < nEvent ; i ++){
|
||||
// int j = (calIndexes[ch][0] + i) % MaxNData;
|
||||
// int j = (calIndexes[ch][0] + i) % dataSize;
|
||||
// tList.push_back( Timestamp[ch][j]);
|
||||
// }
|
||||
// if( DPPType == DPPType::DPP_QDC_CODE){
|
||||
|
@ -521,8 +618,8 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
//double sec = ( tList.back() - tList.front() ) * tick2ns / 1e9;
|
||||
|
||||
|
||||
unsigned long long t0 = Timestamp[ch][(calIndexes[ch][0]) % MaxNData]; // earlier
|
||||
unsigned long long t1 = Timestamp[ch][(calIndexes[ch][1]) % MaxNData];; // latest
|
||||
unsigned long long t0 = Timestamp[ch][(calIndexes[ch][0]) % dataSize]; // earlier
|
||||
unsigned long long t1 = Timestamp[ch][(calIndexes[ch][1]) % dataSize];; // latest
|
||||
|
||||
if( t0 > t1 ) {
|
||||
printf("digi-%d, ch-%d | data is not in time order\n", boardSN, ch);
|
||||
|
@ -537,7 +634,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
|
||||
short pileUpCount = 0;
|
||||
for( int i = 0 ; i < nEvent; i++ ) {
|
||||
int j = (calIndexes[ch][0] + i) % MaxNData;
|
||||
int j = (calIndexes[ch][0] + i) % dataSize;
|
||||
if( PileUp[ch][j] ) pileUpCount ++;
|
||||
}
|
||||
NonPileUpRate[ch] = (nEvent - pileUpCount)/sec;
|
||||
|
@ -770,7 +867,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
if( rollOver == 0 ) { // non-time roll over fake event
|
||||
DataIndex[channel] ++;
|
||||
if( DataIndex[channel] >= MaxNData ) {
|
||||
if( DataIndex[channel] >= dataSize ) {
|
||||
LoopIndex[channel] ++;
|
||||
DataIndex[channel] = 0;
|
||||
}
|
||||
|
@ -797,7 +894,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
}
|
||||
}
|
||||
|
||||
//if( DataIndex[channel] > MaxNData ) ClearData(); // if any channel has more data then MaxNData, clear all stored data
|
||||
//if( DataIndex[channel] > dataSize ) ClearData(); // if any channel has more data then dataSize, clear all stored data
|
||||
|
||||
if( verbose >= 1 ) printf("evt %4d(%2d) | ch : %2d, PileUp : %d , energy : %5d, rollOver: %d, timestamp : %16llu (%10llu), triggerAt : %d, nSample : %d, %f sec\n",
|
||||
DataIndex[channel], LoopIndex[channel], channel, pileUp, energy, rollOver, timeStamp * tick2ns, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9);
|
||||
|
@ -972,7 +1069,7 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
if( isEnergyCorrect == 0 ) {
|
||||
DataIndex[channel] ++;
|
||||
if( DataIndex[channel] >= MaxNData ) {
|
||||
if( DataIndex[channel] >= dataSize ) {
|
||||
LoopIndex[channel] ++;
|
||||
DataIndex[channel] = 0;
|
||||
}
|
||||
|
@ -1002,7 +1099,7 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
}
|
||||
|
||||
//if( DataIndex[channel] >= MaxNData ) ClearData();
|
||||
//if( DataIndex[channel] >= dataSize ) ClearData();
|
||||
|
||||
//if( verbose >= 2 ) printf("extra : 0x%08x, Qshort : %d, Qlong : %d \n", extra, Qshort, Qlong);
|
||||
if( verbose == 1 ) printf("ch : %2d, Qshort : %6d, Qlong : %6d, timestamp : %llu\n",
|
||||
|
@ -1128,7 +1225,7 @@ inline int Data::DecodeQDCGroupedChannelBlock(unsigned int ChannelMask, bool fas
|
|||
unsigned short channel = ChannelMask*8 + subCh;
|
||||
|
||||
DataIndex[channel] ++;
|
||||
if( DataIndex[channel] >= MaxNData ) {
|
||||
if( DataIndex[channel] >= dataSize ) {
|
||||
LoopIndex[channel] ++;
|
||||
DataIndex[channel] = 0;
|
||||
}
|
||||
|
|
|
@ -278,6 +278,12 @@ void Digitizer::SetRegChannelOnOff(unsigned short ch, bool onOff){
|
|||
SetRegChannelMask(regChannelMask);
|
||||
}
|
||||
|
||||
void Digitizer::ProgramBoard(){
|
||||
if( DPPType == DPPType::DPP_PHA_CODE ) ProgramBoard_PHA();
|
||||
if( DPPType == DPPType::DPP_PSD_CODE ) ProgramBoard_PSD();
|
||||
if( DPPType == DPPType::DPP_QDC_CODE ) ProgramBoard_QDC();
|
||||
}
|
||||
|
||||
int Digitizer::ProgramBoard_PHA(){
|
||||
if( softwareDisable ) return 0;
|
||||
|
||||
|
@ -342,11 +348,10 @@ int Digitizer::ProgramBoard_PHA(){
|
|||
//ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::MaxAggregatePerBlockTransfer), 100);
|
||||
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::DPPAlgorithmControl) + 0x7000, 0x030200f);
|
||||
|
||||
ret |= CAEN_DGTZ_SetNumEventsPerAggregate(handle, 10);
|
||||
ret |= CAEN_DGTZ_SetDPPEventAggregation(handle, 0, 0); // Auto set
|
||||
|
||||
if( ret != 0 ) { printf("!!!!!!!! set channels error.\n");}
|
||||
|
||||
AutoSetDPPEventAggregation();
|
||||
|
||||
/// change address 0xEF08 (5 bits), this will reflected in the 2nd word of the Board Agg. header.
|
||||
ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardID, (DPPType & 0xF));
|
||||
//WriteRegister(DPP::BoardID, (DPPType & 0xF));
|
||||
|
@ -407,8 +412,7 @@ int Digitizer::ProgramBoard_PSD(){
|
|||
ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardID, (DPPType & 0xF));
|
||||
//WriteRegister(DPP::BoardID, (DPPType & 0xF));
|
||||
|
||||
ret |= CAEN_DGTZ_SetNumEventsPerAggregate(handle, 10);
|
||||
ret |= CAEN_DGTZ_SetDPPEventAggregation(handle, 0, 0); // Auto set
|
||||
AutoSetDPPEventAggregation();
|
||||
|
||||
isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard();
|
||||
|
||||
|
@ -454,7 +458,7 @@ int Digitizer::ProgramBoard_QDC(){
|
|||
WriteRegister(DPP::QDC::TriggerThreshold_sub6, 100, -1);
|
||||
WriteRegister(DPP::QDC::TriggerThreshold_sub7, 100, -1);
|
||||
|
||||
WriteRegister(DPP::BoardConfiguration, 0xC0110);
|
||||
WriteRegister(DPP::BoardConfiguration, 0xE0110);
|
||||
//WriteRegister(DPP::AggregateOrganization, 0x0);
|
||||
//WriteRegister(DPP::MaxAggregatePerBlockTransfer, 100);
|
||||
WriteRegister(DPP::AcquisitionControl, 0x0);
|
||||
|
@ -467,8 +471,7 @@ int Digitizer::ProgramBoard_QDC(){
|
|||
ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardID, (DPPType & 0xF));
|
||||
//WriteRegister(DPP::BoardID, (DPPType & 0xF));
|
||||
|
||||
ret |= CAEN_DGTZ_SetNumEventsPerAggregate(handle, 10);
|
||||
ret |= CAEN_DGTZ_SetDPPEventAggregation(handle, 0, 0); // Auto set
|
||||
AutoSetDPPEventAggregation();
|
||||
|
||||
isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard();
|
||||
|
||||
|
|
|
@ -64,6 +64,10 @@ class Digitizer{
|
|||
|
||||
uint32_t acqStatus;
|
||||
|
||||
int ProgramBoard_PHA() ; /// program a default PHA board with dual trace
|
||||
int ProgramBoard_PSD() ;
|
||||
int ProgramBoard_QDC() ;
|
||||
|
||||
public:
|
||||
Digitizer(); /// no digitizer open
|
||||
Digitizer(int boardID, int portID = 0, bool program = false, bool verbose = false);
|
||||
|
@ -83,10 +87,14 @@ class Digitizer{
|
|||
void DisableBoard() {softwareDisable = true;}
|
||||
bool IsBoardDisabled() const {return softwareDisable;}
|
||||
|
||||
void PrintBoard() ;
|
||||
int ProgramBoard_PHA() ; /// program a default PHA board with dual trace
|
||||
int ProgramBoard_PSD() ;
|
||||
int ProgramBoard_QDC() ;
|
||||
void PrintBoard();
|
||||
void ProgramBoard();
|
||||
void AutoSetDPPEventAggregation(){
|
||||
ret = CAEN_DGTZ_SetDPPAcquisitionMode(handle, CAEN_DGTZ_DPP_ACQ_MODE_List, CAEN_DGTZ_DPP_SAVE_PARAM_EnergyAndTime);
|
||||
ret |= CAEN_DGTZ_SetNumEventsPerAggregate(handle, 10);
|
||||
ret |= CAEN_DGTZ_SetDPPEventAggregation(handle, 0, 0); // AutoSet
|
||||
if( ret != 0 ) { printf("!!!!!!!! set %s error.\n", __func__);}
|
||||
}
|
||||
|
||||
//^================ ACQ control
|
||||
void StopACQ();
|
||||
|
|
|
@ -184,15 +184,11 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
|
|||
bnProgramPreDefined = new QPushButton("Program Default", this);
|
||||
buttonLayout->addWidget(bnProgramPreDefined, rowID, 1);
|
||||
connect(bnProgramPreDefined, &QPushButton::clicked, this, [=](){
|
||||
if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) digi[ID]->ProgramBoard_PHA();
|
||||
if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) digi[ID]->ProgramBoard_PSD();
|
||||
if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) digi[ID]->ProgramBoard_QDC();
|
||||
|
||||
digi[ID]->ProgramBoard();
|
||||
usleep(1000*500); // wait for 0.2 sec
|
||||
|
||||
UpdatePanelFromMemory();
|
||||
emit UpdateOtherPanels();
|
||||
|
||||
});
|
||||
|
||||
bnClearBuffer = new QPushButton("Clear Buffer/FIFO/Data", this);
|
||||
|
|
61
FSUDAQ.cpp
61
FSUDAQ.cpp
|
@ -55,7 +55,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
|
|||
cbOpenDigitizers = new RComboBox(this);
|
||||
cbOpenDigitizers->addItem("Open Digitizers ... ", 0);
|
||||
cbOpenDigitizers->addItem("Open Digitizers w/o load Settings", 1);
|
||||
cbOpenDigitizers->addItem("Open Digitizers + load Settings", 2);
|
||||
cbOpenDigitizers->addItem("Open Digitizers (default program)", 2);
|
||||
cbOpenDigitizers->addItem("Open Digitizers + load Settings", 3);
|
||||
//cbOpenDigitizers->addItem("Open Digitizers via USB", 3);
|
||||
cbOpenDigitizers->addItem("Open Digitizers via A4818", 4);
|
||||
layout->addWidget(cbOpenDigitizers, 0, 0);
|
||||
|
@ -613,11 +614,10 @@ void MainWindow::OpenDigitizers(){
|
|||
cbOpenDigitizers->setCurrentIndex(0);
|
||||
return;
|
||||
}else{
|
||||
if( cbOpenDigitizers->currentIndex() == 1 ) {
|
||||
LogMsg(QString("Done seraching. Found %1 digitizer(s). Opening digitizer(s)....").arg(nDigi));
|
||||
}else{
|
||||
LogMsg(QString("Done seraching. Found %1 digitizer(s). Opening digitizer(s) and load settings....").arg(nDigi));
|
||||
}
|
||||
if( cbOpenDigitizers->currentIndex() == 1 ) LogMsg(QString("Done seraching. Found %1 digitizer(s). Opening digitizer(s)....").arg(nDigi));
|
||||
if( cbOpenDigitizers->currentIndex() == 2 ) LogMsg(QString("Done seraching. Found %1 digitizer(s). Opening digitizer(s) and program default....").arg(nDigi));
|
||||
if( cbOpenDigitizers->currentIndex() == 3 ) LogMsg(QString("Done seraching. Found %1 digitizer(s). Opening digitizer(s) and load settings....").arg(nDigi));
|
||||
|
||||
}
|
||||
|
||||
digi = new Digitizer * [nDigi];
|
||||
|
@ -627,32 +627,33 @@ void MainWindow::OpenDigitizers(){
|
|||
digi[i] = new Digitizer(portList[i].first, portList[i].second);
|
||||
//digi[i]->Reset();
|
||||
|
||||
if( cbOpenDigitizers->currentIndex() == 2 ) {
|
||||
digi[i]->ProgramBoard();
|
||||
}
|
||||
|
||||
///============== load settings
|
||||
QString fileName = rawDataPath + "/Digi-" + QString::number(digi[i]->GetSerialNumber()) + "_" + QString::fromStdString(digi[i]->GetData()->DPPTypeStr) + ".bin";
|
||||
QFile file(fileName);
|
||||
if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) {
|
||||
if( cbOpenDigitizers->currentIndex() == 3 ){
|
||||
QString fileName = rawDataPath + "/Digi-" + QString::number(digi[i]->GetSerialNumber()) + "_" + QString::fromStdString(digi[i]->GetData()->DPPTypeStr) + ".bin";
|
||||
QFile file(fileName);
|
||||
if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) {
|
||||
|
||||
if( digi[i]->GetDPPType() == V1730_DPP_PHA_CODE ) {
|
||||
//digi[i]->ProgramBoard_PHA();
|
||||
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PHA settings.");
|
||||
LogMsg("<b>" + fileName + "</b> not found.");
|
||||
}
|
||||
|
||||
if( digi[i]->GetDPPType() == V1730_DPP_PSD_CODE ){
|
||||
//digi[i]->ProgramBoard_PSD();
|
||||
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PSD settings.");
|
||||
LogMsg("<b>" + fileName + "</b> not found.");
|
||||
}
|
||||
|
||||
if( digi[i]->GetDPPType() == V1740_DPP_QDC_CODE ){
|
||||
//digi[i]->ProgramBoard_QDC();
|
||||
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PSD settings.");
|
||||
LogMsg("<b>" + fileName + "</b> not found.");
|
||||
}
|
||||
|
||||
}else{
|
||||
LogMsg("Found <b>" + fileName + "</b> for digitizer settings.");
|
||||
if( cbOpenDigitizers->currentIndex() == 2 ) {
|
||||
if( digi[i]->GetDPPType() == V1730_DPP_PHA_CODE ) {
|
||||
//digi[i]->ProgramBoard_PHA();
|
||||
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PHA settings.");
|
||||
LogMsg("<b>" + fileName + "</b> not found.");
|
||||
}
|
||||
if( digi[i]->GetDPPType() == V1730_DPP_PSD_CODE ){
|
||||
//digi[i]->ProgramBoard_PSD();
|
||||
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PSD settings.");
|
||||
LogMsg("<b>" + fileName + "</b> not found.");
|
||||
}
|
||||
if( digi[i]->GetDPPType() == V1740_DPP_QDC_CODE ){
|
||||
//digi[i]->ProgramBoard_QDC();
|
||||
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PSD settings.");
|
||||
LogMsg("<b>" + fileName + "</b> not found.");
|
||||
}
|
||||
}else{
|
||||
LogMsg("Found <b>" + fileName + "</b> for digitizer settings.");
|
||||
if( digi[i]->LoadSettingBinaryToMemory(fileName.toStdString().c_str()) == 0 ){
|
||||
LogMsg("Loaded settings file <b>" + fileName + "</b> for Digi-" + QString::number(digi[i]->GetSerialNumber()));
|
||||
digi[i]->ProgramSettingsToBoard();
|
||||
|
|
|
@ -6,7 +6,10 @@ MultiBuilder::MultiBuilder(Data ** multiData, std::vector<int> type, std::vector
|
|||
data = multiData;
|
||||
typeList = type;
|
||||
snList = sn;
|
||||
for( int i = 0; i < (int) type.size(); i++) idList.push_back(i);
|
||||
for( uShort i = 0; i < nData; i++) {
|
||||
idList.push_back(i);
|
||||
dataSize.push_back(data[i]->GetDataSize());
|
||||
}
|
||||
timeWindow = 100;
|
||||
leftOverTime = 100;
|
||||
breakTime = -1;
|
||||
|
@ -14,6 +17,7 @@ MultiBuilder::MultiBuilder(Data ** multiData, std::vector<int> type, std::vector
|
|||
lastEventTime = 0;
|
||||
ClearEvents();
|
||||
|
||||
|
||||
// for( int i = 0; i < nData; i++){
|
||||
// printf("sn: %d, numCh : %d \n", snList[i], data[i]->GetNChannel());
|
||||
// }
|
||||
|
@ -107,7 +111,7 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
|
|||
|
||||
if( data[i]->Timestamp[ch][data[i]->DataIndex[ch]] == 0 ||
|
||||
data[i]->DataIndex[ch] == -1 ||
|
||||
loopIndex[i][ch] * MaxNData + nextIndex[i][ch] > data[i]->LoopIndex[ch] * MaxNData + data[i]->DataIndex[ch]) {
|
||||
loopIndex[i][ch] * dataSize[i] > data[i]->LoopIndex[ch] * dataSize[i] + data[i]->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[i][ch] = true;
|
||||
continue;
|
||||
|
@ -172,6 +176,7 @@ void MultiBuilder::FindEarlistTimeAmongLastData(bool verbose){
|
|||
latestDigi = -1;
|
||||
for( int i = 0; i < nData; i++){
|
||||
for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){
|
||||
if( chExhaused[i][ch] ) continue;
|
||||
int index = data[i]->DataIndex[ch];
|
||||
if( index == -1 ) continue;
|
||||
if( data[i]->Timestamp[ch][index] < latestTime ) {
|
||||
|
@ -235,7 +240,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
int ch = (i + earlistCh ) % numCh;
|
||||
// printf("ch : %d | exhaused ? %s \n", ch, chExhaused[bd][ch] ? "Yes" : "No");
|
||||
if( chExhaused[bd][ch] ) continue;
|
||||
if( loopIndex[bd][ch] * MaxNData + nextIndex[bd][ch] > data[bd]->LoopIndex[ch] * MaxNData + data[bd]->DataIndex[ch]) {
|
||||
if( loopIndex[bd][ch] * dataSize[bd] + nextIndex[bd][ch] > data[bd]->LoopIndex[ch] * dataSize[bd] + data[bd]->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[bd][ch] = true;
|
||||
continue;
|
||||
|
@ -259,7 +264,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
|
||||
events[eventIndex].push_back(em);
|
||||
nextIndex[bd][ch]++;
|
||||
if( nextIndex[bd][ch] >= MaxNData) {
|
||||
if( nextIndex[bd][ch] >= dataSize[bd]) {
|
||||
loopIndex[bd][ch] ++;
|
||||
nextIndex[bd][ch] = 0;
|
||||
}
|
||||
|
@ -380,7 +385,7 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
|
|||
|
||||
events[eventIndex].push_back(em);
|
||||
nextIndex[bd][ch]--;
|
||||
if( nextIndex[bd][ch] < 0 && data[bd]->LoopIndex[ch] > 0 ) nextIndex[bd][ch] = MaxNData - 1;
|
||||
if( nextIndex[bd][ch] < 0 && data[bd]->LoopIndex[ch] > 0 ) nextIndex[bd][ch] = dataSize[bd] - 1;
|
||||
|
||||
}else{
|
||||
break;
|
||||
|
|
|
@ -49,6 +49,8 @@ private:
|
|||
const unsigned short nData;
|
||||
Data ** data; // assume all data has MaxNChannel (16)
|
||||
|
||||
std::vector<uShort> dataSize;
|
||||
|
||||
unsigned short timeWindow;
|
||||
unsigned long long leftOverTime;
|
||||
unsigned long long breakTime; // timestamp for breaking the event builder
|
||||
|
|
|
@ -208,8 +208,8 @@ void SingleSpectra::FillHistograms(){
|
|||
int lastIndex = digi[i]->GetData()->DataIndex[ch];
|
||||
int loopIndex = digi[i]->GetData()->LoopIndex[ch];
|
||||
|
||||
int temp1 = lastIndex + loopIndex*MaxNData;
|
||||
int temp2 = lastFilledIndex[i][ch] + loopFilledIndex[i][ch]*MaxNData;
|
||||
int temp1 = lastIndex + loopIndex * digi[i]->GetData()->GetDataSize();
|
||||
int temp2 = lastFilledIndex[i][ch] + loopFilledIndex[i][ch] * digi[i]->GetData()->GetDataSize();
|
||||
|
||||
// printf("%d |%d %d \n", ch, temp2, temp1);
|
||||
if( lastIndex < 0 ) continue;
|
||||
|
@ -218,7 +218,7 @@ void SingleSpectra::FillHistograms(){
|
|||
|
||||
for( int j = 0 ; j <= temp1 - temp2; j ++){
|
||||
lastFilledIndex[i][ch] ++;
|
||||
if( lastFilledIndex[i][ch] > MaxNData ) {
|
||||
if( lastFilledIndex[i][ch] > digi[i]->GetData()->GetDataSize() ) {
|
||||
lastFilledIndex[i][ch] = 0;
|
||||
loopFilledIndex[i][ch] ++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user