added Mapping.h and SolReader.h

This commit is contained in:
Ryan Tang 2023-03-17 15:16:57 -04:00
parent df348af0ff
commit 3c06492cee
6 changed files with 458 additions and 5 deletions

18
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/x86_64-linux-gnu/qt6/**",
"/opt/root/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}

159
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,159 @@
{
"files.associations": {
"script.C": "cpp",
"SOLARIS_Qt6_DAQ.pro": "makefile",
"qlineseries": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"qdatetime": "cpp",
"fstream": "cpp",
"allocator": "cpp",
"qsignalmapper": "cpp"
},
"better-comments.multilineComments": true,
"better-comments.tags" : [
{
"tag": "!",
"color": "#FF2D00",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "?",
"color": "#0076FF",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "@",
"color": "#00F8FF",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "/",
"color": "#00A0FF",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "//",
"color": "#474747",
"strikethrough": true,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "^",
"color": "#EAF622",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "*",
"color": "#28FF00",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "&",
"color": "#FF06A0",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "~",
"color": "#BE00FF",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "todo",
"color": "#FF8C00",
"strikethrough": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
}
]
}

42
Mapping.h Normal file
View File

@ -0,0 +1,42 @@
//^===============================================================================
//^ This is mapping file for SOLARIS
//^ This file is used to constructe the SOLARIS panel in the SOLARIS DAQ
//^ If this file is modified, please Close Digitizer and Open again
//^-------------------------------------------------------------------------------
//^
//^ Array : 0 - 199
//^ Recoil : 200 - 299
//^
//^
//^===============================================================================
#define NARRAY 60
#define NRDT 10
#define PARITYARRAY 1
#define PARITYRDT 1
#define NDIGITIZER 2
#define NCHANNEL 64 // number of channel per digitizer
int mapping[NDIGITIZER][NCHANNEL] = {
{
//* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove
0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, /// 0 - 15
5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, /// 16 - 31
10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, /// 32 - 47
16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, -1 /// 48 - 63
//*------------- end of a digitizer // this line is an indicator DON'T Remove
},
{
//* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove
21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, /// 0 - 15
26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31, /// 16 - 31
31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, /// 32 - 47
37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, -1 /// 48 - 63
//*------------- end of a digitizer // this line is an indicator DON'T Remove
}
};
//& if all array is arrange like this, no need kind mapping. it is always e, xf, xn

234
SolReader.h Normal file
View File

@ -0,0 +1,234 @@
#ifndef SOLREADER_H
#define SOLREADER_H
#include <stdio.h> /// for FILE
#include <cstdlib>
#include <string>
#include <vector>
#include <unistd.h>
#include <time.h> // time in nano-sec
#include "../SOLARIS_QT6_DAQ/Event.h"
class SolReader {
private:
FILE * inFile;
unsigned int inFileSize;
unsigned int filePos;
unsigned int totNumBlock;
unsigned short blockStartIdentifier;
unsigned int numBlock;
bool isScanned;
void init();
std::vector<unsigned int> blockPos;
public:
SolReader();
SolReader(std::string fileName, unsigned short dataType);
~SolReader();
void OpenFile(std::string fileName);
int ReadNextBlock(int opt = 0); // opt = 0, noraml, 1, fast
int ReadBlock(unsigned int index);
void ScanNumBlock();
unsigned int GetNumBlock() {return numBlock;}
unsigned int GetTotalNumBlock() {return totNumBlock;}
unsigned int GetFilePos() {return filePos;}
unsigned int GetFileSize() {return inFileSize;}
void RewindFile();
Event * evt;
};
void SolReader::init(){
inFileSize = 0;
numBlock = 0;
filePos = 0;
totNumBlock = 0;
evt = new Event();
isScanned = false;
blockPos.clear();
}
SolReader::SolReader(){
init();
}
SolReader::SolReader(std::string fileName, unsigned short dataType = 0){
init();
OpenFile(fileName);
evt->SetDataType(dataType);
}
SolReader::~SolReader(){
if( !inFile ) fclose(inFile);
delete evt;
}
inline void SolReader::OpenFile(std::string fileName){
inFile = fopen(fileName.c_str(), "r");
if( inFile == NULL ){
printf("Cannot open file : %s \n", fileName.c_str());
}else{
fseek(inFile, 0L, SEEK_END);
inFileSize = ftell(inFile);
rewind(inFile);
}
}
inline int SolReader::ReadBlock(unsigned int index){
if( isScanned == false) return -1;
if( index >= totNumBlock )return -1;
fseek(inFile, 0L, SEEK_SET);
printf("-----------%u, %u\n", index, blockPos[index]);
fseek(inFile, blockPos[index], SEEK_CUR);
numBlock = index;
return ReadNextBlock();
}
inline int SolReader::ReadNextBlock(int opt){
if( inFile == NULL ) return -1;
if( feof(inFile) ) return -1;
if( filePos >= inFileSize) return -1;
fread(&blockStartIdentifier, 2, 1, inFile);
if( (blockStartIdentifier & 0xAAA0) != 0xAAA0 ) {
printf("header fail.\n");
return -2 ;
}
if( ( blockStartIdentifier & 0xF ) == 15 ){
evt->SetDataType(15);
}
evt->dataType = blockStartIdentifier & 0xF;
if( evt->dataType == 0){
if( opt == 0 ){
fread(&evt->channel, 1, 1, inFile);
fread(&evt->energy, 2, 1, inFile);
fread(&evt->timestamp, 6, 1, inFile);
fread(&evt->fine_timestamp, 2, 1, inFile);
fread(&evt->flags_high_priority, 1, 1, inFile);
fread(&evt->flags_low_priority, 2, 1, inFile);
fread(&evt->downSampling, 1, 1, inFile);
fread(&evt->board_fail, 1, 1, inFile);
fread(&evt->flush, 1, 1, inFile);
fread(&evt->trigger_threashold, 2, 1, inFile);
fread(&evt->event_size, 8, 1, inFile);
fread(&evt->aggCounter, 4, 1, inFile);
}else{
fseek(inFile, 31, SEEK_CUR);
}
fread(&evt->traceLenght, 8, 1, inFile);
if( opt == 0){
fread(evt->analog_probes_type, 2, 1, inFile);
fread(evt->digital_probes_type, 4, 1, inFile);
fread(evt->analog_probes[0], evt->traceLenght*4, 1, inFile);
fread(evt->analog_probes[1], evt->traceLenght*4, 1, inFile);
fread(evt->digital_probes[0], evt->traceLenght, 1, inFile);
fread(evt->digital_probes[1], evt->traceLenght, 1, inFile);
fread(evt->digital_probes[2], evt->traceLenght, 1, inFile);
fread(evt->digital_probes[3], evt->traceLenght, 1, inFile);
}else{
fseek(inFile, 6 + evt->traceLenght*(12), SEEK_CUR);
}
}else if( evt->dataType == 1){
if( opt == 0 ){
fread(&evt->channel, 1, 1, inFile);
fread(&evt->energy, 2, 1, inFile);
fread(&evt->timestamp, 6, 1, inFile);
fread(&evt->fine_timestamp, 2, 1, inFile);
fread(&evt->flags_high_priority, 1, 1, inFile);
fread(&evt->flags_low_priority, 2, 1, inFile);
}else{
fseek(inFile, 14, SEEK_CUR);
}
fread(&evt->traceLenght, 8, 1, inFile);
if( opt == 0){
fread(&evt->analog_probes_type[0], 1, 1, inFile);
fread(evt->analog_probes[0], evt->traceLenght*4, 1, inFile);
}else{
fseek(inFile, 1 + evt->traceLenght*4, SEEK_CUR);
}
}else if( evt->dataType == 2){
if( opt == 0 ){
fread(&evt->channel, 1, 1, inFile);
fread(&evt->energy, 2, 1, inFile);
fread(&evt->timestamp, 6, 1, inFile);
fread(&evt->fine_timestamp, 2, 1, inFile);
fread(&evt->flags_high_priority, 1, 1, inFile);
fread(&evt->flags_low_priority, 2, 1, inFile);
}else{
fseek(inFile, 14, SEEK_CUR);
}
}else if( evt->dataType == 3){
if( opt == 0 ){
fread(&evt->channel, 1, 1, inFile);
fread(&evt->energy, 2, 1, inFile);
fread(&evt->timestamp, 6, 1, inFile);
}else{
fseek(inFile, 9, SEEK_CUR);
}
}else if( evt->dataType == 15){
fread(&evt->dataSize, 8, 1, inFile);
if( opt == 0){
fread(evt->data, evt->dataSize, 1, inFile);
}else{
fseek(inFile, evt->dataSize, SEEK_CUR);
}
}
numBlock ++;
filePos = ftell(inFile);
return 0;
}
void SolReader::RewindFile(){
rewind(inFile);
filePos = 0;
numBlock = 0;
}
void SolReader::ScanNumBlock(){
if( inFile == NULL ) return;
if( feof(inFile) ) return;
numBlock = 0;
blockPos.clear();
blockPos.push_back(0);
while( ReadNextBlock(1) == 0){
blockPos.push_back(filePos);
printf("%u, %.2f%% %u/%u\n\033[A\r", numBlock, filePos*100./inFileSize, filePos, inFileSize);
}
totNumBlock = numBlock;
numBlock = 0;
isScanned = true;
printf("\nScan complete: number of data Block : %u\n", totNumBlock);
rewind(inFile);
filePos = 0;
//for( int i = 0; i < totNumBlock; i++){
// printf("%7d | %u \n", i, blockPos[i]);
//}
}
#endif

View File

@ -1 +1 @@
/mnt/data0/haha
/mnt/data0/Master

View File

@ -1,5 +1,5 @@
expName=haha
rawDataPath=/mnt/data0/haha
expName=Master
rawDataPath=/mnt/data0/Master
runID=-1
elogID=0
//------------end of file.
elogID=-1
//------------end of file.