#include #include #include #include // ROOT includes #include "TFile.h" #include "TObjectTable.h" #include "TROOT.h" #include "TTree.h" // user includes #include "TBEvent/Event.h" #include "TBEvent/TkrLayer.h" #define IN_PREFIX "run" #define OUT_PREFIX "zip" #define RUN "300" #define N_EVENT -1 int main ( int argc, char* argv[] ) { int c = 0; extern char* optarg; short helpFlag = 0; char inPrefix[] = IN_PREFIX; char outPrefix[] = OUT_PREFIX; char run[8] = RUN; int nEvent = N_EVENT; while ( ( c = getopt ( argc, argv, "r:n:h?") ) != EOF ) { switch ( c ) { case 'r': strncpy ( run, optarg, sizeof(optarg) ); break; case 'n': sscanf ( optarg, "%d", &nEvent ); break; case '?': helpFlag = 1; break; default: break; } } if ( helpFlag ) { cerr << endl << argv[0] << " [ -r # ] [ -n # ] [ -h ] [ -? ]" << endl; cerr << " Options:" << endl; cerr << "\t-r # the run number. Default: " << RUN << endl; cerr << "\t-n # the number of events to read. -1 means all events. Default: " << N_EVENT << endl; cerr << "\t-h -? this text." << endl << endl; exit(1); } Int_t maxVirtualSize = 8000000; // limits the amount of memory used for buffering. char file[128] = ""; strcat ( strcat ( strcpy ( file, inPrefix ), run ), ".root" ); TROOT rootSys ( "GLAST", "GLAST Event" ); // initializes ROOT. TFile* f = new TFile ( file, "read" ); // opens the data file for reading. TTree* T = (TTree*)f->Get("T"); // extracts the tree. T->SetMaxVirtualSize(maxVirtualSize); Event* event = new Event(); // defines the Event structure. T->SetBranchAddress ( "Event", &event ); // tells the tree to fill event of type Event into branch Event. T->SetBranchStatus ( "*", 0 ); // flag to disactivate all branches. T->SetBranchStatus ( "m_event", 1 ); // activates branch m_event. T->SetBranchStatus ( "m_TKR", 1 ); // activates branch m_TKR. char outFile[128] = ""; strcat ( strcat ( strcpy ( outFile, outPrefix ), run ), ".root" ); TFile* of = new TFile ( outFile, "recreate", "stripped test beam file" ); // opens a new data file for writing. TTree* oT = T->CloneTree(0); // clones the TTree. oT->Reset(); oT->SetMaxVirtualSize(maxVirtualSize); oT->SetAutoSave(maxVirtualSize); // autosaves when 8MB are written. oT->GetBranch("m_event")->SetFile(outFile); // diverts branch m_event to the new file. oT->GetBranch("m_TKR")->SetFile(outFile); // diverts branch m_TKR to the new file. gObjectTable->Print(); oT->CopyEntries( T, nEvent ); // copies the events. gObjectTable->Print(); // oT->Dump(); // dumps the Tree structure to the screen. of->Write(); // writes the buffers to the output file. delete of; // deletes the output file pointer. delete f; // deletes the input file pointer. }