CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FWCore/Skeletons/scripts/mkTemplates/TSelector/tselector.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    tselname
00004 // Class:      tselname
00005 // 
00006 /*
00007 
00008  Description: [one line class summary]
00009 
00010  Implementation:
00011      [Notes on implementation]
00012 */
00013 //
00014 // Original Author:  John Doe
00015 //         Created:  day-mon-xx
00016 // RCS(Id)
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <iostream>
00024 
00025 #include "TCanvas.h"
00026 // user include files
00027 #include "skelsubsys/tselname/src/tselname.h"
00028 #include "DataFormats/Common/interface/Handle.h"
00029 #include "FWCore/Framework/interface/Event.h"
00030 
00031 @example_track #include "DataFormats/TrackReco/interface/Track.h"
00032 //
00033 // constants shared between the Selector and the Workers
00034 //
00035 @example_track const char* const kPt = "pt";
00036 //const char* const kA = "a";
00037 
00038 //===============================================
00039 //A worker processes the events.
00040 // A new worker is created each time the events are processed
00041 //===============================================
00042 
00043 // ------------ constructed for each PROOF Node  ------------
00044 // The arguments are
00045 //   fromSelector: these are copies of values set in the selector and sent to all workers
00046 //            out: these are the items which will be passed back to the selector (e.g. histograms)
00047 tselnameWorker::tselnameWorker(const TList* fromSelector, TList& out ) {
00048   //h_a  = new TH1F( kA , "a"  , 100,  0, 20 );
00049   //out.Add(h_a);  
00050 @example_track  h_pt = new TH1F(kPt, "P_t",100,0,100);
00051 @example_track  out.Add(h_pt);
00052 }
00053 
00054 tselnameWorker::~tselnameWorker()
00055 {
00056 }
00057 // ------------ method called for each event  ------------
00058 void 
00059 tselnameWorker::process( const edm::Event& iEvent ) {
00060   using namespace edm;
00061 @example_track    using reco::TrackCollection;
00062   
00063 @example_track    Handle<TrackCollection> tracks;
00064 @example_track    iEvent.getByLabel("ctfWithMaterialTracks",tracks);
00065 @example_track    for(TrackCollection::const_iterator itTrack = tracks->begin();
00066 @example_track        itTrack != tracks->end();                      
00067 @example_track        ++itTrack) {
00068 @example_track       h_pt->Fill(itTrack->pt());  
00069 @example_track    }
00070   
00071 //  using namespace edmtest;
00072 //  edm::Handle<ThingCollection> hThings;
00073 //  iEvent.getByLabel("Thing",hThings);
00074 //  for ( ThingCollection::const_iterator it = hThings->begin(); 
00075 //        it != hThings->end(); ++it ) {
00076 //    h_a ->Fill( it->a );
00077 //  }
00078   
00079 }
00080 
00081 // ------------ called after processing the events  ------------
00082 // The argument is the same as for the constructor
00083 void 
00084 tselnameWorker::postProcess(TList& out)
00085 {
00086 }
00087 
00088 
00089 //===============================================
00090 //Only one Selector is made per job. It gets all the results from each worker.
00091 //===============================================
00092 tselname::tselname()
00093 {
00094 }
00095 
00096 tselname::~tselname()
00097 {
00098 }
00099 
00100 // ------------ called just before all workers are constructed  ------------
00101 void tselname::begin(TList*& toWorkers)
00102 {
00103 }
00104 
00105 // ------------ called after all workers have finished  ------------
00106 // The argument 'fromWorkers' contains the accumulated output of all Workers
00107 void tselname::terminate(TList& fromWorkers) {
00108   using namespace std;
00109   std::auto_ptr<TCanvas> canvas( new TCanvas() );
00110 //  {
00111 //    TObject* hist = fromWorkers.FindObject(kA);
00112 //    if(0!=hist) {
00113 //      hist->Draw();
00114 //      canvas->SaveAs( "a.jpg" );
00115 //    } else {
00116 //      cout <<"no '"<<kA<<"' histogram"<<endl;
00117 //    }
00118  // }
00119 
00120 @example_track  {
00121 @example_track    TObject* hist = fromWorkers.FindObject(kPt);
00122 @example_track    if(0!=hist) {
00123 @example_track      hist->Draw();
00124 @example_track      canvas->SaveAs( "pt.jpg" );
00125 @example_track    } else {
00126 @example_track      cout <<"no '"<<kPt<<"' histogram"<<endl;
00127 @example_track    }
00128 @example_track  }
00129   
00130 }