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