FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMCObject.h
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  * FairMCStage.h
10  *
11  * Created on: Dec 1, 2009
12  * Author: stockman
13  */
14 
15 #ifndef FAIRMCOBJECT_H_
16 #define FAIRMCOBJECT_H_
17 
18 #include "FairLink.h" // for FairLink
19 #include "FairMCEntry.h" // for FairMCEntry
20 #include "FairMultiLinkedData.h" // for FairMultiLinkedData
21 
22 #include <Rtypes.h> // for Int_t, FairMCObject::Class, etc
23 #include <TObject.h> // for TObject
24 #include <iostream> // for ostream, etc
25 #include <utility> // for pair
26 #include <vector> // for vector
27 
28 class FairMCObject : public TObject
29 {
30  public:
31  FairMCObject();
32  FairMCObject(Int_t type)
33  : TObject()
34  , fStage()
35  , fStageId(type)
36  {}
38  : TObject(obj)
39  , fStage(obj.GetEntryVector())
40  , fStageId(obj.GetStageId())
41  {}
42  FairMCObject(Int_t type, std::vector<FairMCEntry> stage)
43  : TObject()
44  , fStage(stage)
45  , fStageId(type)
46  {}
47 
49  {
50  if (this == &from) {
51  return *this;
52  }
53 
54  TObject::operator=(from);
55  fStage = from.fStage;
56  fStageId = from.fStageId;
57 
58  return *this;
59  }
60 
61  virtual ~FairMCObject();
62 
63  void SetStageId(Int_t type) { fStageId = type; }
64 
65  void SetEntry(std::vector<Int_t> type, std::vector<Int_t> link, int index);
66  void SetEntry(FairMultiLinkedData* data, int index);
67  void SetEntry(FairMCEntry link);
68 
69  void SetStage(std::vector<FairMCEntry> stage) { fStage = stage; }
70  void SetLink(FairLink link, int index);
71  void AddLink(FairLink link, int index);
72 
73  FairMCEntry GetEntry(int index) const { return fStage[index]; }
74  FairLink GetSingleLink(int entryIndex, int linkIndex) const { return fStage.at(entryIndex).GetLink(linkIndex); }
75 
76  Int_t GetStageId(void) const { return fStageId; }
77 
78  FairMCEntry GetMCLink(Int_t index) { return fStage.at(index); }
79 
80  int GetNEntries() const { return fStage.size(); }
81  int GetNLinks(int entryIndex) const { return fStage.at(entryIndex).GetNLinks(); }
82  std::vector<FairMCEntry> GetEntryVector() const { return fStage; }
83 
84  FairMultiLinkedData PosInList(std::pair<int, int> link);
86 
88  {
89  FairMultiLinkedData result;
90  for (int i = 0; i < GetNEntries(); i++) {
91  result.AddLinks(GetMCLink(i).GetLinksWithType(type));
92  }
93  return result;
94  }
95 
96  void RemoveType(Int_t type);
97 
98  virtual void ClearEntries() { fStage.clear(); }
99 
100  virtual void PrintInfo(std::ostream& out = std::cout) { out << *this; }
101 
102  /*
103  void operator=(const FairMCObject& obj) {
104  fStageId = obj.GetStageId();
105  fStage = obj.GetEntryVector();
106  }
107  */
108 
109  friend std::ostream& operator<<(std::ostream& out, const FairMCObject& obj)
110  {
111  std::vector<FairMCEntry> stages = obj.GetEntryVector();
112  for (unsigned int i = 0; i < stages.size(); i++) {
113  if (stages[i].GetNLinks() > 0) {
114  out << i << ": ";
115  stages[i].PrintInfo(out);
116  out << std::endl;
117  }
118  }
119  return out;
120  }
121 
122  private:
123  void AdoptSize(int index);
124  std::vector<FairMCEntry> fStage;
125  Int_t fStageId;
126 
127  ClassDef(FairMCObject, 0);
128 };
129 
130 #endif /* FAIRMCOBJECT_H_ */
FairMultiLinkedData PosInList(std::pair< int, int > link)
FairMultiLinkedData GetLinksWithType(Int_t type)
Definition: FairMCObject.h:87
void RemoveType(Int_t type)
FairMCObject(const FairMCObject &obj)
Definition: FairMCObject.h:37
virtual void PrintInfo(std::ostream &out=std::cout)
Definition: FairMCObject.h:100
FairMCObject(Int_t type)
Definition: FairMCObject.h:32
std::vector< FairMCEntry > GetEntryVector() const
Definition: FairMCObject.h:82
friend std::ostream & operator<<(std::ostream &out, const FairMCObject &obj)
Definition: FairMCObject.h:109
void SetLink(FairLink link, int index)
FairMCEntry GetEntry(int index) const
Definition: FairMCObject.h:73
FairMCObject & operator=(const FairMCObject &from)
Definition: FairMCObject.h:48
virtual ~FairMCObject()
virtual void AddLinks(FairMultiLinkedData links, Float_t mult=1.0)
Adds a List of FairLinks (FairMultiLinkedData) to fLinks.
virtual void ClearEntries()
Definition: FairMCObject.h:98
void AddLink(FairLink link, int index)
int GetNEntries() const
Definition: FairMCObject.h:80
FairMCObject(Int_t type, std::vector< FairMCEntry > stage)
Definition: FairMCObject.h:42
FairMCEntry GetMCLink(Int_t index)
Definition: FairMCObject.h:78
int GetNLinks(int entryIndex) const
Definition: FairMCObject.h:81
void SetStageId(Int_t type)
Definition: FairMCObject.h:63
Int_t GetStageId(void) const
Definition: FairMCObject.h:76
void SetStage(std::vector< FairMCEntry > stage)
Definition: FairMCObject.h:69
void SetEntry(std::vector< Int_t > type, std::vector< Int_t > link, int index)
FairLink GetSingleLink(int entryIndex, int linkIndex) const
Definition: FairMCObject.h:74