CbmRoot
CbmMcbm2019TimeWinEventBuilderTask.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  ********************************************************************************/
9 
10 #include "CbmEvent.h"
11 
12 #include "FairLogger.h"
13 #include "FairRootManager.h"
14 #include "FairRunOnline.h"
15 
16 #include "TClonesArray.h"
17 #include "TH1.h"
18 #include "TH2.h"
19 #include "THttpServer.h"
20 #include <TFile.h>
21 
22 // ---- Default constructor -------------------------------------------
24  : FairTask("CbmMcbm2019TimeWinEventBuilderTask") {
27 }
28 
29 // ---- Destructor ----------------------------------------------------
31 
32 // ---- Initialisation ----------------------------------------------
35 }
36 
37 // ---- Init ----------------------------------------------------------
40  FairRootManager* ioman = FairRootManager::Instance();
41 
43  fEvents = new TClonesArray("CbmEvent", 100);
44  ioman->Register(
45  "CbmEvent", "Cbm Event", fEvents, IsOutputBranchPersistent("CbmEvent"));
46 
47  if (!fEvents) LOG(fatal) << "Output branch was not created";
48 
50  if (kTRUE == fpAlgo->InitAlgo())
51  return kSUCCESS;
52  else
53  return kFATAL;
54 }
55 
56 // ---- ReInit -------------------------------------------------------
57 InitStatus CbmMcbm2019TimeWinEventBuilderTask::ReInit() { return kSUCCESS; }
58 
59 // ---- Exec ----------------------------------------------------------
60 void CbmMcbm2019TimeWinEventBuilderTask::Exec(Option_t* /*option*/) {
61  LOG(debug2)
62  << "CbmMcbm2019TimeWinEventBuilderTask::Exec => Starting sequence";
64  fpAlgo->ProcessTs();
65 
67  FillOutput();
68  LOG(debug2) << "CbmMcbm2019TimeWinEventBuilderTask::Exec => Done";
69 }
70 
71 
72 // ---- Finish --------------------------------------------------------
74  if (fbFillHistos) { SaveHistos(); } // if( fbFillHistos )
75 
77  fpAlgo->Finish();
78 }
79 
80 //----------------------------------------------------------------------
83  fEvents->Delete();
84 
86  std::vector<CbmEvent*> vEvents = fpAlgo->GetEventVector();
87 
89  for (CbmEvent* event : vEvents) {
90  LOG(debug) << "Vector: " << event->ToString();
91  new ((*fEvents)[fEvents->GetEntriesFast()]) CbmEvent(std::move(*event));
92  LOG(debug) << "TClonesArray: "
93  << static_cast<CbmEvent*>(
94  fEvents->At(fEvents->GetEntriesFast() - 1))
95  ->ToString();
96  } // for( CbmEvent* event: vEvents )
97 
100 }
101 //----------------------------------------------------------------------
104  std::vector<std::pair<TNamed*, std::string>> vHistos =
106 
108  TDirectory* oldDir = NULL;
109  TFile* histoFile = NULL;
111  oldDir = gDirectory;
113  histoFile = new TFile(fsOutFileName, "RECREATE");
114  histoFile->cd();
115 
117  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
119  TString sFolder = vHistos[uHisto].second.data();
120  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
121  gDirectory->cd(sFolder);
122 
124  vHistos[uHisto].first->Write();
125 
126  histoFile->cd();
127  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
128 
130  oldDir->cd();
131  histoFile->Close();
132 }
133 //----------------------------------------------------------------------
135  fbFillHistos = bFlag;
136  if (nullptr != fpAlgo) fpAlgo->SetFillHistos(fbFillHistos);
137 }
139  fsOutFileName = sNameIn;
140 }
141 
143  ECbmModuleId refDet) {
144  if (nullptr != fpAlgo) fpAlgo->SetReferenceDetector(refDet);
145 }
147  if (nullptr != fpAlgo) fpAlgo->AddDetector(selDet);
148 }
150  if (nullptr != fpAlgo) fpAlgo->RemoveDetector(selDet);
151 }
152 
154  EventBuilderDetector refDet) {
155  if (nullptr != fpAlgo) fpAlgo->SetReferenceDetector(refDet);
156 }
158  EventBuilderDetector selDet) {
159  if (nullptr != fpAlgo) fpAlgo->AddDetector(selDet);
160 }
162  EventBuilderDetector selDet) {
163  if (nullptr != fpAlgo) fpAlgo->RemoveDetector(selDet);
164 }
165 
167  ECbmModuleId selDet,
168  UInt_t uVal) {
169  if (nullptr != fpAlgo) fpAlgo->SetTriggerMinNumber(selDet, uVal);
170 }
172  ECbmModuleId selDet,
173  Int_t iVal) {
174  if (nullptr != fpAlgo) fpAlgo->SetTriggerMaxNumber(selDet, iVal);
175 }
176 
178  Double_t dWinBeg,
179  Double_t dWinEnd) {
180  if (nullptr != fpAlgo) fpAlgo->SetTriggerWindow(det, dWinBeg, dWinEnd);
181 }
182 
184  EOverlapMode mode) {
185  if (nullptr != fpAlgo) fpAlgo->SetEventOverlapMode(mode);
186 }
188  if (nullptr != fpAlgo) fpAlgo->SetIgnoreTsOverlap(bFlagIn);
189 }
190 
191 //----------------------------------------------------------------------
192 
CbmMcbm2019TimeWinEventBuilderTask::FillOutput
void FillOutput()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:81
CbmMcbm2019TimeWinEventBuilderTask::Exec
virtual void Exec(Option_t *)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:60
CbmMcbm2019TimeWinEventBuilderTask::fpAlgo
CbmMcbm2019TimeWinEventBuilderAlgo * fpAlgo
Definition: CbmMcbm2019TimeWinEventBuilderTask.h:86
CbmMcbm2019TimeWinEventBuilderTask::SetTriggerWindow
void SetTriggerWindow(ECbmModuleId det, Double_t dWinBeg, Double_t dWinEnd)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:177
CbmMcbm2019TimeWinEventBuilderTask::CbmMcbm2019TimeWinEventBuilderTask
CbmMcbm2019TimeWinEventBuilderTask()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:23
CbmMcbm2019TimeWinEventBuilderTask::ReInit
virtual InitStatus ReInit()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:57
CbmMcbm2019TimeWinEventBuilderTask::SetTriggerMinNumber
void SetTriggerMinNumber(ECbmModuleId selDet, UInt_t uVal)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:166
ECbmModuleId
ECbmModuleId
Definition: CbmDefs.h:33
CbmMcbm2019TimeWinEventBuilderTask::fbFillHistos
Bool_t fbFillHistos
output container of CbmEvents
Definition: CbmMcbm2019TimeWinEventBuilderTask.h:90
CbmMcbm2019TimeWinEventBuilderAlgo::SetFillHistos
void SetFillHistos(Bool_t var)
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:128
CbmMcbm2019TimeWinEventBuilderAlgo::InitAlgo
Bool_t InitAlgo()
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:43
CbmMcbm2019TimeWinEventBuilderTask::Finish
virtual void Finish()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:73
CbmMcbm2019TimeWinEventBuilderTask::SetTriggerMaxNumber
void SetTriggerMaxNumber(ECbmModuleId selDet, Int_t iVal)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:171
CbmMcbm2019TimeWinEventBuilderTask::fsOutFileName
TString fsOutFileName
Switch ON/OFF filling of histograms.
Definition: CbmMcbm2019TimeWinEventBuilderTask.h:93
CbmMcbm2019TimeWinEventBuilderTask::Init
virtual InitStatus Init()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:38
CbmEvent.h
CbmMcbm2019TimeWinEventBuilderAlgo::SetEventOverlapMode
void SetEventOverlapMode(EOverlapMode mode)
Control flags.
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:161
CbmMcbm2019TimeWinEventBuilderAlgo::Finish
void Finish()
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:128
CbmMcbm2019TimeWinEventBuilderTask::SaveHistos
void SaveHistos()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:102
CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow
void SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:1012
CbmMcbm2019TimeWinEventBuilderAlgo::RemoveDetector
void RemoveDetector(ECbmModuleId selDet) __attribute__((deprecated))
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:842
CbmMcbm2019TimeWinEventBuilderAlgo::ProcessTs
void ProcessTs()
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:90
CbmMcbm2019TimeWinEventBuilderTask::~CbmMcbm2019TimeWinEventBuilderTask
~CbmMcbm2019TimeWinEventBuilderTask()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:30
CbmMcbm2019TimeWinEventBuilderAlgo::ClearEventVector
void ClearEventVector()
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:115
CbmMcbm2019TimeWinEventBuilderTask.h
CbmMcbm2019TimeWinEventBuilderAlgo::SetIgnoreTsOverlap
void SetIgnoreTsOverlap(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:162
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector
void AddDetector(ECbmModuleId selDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:727
CbmMcbm2019TimeWinEventBuilderTask
Definition: CbmMcbm2019TimeWinEventBuilderTask.h:29
EventBuilderDetector
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:37
CbmMcbm2019TimeWinEventBuilderAlgo::GetEventVector
std::vector< CbmEvent * > & GetEventVector()
Data output access.
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:183
CbmMcbm2019TimeWinEventBuilderTask::SetIgnoreTsOverlap
void SetIgnoreTsOverlap(Bool_t bFlagIn)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:187
CbmMcbm2019TimeWinEventBuilderTask::RemoveDetector
void RemoveDetector(ECbmModuleId selDet) __attribute__((deprecated))
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:149
CbmMcbm2019TimeWinEventBuilderTask::SetReferenceDetector
void SetReferenceDetector(ECbmModuleId refDet) __attribute__((deprecated))
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:142
CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector
void SetReferenceDetector(ECbmModuleId refDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:709
CbmMcbm2019TimeWinEventBuilderTask::SetParContainers
virtual void SetParContainers()
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:33
CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMinNumber
void SetTriggerMinNumber(ECbmModuleId selDet, UInt_t uVal)
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:948
CbmMcbm2019TimeWinEventBuilderTask::AddDetector
void AddDetector(ECbmModuleId selDet) __attribute__((deprecated))
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:146
CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMaxNumber
void SetTriggerMaxNumber(ECbmModuleId selDet, Int_t iVal)
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.cxx:980
CbmMcbm2019TimeWinEventBuilderAlgo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:171
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmMcbm2019TimeWinEventBuilderTask::SetEventOverlapMode
void SetEventOverlapMode(EOverlapMode mode)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:183
EOverlapMode
EOverlapMode
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:35
CbmMcbm2019TimeWinEventBuilderTask::fEvents
TClonesArray * fEvents
Definition: CbmMcbm2019TimeWinEventBuilderTask.h:88
CbmMcbm2019TimeWinEventBuilderTask::SetOutFilename
void SetOutFilename(TString sNameIn)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:138
Cbm::ToString
std::string ToString(const T &value)
Definition: CbmUtils.h:16
CbmMcbm2019TimeWinEventBuilderAlgo
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:106
CbmMcbm2019TimeWinEventBuilderTask::SetFillHistos
void SetFillHistos(Bool_t bFlag=kTRUE)
Definition: CbmMcbm2019TimeWinEventBuilderTask.cxx:134