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

Comparing UserCode/MitAna/TreeMod/src/OutputMod.cc (file contents):
Revision 1.2 by loizides, Tue Dec 2 09:34:17 2008 UTC vs.
Revision 1.3 by loizides, Wed Dec 3 17:44:05 2008 UTC

# Line 25 | Line 25 | OutputMod::OutputMod(const char *name, c
25    fDoReset(kFALSE),
26    fCheckTamBr(kTRUE),
27    fKeepTamBr(kTRUE),
28  fHltFwkModName("HLTFwkMod"),
28    fTreeWriter(0),
29 <  fMyEventHeader(0),
30 <  fMyRunInfo(0),
31 <  fMyLaHeader(0),
29 >  fEventHeader(0),
30 >  fAllEventHeader(0),
31 >  fRunInfo(0),
32 >  fLaHeader(0),
33    fNBranchesMax(1024),
34 <  fHltFwkMod(0)
34 >  fRunTree(0),
35 >  fLATree(0),
36 >  fAllTree(0),
37 >  fL1Tree(0),
38 >  fHltTree(0),
39 >  fRunEntries(0),
40 >  fOrigL1Entry(-1),
41 >  fL1Entries(0),
42 >  fOrigHltEntry(-1),
43 >  fHltEntries(0),
44 >  fFileNum(0)
45   {
46    // Constructor.
47   }
# Line 39 | Line 49 | OutputMod::OutputMod(const char *name, c
49   //--------------------------------------------------------------------------------------------------
50   void OutputMod::BeginRun()
51   {
52 <  // Todo.
52 >  // Create HLT tree if HLTFwkMod is being run.
53 >
54 >  if (!HasHLTInfo())
55 >    return;
56  
57 +  if (!fHltTree) {
58 +    HLTFwkMod *hm = const_cast<HLTFwkMod*>(GetHltFwkMod());
59 +    fTreeWriter->AddBranchToTree(hm->HLTTreeName(), hm->HLTTabName(), &(hm->fHLTTab), 32000, 0);
60 +    fTreeWriter->AddBranchToTree(hm->HLTTreeName(), hm->HLTLabName(), &(hm->fHLTLab), 32000, 0);
61 +    fTreeWriter->SetAutoFill(hm->HLTTreeName(), 0);
62 +    fHltTree = fTreeWriter->GetTree(hm->HLTTreeName());
63 +  }
64   }
65  
66   //--------------------------------------------------------------------------------------------------
# Line 146 | Line 166 | void OutputMod::CheckAndResolveDep(Bool_
166   }
167  
168   //--------------------------------------------------------------------------------------------------
169 < void OutputMod::RequestBranch(const char *bname)
169 > void OutputMod::FillAllEventHeader(Bool_t isremoved)
170   {
171 <  // Request given branch from TAM.
171 >  // Fill event header into the all-event-header tree.
172  
173 <  if (GetNBranches()>=fNBranchesMax) {
174 <    Error("RequestBranch", "Can not request branch for %bname"
175 <          "since maximum number of branches [%d] is reached", bname, fNBranchesMax);
173 >  const EventHeader *eh = GetEventHeader();
174 >  fAllEventHeader->SetEvtNum(eh->EvtNum());
175 >  fAllEventHeader->SetLumiSec(eh->LumiSec());
176 >  fAllEventHeader->SetRunNum(eh->RunNum());
177 >  if (isremoved)
178 >    fAllEventHeader->SetRunEntry(-1);
179 >  else
180 >    fAllEventHeader->SetRunEntry(eh->RunEntry());
181 >  fAllEventHeader->SetIsRemoved(isremoved);
182 >
183 >  fAllTree->Fill();
184 > }
185 >
186 > //--------------------------------------------------------------------------------------------------
187 > void OutputMod::FillL1Info()
188 > {
189 >  // Not doing anything here until the production writes out L1 information.
190 >
191 >  if (!fL1Tree)
192      return;
157  }
158  
159  fBranches[GetNBranches()-1] = 0;
160  ReqBranch(bname, fBranches[GetNBranches()-1]);
193   }
194  
195   //--------------------------------------------------------------------------------------------------
196 < void OutputMod::EndRun()
196 > void OutputMod::FillHltInfo()
197   {
198    // Todo.
199  
200 +  if (!fHltTree)
201 +    return;
202 +
203 +  if (fOrigHltEntry == GetHltFwkMod()->fCurEnt)
204 +    return;
205 +
206 +  fHltTree->Fill();
207 +  fOrigHltEntry = GetHltFwkMod()->fCurEnt;
208 +  ++fHltEntries;
209   }
210  
211   //--------------------------------------------------------------------------------------------------
# Line 238 | Line 279 | void OutputMod::LoadBranches()
279   //--------------------------------------------------------------------------------------------------
280   void OutputMod::Process()
281   {
282 <  // Pre and post event processing at once?!
282 >  // Write out the kept branches of the current event. Make sure the meta information is
283 >  // correctly updated.
284  
285    fTreeWriter->BeginEvent(fDoReset);
286  
# Line 252 | Line 294 | void OutputMod::Process()
294      SetupBranches();
295    }
296  
297 <  LoadBranch("EventHeader");
298 < //  fMyEventHeader
297 >  // reset per file quantities if a new file was opened
298 >  if (fTreeWriter->GetFileNumber()!=fFileNum) {
299 >    fRunmap.clear();
300 >    fRunEntries = 0;
301 >    fL1Entries  = -1;
302 >    fHltEntries = -1;
303 >    fFileNum = fTreeWriter->GetFileNumber();
304 >  }
305 >
306 >  UInt_t runnum = GetEventHeader()->RunNum();
307 >
308 >  // store look ahead information
309 >  if (fRunEntries>0) {
310 >    fLaHeader->SetRunNum(runnum);
311 >    fLATree->Fill();
312 >  }
313 >
314 >  // fill event header
315 >  fEventHeader->SetEvtNum(GetEventHeader()->EvtNum());
316 >  fEventHeader->SetLumiSec(GetEventHeader()->LumiSec());
317 >  fEventHeader->SetRunNum(runnum);
318 >
319 >  // fill all event header
320 >  //  *** note that we need to read an existing tree in
321 >  //      the future to make sure we can do skims of skims ***
322 >  FillAllEventHeader(kFALSE);
323 >
324 >  // look-up if entry is in map
325 >  map<UInt_t,Int_t>::iterator riter = fRunmap.find(runnum);
326 >  if (riter != fRunmap.end()) { // found existing run info
327 >    Int_t runentry = riter->second;
328 >    fEventHeader->SetRunEntry(runentry);
329 >
330 >    IncNEventsProcessed();
331 >    fTreeWriter->EndEvent(fDoReset);
332 >    return;
333 >  }
334  
335 +  // fill new run info
336 +  Int_t runentry = fRunEntries;
337 +  ++fRunEntries;
338 +  fEventHeader->SetRunEntry(runentry);
339 +  fRunmap.insert(pair<UInt_t,Int_t>(runnum,runentry));
340 +  fRunInfo->SetRunNum(runnum);
341 +
342 +  Int_t l1entry = fL1Entries;
343 +  FillL1Info();
344 +  fRunInfo->SetL1Entry(l1entry);
345 +
346 +  Int_t hltentry = fHltEntries;
347 +  FillHltInfo();
348 +  fRunInfo->SetHltEntry(hltentry);
349 +  
350 +  fRunTree->Fill();
351 +  
352    IncNEventsProcessed();
353    fTreeWriter->EndEvent(fDoReset);
354   }
355  
356   //--------------------------------------------------------------------------------------------------
357 + void OutputMod::ProcessAll()
358 + {
359 +  // Called by the Selector class for events that were skipped.
360 +
361 +  FillAllEventHeader(kTRUE);
362 + }
363 +
364 + //--------------------------------------------------------------------------------------------------
365 + void OutputMod::RequestBranch(const char *bname)
366 + {
367 +  // Request given branch from TAM.
368 +
369 +  if (GetNBranches()>=fNBranchesMax) {
370 +    Error("RequestBranch", "Can not request branch for %bname"
371 +          "since maximum number of branches [%d] is reached", bname, fNBranchesMax);
372 +    return;
373 +  }
374 +  
375 +  fBranches[GetNBranches()-1] = 0;
376 +  ReqBranch(bname, fBranches[GetNBranches()-1]);
377 + }
378 +
379 + //--------------------------------------------------------------------------------------------------
380   void OutputMod::SetupBranches()
381   {
382    // Setup branches in tree writer.
# Line 279 | Line 396 | void OutputMod::SetupBranches()
396   //--------------------------------------------------------------------------------------------------
397   void OutputMod::SlaveBegin()
398   {
399 <  // Todo
283 <
284 <  // request here branches we want
285 <  
399 >  // Setup the tree writer and create branches that can already be created at this point.
400  
401    // setup tree writer
402    fTreeWriter = new TreeWriter(fTreeName, kFALSE);
# Line 296 | Line 410 | void OutputMod::SlaveBegin()
410    fTreeWriter->DoBranchRef(fTreeName);
411  
412    // deal with my own tree objects
413 <  fMyEventHeader = new EventHeader;
414 <  fTreeWriter->AddBranch(Names::gkEvtHeaderBrn, &fMyEventHeader);
415 <  fMyRunInfo = new RunInfo;
416 <  fTreeWriter->AddBranchToTree(Names::gkRunTreeName, Names::gkRunInfoBrn, &fMyRunInfo);
417 <  fTreeWriter->SetAutoFill(Names::gkRunTreeName,0);
418 <  fMyLaHeader = new LAHeader;
419 <  fTreeWriter->AddBranchToTree(Names::gkLATreeName, Names::gkLAHeaderBrn, &fMyLaHeader);
420 <  fTreeWriter->SetAutoFill(Names::gkLATreeName,0);
421 <
422 <
423 <  // add branches to HLT trigger info tree
424 <  //tws.AddBranchToTree(Names::gkHltTreeName,hltTableName_.c_str(),&hltTable_,32000,0);
425 <  //tws.SetAutoFill(Names::gkHltTreeName,0);
426 <  //tws.AddBranchToTree(Names::gkHltTreeName,hltLabelName_.c_str(),&hltLabels_,32000,0);
427 <  //tws.SetAutoFill(Names::gkHltTreeName,0);
428 <  //hltTree_=tws.GetTree(Names::gkHltTreeName);
429 <
430 <
431 <  if (HasHLTInfo(fHltFwkModName)) {
318 <    const TList *tasks = GetSelector()->GetTopModule()->GetSubModules();
319 <    fHltFwkMod = static_cast<HLTFwkMod*>(tasks->FindObject(fHltFwkModName));
320 <  }
413 >  fEventHeader = new EventHeader;
414 >  fTreeWriter->AddBranch(GetSel()->GetEvtHdrName(), &fEventHeader);
415 >
416 >  // deal with other trees
417 >  const char *tname = 0;
418 >  fRunInfo = new RunInfo;
419 >  tname = GetSel()->GetRunTreeName();
420 >  fTreeWriter->AddBranchToTree(tname, GetSel()->GetRunInfoName(), &fRunInfo);
421 >  fTreeWriter->SetAutoFill(tname, 0);
422 >  fRunTree = fTreeWriter->GetTree(tname);
423 >  fLaHeader = new LAHeader;
424 >  tname = GetSel()->GetLATreeName();
425 >  fTreeWriter->AddBranchToTree(tname, GetSel()->GetLAHdrName(), &fLaHeader);
426 >  fTreeWriter->SetAutoFill(tname,0);
427 >  fLATree = fTreeWriter->GetTree(tname);
428 >  fAllEventHeader = new EventHeader;
429 >  tname = GetSel()->GetAllEvtTreeName();
430 >  fTreeWriter->AddBranchToTree(tname, GetSel()->GetAllEvtHdrBrn(), &fAllEventHeader);
431 >  fAllTree = fTreeWriter->GetTree(tname);
432  
433 +  // get pointer to fAllTreeIn todo
434 +  // todo
435    // deal here with published objects
436 +  // todo
437  
438    // create TObject space for TAM
439    fBranches = new TObject*[fNBranchesMax];      
# Line 332 | Line 446 | void OutputMod::SlaveBegin()
446   //--------------------------------------------------------------------------------------------------
447   void OutputMod::SlaveTerminate()
448   {
449 <  // Todo
449 >  // Terminate tree writing and do cleanup.
450  
451    delete fTreeWriter;
452    fTreeWriter = 0;
453  
454 <  delete fMyEventHeader;
454 >  delete fEventHeader;
455 >  delete fRunInfo;
456 >  delete fLaHeader;
457 >  delete fAllEventHeader;
458  
459    delete[] fBranches;
460   }
461  
345 //--------------------------------------------------------------------------------------------------

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines