// // To compile this code run: g++ -Wall -std=c++11 -o candle2root candle2root.cpp `root-config --cflags --glibs` -lSpectrum // #include #include #include "TROOT.h" #include "TFile.h" #include "TTree.h" #include "TH1.h" #define NSIGMAX 500 //#include //#include #include #include #include #include "COMMON.h" using namespace std; void expand (datapackptr inbuf, datapackptr outbuf); int32 debug=0; datapack buf, readbuf; int32 process_event_block (datapackptr rdbuf) { expand (rdbuf, &buf); if (debug) { unsigned i, k; //printf ("eventSize=%d. eventsPerBlock=%d compressedSize=%d words\n", // rdbuf->header.unitsize, rdbuf->header.number_of_units, // rdbuf->header.size_in_bytes / 2); for (k=0; k= 2) { strcpy (filename, argv [1]); if (argc > 2) debug = 1; } else { cerr<< endl<< "Usage: candle2root candleFile.0* \n" <Branch(sig_name[br_loop], &signals[br_loop],sig_format[br_loop]); //Added by AYDeo..from here infile>>nm; his[br_loop]=new TH1F(nm,nm,16384,0.,16384.); //..upto here }//each signal made_branches=1; }//made the branches switch (buf.header.block) { case datarate : memcpy (&rate, &readbuf, sizeof (ratepack)); if (prevBlock != event) break; dcr = rate.evn_during_thisblock; if (rate.time_for_thisblock > 0) dcr /= rate.time_for_thisblock; icr = rate.evn_since_start; if (rate.time_since_start > 0) icr /= rate.time_since_start; //printf ("%c[1;35m%8ld blocks in %.2lf sec ", // 27, num_ev_blocks, rate.time_since_start*1e-3); //printf (" DCR=%.2lf KE/s ICR=%.2lf KE/s%c[0;39m\r", // dcr, icr, 27); fflush (stdout); break; case event: ++num_ev_blocks; num_events += process_event_block (&readbuf); for (unsigned int k=0; k 0) his[i]->Fill(signals[i]); //AYDeo //if((i==0) && (data!=0)) return(-1);; } CandleTree->Fill(); //fprintf (stdout, "\n"); } if (! blockSize) { blockSize = num_events; eventSize = readbuf.header.unitsize; } break; case hgram: if (prevBlock != hgram) { printf ("\n"); singID = 0; } printf ("\nMCA-%02d : Size = %d (TimeSinceRunStart=%d mins)\n", ++singID, readbuf.header.unitsize, (int32) (rate.time_since_start/ONE_MINUTE)); break; case scaler: printf ("\n--- SCALER BLOCK BEGIN ---\n"); printf ("%s\n", (char *) readbuf.data); printf ("--- SCALER BLOCK END ---\n"); break; case start: printf ("\n--- START BLOCK BEGIN ---\n"); printf ("%s", (char *) readbuf.data); printf ("--- START BLOCK END ---\n\n"); break; case stop: printf ("\n\n--- STOP BLOCK BEGIN ---\n"); printf ("%s", (char *) readbuf.data); printf ("--- STOP BLOCK END ---\n\n"); break; case Pause: printf ("\n--- PAUSE BLOCK BEGIN ---\n"); printf ("%s\n", (char *) readbuf.data); printf ("--- PAUSE BLOCK END ---\n"); break; case resume: printf ("\n--- RESUME BLOCK BEGIN START ---\n"); printf ("%s\n",(char *) readbuf.data); printf ("--- RESUME BLOCK END ---\n"); break; case names: printf ("\n--- NAMES BLOCK BEGIN ---\n"); printf ("%s", (char *) readbuf.data); printf ("--- NAMES BLOCK END ---\n"); sscanf((char *)readbuf.data,"%s %d",&sig_name[0][0],&n_signals); for(int br_loop=0;br_loopPrint(); OutFile->Write(); inFile.close(); return 0; } void expand(datapackptr inbuf, datapackptr outbuf) { int32 nwords = inbuf->header.number_of_units * inbuf->header.unitsize; int16ptr dstart,wrtptr,rdptr,patptr; int32 i, numpats; unsigned short mask; if (inbuf->header.block != event) { memcpy (outbuf, inbuf, inbuf->size); return; } memset (outbuf, 0, sizeof (datapack)); numpats = nwords / 16; if (nwords % 16) ++numpats; rdptr = inbuf->data + numpats; patptr = inbuf->data; dstart = wrtptr = outbuf->data; mask = 1; for (i=0; iheader.block = inbuf->header.block; outbuf->header.number_of_units = inbuf->header.number_of_units; outbuf->header.unitsize = inbuf->header.unitsize; outbuf->header.compstatus = 0; outbuf->header.size_in_bytes = 2 * inbuf->header.number_of_units * inbuf->header.unitsize; }