-
Notifications
You must be signed in to change notification settings - Fork 0
/
treestream.cc
2490 lines (2057 loc) · 62.7 KB
/
treestream.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//----------------------------------------------------------------------------
// File: treestream.cc
//
// Description: The classes itreestream and otreestream provide a convenient
// interface to the kind of Root-trees typically used in
// analyses in Dzero and CMS. All the boilerplate code for
// getting at the tree, its branches and its leaves is hidden
// from the user.
//
// The design is based on the observation that, ultimately, data
// reduce to a set of name/value pairs in which the value
// can be regarded as a homogeneous sequence of doubles, floats
// or ints. Moreover, an arbitrarily complex graph of the
// name/value pairs is readily achieved with, well, name/value
// pairs! Name/value pair is just another name for variable.
//
// Thinking in terms of objects, in the context of high energy
// physics analysis, has yielded great complexity. On the other
// hand, thinking in terms of name/value pairs reduces the
// complexity enormously. The irreducible complexity, which
// surely exists, properly resides in the graph generated by
// the set of name/value pairs, that is, variables.
//
// Of course, it is often convenient to package name/value pairs
// into objects to avail oneself of their useful behaviour. This
// may be useful, for example, to model a particularly
// complicated sub-graph of name/value pairs. Sometimes this is
// useful if an object defines functions on the name/value pairs.
// A nice example of packaging name/value pairs for this reason
// is the packaging of the name/value pairs, Px, Py, Pz and E
// into TLorentzVector objects, which provides a host of useful
// mathematical operations on them.
//
// Created: 19-Feb-2005 Harrison B. Prosper, based on 12-Mar-2001 version of
// the same.
// 14-Jul-2005 HBP Make even simpler!
// 13-Aug-2005 HBP ..and simpler still!
// 30-Nov-2005 HBP fix counter loading bug
// 31-Oct-2009 HBP allow use of regexes in branch names
// fix looping bug so operator[] works for Python
// 02-Oct-2010 HBP minor change to itreestream to handle vector types
// directly.
// 22-Nov-2010 HBP allow reading of multiple trees
// 22-Nov-2011 HBP handle reading/storing of strings
//$Revision: 1.5 $
//----------------------------------------------------------------------------
#ifdef PROJECT_NAME
#include <boost/regex.hpp>
#endif
#include <glob.h>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <typeinfo>
#include <cctype>
#include <cassert>
#include "TList.h"
#include "TKey.h"
#include "TFile.h"
#include "TLeaf.h"
#include "TDirectory.h"
#include "TTree.h"
#include "TClass.h"
#include "TChain.h"
#include "TString.h"
#include "TList.h"
#include "TIterator.h"
#include "TFriendElement.h"
#ifdef PROJECT_NAME
#include "PhysicsTools/TheNtupleMaker/interface/treestream.h"
#else
#include "treestream.h"
#endif
//----------------------------------------------------------------------------
#ifdef __WITH_CINT__
ClassImp(itreestream)
ClassImp(otreestream)
#endif
using namespace std;
// Status codes
const int kSUCCESS=0;
const int kBADOPEN=1;
const int kBADTREE=2;
const int kBADBRANCH=3;
int DEBUGLEVEL=0;
// Make following visible only to this compilation unit.
namespace
{
void fatal(string message)
{
cout << "** Error ** " << message << endl;
exit(1);
}
void warning(string message)
{
cout << "** Warning ** " << message << endl;
}
string blank(" ");
void DBUG(string message, int level=1)
{
if ( getenv("DBtreestream") > 0 )
DEBUGLEVEL = atoi(getenv("DBtreestream"));
else
DEBUGLEVEL = 0;
if ( DEBUGLEVEL >= level ) cout << message << endl;
}
void split(string str, vector<string>& vstr)
{
vstr.clear();
istringstream stream(str);
while ( stream )
{
string strg;
stream >> strg;
if ( stream ) vstr.push_back(strg);
}
}
// For given leaf, find maximum number of items.
int getmaxsize(TLeaf* leaf)
{
int count = 0;
TLeaf* leafcounter = leaf->GetLeafCounter(count);
if ( leafcounter != 0 )
// Variable length array
return leafcounter->GetMaximum();
else
// Either fixed length array or a simple variable
return leaf->GetLen();
}
// ----------------------------------------------------------------------
// return value of given internal buffer
// ----------------------------------------------------------------------
template <class T>
inline
T
invalue(Field* field, int index=0, int which=0)
{
if ( which == 0 )
return static_cast<T>(field->leaf->GetValue(index));
else
{
assert(index >= 0);
FieldBuffer<T>* d = dynamic_cast<FieldBuffer<T>*>(field);
if ( d == 0 ) fatal("getinvalue - dynamic_cast failed " +
string(field->branch->GetName()));
assert(index < (int)d->value.size());
return d->value[index];
}
}
template <class T>
inline
int
insize(Field* field)
{
FieldBuffer<T>* d = dynamic_cast<FieldBuffer<T>*>(field);
if ( d == 0 ) fatal("getinvalue - dynamic_cast failed " +
string(field->branch->GetName()));
return (int)d->value.size();
}
// For debug only
double
getinvalue(Field* field, int index=0, int which=0)
{
if ( which == 0 )
return field->leaf->GetValue(index);
else
{
double val = 0;
switch(field->iotype)
{
case 'D':
val = invalue<double>(field, index, 1);
break;
case 'F':
val = static_cast<double>(invalue<float>(field, index, 1));
break;
case 'L':
val = static_cast<double>(invalue<long>(field, index, 1));
break;
case 'I':
val = static_cast<double>(invalue<int>(field, index, 1));
break;
case 'S':
val = static_cast<double>(invalue<short>(field, index, 1));
break;
case 'B':
val = static_cast<double>(invalue<char>(field, index, 1));
break;
case 'l':
val = static_cast<double>(invalue<unsigned long>(field, index, 1));
break;
case 'i':
val = static_cast<double>(invalue<unsigned int>(field, index, 1));
break;
case 's':
val=static_cast<double>(invalue<unsigned short>(field, index, 1));
break;
case 'b':
val = static_cast<double>(invalue<unsigned char>(field, index, 1));
break;
default:
val = invalue<double>(field, index, 1);
break;
}
return val;
}
}
int
getinsize(Field* field)
{
int size = 0;
switch(field->iotype)
{
case 'D':
size = insize<double>(field);
break;
case 'F':
size = insize<float>(field);
break;
case 'L':
size = insize<long>(field);
break;
case 'I':
size = insize<int>(field);
break;
case 'S':
size = insize<short>(field);
break;
case 'B':
size = insize<char>(field);
break;
case 'C':
size = insize<string>(field);
break;
case 'l':
size = insize<unsigned long>(field);
break;
case 'i':
size = insize<unsigned int>(field);
break;
case 's':
size = insize<unsigned short>(field);
break;
case 'b':
size = insize<unsigned char>(field);
break;
default:
size = insize<double>(field);
break;
}
return size;
}
// ----------------------------------------------------------------------
// return value of given external buffer
// T is type of external buffer
// ----------------------------------------------------------------------
template <class T>
inline
T
exvalue(Field* field, int index=0)
{
T val;
if ( field->isvector )
{
vector<T>* d = reinterpret_cast<vector<T>*>(field->address);
if ( d == 0 ) fatal("exvalue - reinterpret_cast failed" +
string(field->branch->GetName()));
val = (*d)[index];
}
else
{
T* d = reinterpret_cast<T*>(field->address);
if ( d == 0 ) fatal("exvalue - reinterpret_cast failed" +
string(field->branch->GetName()));
val = *d;
}
if ( DEBUGLEVEL > 0 )
cout << "\texternal value(" << val << ")" << endl;
return val;
}
template <class T>
inline
int
exsize(Field* field)
{
int val = 1;
if ( field->isvector )
{
vector<T>* d = reinterpret_cast<vector<T>*>(field->address);
if ( d == 0 ) fatal("exvalue - reinterpret_cast failed" +
string(field->branch->GetName()));
val = d->size();
//
if ( DEBUGLEVEL > 1 )
cout << "EXSIZE(" << val << ") "
<< string(field->branch->GetName()) << endl;
}
return val;
}
string
getiotype(Field* field)
{
char iotype[2]; iotype[0] = field->iotype; iotype[1] = 0;
return string(iotype);
}
string
getsrctype(Field* field)
{
char srctype[2]; srctype[0] = field->srctype; srctype[1] = 0;
return string(srctype);
}
// For debug only
double
getexvalue(Field* field, int index=0)
{
double d = 0;
switch(field->srctype)
{
case 'D':
d = exvalue<double>(field, index);
break;
case 'F':
d = static_cast<double>(exvalue<float>(field, index));
break;
case 'L':
d = static_cast<double>(exvalue<long>(field, index));
break;
case 'I':
d = static_cast<double>(exvalue<int>(field, index));
break;
case 'S':
d = static_cast<double>(exvalue<short>(field, index));
break;
case 'B':
d = static_cast<double>(exvalue<char>(field, index));
break;
case 'l':
d = static_cast<double>(exvalue<unsigned long>(field, index));
break;
case 'i':
d = static_cast<double>(exvalue<unsigned int>(field, index));
break;
case 's':
d = static_cast<double>(exvalue<unsigned short>(field, index));
break;
case 'b':
d = static_cast<double>(exvalue<unsigned char>(field, index));
break;
}
return d;
}
int
getexsize(Field* field)
{
int size = 0;
switch(field->srctype)
{
case 'D':
size = exsize<double>(field);
break;
case 'F':
size = exsize<float>(field);
break;
case 'L':
size = exsize<long>(field);
break;
case 'I':
size = exsize<int>(field);
case 'S':
size = exsize<short>(field);
case 'B':
size = exsize<char>(field);
case 'C':
size = exsize<string>(field);
case 'l':
size = exsize<unsigned long>(field);
break;
case 'i':
size = exsize<unsigned int>(field);
break;
case 's':
size = exsize<unsigned short>(field);
break;
case 'b':
size = exsize<unsigned char>(field);
default:
size = exsize<double>(field);
break;
}
return size;
}
// ----------------------------------------------------------------------
// Copy from external buffer to internal buffer.
// Note: T is the type of the internal buffer
// ----------------------------------------------------------------------
template <class T>
inline
void
fromexternal(Field* field, int count)
{
if ( DEBUGLEVEL > 0 )
{
char preamble[160];
sprintf(preamble,
"BEGIN fromexternal\n\t%-16s (%s <- %s) count = %d",
field->leaf->GetName(),
getiotype (field).c_str(),
getsrctype(field).c_str(),
count);
cout << preamble << endl;
}
FieldBuffer<T>* d = dynamic_cast<FieldBuffer<T>*>(field);
if ( d == 0 ) fatal("fromexternal - dynamic_cast failed " +
string(field->branch->GetName()));
switch(field->srctype)
{
case 'D':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<double>(field, i));
break;
case 'F':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<float>(field, i));
break;
case 'L':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<long>(field, i));
break;
case 'I':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<int>(field, i));
break;
case 'S':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<short>(field, i));
break;
case 'B':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<char>(field, i));
break;
case 'l':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<unsigned long>(field, i));
break;
case 'i':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<unsigned int>(field, i));
break;
case 's':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<unsigned short>(field, i));
break;
case 'b':
for(int i=0; i < count; i++)
d->value[i] = static_cast<T>(exvalue<unsigned char>(field, i));
break;
}
if ( DEBUGLEVEL > 0 )
{
cout << "\tinternal value = " << d->value[0] << endl;
cout << "\taddress = " << &d->value[0] << endl;
cout << "END fromexternal" << endl;
}
}
template <>
inline
void
fromexternal<string>(Field* field, int count)
{
if ( DEBUGLEVEL > 0 )
{
char preamble[160];
sprintf(preamble,
"BEGIN fromexternal\n\t%-16s (%s <- %s) count = %d",
field->leaf->GetName(),
getiotype (field).c_str(),
getsrctype(field).c_str(),
count);
cout << preamble << endl;
}
FieldBuffer<string>* d = dynamic_cast<FieldBuffer<string>*>(field);
if ( d == 0 ) fatal("fromexternal - dynamic_cast failed " +
string(field->branch->GetName()));
// IMPORTANT: use c_str() so that bytes are copied into existing
// string.
for(int i=0; i < count; i++)
d->value[i] = exvalue<string>(field, i).c_str();
if ( DEBUGLEVEL > 0 )
{
cout << "\tinternal value(" << d->value[0] << ")" << endl;
void* address = (void*)(d->value[0].c_str());
cout << "\tAddr(d->value[0].c_str()): " << address << endl;
cout << "END fromexternal" << endl;
}
}
// ----------------------------------------------------------------------
// Copy to external buffer from internal buffer.
// Note: T is the type of the external buffer
// Make sure external buffer is of the correct size
// ----------------------------------------------------------------------
template <class T>
inline
void
toexternal(Field* field)
{
int count = min(field->leaf->GetLen(), field->maxsize);
//int count = getmaxsize(field->leaf);
if ( DEBUGLEVEL > 0 )
{
char preamble[160];
sprintf(preamble,
"BEGIN toexternal\n\t%-16s (%s -> %s) count = %d",
field->leaf->GetName(),
getiotype (field).c_str(),
getsrctype(field).c_str(),
count);
cout << preamble << endl;
}
// Make sure external buffer is of the correct size
if ( field->isvector )
{
vector<T>* d = reinterpret_cast<vector<T>*>(field->address);
if ( d == 0 ) fatal("toexternal - reinterpret_cast failed" +
string(field->fullname));
if ( (int)d->size() != count ) d->resize(count, 0);
if ( (int)d->size() != count )
fatal("toexternal - unable to resize external buffer for " +
field->leafname);
for(int index=0; index < count; index++)
(*d)[index] = static_cast<T>(field->leaf->GetValue(index));
if ( DEBUGLEVEL > 0 )
cout << "\texternal value = " << (*d)[0] << endl;
}
else
{
T* d = reinterpret_cast<T*>(field->address);
if ( d == 0 ) fatal("toexternal - reinterpret_cast failed" +
string(field->fullname));
*d = static_cast<T>(field->leaf->GetValue());
if ( DEBUGLEVEL > 0 )
{
cout << "\texternal value = " << *d;
if ( field->iscounter ) cout << " (counter)";
cout << endl;
}
}
if ( DEBUGLEVEL > 0 )
cout << "END toexternal" << endl;
}
template <>
inline
void
toexternal<string>(Field* field)
{
int count = field->leaf->GetLen();
if ( DEBUGLEVEL > 0 )
{
char preamble[160];
sprintf(preamble,
"BEGIN toexternal\n\t%-16s (%s -> %s) maxsize = %d",
field->leaf->GetName(),
getiotype (field).c_str(),
getsrctype(field).c_str(),
count);
cout << preamble << endl;
}
// Make sure external buffer is of the correct size
string* d = reinterpret_cast<string*>(field->address);
if ( d == 0 ) fatal("toexternal - reinterpret_cast failed" +
string(field->fullname));
d->assign(count, 0); // assign new content to string
int size=0;
for(int index=0; index < count; index++)
{
(*d)[index] = static_cast<char>(field->leaf->GetValue(index));
if ( (*d)[index] == 0 ) break;
size++;
}
d->resize(size);
if ( DEBUGLEVEL > 0 )
cout << "\texternal value = " << *d << endl;
if ( DEBUGLEVEL > 0 )
cout << "END toexternal" << endl;
}
// ----------------------------------------------------------------------
// IMPORTANT: In tree->Branch(..), it is necessary to use the correct
// type when giving the address of the variable from which data are to
// be read, otherwise tree->Fill() gets really confused and can even hang
// your computer!
// ----------------------------------------------------------------------
template <class T>
inline
void
createbranch(TTree* tree, Field* field,
const char* format,
SelectedData& selecteddata)
{
DBUG("\tcreatebranch: BEGIN");
if ( tree == 0 ) fatal("createbranch - tree pointer is zero ");
if ( field == 0 ) fatal("createbranch - field pointer is zero ");
FieldBuffer<T>* v = new FieldBuffer<T>();
assert(v != 0);
v->iotype = field->iotype;
v->srctype = field->srctype;
v->address = field->address;
v->isvector= field->isvector;
v->maxsize = field->maxsize;
v->branchname= field->branchname;
v->leafname= field->branchname;
v->iscounter = false;
v->branch = 0;
v->leaf = 0;
v->leafname= "";
v->value.clear();
v->value.reserve(v->maxsize);
v->value.resize(v->maxsize, 0);
if ( DEBUGLEVEL > 0 )
{
cout << "\tcreatebranch: maxsize: " << v->value.size() << endl;
cout << "\tcreatebranch: ADDRESS: " << v->address << endl;
}
// Store in map
selecteddata[v->branchname] = v;
DBUG("\tcreatebranch: " + v->branchname + "\t" + format);
void* address = &(v->value[0]);
tree->Branch(v->branchname.c_str(), address, format);
TBranch* branch = tree->GetBranch(v->branchname.c_str());
if ( branch == 0 ) fatal("createbranch - unable create branch " +
v->branchname);
v->branch = branch;
v->leaf = branch->GetLeaf(v->branchname.c_str());
assert(v->leaf);
DBUG("\tcreatebranch: END");
}
template <>
inline
void
createbranch<string>(TTree* tree, Field* field,
const char* format,
SelectedData& selecteddata)
{
DBUG("\tcreatebranch: BEGIN");
if ( tree == 0 ) fatal("createbranch - tree pointer is zero ");
if ( field == 0 ) fatal("createbranch - field pointer is zero ");
FieldBuffer<string>* v = new FieldBuffer<string>();
assert(v != 0);
v->iotype = field->iotype;
v->srctype = field->srctype;
v->address = field->address;
v->isvector= field->isvector;
v->maxsize = field->maxsize;
v->branchname= field->branchname;
v->leafname= field->branchname;
v->iscounter = false;
v->branch = 0;
v->leaf = 0;
v->leafname= "";
string* d = reinterpret_cast<string*>(field->address);
if ( d == 0 ) fatal("createbranch - reinterpret_cast failed" +
string(field->fullname));
v->value.clear();
v->value.reserve(v->maxsize);
v->value.resize(v->maxsize, *d);
if ( DEBUGLEVEL > 0 )
{
cout << "\tcreatebranch: init value(" << v->value[0] << ")" << endl;
cout << "\tcreatebranch: maxsize: " << v->value.size() << endl;
}
// Store in map
selecteddata[v->branchname] = v;
DBUG("\tcreatebranch: " + v->branchname + "\t" + format);
void* address = (void*)(v->value[0].c_str());
tree->Branch(v->branchname.c_str(), address, format);
TBranch* branch = tree->GetBranch(v->branchname.c_str());
if ( branch == 0 ) fatal("createbranch - unable create branch " +
v->branchname);
v->branch = branch;
v->leaf = branch->GetLeaf(v->branchname.c_str());
assert(v->leaf);
DBUG("\tcreatebranch: END");
}
void
readbranch(Field* field, int entry)
{
assert(field != 0);
if ( field->branch ==0 ) return;
assert(field->branch != 0);
assert(field->leaf != 0);
// Read entry for current branch
field->branch->GetEntry(entry);
// If address field is zero, this signals that
// the caller has not provided a location into which
// the value of the current variable is to be written.
// This should happen only for leaf counter variables.
// In this case, just return
if ( field->address == 0) return;
// If this is intrinsically a vector type, we let Root handle it
// directly
if ( field->iotype == 'v' ) return;
// Copy data from internal to external buffers
// iotype -> srctype
switch(field->srctype)
{
case 'D':
toexternal<double>(field);
break;
case 'F':
toexternal<float>(field);
break;
case 'L':
toexternal<long>(field);
break;
case 'I':
toexternal<int>(field);
break;
case 'S':
toexternal<short>(field);
break;
case 'B':
toexternal<char>(field);
break;
case 'C':
toexternal<string>(field);
break;
case 'l':
toexternal<unsigned long>(field);
break;
case 'i':
toexternal<unsigned int>(field);
break;
case 's':
toexternal<unsigned short>(field);
break;
case 'b':
toexternal<unsigned char>(field);
break;
default:
toexternal<double>(field);
break;
}
}
}
// Default constructor
itreestream::itreestream()
: _tree(0),
_chain(0),
_statuscode(kSUCCESS),
_current(-1),
_entries(0),
_entry(0),
_index(0),
_buffer(vector<double>(1000)),
data(Data()),
selecteddata(SelectedData()),
_delete(true)
{}
itreestream::itreestream(string filename_, int bufsize)
: _tree(0),
_chain(0),
_statuscode(kSUCCESS),
_current(-1),
_entries(0),
_entry(0),
_index(0),
_buffer(vector<double>(bufsize)),
data(Data()),
selecteddata(SelectedData()),
_delete(true)
{
vector<string> fname;
split(filename_, fname);
vector<string> tname;
_open(fname, tname);
}
itreestream::itreestream(vector<string>& fname, int bufsize)
: _tree(0),
_chain(0),
_statuscode(kSUCCESS),
_current(-1),
_entries(0),
_entry(0),
_index(0),
_buffer(vector<double>(bufsize)),
data(Data()),
selecteddata(SelectedData()),
_delete(true)
{
vector<string> tname;
_open(fname, tname);
}
itreestream::itreestream(string filename_, string treename, int bufsize)
: _tree(0),
_chain(0),
_statuscode(kSUCCESS),
_current(-1),
_entries(0),
_entry(0),
_index(0),
_buffer(vector<double>(bufsize)),
data(Data()),
selecteddata(SelectedData()),
_delete(true)
{
vector<string> fname;
split(filename_, fname);
vector<string> tname;
split(treename, tname);
_open(fname, tname);
}
itreestream::itreestream(vector<string>& fname, string treename, int bufsize)
: _tree(0),
_chain(0),
_statuscode(kSUCCESS),
_current(-1),
_entries(0),
_entry(0),
_index(0),
_buffer(vector<double>(bufsize)),
data(Data()),
selecteddata(SelectedData()),
_delete(true)
{
vector<string> tname;
split(treename, tname);
_open(fname, tname);
}
void
itreestream::init(TTree* tree_)
{
_delete = false;
_tree = tree_;
vector<string> fname;
vector<string> tname;