improved ClassData and MultiBuilder
This commit is contained in:
parent
87d833503e
commit
0177be09cc
|
@ -9,6 +9,7 @@
|
|||
#include "TTree.h"
|
||||
|
||||
#define MAX_MULTI 100
|
||||
#define BUFFERFILL 0.5 // only 0.5 * MAXNData will be filled in memeory each time
|
||||
|
||||
template<typename T> void swap(T * a, T *b );
|
||||
int partition(int arr[], int kaka[], TString file[], int start, int end);
|
||||
|
@ -214,7 +215,7 @@ int main(int argc, char **argv) {
|
|||
do{
|
||||
|
||||
/// fill the data class with some agg;
|
||||
bool breakFlag = false;
|
||||
bool fillFlag = true;
|
||||
do{
|
||||
|
||||
// Get many agg. from each file.
|
||||
|
@ -239,7 +240,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
}else{
|
||||
fseek(inFile[i], -4, SEEK_CUR); // rool back
|
||||
fseek(inFile[i], -4, SEEK_CUR); // roll back
|
||||
|
||||
short header = ((word[0] >> 28 ) & 0xF);
|
||||
if( header != 0xA ) break;
|
||||
|
@ -270,19 +271,33 @@ int main(int argc, char **argv) {
|
|||
//printf("-----------------------------------\n");
|
||||
for( int i = 0; i < nGroup; i++){
|
||||
for( int ch = 0; ch < data[i]->GetNChannel(); ch ++){
|
||||
if( data[i]->LoopIndex[ch]*MaxNData + data[i]->DataIndex[ch] - lastLoopIndex[i][ch]*MaxNData - lastDataIndex[i][ch] > MaxNData * 0.5 ) {
|
||||
breakFlag = true;
|
||||
//printf("digi:%d | ch: %d DataIndex: %d (%d) \n", data[i]->boardSN, ch, data[i]->DataIndex[ch], lastDataIndex[i][ch]);
|
||||
|
||||
int iData = data[i]->DataIndex[ch];
|
||||
int iLoop = data[i]->LoopIndex[ch];
|
||||
|
||||
if( (iLoop*MaxNData + iData) - (lastLoopIndex[i][ch]*MaxNData + lastDataIndex[i][ch]) > MaxNData * BUFFERFILL ) {
|
||||
fillFlag = false;
|
||||
}
|
||||
|
||||
//unsigned long long t1 = data[i]->Timestamp[ch][iData];
|
||||
//printf("digi:%d | ch: %2d DataIndex: %5d (%d) [%5d(%d)] | %llu\n", data[i]->boardSN, ch, iData, iLoop, lastDataIndex[i][ch], lastLoopIndex[i][ch], t1);
|
||||
|
||||
}
|
||||
//printf("%3d | agg : %d | %u | %s\n", snList[i], aggCount[i], data[i]->aggTime, fillFlag ? "cont. fill" : "break." );
|
||||
//data[i]->PrintStat();
|
||||
}
|
||||
|
||||
}while(fillFlag);
|
||||
|
||||
for( int i = 0; i < nGroup; i++){
|
||||
for( int ch = 0; ch < data[i]->GetNChannel(); ch ++){
|
||||
lastDataIndex[i][ch] = data[i]->DataIndex[ch];
|
||||
lastLoopIndex[i][ch] = data[i]->LoopIndex[ch];
|
||||
}
|
||||
//printf("%3d | agg : %d | %s\n", snList[i], aggCount[i], breakFlag ? "Break" : "cont." );
|
||||
}
|
||||
|
||||
}while(breakFlag);
|
||||
|
||||
mb->BuildEvents(0, 0, debug);
|
||||
//mb->PrintStat();
|
||||
|
||||
///----------- save to tree;
|
||||
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
|
||||
|
@ -329,6 +344,7 @@ int main(int argc, char **argv) {
|
|||
printf("------------------- build the last data\n");
|
||||
|
||||
mb->BuildEvents(1, 0, debug);
|
||||
//mb->PrintStat();
|
||||
|
||||
///----------- save to tree;
|
||||
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
|
||||
|
|
27
ClassData.h
27
ClassData.h
|
@ -42,6 +42,8 @@ class Data{
|
|||
unsigned short NumEventsDecoded [MaxNChannels]; /// reset at every decode
|
||||
unsigned short NumNonPileUpDecoded [MaxNChannels]; /// reset at every decode
|
||||
|
||||
unsigned int aggTime; /// update every decode
|
||||
|
||||
/// store data for event building and deduce the trigger rate.
|
||||
//it is a circular memory
|
||||
bool IsNotRollOverFakeAgg;
|
||||
|
@ -415,8 +417,8 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
if( verbose >= 1 ) printf("Board Agg Counter : %u \n", bdAggCounter & 0x7FFFFF);
|
||||
|
||||
nw = nw + 1;
|
||||
unsigned int bdAggTimeTag = ReadBuffer(nw, verbose);
|
||||
if( verbose >= 2 ) printf("Agg Time Tag : %u \n", bdAggTimeTag);
|
||||
aggTime = ReadBuffer(nw, verbose);
|
||||
if( verbose >= 1 ) printf("Agg Time Tag : %u \n", aggTime);
|
||||
|
||||
for( int chMask = 0; chMask < 8 ; chMask ++ ){ // the max numnber of Coupled/RegChannel is 8 for PHA, PSD, QDC
|
||||
if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue;
|
||||
|
@ -583,6 +585,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
case 7: printf("Reserved\n"); break;
|
||||
}
|
||||
}
|
||||
if( hasWaveForm ){
|
||||
printf("...... Analog Probe 1 : ");
|
||||
switch (analogProbe1 ){
|
||||
case 0 : printf("Input \n"); break;
|
||||
|
@ -615,6 +618,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nEvents = (aggSize - 2) / (nSample/2 + 2 + hasExtra2 );
|
||||
if( verbose >= 2 ) printf("----------------- nEvents : %d, fast decode : %d\n", nEvents, fastDecode);
|
||||
}else{
|
||||
|
@ -805,7 +809,7 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
if( hasExtra ){
|
||||
printf(".... extra : ");
|
||||
switch(extraOption){
|
||||
case 0: printf("[0:15] trapwzoid baseline * 4 [16:31] Extended timestamp (16-bit)\n"); break;
|
||||
case 0: printf("[0:15] baseline * 4 [16:31] Extended timestamp (16-bit)\n"); break;
|
||||
case 1: printf("[0:11] reserved [12] lost trigger counted [13] 1024 trigger counted [14] Over-range\n");
|
||||
printf("[15] trigger lost [16:31] Extended timestamp (16-bit)\n"); break;
|
||||
case 2: printf("[0:9] Fine time stamp [10:15] flag [10:15] Reserved [16:31] Extended timestamp (16-bit)\n"); break;
|
||||
|
@ -816,6 +820,7 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
case 7: printf("debug, must be 0x12345678\n"); break;
|
||||
}
|
||||
}
|
||||
if( hasWaveForm ){
|
||||
printf(".... digital Probe 1 : ");
|
||||
switch(digitalProbe1){
|
||||
case 0 : printf("Long gate \n"); break;
|
||||
|
@ -853,6 +858,10 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
}
|
||||
}
|
||||
|
||||
if( !hasExtra && !hasWaveForm) printf("\n");
|
||||
|
||||
}
|
||||
|
||||
nEvents = (aggSize -2) / (nSample/2 + 2 + hasExtra );
|
||||
if( verbose >= 2 ) printf("----------------- nEvents : %d, fast decode : %d\n", nEvents, fastDecode);
|
||||
|
||||
|
@ -912,6 +921,7 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
if( hasExtra ){
|
||||
nw = nw +1 ; word = ReadBuffer(nw, verbose);
|
||||
if( verbose > 2 ) printf("extra \n");
|
||||
extra = word;
|
||||
extTimeStamp = 0;
|
||||
if( extraOption == 0 || extraOption == 2 ) extTimeStamp = (extra >> 16);
|
||||
|
@ -960,10 +970,13 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
//if( DataIndex[channel] >= MaxNData ) ClearData();
|
||||
|
||||
if( verbose >= 2 ) printf("extra : 0x%08x, Qshort : %d, Qlong : %d \n", extra, Qshort, Qlong);
|
||||
|
||||
if( verbose >= 1 ) printf("ch : %2d, Qshort : %d, Qlong : %d, timestamp : %llu\n",
|
||||
//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",
|
||||
channel, Qshort, Qlong, timeStamp);
|
||||
if( verbose >= 2 ) printf("Qshort : %6d, Qlong : %6d, timestamp : %llu\n",
|
||||
Qshort, Qlong, timeStamp);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -998,6 +1011,7 @@ inline int Data::DecodeQDCGroupedChannelBlock(unsigned int ChannelMask, bool fas
|
|||
|
||||
if( verbose >= 2 ) {
|
||||
printf("Charge : %d, Time: %d, Wave : %d, Extra: %d\n", hasEnergy, hasTimeStamp, hasWaveForm, hasExtra);
|
||||
if( hasWaveForm ){
|
||||
printf(".... analog Probe (%d): ", analogProbe);
|
||||
switch(analogProbe){
|
||||
case 0 : printf("Input\n"); break;
|
||||
|
@ -1005,6 +1019,7 @@ inline int Data::DecodeQDCGroupedChannelBlock(unsigned int ChannelMask, bool fas
|
|||
case 2 : printf("Baseline\n"); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nEvents = (aggSize -2) / (nSample/2 + 2 + hasExtra );
|
||||
if( verbose >= 2 ) printf("----------------- nEvents : %d, fast decode : %d\n", nEvents, fastDecode);
|
||||
|
|
|
@ -8,6 +8,8 @@ MultiBuilder::MultiBuilder(Data ** multiData, std::vector<int> type, std::vector
|
|||
snList = sn;
|
||||
for( int i = 0; i < (int) type.size(); i++) idList.push_back(i);
|
||||
timeWindow = 100;
|
||||
leftOverTime = 100;
|
||||
breakTime = -1;
|
||||
ClearEvents();
|
||||
}
|
||||
|
||||
|
@ -18,6 +20,8 @@ MultiBuilder::MultiBuilder(Data * singleData, int type, int sn): nData(1){
|
|||
snList.push_back(sn);
|
||||
idList.push_back(0);
|
||||
timeWindow = 100;
|
||||
leftOverTime = 100;
|
||||
breakTime = -1;
|
||||
ClearEvents();
|
||||
}
|
||||
|
||||
|
@ -253,7 +257,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
for( int i = 0; i <(int) events[eventIndex].size(); i++){
|
||||
int chxxx = events[eventIndex][i].ch;
|
||||
int bd = events[eventIndex][i].bd;
|
||||
printf("%02d, %02d | %d | %5d %llu \n", bd, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp);
|
||||
printf("%02d, %02d | %5d | %5d %llu \n", bd, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp);
|
||||
}
|
||||
|
||||
if( nExhaushedCh == nData * MaxNChannels ) {
|
||||
|
@ -261,16 +265,20 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
|||
break;
|
||||
}
|
||||
printf("----- next bd : %d, ch : %d, next earlist Time : %llu.\n", earlistDigi, earlistCh, earlistTime);
|
||||
|
||||
printf("leftOver %llu, breakTime %llu \n", leftOverTime, breakTime);
|
||||
}
|
||||
|
||||
if( !isFinal && latestTime - earlistTime <= timeWindow ) {
|
||||
if( verbose ) {
|
||||
printf("######################### left over data for next build, latesTime : %llu.\n", latestTime);
|
||||
}
|
||||
if( !isFinal ){
|
||||
if( latestTime - earlistTime <= leftOverTime){
|
||||
if( verbose ) printf("######################### left over data for next build, latesTime : %llu. | leftOverTime : %llu\n", latestTime, leftOverTime);
|
||||
break;
|
||||
}
|
||||
|
||||
if( earlistTime > breakTime ) {
|
||||
if( verbose ) printf("######################### left over data for next build, earlistTime : %llu. | breakTime : %llu\n", earlistTime, breakTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}while(nExhaushedCh < nData * MaxNChannels);
|
||||
|
||||
}
|
||||
|
|
|
@ -45,8 +45,14 @@ public:
|
|||
MultiBuilder(Data * singleData, int type, int sn);
|
||||
~MultiBuilder();
|
||||
|
||||
void SetTimeWindow(int ticks) {timeWindow = ticks;}
|
||||
int GetTimeWindow() const{return timeWindow;}
|
||||
void SetTimeWindow(unsigned short ticks) {timeWindow = ticks;}
|
||||
unsigned short GetTimeWindow() const{return timeWindow;}
|
||||
|
||||
void SetLeftOverTime(unsigned long long ticks) {leftOverTime = ticks;}
|
||||
unsigned long long GetLeftOverTime() const{return leftOverTime;}
|
||||
|
||||
void SetBreakTime(unsigned long long ticks) {breakTime = ticks;}
|
||||
unsigned long long GetBreakTime() const{return breakTime;}
|
||||
|
||||
unsigned int GetNumOfDigitizer() const {return nData;}
|
||||
std::vector<int> GetDigiIDList() const {return idList;}
|
||||
|
@ -71,6 +77,8 @@ private:
|
|||
Data ** data; // assume all data has MaxNChannel (16)
|
||||
|
||||
unsigned short timeWindow;
|
||||
unsigned long long leftOverTime;
|
||||
unsigned long long breakTime; // timestamp for breaking the event builder
|
||||
int loopIndex[MaxNDigitizer][MaxNChannels];
|
||||
int nextIndex[MaxNDigitizer][MaxNChannels];
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user