Project
Loading...
Searching...
No Matches
FairLink.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 * FairLink.h
10 *
11 * Created on: Dec 23, 2009
12 * Author: stockman
13 * "Pointer" to any data structure inside a root file with a tree structure
14 * Contains four information:
15 * File : in which file is the data written (-1 : actual number; 254 : maximum number)
16 * Entry: entry number in branch of a tree (-1 : actual entry)
17 * Type : branch inside the tree (-1 : FairLink not set; 65534 : maximum number)
18 * Index: position inside a container stored in the given branch and entry
19 * Weight: weighting factor to describe probabilities of a MC truth match
20 *
21 */
22
23#ifndef FAIRLINK_H_
24#define FAIRLINK_H_
25
26#include <Rtypes.h> // for Int_t, Float_t, etc, ClassDefNV
27#include <iostream> // for ostream, cout
28
30{
31 public:
32 FairLink();
33 FairLink(Int_t type, Int_t index, Float_t weight = 1.);
34 FairLink(TString branchName, Int_t index, Float_t weight = 1.);
35 FairLink(Int_t file, Int_t entry, Int_t type, Int_t index, Float_t weight = 1.);
36 FairLink(Int_t file, Int_t entry, TString branchName, Int_t index, Float_t weight = 1.);
38
39 void SetLink(Int_t file, Int_t entry, Int_t type, Int_t index, Float_t weight = 1.)
40 {
41 SetFile(file);
46 };
47 void SetLink(Int_t type, Int_t index, Float_t weight = 1.)
48 {
49 SetFile(-1);
50 SetEntry(-1);
54 };
55 int GetFile() const;
56 int GetEntry() const { return fEntry; }
57 int GetType() const;
58 int GetIndex() const { return fIndex; }
59 float GetWeight() const { return fWeight; }
60
61 void SetFile(int file);
62 void SetEntry(int entry) { fEntry = entry; };
63 void SetType(int type);
64 void SetIndex(int index) { fIndex = index; };
65
66 void SetWeight(Float_t weight) { fWeight = weight; }
67 void AddWeight(Float_t weight) { fWeight += weight; }
68
69 void PrintLinkInfo(std::ostream& out = std::cout) const;
70
71 bool operator==(const FairLink& link) const
72 {
73 if ((GetFile() == link.GetFile() || link.GetFile() == -1)
74 && (GetEntry() == link.GetEntry() || link.GetEntry() == -1) && GetType() == link.GetType()
75 && GetIndex() == link.GetIndex()) {
76 return true;
77 } else {
78 return false;
79 }
80 }
81
82 bool operator<(const FairLink& link) const
83 {
84 if (GetFile() != -1 && link.GetFile() != -1) {
85 if (GetFile() < link.GetFile())
86 return true;
87 else if (link.GetFile() < GetFile())
88 return false;
89 }
90 if (GetEntry() != -1 && link.GetEntry() != -1) {
91 if (GetEntry() < link.GetEntry())
92 return true;
93 else if (link.GetEntry() < GetEntry())
94 return false;
95 }
96 if (GetType() < link.GetType())
97 return true;
98 else if (link.GetType() < GetType())
99 return false;
100 if (GetIndex() < link.GetIndex())
101 return true;
102 else if (link.GetIndex() < GetIndex())
103 return false;
104
105 return false;
106 }
107
108 friend std::ostream& operator<<(std::ostream& out, const FairLink& link)
109 {
110 link.PrintLinkInfo(out);
111 return out;
112 }
113
115
116 template<class Archive>
117 void serialize(Archive& ar, const unsigned int)
118 {
119 ar& fFile;
120 ar& fType;
121 ar& fEntry;
122 ar& fIndex;
123 ar& fWeight;
124 }
125
126 private:
127 unsigned char fFile;
128 unsigned short fType;
129 int fEntry;
130 int fIndex;
131 float fWeight;
132};
133
135 : fFile(0)
136 , fType(0)
137 , fEntry(-1)
138 , fIndex(-1)
139 , fWeight(1.0)
140{}
141
143 : fFile(0)
144 , fType(0)
145 , fEntry(-1)
146 , fIndex(index)
147 , fWeight(weight)
148{
149 SetType(type);
150}
151
152inline FairLink::FairLink(Int_t file, Int_t entry, Int_t type, Int_t index, Float_t weight)
153 : fFile(0)
154 , fType(0)
155 , fEntry(entry)
156 , fIndex(index)
157 , fWeight(weight)
158{
159 SetFile(file);
160 SetType(type);
161}
162
163inline void FairLink::SetType(int type)
164{
165 if (type < -1)
166 return;
167 fType = type + 1;
168}
169
170inline int FairLink::GetType() const
171{
172 int type = fType;
173 return type - 1;
174}
175
176inline void FairLink::SetFile(int file)
177{
178 if (file < -1)
179 return;
180 fFile = file + 1;
181}
182
183inline int FairLink::GetFile() const
184{
185 int file = fFile;
186 return file - 1;
187}
188
189#endif /* FAIRLINK_H_ */
GLuint entry
Definition glcorearb.h:5735
GLuint index
Definition glcorearb.h:781
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275