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