CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ThingsTSelector2.cc
Go to the documentation of this file.
2 #include <TCanvas.h>
3 #include <iostream>
4 #include "Rtypes.h"
7 #include "DataFormats/TestObjects/interface/OtherThingCollection.h"
8 #include "DataFormats/TestObjects/interface/ThingCollection.h"
9 
10 using namespace tfwliteselectortest;
11 
12 //Names used in common between the worker and the Selector
13 static const char* kA = "a";
14 static const char* kRefA = "refA";
15 
16 
17 
18 ThingsWorker::ThingsWorker(const TList*, TList& out ) {
19  std::cout << "begin" << std::endl;
20  h_a = new TH1F( kA , "a" , 100, 0, 20 );
21  out.Add(h_a);
22 
23  h_refA = new TH1F( kRefA , "refA" , 100, 0, 20 );
24  out.Add(h_refA);
25 }
26 
27 
28 
29 void
31  std::cout << "processing event " << std::endl;
32  // chain->GetEntry( entry );
33  using namespace edmtest;
35  try {
36  iEvent.getByLabel("OtherThing", "testUserTag", hOThings);
37 
38  std::cout << ">> other things found:" << hOThings->size() << std::endl;
39  for ( size_t i = 0; i < hOThings->size(); ++i ) {
40  const OtherThing & thing = (*hOThings)[ i ];
41  h_refA ->Fill( thing.ref->a );
42  std::cout << ">> ref->a: " << thing.ref->a << std::endl;
43  }
44 
46  iEvent.getByLabel("Thing",hThings);
47  const ThingCollection& things = *hThings;
48  std::cout << ">> things found:" << things.size() << std::endl;
49  for ( size_t i = 0; i < things.size(); ++i ) {
50  const Thing & thing = things[ i ];
51  h_a ->Fill( thing.a );
52  std::cout << ">> a: " << thing.a << std::endl;
53  }
54  } catch (cms::Exception& x) {
55  std::cout << std::endl << "Failed with cms::Exception: " << std::endl;
56  std::cout << x.what() << std::endl;
57  abort();
58  } catch (std::exception& x) {
59  std::cout << std::endl << "Failed with std::exception" << std::endl;
60  std::cout << x.what() << std::endl;
61  abort();
62  } catch (...) {
63  std::cout << std::endl << "Failed with unknown exception" << std::endl;
64  abort();
65  }
66 }
67 
68 void
70 {
71 }
72 
73 
74 
76 {
77 }
78 
80  std::cout << "terminate" << std::endl;
81  TCanvas * canvas = new TCanvas( );
82  {
83  TObject* hist = out.FindObject(kA);
84  if(0!=hist) {
85  hist->Draw();
86  canvas->SaveAs( "a.jpg" );
87  } else {
88  std::cout <<"no '"<<kA<<"' histogram"<< std::endl;
89  }
90  }
91  std::cout <<"refA"<< std::endl;
92  {
93  TObject* hist = out.FindObject(kRefA);
94  if( 0 != hist ) {
95  hist->Draw();
96  canvas->SaveAs( "refA.jpg" );
97  } else {
98  std::cout <<"no '"<<kRefA<<"' histogram"<< std::endl;
99  }
100  }
101  delete canvas;
102 }
103 
104 
virtual char const * what() const
Definition: Exception.cc:141
int i
Definition: DBlmapReader.cc:9
def canvas
Definition: svgfig.py:481
int iEvent
Definition: GenABIO.cc:243
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple out
Definition: dbtoconf.py:99
static const char * kA
static const char * kRefA
ThingsWorker(const TList *, TList &)
void process(const edm::Event &iEvent)
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10