ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/AnaFwkMod.cc
(Generate patch)

Comparing UserCode/MitAna/TreeMod/src/AnaFwkMod.cc (file contents):
Revision 1.3 by loizides, Tue Nov 25 15:57:49 2008 UTC vs.
Revision 1.4 by loizides, Mon Mar 9 17:07:05 2009 UTC

# Line 2 | Line 2
2  
3   #include "MitAna/TreeMod/interface/AnaFwkMod.h"
4   #include "MitAna/DataUtil/interface/Debug.h"
5 + #include <TFile.h>
6   #include <TH1D.h>
7   #include <TStopwatch.h>
8 + #include <TTree.h>
9  
10   using namespace mithep;
11  
# Line 13 | Line 15 | ClassImp(mithep::AnaFwkMod)
15   AnaFwkMod::AnaFwkMod(const char *name, const char *title) :
16    BaseMod(name,title),
17    fSWtotal(0),
18 <  fSWevent(0)
18 >  fSWevent(0),
19 >  fAllHeaders(0,"AllEventHeaders"),
20 >  fAllHeadTree(0),
21 >  fAllEventHeader(0),
22 >  fReload(kFALSE),
23 >  fCurEnt(-2)
24   {
25    // Constructor.
26   }
27  
28   //--------------------------------------------------------------------------------------------------
29 + void AnaFwkMod::BeginRun()
30 + {
31 +  // Get HLT tree and set branches if new file was opened. Read next entry in HLT key
32 +  // depending on entry in RunInfo.
33 +
34 +  if (fReload) {
35 +
36 +    // reset to be (re-)loaded variables
37 +    fReload         = 0;
38 +    fAllHeadTree    = 0;
39 +    fAllEventHeader = 0;
40 +    fCurEnt         = 0;
41 +
42 +    // get current file
43 +    TFile *file = GetCurrentFile();
44 +    if (!file)
45 +      return;
46 +
47 +    // get HLT tree
48 +    fAllHeadTree = dynamic_cast<TTree*>(file->Get(fAllHeadTreeName));
49 +    if (!fAllHeadTree) {
50 +      return;
51 +    }
52 +  }
53 +
54 +  // get HLT trigger name branch
55 +  if (fAllHeadTree->GetBranch(fAllHeadBrName)) {
56 +    fAllHeadTree->SetBranchAddress(fAllHeadBrName, &fAllEventHeader);
57 +  } else {
58 +    SendError(kWarning, "BeginRun",
59 +              "Can not find branch with name %s in tree %s",
60 +              fAllHeadBrName.Data(), fAllHeadTreeName.Data());
61 +    return;
62 +  }
63 + }
64 +
65 + //--------------------------------------------------------------------------------------------------
66 + void AnaFwkMod::CopyAllEventHeaders()
67 + {
68 +  // Deal with the headers from all events if needed.
69 +
70 +  fAllHeaders.Reset();
71 +
72 +  const EventHeader *curev = GetEventHeader();
73 +  if (!curev) {
74 +    SendError(kWarning, "CopyAllEventHeaders", "Can not obtain current event");
75 +    return;
76 +  }
77 +
78 +  if (fAllHeadTree) {
79 +    fAllHeadTree->GetEntry(fCurEnt++);
80 +    while(fAllEventHeader->IsRemoved()) {
81 +      EventHeader *eh = fAllHeaders.AddNew();
82 +      eh->SetRunNum(fAllEventHeader->RunNum());
83 +      eh->SetEvtNum(fAllEventHeader->EvtNum());
84 +      eh->SetLumiSec(fAllEventHeader->LumiSec());
85 +      eh->SetIsRemoved(fAllEventHeader->RunEntry());
86 +      eh->SetRunEntry(fAllEventHeader->IsRemoved());
87 +      fAllHeadTree->GetEntry(fCurEnt++);
88 +    }
89 +    if ((fAllEventHeader->RunNum()!=curev->RunNum())   ||
90 +        (fAllEventHeader->EvtNum()!=curev->EvtNum())   ||
91 +        (fAllEventHeader->LumiSec()!=curev->LumiSec()) ||
92 +        (fAllEventHeader->RunEntry()!=curev->RunEntry())) {
93 +      SendError(kWarning, "CopyAllEventHeaders",
94 +                "Event header information inconsistent: %d==%d, %d==%d, %d==%d, %d==%d",
95 +                fAllEventHeader->RunNum(),   curev->RunNum(),
96 +                fAllEventHeader->EvtNum(),   curev->EvtNum(),
97 +                fAllEventHeader->LumiSec(),  curev->LumiSec(),
98 +                fAllEventHeader->RunEntry(), curev->RunEntry());
99 +      return;
100 +    }
101 +  }
102 + }
103 +
104 + //--------------------------------------------------------------------------------------------------
105 + Bool_t AnaFwkMod::Notify()
106 + {
107 +  // Make sure to get the new "AllEvents" tree when the file changes.
108 +
109 +  fReload = kTRUE;
110 +  return kTRUE;
111 + }
112 +
113 + //--------------------------------------------------------------------------------------------------
114   void AnaFwkMod::Process()
115   {
116    // Do event counting and print out timing information.
117  
118 +  
119 +
120    // counting events
121    IncNEventsProcessed();
122  
# Line 65 | Line 159 | void AnaFwkMod::SlaveBegin()
159  
160    fSWtotal = new TStopwatch;
161    fSWevent = new TStopwatch;
162 +
163 +  if (!PublishObj(&fAllHeaders)) {
164 +    SendError(kAbortAnalysis, "SlaveBegin",
165 +              "Could not publish all event headers with name %s.", fAllHeaders.GetName());
166 +    return;
167 +  }
168   }
169  
170   //--------------------------------------------------------------------------------------------------
# Line 72 | Line 172 | void AnaFwkMod::SlaveTerminate()
172   {
173    // Fill event histogram and printout timing information.
174  
175 +  RetractObj(fAllHeaders.GetName());
176 +
177    SaveNEventsProcessed();
178  
179    fSWtotal->Stop();
# Line 85 | Line 187 | void AnaFwkMod::SlaveTerminate()
187    delete fSWtotal;
188    delete fSWevent;
189   }
190 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines