CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/FWCore/TFWLiteSelectorTest/src/ThingsTSelector2.cc

Go to the documentation of this file.
00001 #include "FWCore/TFWLiteSelectorTest/src/ThingsTSelector2.h"
00002 #include <TCanvas.h>
00003 #include <iostream>
00004 #include "Rtypes.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "DataFormats/TestObjects/interface/OtherThingCollection.h"
00008 #include "DataFormats/TestObjects/interface/ThingCollection.h"
00009 
00010 using namespace tfwliteselectortest;
00011 
00012 //Names used in common between the worker and the Selector
00013 static const char* kA = "a";
00014 static const char* kRefA = "refA";
00015 
00016 
00017 
00018 ThingsWorker::ThingsWorker(const TList*, TList& out ) {
00019     std::cout << "begin" << std::endl;
00020     h_a  = new TH1F( kA , "a"  , 100,  0, 20 );
00021     out.Add(h_a);
00022     
00023     h_refA  = new TH1F( kRefA , "refA"  , 100,  0, 20 );
00024     out.Add(h_refA);
00025 }
00026   
00027   
00028   
00029 void 
00030 ThingsWorker::process( const edm::Event& iEvent ) {
00031   std::cout << "processing event " << std::endl;
00032   //  chain->GetEntry( entry );
00033   using namespace edmtest;
00034   edm::Handle<OtherThingCollection> hOThings;
00035   try {
00036     iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
00037     
00038     std::cout << ">> other things found:" << hOThings->size() << std::endl;
00039     for ( size_t i = 0; i < hOThings->size(); ++i ) {
00040       const OtherThing & thing = (*hOThings)[ i ];
00041       h_refA ->Fill( thing.ref->a );
00042       std::cout << ">> ref->a:  " << thing.ref->a << std::endl;
00043     }
00044     
00045     edm::Handle<ThingCollection> hThings;
00046     iEvent.getByLabel("Thing",hThings);
00047     const ThingCollection& things = *hThings;
00048     std::cout << ">> things found:" << things.size() << std::endl;
00049     for ( size_t i = 0; i < things.size(); ++i ) {
00050       const Thing & thing = things[ i ];
00051       h_a ->Fill( thing.a );
00052       std::cout << ">> a:  " << thing.a << std::endl;
00053     }
00054   } catch (cms::Exception& x) {
00055     std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
00056     std::cout << x.what() << std::endl;
00057     abort();
00058   } catch (std::exception& x) {
00059     std::cout << std::endl << "Failed with std::exception" << std::endl;
00060     std::cout << x.what() << std::endl;
00061     abort();
00062   } catch (...) {
00063     std::cout << std::endl << "Failed with unknown exception" << std::endl;
00064     abort();
00065   }
00066 }
00067   
00068 void 
00069 ThingsWorker::postProcess(TList&)
00070 {
00071 }
00072 
00073 
00074 
00075 void ThingsTSelector2::begin(TList*&)
00076 {
00077 }
00078 
00079 void ThingsTSelector2::terminate(TList& out) {
00080   std::cout << "terminate" << std::endl;
00081   TCanvas * canvas = new TCanvas( );
00082   {
00083      TObject* hist = out.FindObject(kA);
00084      if(0!=hist) {
00085         hist->Draw();
00086         canvas->SaveAs( "a.jpg" );
00087      } else {
00088         std::cout <<"no '"<<kA<<"' histogram"<< std::endl;
00089      }
00090   }
00091   std::cout <<"refA"<< std::endl;
00092   {
00093      TObject* hist = out.FindObject(kRefA);
00094      if( 0 != hist ) {
00095         hist->Draw();
00096         canvas->SaveAs( "refA.jpg" );
00097      } else {
00098         std::cout <<"no '"<<kRefA<<"' histogram"<< std::endl;
00099      }
00100   }
00101   delete canvas;
00102 }
00103 
00104