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