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