simple_loop.cc

Go to the documentation of this file.
00001 #include <TSystem.h>
00002 #include <storage_manager.hh>
00003 #include <constants.hh>
00004 
00005 int main(){
00006 
00007   //
00008   // A simple routine to read a data file and perform an event loop.
00009   // This is a test routine for storage_manager class which interacts
00010   // decoder output root file. 
00011   //
00012 
00013   storage_manager kazu;
00014 
00015   // If you wish, change the message level to DEBUG.
00016   // Commented out by default.
00017   kazu.set_verbosity(MSG::DEBUG);
00018   
00019 
00020   // Step 0: Set I/O mode: we are reading in, so "READ"
00021   kazu.set_io_mode(storage_manager::READ);
00022 
00023   // Step 1: Set input file 
00024   kazu.add_in_filename(Form("%s/dat/sample.root",gSystem->Getenv("ANA_PROC_DIR")));
00025 
00026   // Step 2: Open a file.
00027   kazu.open();
00028 
00029   // Step 3: Check if a file is opened.
00030   if(!kazu.is_open()) {
00031     std::cerr << "File open failed!" << std::endl;
00032     return 0;
00033   }
00034   
00035   // Step 4: Check if it's ready to perform I/O
00036   if(!kazu.is_ready_io()) {
00037     std::cerr << "I/O preparation failed!" << std::endl;
00038   }
00039 
00040   //
00041   // Done preparation. Ready to perform an event loop.
00042   // We can read events indefinitely until we reach EOF by calling
00043   // storage_manager::next_event() function. This function returns
00044   // true upon successful read-in. It returns false if the retrieved
00045   // event is the last event entry in the input file.
00046   //
00047   // FYI: Step 2 to 4 can be ignored if you simply call next_event()
00048   //      function actually. next_event() function calls open() function
00049   //      if file is not yet opened. Above steps 2 to 4 are really just
00050   //      explicit testing purpose.
00051   //
00052 
00053   // Let's count # of events, and maybe loop over ADC samples to get the
00054   // highest ADC count.
00055   //pmt_wf_collection* data=0;
00056   int ctr=0;
00057   int highest_adc=-1;
00058   int highest_adc_pmt=-1;
00059   while(kazu.next_event()){
00060 
00061     ctr++;
00062     pmt_wf_collection *data=(pmt_wf_collection*)(kazu.get_data(DATA_STRUCT::PMT_WF_COLLECTION));
00063 
00064     // Let's loop over pmt-wise information. You can access this using
00065     // a index number such as data[0] to access the 1st entry. But here
00066     // I use an iterator.
00067     for(pmt_wf_collection::const_iterator pmt_iter(data->begin());
00068     pmt_iter!=data->end();
00069     ++pmt_iter) {
00070 
00071       // Now you have pmt_waveform object in "(*pmt_iter)" expression!
00072       // Let's loop over ADC count in THIS PMT's waveform.
00073       for(pmt_waveform::const_iterator adc_iter((*pmt_iter).begin());
00074       adc_iter!=(*pmt_iter).end();
00075       ++adc_iter){
00076     if((*adc_iter) > highest_adc){
00077       std::cout 
00078         << Form("Found a new highest adc count: %d (Ch=%-3d)",
00079             (*adc_iter),(*pmt_iter).channel_number())
00080         << std::endl;
00081       highest_adc=(*adc_iter);
00082       highest_adc_pmt=(*pmt_iter).channel_number();
00083     }
00084       }// end of adc sample looping in THIS PMT.
00085     }// end of pmt_waveform looping in THIS event.
00086   }// end of event loop.
00087 
00088   std::cout 
00089     << std::endl
00090     << ctr << " events retrieved!" << std::endl
00091     << "Ch. " << highest_adc_pmt << " had the highest adc count: " << highest_adc
00092     << std::endl << std::endl;
00093 
00094   kazu.close();
00095   return 1;
00096 }
00097 
00098 

Generated on Mon Apr 7 15:35:12 2014 for MyProject by  doxygen 1.4.7