FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairRingSorterTask.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 // -------------------------------------------------------------------------
9 // ----- FairRingSorterTaskT source file -----
10 // -------------------------------------------------------------------------
11 
12 #include "FairRingSorterTask.h"
13 
14 #include "FairLink.h" // for FairLink
15 #include "FairRootManager.h" // for FairRootManager
16 #include "FairTimeStamp.h" // for FairTimeStamp
17 
18 #include <TClass.h> // for TClass
19 #include <TClonesArray.h> // for TClonesArray
20 #include <iostream> // for operator<<, cout, ostream, etc
21 #include <vector> // for vector
22 
24 
25 FairRingSorter* FairRingSorterTask::InitSorter(Int_t numberOfCells, Double_t widthOfCells) const
26 {
27  return new FairRingSorter(numberOfCells, widthOfCells);
28 }
29 
31 {
33  if (!ioman) {
34  std::cout << "-E- FairRingSorterTaskT::Init: "
35  << "RootManager not instantiated!" << std::endl;
36  return kFATAL;
37  }
38 
40 
41  // Create and register output array
43 
44  if (fVerbose > 1) {
45  Info("Init", "Registering this branch: %s/%s", fFolder.Data(), fOutputBranch.Data());
46  }
47  fOutputArray = ioman->Register(fOutputBranch, fInputArray->GetClass()->GetName(), fFolder, fPersistance);
48 
49  return kSUCCESS;
50 }
51 
52 void FairRingSorterTask::Exec(Option_t*)
53 {
55  if (fVerbose > 1) {
56  std::cout << "-I- FairRingSorterTask: Size PixelArray: " << fInputArray->GetEntriesFast() << std::endl;
57  }
58  for (int i = 0; i < fInputArray->GetEntriesFast(); i++) {
59  FairTimeStamp* myData = static_cast<FairTimeStamp*>(fInputArray->At(i));
60  myData->SetEntryNr(FairLink(0, fEntryNr, fInputBranch, i));
61  if (fVerbose > 1) {
62  std::cout << "Sorter filled with: ";
63  myData->Print();
64  std::cout << std::endl;
65  }
66  fSorter->AddElement(myData, myData->GetTimeStamp());
67  }
68  if (fVerbose > 2) {
69  fSorter->Print();
70  }
71 
72  std::vector<FairTimeStamp*> sortedData = fSorter->GetOutputData();
73 
75  for (unsigned int i = 0; i < sortedData.size(); i++) {
76  AddNewDataToTClonesArray(sortedData[i]);
77  }
79  fEntryNr++;
80 }
81 
83 {
85  TClonesArray* myArray = ioman->GetTClonesArray(fOutputBranch);
86  (*myArray)[myArray->GetEntries()] = data;
87 }
88 
90 
92 {
94  if (fVerbose > 2) {
95  std::cout << "-I- FairRingSorterTaskT::FinishTask Size InputArray: " << fInputArray->GetEntriesFast()
96  << std::endl;
97  }
98  for (int i = 0; i < fInputArray->GetEntriesFast(); i++) {
99  FairTimeStamp* myDigi = static_cast<FairTimeStamp*>(fInputArray->At(i));
100  fSorter->AddElement(myDigi, (static_cast<FairTimeStamp*>(myDigi))->GetTimeStamp());
101  }
102  fSorter->Print();
103  fSorter->WriteOutAll();
104  std::vector<FairTimeStamp*> sortedData = fSorter->GetOutputData();
105 
108  for (unsigned int i = 0; i < sortedData.size(); i++) {
109  if (fVerbose > 2) {
110  std::cout << i << " FinishTask : ";
111  sortedData[i]->Print();
112  std::cout << std::endl;
113  }
114 
115  AddNewDataToTClonesArray(sortedData[i]);
116  }
118  if (fVerbose > 1) {
119  fSorter->Print();
120  }
121  ioman->SetLastFill();
122 }
123 
TClonesArray * fInputArray
virtual InitStatus Init()
virtual void FinishEvent()
InitStatus
Definition: FairTask.h:33
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void AddElement(FairTimeStamp *digi, double timestamp)
virtual void AddNewDataToTClonesArray(FairTimeStamp *data)
virtual void DeleteOutputData()
TClonesArray * GetTClonesArray(TString branchName)
Int_t fVerbose
Definition: FairTask.h:100
void SetLastFill(Bool_t val=kTRUE)
virtual void FinishTask()
virtual std::vector< FairTimeStamp * > GetOutputData()
Double_t GetTimeStamp() const
Definition: FairTimeStamp.h:44
virtual void WriteOutAll()
virtual void Exec(Option_t *opt)
virtual InitStatus ReInit()
FairRingSorter * fSorter
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
TClonesArray * GetEmptyTClonesArray(TString branchName)
TClonesArray * fOutputArray
virtual FairRingSorter * InitSorter(Int_t numberOfCells, Double_t widthOfCells) const