00001 #include "FWCore/TFWLiteSelectorTest/src/ThingsTSelector.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
00009 using namespace tfwliteselectortest;
00010
00011 static const char* kA = "a";
00012 static const char* kRefA = "refA";
00013 void ThingsTSelector::begin(TList*&)
00014 {
00015 }
00016
00017 void ThingsTSelector::preProcessing(const TList*, TList& out ) {
00018 if(0!=h_a) {
00019 out.Remove(h_a);
00020 delete h_a;
00021 h_a=0;
00022 }
00023 h_a = new TH1F( kA , "a" , 100, 0, 20 );
00024 out.Add(h_a);
00025
00026 if(0!=h_refA) {
00027 out.Remove(h_refA);
00028 delete h_refA;
00029 h_refA=0;
00030 }
00031 h_refA = new TH1F( kRefA , "refA" , 100, 0, 20 );
00032 out.Add(h_refA);
00033 }
00034
00035 void ThingsTSelector::process( const edm::Event& iEvent ) {
00036 std::cout << "processing event " << std::endl;
00037
00038 using namespace edmtest;
00039 edm::Handle<OtherThingCollection> hOThings;
00040
00041 try {
00042 iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
00043 std::cout << ">> other things found:" << hOThings->size() << std::endl;
00044
00045 for ( size_t i = 0; i < hOThings->size(); ++i ) {
00046 const OtherThing & thing = (*hOThings)[ i ];
00047 h_refA ->Fill( thing.ref->a );
00048 std::cout << ">> ref->a: " << thing.ref->a << std::endl;
00049 }
00050
00051 edm::Handle<ThingCollection> hThings;
00052 iEvent.getByLabel("Thing",hThings);
00053 const ThingCollection& things = *hThings;
00054 std::cout << ">> things found:" << things.size() << std::endl;
00055 for ( size_t i = 0; i < things.size(); ++i ) {
00056 const Thing & thing = things[ i ];
00057 h_a ->Fill( thing.a );
00058 std::cout << ">> a: " << thing.a << std::endl;
00059 }
00060 } catch (cms::Exception& x) {
00061 std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
00062 std::cout << x.what() << std::endl;
00063 exit(10);
00064 } catch (std::exception& x) {
00065 std::cout << std::endl << "Failed with std::exception" << std::endl;
00066 std::cout << x.what() << std::endl;
00067 exit(10);
00068 } catch (...) {
00069 std::cout << std::endl << "Failed with unknown exception" << std::endl;
00070 exit(10);
00071 }
00072
00073 }
00074
00075 void ThingsTSelector::postProcessing(TList&)
00076 {
00077 }
00078
00079 void ThingsTSelector::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 {
00092 TObject* hist = out.FindObject(kRefA);
00093 if(0 != hist) {
00094 hist->Draw();
00095 canvas->SaveAs( "refA.jpg" );
00096 } else {
00097 std::cout <<"no '"<<kRefA<<"' histogram"<< std::endl;
00098 }
00099 }
00100 delete canvas;
00101 }