#include <TROOT.h>#include <TFile.h>#include <TTree.h>#include "pmt_waveform.hh"Go to the source code of this file.
Functions | |
| int | main () |
| int main | ( | ) |
Definition at line 6 of file AnaProcess/DataFormat/bin/simple_io.cc.
References pmt_wf_collection::event_id(), and pmt_wf_collection::set_event_id().
00006 { 00007 00008 // 00009 // Simple routine to make sure data format class can be written in/out. 00010 // 00011 00012 // Event ID for testing. 00013 int event_id=1234; 00014 00015 // 00016 // Step 1: write out an empty event. 00017 // 00018 00019 // Create an empty data 00020 pmt_wf_collection* data=new pmt_wf_collection(); 00021 data->set_event_id(event_id); 00022 00023 // Save in TTree & File. 00024 TFile *fout=TFile::Open("tmp.root","RECREATE"); 00025 TTree *tree=new TTree("tmp_tree",Form("Tree For %s",data->GetName())); 00026 tree->Branch(data->GetName(),data->GetName(),&data); 00027 tree->Fill(); 00028 tree->Write(); 00029 fout->Close(); 00030 00031 std::cout 00032 << "Saved Tree..." << std::endl 00033 << "Setting the in-memory event id to something else..." << std::endl; 00034 data->set_event_id(4321); 00035 00036 // 00037 // Step 2: read out the event from the saved file. 00038 // 00039 00040 TFile *fin=TFile::Open("tmp.root","READ"); 00041 tree = (TTree*)(fin->Get("tmp_tree")); 00042 tree->SetBranchAddress(data->GetName(),&data); 00043 tree->GetEntry(0); 00044 00045 std::cout 00046 << Form("Reading event id from tree: %d", data->event_id()) 00047 << std::endl; 00048 00049 int return_val=0; 00050 if(data->event_id()==event_id) { 00051 std::cout << "SUCCESS!" << std::endl; 00052 return_val=0; 00053 }else{ 00054 std::cout << "FAILURE!" << std::endl; 00055 return_val=1; 00056 } 00057 00058 std::cout<<"Removing a tmporary file..."<<std::endl; 00059 gROOT->ProcessLine(".! rm tmp.root;"); 00060 00061 return return_val; 00062 }
1.4.7