00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "TLeafB.h"
00018 #include "TBranch.h"
00019 #include "TClonesArray.h"
00020 #include "Riostream.h"
00021
00022 ClassImp(TLeafB)
00023
00024
00025 TLeafB::TLeafB()
00026 : TLeaf()
00027 , fMinimum(0)
00028 , fMaximum(0)
00029 , fValue(0)
00030 , fPointer(0)
00031 {
00032
00033 fLenType = 1;
00034 }
00035
00036
00037 TLeafB::TLeafB(TBranch *parent, const char* name, const char* type)
00038 : TLeaf(parent, name, type)
00039 , fMinimum(0)
00040 , fMaximum(0)
00041 , fValue(0)
00042 , fPointer(0)
00043 {
00044
00045 fLenType = 1;
00046 }
00047
00048
00049 TLeafB::~TLeafB()
00050 {
00051
00052 if (ResetAddress(0, kTRUE)) {
00053 delete[] fValue;
00054 fValue = 0;
00055 }
00056
00057 fPointer = 0;
00058 }
00059
00060
00061 void TLeafB::Export(TClonesArray* list, Int_t n)
00062 {
00063
00064
00065 for (Int_t i = 0, j = 0; i < n; i++, j += fLen) {
00066 memcpy(((char*) list->UncheckedAt(i)) + fOffset, &fValue[j], fLen);
00067 }
00068 }
00069
00070
00071 void TLeafB::FillBasket(TBuffer& b)
00072 {
00073
00074
00075 Int_t len = GetLen();
00076 if (fPointer) {
00077 fValue = *fPointer;
00078 }
00079 if (IsRange()) {
00080 if (fValue[0] > fMaximum) {
00081 fMaximum = fValue[0];
00082 }
00083 }
00084 if (IsUnsigned()) {
00085 for (Int_t i = 0; i < len; i++) {
00086 b << (UChar_t) fValue[i];
00087 }
00088 } else {
00089 b.WriteFastArray(fValue, len);
00090 }
00091 }
00092
00093
00094 const char *TLeafB::GetTypeName() const
00095 {
00096
00097
00098 if (fIsUnsigned) {
00099 return "UChar_t";
00100 }
00101 return "Char_t";
00102 }
00103
00104
00105 void TLeafB::Import(TClonesArray *list, Int_t n)
00106 {
00107
00108
00109 for (Int_t i = 0, j = 0; i < n; i++, j+= fLen) {
00110 memcpy(&fValue[j], ((char*) list->UncheckedAt(i)) + fOffset, fLen);
00111 }
00112 }
00113
00114
00115 void TLeafB::PrintValue(Int_t l) const
00116 {
00117
00118
00119 if (fIsUnsigned) {
00120 UChar_t *uvalue = (UChar_t*) GetValuePointer();
00121 printf("%u", uvalue[l]);
00122 } else {
00123 Char_t *value = (Char_t*) GetValuePointer();
00124 printf("%d", value[l]);
00125 }
00126 }
00127
00128
00129 void TLeafB::ReadBasket(TBuffer &b)
00130 {
00131
00132
00133 if (!fLeafCount && (fNdata == 1)) {
00134 b >> fValue[0];
00135 } else {
00136 if (fLeafCount) {
00137 Long64_t entry = fBranch->GetReadEntry();
00138 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
00139 fLeafCount->GetBranch()->GetEntry(entry);
00140 }
00141 Int_t len = Int_t(fLeafCount->GetValue());
00142 if (len > fLeafCount->GetMaximum()) {
00143 Error("ReadBasket", "leaf: '%s' len: %d max: %d", GetName(), len, fLeafCount->GetMaximum());
00144 len = fLeafCount->GetMaximum();
00145 }
00146 fNdata = len * fLen;
00147 b.ReadFastArray(fValue, len*fLen);
00148 } else {
00149 b.ReadFastArray(fValue, fLen);
00150 }
00151 }
00152 }
00153
00154
00155 void TLeafB::ReadBasketExport(TBuffer& b, TClonesArray* list, Int_t n)
00156 {
00157
00158
00159 b.ReadFastArray(fValue, n*fLen);
00160
00161 for (Int_t i = 0, j = 0; i < n; i++, j += fLen) {
00162 memcpy(((char*) list->UncheckedAt(i)) + fOffset, &fValue[j], fLen);
00163 }
00164 }
00165
00166
00167 void TLeafB::ReadValue(istream &s)
00168 {
00169
00170 char* value = (char*) GetValuePointer();
00171 s >> value;
00172 }
00173
00174
00175 void TLeafB::SetAddress(void *addr)
00176 {
00177
00178
00179
00180
00181 if (ResetAddress(addr)) {
00182
00183 delete[] fValue;
00184 fValue = 0;
00185 }
00186 if (addr) {
00187
00188 if (TestBit(kIndirectAddress)) {
00189
00190 fPointer = (Char_t**) addr;
00191
00192
00193 Int_t ncountmax = fLen;
00194 if (fLeafCount) {
00195 ncountmax = (fLeafCount->GetMaximum() + 1) * fLen;
00196 }
00197
00198 if ((fLeafCount && (Int_t(fLeafCount->GetValue()) < ncountmax)) ||
00199 (fNdata < ncountmax) ||
00200 (*fPointer == 0)) {
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 if (fNdata < ncountmax) {
00223 fNdata = ncountmax;
00224 }
00225 delete[] *fPointer;
00226 *fPointer = 0;
00227 *fPointer = new Char_t[fNdata];
00228 }
00229 fValue = *fPointer;
00230 } else {
00231
00232
00233 fValue = (char*) addr;
00234 }
00235 } else {
00236
00237
00238 fValue = new char[fNdata];
00239
00240 fValue[0] = 0;
00241 }
00242 }
00243