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