FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairEventBuilderManager.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 /* $Id: */
9 
10 // -------------------------------------------------------------------------
11 // ----- FairEventBuilderManager source file -----
12 // ----- Created 23/09/2013 by R. Karabowicz -----
13 // -------------------------------------------------------------------------
14 
32 
33 #include "FairRecoEventHeader.h"
34 #include "FairRootManager.h"
35 #include "FairRunAna.h"
36 
37 #include <TMath.h>
38 #include <iostream>
39 
40 using std::cout;
41 using std::endl;
42 
44  : FairTask("FairEventBuilderManager", 0)
45  , fEventBuilders()
46  , fPossibleEvents()
47 {}
48 
49 FairEventBuilderManager::FairEventBuilderManager(const char* name, Int_t iVerbose)
50  : FairTask(name, iVerbose)
51  , fEventBuilders()
52  , fPossibleEvents()
53 {}
54 
56 
58 {
59  if (fVerbose) {
60  cout << "FairEventBuilderManager::Exec() begin" << endl;
61  }
62 
63  Double_t maxEventTimeAllowed = FillEventVectors();
64 
65  if (fVerbose) {
66  cout << "++ CAN CREATE EVENTS THAT ARE SMALLER THAN " << maxEventTimeAllowed << " ns" << endl;
67  }
68 
69  // AnalyzeAndExtractEvents function:
70  // - works on fEventBuilders[ieb]
71  // - should extract possible events
72  // - is implemented by different experiments
73  AnalyzeAndExtractEvents(maxEventTimeAllowed);
74 
75  return;
76 }
77 
79 {
80  // for (std::vector<FairEventBuilder*>::iterator it = fEventBuilders.begin() ; it != fEventBuilders.end() ; ++it) {
81  // *it.FindEvents();
82  // }
83  Double_t maxEventTimeAllowed = 10.e6;
84  for (UInt_t ieb = 0; ieb < fEventBuilders.size(); ieb++) {
85  if (fVerbose) {
86  cout << "***** " << fEventBuilders[ieb]->GetName() << " *****" << endl;
87  }
88  if (fVerbose) {
89  cout << " there are " << fPossibleEvents[ieb].size() << " possible events" << endl;
90  }
91  std::vector<std::pair<double, FairRecoEventHeader*>> tempBuilder = fEventBuilders[ieb]->FindEvents();
92  if (fVerbose) {
93  cout << " event buffer " << fEventBuilders[ieb]->GetName() << " found " << tempBuilder.size() << " events"
94  << endl;
95  }
96  for (UInt_t ipair = 0; ipair < tempBuilder.size(); ipair++) {
97  fPossibleEvents[ieb].push_back(tempBuilder[ipair]);
98  if (fVerbose)
99  cout << " added event " << fPossibleEvents[ieb][fPossibleEvents[ieb].size() - 1].second << " at "
100  << fPossibleEvents[ieb][fPossibleEvents[ieb].size() - 1].second->GetEventTime() << " ns." << endl;
101  }
102  if (fVerbose) {
103  cout << " and now " << fPossibleEvents[ieb].size() << " possible events" << endl;
104  }
105 
106  if (fEventBuilders[ieb]->AllowedTime() < maxEventTimeAllowed) {
107  maxEventTimeAllowed = fEventBuilders[ieb]->AllowedTime();
108  }
109  }
110  return maxEventTimeAllowed;
111 }
112 
114 {
115  for (UInt_t ieb = 0; ieb < fEventBuilders.size(); ieb++) {
116  fEventBuilders[ieb]->StoreEventData(recoEvent);
117  fEventBuilders[ieb]->WriteOutAllDeadTimeData();
118  }
119 
121 
122  for (UInt_t ieb = 0; ieb < fEventBuilders.size(); ieb++) {
123  fEventBuilders[ieb]->DeleteOldData();
124  }
125 }
126 
128 {
129  fEventBuilders.push_back(eventBuilder);
130  std::vector<std::pair<double, FairRecoEventHeader*>> tcArray;
131  fPossibleEvents.push_back(tcArray);
132  // if (fVerbose)
133  cout << "*** FairEventBuilderManager. Registered " << eventBuilder->GetName() << endl;
134 }
135 
136 void FairEventBuilderManager::SetParContainers()
137 {
138  // Get run and runtime database
140  if (!run) {
141  Fatal("SetParContainers", "No analysis run");
142  } else {
143  FairRuntimeDb* db = run->GetRuntimeDb();
144  if (!db) {
145  Fatal("SetParContainers", "No runtime database");
146  }
147  }
148 }
149 
150 InitStatus FairEventBuilderManager::Init()
151 {
152  // Get input array
154  if (!ioman) {
155  Fatal("Init", "No FairRootManager");
156  }
157 
158  cout << "*** FairEventBuilderManager. " << fEventBuilders.size() << " event builders registered." << endl;
159 
160  for (UInt_t ieb = 0; ieb < fEventBuilders.size(); ieb++) {
161  fEventBuilders[ieb]->SetIdentifier(TMath::Power(2, static_cast<Int_t>(ieb)));
162  fEventBuilders[ieb]->Init();
163  }
164 
165  return kSUCCESS;
166 }
167 
168 InitStatus FairEventBuilderManager::ReInit() { return kSUCCESS; }
169 
170 void FairEventBuilderManager::Finish()
171 {
173 
174  cout << "==================== " << fName.Data() << " : Summary ========================" << endl;
175  for (UInt_t ieb = 0; ieb < fEventBuilders.size(); ieb++) {
176  fEventBuilders[ieb]->Finish();
177  }
178  cout << "=====================================================================" << endl;
179 }
180 
list of container factories
Definition: FairRuntimeDb.h:24
virtual void Exec(Option_t *opt)
InitStatus
Definition: FairTask.h:33
virtual void AddEventBuilder(FairEventBuilder *eventBuilder)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
std::vector< std::vector< std::pair< double, FairRecoEventHeader * > > > fPossibleEvents
Int_t fVerbose
Definition: FairTask.h:100
static FairRunAna * Instance()
Definition: FairRunAna.cxx:61
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
std::vector< FairEventBuilder * > fEventBuilders
virtual void CreateAndFillEvent(FairRecoEventHeader *recoEvent)
virtual void AnalyzeAndExtractEvents(Double_t maxEventTimeAllowed)=0