Examples of Commissioning With FWLite

Find Events in a File

/*   A macro for printing the runs in a given file, with the number of events in each
*/

#include "DataFormats/FWLite/interface/Handle.h"
#include "DataFormats/FWLite/interface/Event.h"
#include "TFile.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TLegend.h"


#include <iostream>
#include <map>
using namespace std;

void printEvents_fwlite(const char * fname)
{

  TFile  * file = new TFile(fname);
  
  typedef std::map<edm::RunNumber_t, unsigned int> run_map;
  run_map runs;
  
  fwlite::Event ev(file);
  for( ev.toBegin();
       ! ev.atEnd();
       ++ev) {
    
    if ( runs.find(ev.id().run()) == runs.end() ) {
      runs[ev.id().run()] = 0;
    }    
    runs[ ev.id().run() ]++;
  } //end event loop     
  

  for ( run_map::const_iterator runsBegin = runs.begin(),
     runsEnd = runs.end(), runsIt = runsBegin;
   runsIt != runsEnd; ++runsIt ) {
    char buff[1000];
    sprintf( buff, "%12d : %12d",
        runsIt->first, runsIt->second );
    std::cout << buff << std::endl;
  }
}

-- SalvatoreRoccoRappoccio - 09-Nov-2009

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2009-11-09 - SalvatoreRRappoccio
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback