ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/GPetrucc/interface/fwlite/Scanner.h
Revision: 1.1
Committed: Wed Jan 27 23:00:06 2010 UTC (15 years, 3 months ago) by gpetrucc
Content type: text/plain
Branch: MAIN
Log Message:
FWLite Tools
First buggy version of in flight decay finder

File Contents

# Content
1 // these includes are FWLite-safe
2 #include "DataFormats/FWLite/interface/Handle.h"
3 #include "DataFormats/FWLite/interface/Event.h"
4 // these are from ROOT, so they're safe too
5 #include <TString.h>
6 #include <TObjString.h>
7 #include <TObjArray.h>
8
9 #if !defined(__CINT__) && !defined(__MAKECINT__)
10 #include "UserCode/GPetrucc/interface/fwliteHelpers.h"
11 #else
12 // load the library that contains the dictionaries
13 int _load_UserCodeGPetrucc = gSystem->Load("libUserCodeGPetrucc.so");
14 #endif
15
16 namespace fwlite {
17 template<typename T>
18 class Scanner {
19 public:
20 typedef fwlite::Handle<std::vector<T> > HandleT;
21 Scanner(fwlite::EventBase *ev, const char *label, const char *instance = "", const char *process="") :
22 //helper::ScannerBase(Reflex::Type::ByTypeInfo(typeid(T))),
23 event_(ev), label_(label), instance_(instance), printFullEventId_(ev->isRealData())
24 {
25 Reflex::Type wrapperType = Reflex::Type::ByTypeInfo(HandleT::TempWrapT::typeInfo());
26 objType = helpme.elementType(Reflex::Type::ByTypeInfo(HandleT::TempWrapT::typeInfo()));
27 }
28
29
30 void scan(const char *exprs, const char *cut="", int nmax=20) {
31 helper::ScannerBase scanner(objType);
32
33 TObjArray *exprArray = TString(exprs).Tokenize(":");
34 int rowline = 0;
35 if (printFullEventId_) {
36 printf(" : %9s : %4s : %9s : %3s", "RUN", "LUMI", "EVENT", "#IT");
37 rowline += 3*4+9+4+9+3-1; // -1 as first char remain blank
38 } else {
39 printf(" : %5s : %3s", "RECORD", "#IT");
40 rowline += 3+6+3+3-1; // -1 as first char remain blank
41 }
42 for (int i = 0; i < exprArray->GetEntries(); ++i) {
43 const char *ex = ((TObjString *)(*exprArray)[i])->GetString();
44 scanner.addExpression(ex);
45 printf(" : %8s", ex);
46 rowline += 3+8;
47 }
48 std::cout << " :" << std::endl;
49 rowline += 2;
50 delete exprArray;
51
52 TString rule('-', rowline);
53 std::cout << " " << rule << " " << std::endl;
54
55 if (strlen(cut)) scanner.setCut(cut);
56
57 int iev = 0;
58 for (event_->toBegin(); (iev < nmax) && !event_->atEnd(); ++iev, ++(*event_)) {
59 handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
60 const std::vector<T> & vals = *handle_;
61 for (size_t j = 0, n = vals.size(); j < n; ++j) {
62 if (!scanner.test(&vals[j])) continue;
63 if (printFullEventId_) {
64 const edm::EventAuxiliary &id = event_->eventAuxiliary();
65 printf(" : %9d : %4d : %9d : %3d", id.run(), id.luminosityBlock(), id.event(), j);
66 } else {
67 printf(" : %5d : %3d", iev, j);
68 }
69 scanner.print(&vals[j]);
70 std::cout << " :" << std::endl;
71 }
72 }
73 std::cout << std::endl;
74 }
75 void setPrintFullEventId(bool printIt=true) { printFullEventId_ = printIt; }
76 private:
77 bool printFullEventId_;
78 fwlite::Event *event_;
79 std::string label_, instance_, process_;
80 HandleT handle_;
81 helper::Parser helpme;
82 Reflex::Type objType;
83
84 };
85 }