auto output root name

This commit is contained in:
Ryan Tang 2024-07-19 14:13:58 -04:00
parent ee2962d4f9
commit c78a327e25
2 changed files with 39 additions and 25 deletions

View File

@ -18,8 +18,8 @@ inline unsigned int getTime_us(){
#define MAX_TRACE_LENGTH 2000 #define MAX_TRACE_LENGTH 2000
#define MAX_MULTI 100 #define MAX_MULTI 100
#define NMINARG 5 #define NMINARG 4
#define debug 0 #define debug 0 // for > 1 number of hit to debug
//^############################################################# //^#############################################################
//^############################################################# //^#############################################################
@ -33,7 +33,7 @@ int main(int argc, char **argv) {
printf("%s [timeWindow] [withTrace] [outFile] [inFile1] [inFile2] .... \n", argv[0]); printf("%s [timeWindow] [withTrace] [outFile] [inFile1] [inFile2] .... \n", argv[0]);
printf(" timeWindow : in ns, -1 = no event building \n"); printf(" timeWindow : in ns, -1 = no event building \n");
printf(" withTrace : 0 for no trace, 1 for trace \n"); printf(" withTrace : 0 for no trace, 1 for trace \n");
printf(" outFile : output file name\n"); printf(" outFile : Automatics generated\n");
printf("\n"); printf("\n");
printf(" Example: %s -1 0 '\\ls -1 *001*.bin' (no event build, no trace, no verbose)\n", argv[0]); printf(" Example: %s -1 0 '\\ls -1 *001*.bin' (no event build, no trace, no verbose)\n", argv[0]);
printf(" %s 100 0 '\\ls -1 *001*.bin' (event build with 100 ns, no trace, no verbose)\n", argv[0]); printf(" %s 100 0 '\\ls -1 *001*.bin' (event build with 100 ns, no trace, no verbose)\n", argv[0]);
@ -47,20 +47,30 @@ int main(int argc, char **argv) {
///============= read input ///============= read input
long timeWindow = atoi(argv[1]); long timeWindow = atoi(argv[1]);
bool traceOn = atoi(argv[2]); bool traceOn = atoi(argv[2]);
TString outFileName = argv[3];
const int nFile = argc - NMINARG + 1; const int nFile = argc - NMINARG + 1;
TString inFileName[nFile]; TString inFileName[nFile];
for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i + NMINARG -1];} for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i + NMINARG -1];}
/// Form outFileName; /// Form outFileName;
// TString outFileName = inFileName[0]; int pos = inFileName[0].Last('_');
// int pos = outFileName.Last('/'); TString outFileName = "";
// pos = outFileName.Index("_", pos+1); // find next "_" if( pos == -1 ) {
// pos = outFileName.Index("_", pos+1); // find next "_" if( timeWindow < 0 ) {
// if( nFile == 1 ) pos = outFileName.Index("_", pos+1); // find next "_", S/N outFileName ="temp_single.root";
// outFileName.Remove(pos); // remove the rest }else{
// outFileName += "_" + ( timeWindow >= 0 ? std::to_string(timeWindow) : "single"); outFileName = "temp_" + std::to_string(timeWindow) + ".root";
// outFileName += ".root"; }
}else{
TString temp = inFileName[0];
temp.Remove(0, pos+1);
temp.Remove(3);
outFileName = "run" + temp;
if( timeWindow < 0 ) {
outFileName +="_single.root";
}else{
outFileName += "_" + std::to_string(timeWindow) + ".root";
}
}
printf("-------> Out file name : %s \n", outFileName.Data()); printf("-------> Out file name : %s \n", outFileName.Data());
printf("=========================================\n"); printf("=========================================\n");
@ -91,6 +101,7 @@ int main(int argc, char **argv) {
unsigned short e[MAX_MULTI] = {0}; unsigned short e[MAX_MULTI] = {0};
unsigned short e2[MAX_MULTI] = {0}; unsigned short e2[MAX_MULTI] = {0};
unsigned long long e_t[MAX_MULTI] = {0}; unsigned long long e_t[MAX_MULTI] = {0};
unsigned short e_f[MAX_MULTI] = {0};
unsigned short traceLength[MAX_MULTI]; unsigned short traceLength[MAX_MULTI];
short trace[MAX_MULTI][MAX_TRACE_LENGTH]; short trace[MAX_MULTI][MAX_TRACE_LENGTH];
@ -103,6 +114,7 @@ int main(int argc, char **argv) {
tree->Branch("e", e, "e[multi]/s"); tree->Branch("e", e, "e[multi]/s");
tree->Branch("e2", e2, "e2[multi]/s"); tree->Branch("e2", e2, "e2[multi]/s");
tree->Branch("e_t", e_t, "e_t[multi]/l"); tree->Branch("e_t", e_t, "e_t[multi]/l");
tree->Branch("e_f", e_f, "e_f[multi]/s");
tree->Branch("traceLength", traceLength, "traceLength[multi]/s"); tree->Branch("traceLength", traceLength, "traceLength[multi]/s");
if( traceOn ) { if( traceOn ) {
@ -142,7 +154,7 @@ int main(int argc, char **argv) {
// //find earliest time group; // //find earliest time group;
t0 = -1; t0 = -1;
for( short i = 0; i < nFile; i++){ for( short i = 0; i < nFile; i++){
if( debug ) printf("NNNN %d | ID: %lld, %lld, %lld \n", i, ID[i], reader[i].GetHitID(), reader[i].GetNumHit() ); if( debug ) printf("NNNNNNNNNNNNNNN %d | ID: %lld, %lld, %lld \n", i, ID[i], reader[i].GetHitID(), reader[i].GetNumHit() );
if( ID[i] + 1 >= reader[i].GetNumHit()) continue; if( ID[i] + 1 >= reader[i].GetNumHit()) continue;
// if( ID[i] >= reader[i].GetHitID() ) reader[i].ReadBlock(); // if( ID[i] >= reader[i].GetHitID() ) reader[i].ReadBlock();
if( debug ) reader[i].data.Print(); if( debug ) reader[i].data.Print();
@ -156,23 +168,22 @@ int main(int argc, char **argv) {
if( debug ) printf("First timestamp is %llu, file ID : %u\n", t0, g0); if( debug ) printf("First timestamp is %llu, file ID : %u\n", t0, g0);
for( short i = 0; i < nFile; i++){ for( short i = 0; i < nFile; i++){
short ig = (i + g0 ) % nFile;
if( ID[i] + 1 >= reader[ig].GetNumHit() ) continue; if( ID[i] + 1 >= reader[i].GetNumHit() ) continue;
if( timeWindow >= 0 ){ if( timeWindow >= 0 ){
do{ do{
if( (long int)( reader[ig].data.TimeStamp - t0) <= timeWindow ){ if( (long int)( reader[i].data.TimeStamp - t0) <= timeWindow ){
events.push_back(reader[ig].data); events.push_back(reader[i].data);
ID[ig] ++; ID[i] ++;
}else{ }else{
break; break;
} }
}while( reader[ig].ReadBlock() == 1 ); }while( reader[i].ReadBlock() == 1 );
}else{ }else{
events.push_back(reader[ig].data); events.push_back(reader[i].data);
ID[ig] ++; ID[i] ++;
reader[ig].ReadBlock(); reader[i].ReadBlock();
} }
if( timeWindow < 0) break; if( timeWindow < 0) break;
@ -203,7 +214,8 @@ int main(int argc, char **argv) {
ch[p] = events[p].Channel; ch[p] = events[p].Channel;
e[p] = events[p].Energy; e[p] = events[p].Energy;
e2[p] = events[p].Energy_short; e2[p] = events[p].Energy_short;
e_t[p] = events[p].TimeStamp; e_t[p] = events[p].TimeStamp / 1000;
e_f[p] = events[p].TimeStamp % 1000;
traceLength[p] = events[p].NSample; traceLength[p] = events[p].NSample;
if( traceOn ){ if( traceOn ){
@ -235,6 +247,8 @@ int main(int argc, char **argv) {
if( events.size() == 0 ) break; if( events.size() == 0 ) break;
if( debug > 1 && hitProcessed > debug ) break;
}while( nFileFinished < nFile ); }while( nFileFinished < nFile );
tree->Write(); tree->Write();

View File

@ -45,9 +45,9 @@ struct Data{
printf("header : 0x%X \n", Header); printf("header : 0x%X \n", Header);
printf(" Board : %u , Channel : %u\n", BoardID, Channel); printf(" Board : %u , Channel : %u\n", BoardID, Channel);
if( Header & 4 ) { if( Header & 4 ) {
printf("Energy : %u, Energy2 : %u, TimeStamp : %lu ps\n", Energy, Energy_short, TimeStamp); printf("Energy : %5u, Energy2 : %5u, TimeStamp : %16lu ps\n", Energy, Energy_short, TimeStamp);
}else{ }else{
printf("Energy : %u, TimeStamp : %lu ps\n", Energy, TimeStamp); printf("Energy : %5u, TimeStamp : %16lu ps\n", Energy, TimeStamp);
} }
printf(" Flag : 0x%X\n", Flags); printf(" Flag : 0x%X\n", Flags);
if( (Header & 0x8 ) >= 1 ){ /// is waevform exist if( (Header & 0x8 ) >= 1 ){ /// is waevform exist