added FSU2ROOT.cpp, a simple convertor
This commit is contained in:
parent
a4b6db4140
commit
cb1aac16df
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,6 +12,7 @@ DataReaderScript
|
|||
DataReader
|
||||
pid.dat
|
||||
DAQLock.dat
|
||||
FSU2ROOT
|
||||
|
||||
data
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ void DataReader(std::string fileName, int DPPType){
|
|||
fseek(haha, 0, SEEK_SET);
|
||||
|
||||
MultiBuilder * mb = new MultiBuilder(data, DPPType);
|
||||
mb->SetTimeWindow(0);
|
||||
|
||||
char * buffer = nullptr;
|
||||
int countBdAgg = 0;
|
||||
|
@ -60,11 +61,12 @@ void DataReader(std::string fileName, int DPPType){
|
|||
//if( countBdAgg % 100 == 0) data->PrintStat();
|
||||
//data->ClearData();
|
||||
|
||||
//if( countBdAgg > 500 ){
|
||||
// data->PrintAllData();
|
||||
// mb->BuildEventsBackWard(false);
|
||||
// break;
|
||||
//}
|
||||
if( countBdAgg > 10 ){
|
||||
//data->PrintAllData();
|
||||
|
||||
mb->BuildEvents(false, true, false);
|
||||
//mb->BuildEventsBackWard(false);
|
||||
}
|
||||
|
||||
|
||||
}while(!feof(haha) && ftell(haha) < inFileSize);
|
||||
|
@ -74,8 +76,9 @@ void DataReader(std::string fileName, int DPPType){
|
|||
data->PrintStat();
|
||||
//data->PrintAllData();
|
||||
|
||||
mb->BuildEvents(true, true, false);
|
||||
|
||||
//mb->PrintStat();
|
||||
mb->PrintStat();
|
||||
|
||||
delete mb;
|
||||
delete data;
|
||||
|
|
188
FSU2ROOT.cpp
Normal file
188
FSU2ROOT.cpp
Normal file
|
@ -0,0 +1,188 @@
|
|||
/*************
|
||||
|
||||
This can be loaded to root and run the DataReader()
|
||||
|
||||
***********/
|
||||
|
||||
#include "ClassData.h"
|
||||
#include "MultiBuilder.h"
|
||||
|
||||
#include "TROOT.h"
|
||||
#include "TFile.h"
|
||||
#include "TTree.h"
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
printf("=========================================\n");
|
||||
printf("=== *.fsu to root ===\n");
|
||||
printf("=========================================\n");
|
||||
if (argc <= 3) {
|
||||
printf("Incorrect number of arguments:\n");
|
||||
printf("%s [list of inFile\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
///============= read input
|
||||
int nFile = argc - 1;
|
||||
TString inFileName[nFile];
|
||||
for( int i = 0 ; i < nFile ; i++){
|
||||
inFileName[i] = argv[i+1];
|
||||
}
|
||||
|
||||
/// Form outFileName;
|
||||
TString outFileName = inFileName[0];
|
||||
int pos = outFileName.Last('/');
|
||||
outFileName.Remove(0,pos+1);
|
||||
pos = outFileName.Index("_");
|
||||
pos = outFileName.Index("_", pos+1);
|
||||
outFileName.Remove(pos);
|
||||
outFileName += "_single.root";
|
||||
printf("-------> Out file name : %s \n", outFileName.Data());
|
||||
|
||||
|
||||
printf(" Number of Files : %d \n", nFile);
|
||||
|
||||
printf("===================================== input files:\n");
|
||||
|
||||
///============= sorting file by the serial number & order
|
||||
int ID[nFile]; /// serial+ order*1000;
|
||||
int type[nFile];
|
||||
unsigned int fileSize[nFile];
|
||||
for( int i = 0; i < nFile; i++){
|
||||
int pos = inFileName[i].Last('/');
|
||||
int snPos = inFileName[i].Index("_", pos); // first "_"
|
||||
//snPos = inFileName[i].Index("_", snPos + 1);
|
||||
int sn = atoi(&inFileName[i][snPos+5]);
|
||||
TString typeStr = &inFileName[i][snPos+9];
|
||||
typeStr.Resize(3);
|
||||
|
||||
if( typeStr == "PHA" ) type[i] = V1730_DPP_PHA_CODE;
|
||||
if( typeStr == "PSD" ) type[i] = V1730_DPP_PSD_CODE;
|
||||
|
||||
int order = atoi(&inFileName[i][snPos+13]);
|
||||
ID[i] = sn + order * 1000;
|
||||
|
||||
FILE * temp = fopen(inFileName[i].Data(), "rb");
|
||||
if( temp == NULL ) {
|
||||
fileSize[i] = 0;
|
||||
}else{
|
||||
fseek(temp, 0, SEEK_END);
|
||||
fileSize[i] = ftell(temp);
|
||||
}
|
||||
fclose(temp);
|
||||
}
|
||||
|
||||
for( int i = 0; i < nFile; i++) printf("%2d | %s %d %d %u\n", i, inFileName[i].Data(), ID[i], type[i], fileSize[i]);
|
||||
|
||||
//*======================================= open raw files
|
||||
printf("##############################################\n");
|
||||
|
||||
FILE ** inFile = new FILE *[nFile];
|
||||
Data ** data = new Data *[nFile];
|
||||
for( int i = 0; i < nFile; i++){
|
||||
inFile[i] = fopen(inFileName[i].Data(), "r");
|
||||
if( inFile[i] ){
|
||||
data[i] = new Data();
|
||||
data[i]->DPPType = type[i];
|
||||
data[i]->boardSN = ID[i]%1000;
|
||||
}else{
|
||||
data[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char * buffer = nullptr;
|
||||
|
||||
unsigned int word[1]; /// 4 bytes
|
||||
|
||||
//============ tree
|
||||
TFile * rootFile = new TFile(outFileName, "recreate");
|
||||
TTree * tree = new TTree("tree", outFileName);
|
||||
|
||||
unsigned short bd;
|
||||
unsigned short ch;
|
||||
unsigned short e;
|
||||
unsigned long long e_t;
|
||||
|
||||
tree->Branch("bd", &bd, "bd/s");
|
||||
tree->Branch("ch", &ch, "ch/s");
|
||||
tree->Branch("e", &e, "e/s");
|
||||
tree->Branch("e_t", &e_t, "e_t/l");
|
||||
|
||||
|
||||
//============
|
||||
for( int i = 0; i < nFile; i++){
|
||||
if( inFile[i] == nullptr ) continue;
|
||||
|
||||
MultiBuilder * mb = new MultiBuilder(data[i], type[i]);
|
||||
mb->SetTimeWindow(0);
|
||||
int countBdAgg = 0;
|
||||
|
||||
do{
|
||||
|
||||
//long fPos1 = ftell(inFile[i]);
|
||||
size_t dummy = fread(word, 4, 1, inFile[i]);
|
||||
if( dummy != 1) {
|
||||
printf("fread error, should read 4 bytes, but read %ld x 4 byte, file pos: %ld byte\n", dummy, ftell(inFile[i]));
|
||||
break;
|
||||
}
|
||||
|
||||
fseek(inFile[i], -4, SEEK_CUR);
|
||||
short header = ((word[0] >> 28 ) & 0xF);
|
||||
if( header != 0xA ) break;
|
||||
|
||||
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
||||
buffer = new char[aggSize];
|
||||
dummy = fread(buffer, aggSize, 1, inFile[i]);
|
||||
if( dummy != 1) {
|
||||
printf("fread error, should read %d bytes, but read %ld x %d byte, file pos: %ld byte \n", aggSize, dummy, aggSize, ftell(inFile[i]));
|
||||
break;
|
||||
}
|
||||
|
||||
//long fPos2 = ftell(inFile[i]);
|
||||
|
||||
countBdAgg ++;
|
||||
// printf("Board Agg. has %d word = %d bytes | %ld - %ld\n", aggSize/4, aggSize, fPos1, fPos2);
|
||||
// printf("==================== %d Agg\n", countBdAgg);
|
||||
|
||||
data[i]->DecodeBuffer(buffer, aggSize, false, 0); // data own the buffer
|
||||
data[i]->ClearBuffer(); // this will clear the buffer.
|
||||
|
||||
//============ save data into tree
|
||||
mb->BuildEvents(true);
|
||||
|
||||
for(int k = 0; k < mb->eventBuilt; k++){
|
||||
bd = ID[i]%1000;
|
||||
ch = mb->events[k][0].ch;
|
||||
e = mb->events[k][0].energy;
|
||||
e_t = mb->events[k][0].timestamp;
|
||||
|
||||
tree->Fill();
|
||||
}
|
||||
|
||||
mb->ClearEvents();
|
||||
data[i]->ClearData();
|
||||
|
||||
|
||||
}while(!feof(inFile[i]) && ftell(inFile[i]) < fileSize[i]);
|
||||
fclose(inFile[i]);
|
||||
|
||||
printf("================ %s done | Total Agg. %d\n", inFileName[i].Data(), countBdAgg);
|
||||
//data[i]->PrintStat();
|
||||
//data->PrintAllData();
|
||||
|
||||
//mb->BuildEvents(true, true, false);
|
||||
//mb->PrintStat();
|
||||
|
||||
|
||||
delete mb;
|
||||
|
||||
}
|
||||
|
||||
tree->Write();
|
||||
tree->Print();
|
||||
rootFile->Close();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
|
|||
|
||||
OBJS = ClassDigitizer.o MultiBuilder.o
|
||||
|
||||
ALL = test test_indep DataGenerator EventBuilder DataReader
|
||||
ALL = test test_indep DataGenerator EventBuilder DataReader FSU2ROOT
|
||||
|
||||
#########################################################################
|
||||
|
||||
|
@ -37,7 +37,7 @@ test_indep : test_indep.cpp RegisterAddress.h macro.h
|
|||
@echo "--------- making test_indep"
|
||||
$(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS)
|
||||
|
||||
DataGenerator : DataGenerator.cpp ClassDigitizer.o
|
||||
DataGenerator : DataGenerator.cpp ClassDigitizer.o
|
||||
@echo "--------- making DataGenerator"
|
||||
$(CC) $(COPTS) -o DataGenerator DataGenerator.cpp ClassDigitizer.o $(CAENLIBS)
|
||||
|
||||
|
@ -48,3 +48,7 @@ DataReader : DataReaderScript.cpp ClassData.h MultiBuilder.o
|
|||
EventBuilder : EventBuilder.cpp ClassData.h MultiBuilder.o
|
||||
@echo "--------- making EventBuilder"
|
||||
$(CC) $(COPTS) -o EventBuilder EventBuilder.cpp MultiBuilder.o $(CAENLIBS) $(ROOTLIBS)
|
||||
|
||||
FSU2ROOT : FSU2ROOT.cpp ClassData.h MultiBuilder.o
|
||||
@echo "--------- making FSU2ROOT"
|
||||
$(CC) $(COPTS) -o FSU2ROOT FSU2ROOT.cpp ClassData.h MultiBuilder.o $(CAENLIBS) $(ROOTLIBS)
|
||||
|
|
Loading…
Reference in New Issue
Block a user