001 #ifndef HEPNTUPLE_H
002 #define HEPNTUPLE_H
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045 #ifdef COMMENT
046
047 Mods in development:
048
049 7/11/97 mf Codeguard name is HEPTUPLE_H: Rule is if a file name starts
050 with the package''s name-guard because the class it represents
051 does, we don''t repeat that name-guard twice:
052 not HEPHEPTUPLE_H.
053
054 Added clearDataColumn(), and changed name for clearDataBlock().
055 Changed name of capture for a block to captureBlock().
056
057 Added lockOutNewColumns() and allowNewColumns().
058
059 Added private variables and methods area.
060
061 Added to private area: unspecifiedBlock
062 unspecifiedBlockNumber
063 formUnspecifiedBlock()
064 lockNoNewColumns
065
066 7/14/97 mf Added declarations of ZMx classes. These are temporary, and
067 will need to be fleshed out even before full ZM exception
068 mechanism is done.
069
070 7/22/97 pc added isLockedNewColumns() returns whether the addition of new
071 columns is blocked.
072
073 7/28/97 web Granted friendship to HepFileManager
074
075 7/30/97 web Made use of new base class HepObj for consistency in naming
076 1/20/98 pc Change all pertinent char* and char[] to std::string
077 2/21/00 web Improved C++ standard compliance
078
079
080 #endif
081
082
083 #ifdef COMMENT
084
085 In this preliminary version of the header for HepNtuple we
086 don''t know yet how we will want to handle colums of characters (in
087 HBOOK they have 8 types, CHAR4 thru CHAR32). This decision won''t seriously
088 affect the rest of the interface.
089
090 #endif
091
092 #ifndef ZMENVIRONMENT_H
093 #include "ZMutility/ZMenvironment.h"
094 #endif
095
096 #include <string>
097
098 #include "ZMutility/map"
099 #include <vector>
100
101
102 #ifndef HEPOBJ_H
103 #include "HepTuple/HepObj.h"
104 #endif
105
106 #ifndef FIXEDTYPES_H
107 #include "ZMutility/FixedTypes.h"
108 #endif
109 ZM_USING_NAMESPACE( zmfxt )
110
111 #include "HepTuple/ColumnAttribs.h"
112 #include <HepTuple/useMethod.h>
113
114
115 ZM_BEGIN_NAMESPACE( zmht )
116
117 class HepFileManager;
118
119 class Block;
120 class Column;
121 template <class T> class ColumnT;
122
123 class TupleNameTag;
124
125 class HepNtuple : public HepObj {
126
127 friend class HepFileManager;
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 #ifdef COMMENT
144 Methods summary
145
146 (Only the float forms of Tuple data are shown in this summary)
147
148 bool column (const std::string& nametag, float value, float defval=0);
149 bool newColumn (const std::string& nametag, float val, float defval=0);
150 HepNtuple& columnAt (const std::string& nametag, float* address,
151 float defval=0);
152 HepNtuple& columnVia (const std::string& nametag, ZMuseMethod<float>* method,
153 float defval=0);
154 HepNtuple& columnVia (const std::string& nametag, float(*function)(),
155 float defval=0);
156 HepNtuple& columnArray (const std::string& nametag, int ncolumns,
157 float defval=0);
158 HepNtuple& columnDirect (const std::string& nametag, float defval=0);
159 HepNtuple& pack ( float min, float max, int nbits);
160 HepNtuple& pack (const std::string& nametag,float min, float max, int nbits);
161 HepNtuple& span ( int min, int max);
162 HepNtuple& span (const std::string& nametag,int min, int max);
163 HepNtuple& dimension (const std::string& nametag, int dim);
164 HepNtuple& dimension ( int dim);
165 HepNtuple& dimension (const std::string& nametag, int dim1, int dim2,
166 int dim3=0, int dim4=0, int dim5=0, int dim6=0,
167 int dim7=0, int dim8=0, int dim9=0, int dim10=0);
168 HepNtuple& dimension ( int dim1, int dim2,
169 int dim3=0, int dim4=0, int dim5=0, int dim6=0,
170 int dim7=0, int dim8=0, int dim9=0, int dim10=0);
171 HepNtuple& index (const std::string& nametag, const std::string& indextag);
172 HepNtuple& index ( const std::string& indextag);
173 HepNtuple& characters (const std::string& nametag, int length);
174 HepNtuple& characters ( int length);
175 bool block (const std::string& blockName, const std::string& format,
176 std::vector<void*> addresses);
177
178 bool lockOutNewColumns ();
179 bool allowNewColumns ();
180 bool isLockNewColumns();
181
182 bool setRowWise ();
183 bool setColumnWise ();
184 bool setBlockWise ();
185 bool setDiskResident ();
186 bool setMemResident ();
187 bool setSharedMemory (char sharedMemoryArea[]);
188 bool setNwbuff (int nwbuff);
189 bool setBuffLimit (int nbytes);
190 bool setCircularBuffer (int nwbuff);
191 bool setDemandBuffers (int nbytes);
192
193 bool captureThenStore ( );
194 bool capture (const std::string& nametag, float value);
195 int setExistingColumn (const std::string& lbl, float val);
196 bool capture (const std::string& nametag, float value[]);
197 bool capture (const std::string& nametag, float value[], int indexval);
198 bool captureColumn (const std::string& nametag);
199 bool captureBlock (const std::string& blockName);
200 bool capture ( );
201 bool storeCapturedData ( );
202
203 bool clearData ( ); \*H*\
204 bool clearDataBlock (const std::string& blockName);
205 bool clearDataColumn(const std::string& nametag);
206
207 bool readColumn (int irow, const std::string& nametag, float* value);
208 int readColumnArray (int irow, const std::string& nametag, float values[]);
209 int readBlock (int irow, const std::string& blockName);
210 int readRow (int irow);
211 int bulkReadColumn (const int irow, const int nrows,
212 const std::string& nametag, float destination[]);
213
214 HepNtuple destinationAt (const std::string& nametag,
215 float* address);
216 HepNtuple destinationVia (const std::string& nametag,
217 void (* setMethod) (float));
218 HepNtuple destinationVia (const std::string& nametag,
219 void (* setMethod) (float[]));
220 bool blockDestinations (const std::string& blockName,
221 const std::string& format,
222 std::vector<void*> addresses);
223 std::string title ( );
224 std::string dir ( );
225 HepFileManager* manager ( );
226 int id ( );
227 bool isRowWise ( );
228 bool isColumnWise ( );
229 bool isBlockWise ( );
230 char resident ( );
231 Std::String sharedAreaName ( );
232 int nwbuff ( );
233 int buffLimit ( );
234 bool isCircularBuffer ( );
235 bool isDemandBuffers ( );
236
237 int nBlocks ( );
238 std::string blockName (int blockNumber);
239 std::string blockFormat (int blockNumber);
240 std::string blockFormat (const std::string& blockName);
241
242 int nColumns ( );
243 int nColumns (const std::string& blockName);
244 std::string nametag (int columnNumber);
245 std::string nametag (int columnNumber, const std::string& blockName);
246 std::string tag (int columnNumber);
247 std::string tag (int columnNumber, const std::string& blockName);
248
249 std::string columnBlock (const std::string& tag);
250 std::string columnNametag (const std::string& tag);
251 type_info columnType_info (const std::string& nametag);
252 ColumnData_t columnDataType (const std::string& nametag);
253 int columnDimensions (const std::string& nametag, int dims[] );
254 std::string columnIndex (const std::string& nametag);
255 bool columnDefault (const std::string& nametag, float* default);
256 bool setColumnDefault (const std::string& nametag, float default);
257 bool columnSpan (const std::string& nametag, int* min, int* max);
258 void* columnDesignatedVariable (const std::string& nametag);
259 void* columnDestinationVariable (const std::string& nametag);
260 bool columnPacking (const std::string& nametag, float* low, float* high,
261 int* inbits);
262
263 #endif
264
265
266 public:
267
268
269 static const char typeId;
270
271
272
273
274
275
276
277
278
279
280 HepNtuple (HepFileManager* manager, const std::string& title, int id = 0);
281
282
283
284
285
286
287 virtual ~HepNtuple ();
288
289
290
291
292
293
294
295 virtual ZM_COVARIANT_TYPE(HepObj, HepNtuple ) &
296 makeClone(const std::string& new_title, int new_id = 0) const;
297
298 virtual ZM_COVARIANT_TYPE(HepObj, HepNtuple ) &
299 makeClone(HepFileManager* manager,
300 const std::string& new_title, int new_id = 0) const;
301
302 virtual ZM_COVARIANT_TYPE(HepObj, HepNtuple ) &
303 makeEmpty(const std::string& new_title, int new_id = 0) const;
304
305 virtual ZM_COVARIANT_TYPE(HepObj, HepNtuple ) &
306 makeEmpty(HepFileManager* manager,
307 const std::string& new_title, int new_id = 0) const;
308
309
310
311 virtual HepNtuple & append ( const HepNtuple& from );
312
313
314
315 virtual bool isCompatible ( const HepNtuple& hep );
316
317
318
319
320
321
322 bool column (const std::string& nametag, float value, float defval=0);
323 bool newColumn (const std::string& nametag, float val, float defval=0);
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 HepNtuple& columnAt (const std::string& nametag, float* address
352 , float defval=0);
353
354
355
356
357
358
359
360
361 HepNtuple& columnVia (const std::string& nametag, ZMuseMethod<float>* method,
362 float defval=0);
363 HepNtuple& columnVia (const std::string& nametag, float(*function)(),
364 float defval=0);
365
366
367
368
369
370
371
372 HepNtuple& columnArray (const std::string& nametag, int ncolumns
373 , float defval=0);
374
375
376
377
378
379
380
381
382 HepNtuple& columnDirect (const std::string& nametag, float defval=0);
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400 HepNtuple& pack ( float min, float max, int nbits);
401 HepNtuple& pack (const std::string& nametag,float min, float max, int nbits);
402
403
404
405
406
407
408
409
410 HepNtuple& span ( int min, int max);
411 HepNtuple& span (const std::string& nametag, int min, int max);
412
413
414
415
416
417
418
419
420
421 HepNtuple& dimension (const std::string& nametag, int dim);
422 HepNtuple& dimension ( int dim);
423
424
425
426
427
428
429
430
431
432 HepNtuple& dimension (const std::string& nametag, int dim1, int dim2,
433 int dim3=0, int dim4=0, int dim5=0, int dim6=0,
434 int dim7=0, int dim8=0, int dim9=0, int dim10=0);
435 HepNtuple& dimension ( int dim1, int dim2,
436 int dim3=0, int dim4=0, int dim5=0, int dim6=0,
437 int dim7=0, int dim8=0, int dim9=0, int dim10=0);
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452 HepNtuple& index (const std::string& nametag, const std::string& indextag);
453 HepNtuple& index ( const std::string& indextag);
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469 HepNtuple& characters (const std::string& nametag, int length);
470 HepNtuple& characters ( int length);
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 bool block (const std::string& blockName, const std::string& format,
496 std::vector<void*> addresses);
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 bool lockOutNewColumns ();
523 bool allowNewColumns ();
524 bool isLockedNewColumns () const;
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 bool setRowWise ();
554 bool setColumnWise ();
555 bool setBlockWise ();
556
557
558
559
560
561
562
563
564
565
566 bool setDiskResident ();
567 bool setMemResident ();
568 bool setSharedMemory (char sharedMemoryArea[]);
569
570
571
572
573
574 bool setNwbuff (int nwbuff);
575 bool setBuffLimit (int nbytes);
576
577
578
579
580
581
582
583
584
585 bool setCircularBuffer (int nwbuff);
586 bool setDemandBuffers (int nbytes);
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 bool captureThenStore ( );
628
629
630
631
632
633
634
635
636
637 bool capture (const std::string& nametag, float value);
638 int setExistingColumn (const std::string& nametag, float val);
639
640
641
642
643
644
645
646
647
648
649 bool capture (const std::string& nametag, const float value[]);
650 bool capture (const std::string& nametag, const float value[], int indexval);
651
652
653
654
655
656
657
658
659
660
661
662
663
664 bool captureColumn (const std::string& nametag);
665
666
667
668
669
670
671
672 bool captureBlock (const std::string& blockName);
673
674
675
676
677
678
679
680
681 bool capture ( );
682
683
684
685
686
687
688 bool storeCapturedData ( );
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705 bool clearData ( );
706
707
708
709
710
711
712 bool clearDataBlock (const std::string& blockName);
713
714
715
716
717
718
719 bool clearDataColumn (const std::string& nametag);
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 int nrows ( ) const;
746
747
748
749
750
751 bool readColumn (int irow, const std::string& nametag, float* value);
752
753
754
755
756
757
758
759
760 int readColumnArray (int irow, const std::string& nametag, float values[]);
761
762
763
764
765
766
767
768
769
770
771
772
773 int readBlock (int irow, const std::string& blockName);
774
775
776
777
778
779
780
781
782
783
784
785 int readRow (int irow);
786
787
788
789
790
791
792
793
794
795
796
797 int bulkReadColumn (int irow, int nrows,
798 const std::string& nametag, float destination[]);
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 HepNtuple& destinationAt (const std::string& nametag, float* address);
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854 HepNtuple& destinationVia (const std::string& nametag,
855 void (* setMethod) (float));
856 HepNtuple& destinationVia (const std::string& nametag,
857 ZMsetMethod<float>* setMethod);
858 HepNtuple& destinationVia (const std::string& nametag,
859 void (* setMethod) (float[]));
860 HepNtuple& destinationVia (const std::string& nametag,
861 ZMsetMethod<float*>* setMethod);
862
863
864
865
866
867
868
869
870
871
872 bool blockDestinations (const std::string& blockName,
873 const std::string& format,
874 std::vector<void*> addresses);
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891 bool isRowWise ( ) const;
892 bool isColumnWise ( ) const;
893 bool isBlockWise ( ) const;
894 unsigned char resident ( ) const;
895 std::string sharedAreaName ( ) const;
896 int nwbuff ( ) const;
897 int buffLimit ( ) const;
898 bool isCircularBuffer ( ) const;
899 bool isDemandBuffers ( ) const;
900
901
902
903
904
905
906
907 int nBlocks ( ) const;
908 std::string blockName (int blockNumber) const;
909
910
911
912
913
914
915
916 std::string blockFormat (int blockNumber) const;
917 std::string blockFormat (const std::string& blockName) const;
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932 int nColumns ( ) const;
933 int nColumns (const std::string& blockName) const;
934
935
936
937
938
939
940
941
942 std::string nametag (int columnNumber) const;
943 std::string nametag (int columnNumber, const std::string& blockname) const;
944 std::string tag (int columnNumber) const;
945 std::string tag (int columnNumber, const std::string& blockname) const;
946
947
948
949
950
951
952
953
954
955 std::string columnBlock (const std::string& tag) const;
956 std::string columnNametag (const std::string& tag) const;
957
958
959
960
961
962
963
964
965
966
967
968
969 ColumnData_t columnDataType (const std::string& nametag) const;
970
971
972
973
974
975
976
977
978
979
980
981 int columnDimensions (const std::string& nametag, int dims[] ) const;
982
983
984
985
986
987
988
989
990
991
992
993 std::string columnIndex (const std::string& nametag) const;
994
995
996
997
998
999
1000
1001 bool columnDefault (const std::string& nametag, float* defval) const;
1002 bool setColumnDefault (const std::string& nametag, float defval) const;
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012 bool columnSpan (const std::string& nametag, int* min, int* max) const;
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026 void* columnDesignatedVariable (const std::string& nametag) const;
1027 void* columnDestinationVariable (const std::string& nametag) const;
1028
1029
1030
1031
1032
1033
1034 bool columnPacking (const std::string& nametag,
1035 float* low, float* high, int* inbits) const;
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048 #define HEPTUPLE_METHOD_LIST(TYPE) \
1049 bool column (const std::string& nametag, TYPE value, TYPE defval=0); \
1050 bool newColumn (const std::string& nametag, const TYPE value, \
1051 const TYPE defval=0); \
1052 HepNtuple& columnAt (const std::string& nametag, TYPE* address, \
1053 TYPE defval=0); \
1054 HepNtuple& columnVia (const std::string& nametag, ZMuseMethod<TYPE>* method,\
1055 TYPE defval=0); \
1056 HepNtuple& columnVia (const std::string& nametag, TYPE (*function)(), \
1057 TYPE defval=0); \
1058 HepNtuple& columnArray (const std::string& nametag, int ncolumns, \
1059 TYPE defval=0); \
1060 HepNtuple& columnDirect (const std::string& nametag, TYPE defval=0); \
1061 bool capture (const std::string& nametag, const TYPE value); \
1062 bool capture (const std::string& nametag, const TYPE value[]); \
1063 bool capture (const std::string& nametag, const TYPE value[], \
1064 int indexval); \
1065 int setExistingColumn (const std::string& nametag, TYPE val); \
1066 bool readColumn (int irow, const std::string& nametag, TYPE* value); \
1067 int readColumnArray (int irow, const std::string& nametag, TYPE values[]); \
1068 int bulkReadColumn (int irow, int nrows, \
1069 const std::string& nametag, TYPE destination[]); \
1070 HepNtuple& destinationAt ( const std::string& nametag, TYPE* address); \
1071 HepNtuple& destinationVia ( const std::string& nametag, \
1072 void (* setMethod) (TYPE)); \
1073 HepNtuple& destinationVia ( const std::string& nametag, \
1074 ZMsetMethod<TYPE>* setMethod); \
1075 HepNtuple& destinationVia ( const std::string& nametag, \
1076 void (* setMethod) (TYPE[])); \
1077 HepNtuple& destinationVia ( const std::string& nametag, \
1078 ZMsetMethod<TYPE*>* setMethod); \
1079 bool columnDefault (const std::string& nametag, TYPE* defval) const; \
1080 bool setColumnDefault (const std::string& nametag, TYPE defval) const;
1081
1082
1083 HEPTUPLE_METHOD_LIST(Float8)
1084 #ifdef Float16
1085 HEPTUPLE_METHOD_LIST(Float16)
1086 #endif
1087 HEPTUPLE_METHOD_LIST(Int1)
1088 HEPTUPLE_METHOD_LIST(Int2)
1089 HEPTUPLE_METHOD_LIST(Int4)
1090 #ifdef Int8
1091 HEPTUPLE_METHOD_LIST(Int8)
1092 #endif
1093 HEPTUPLE_METHOD_LIST(bool)
1094 HEPTUPLE_METHOD_LIST(void*)
1095
1096
1097 protected:
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107 HepNtuple( );
1108
1109
1110 bool restoreBlock (const std::string& blockName, const std::string& format);
1111
1112 Block* unspecifiedBlock();
1113
1114
1115
1116
1117
1118
1119 Column* findColumn(const std::string& nameTag) const;
1120
1121
1122
1123
1124 Block* findBlock(const std::string& blockName) const;
1125
1126 Column* currentColumn() const;
1127 void setCurrentColumn(Column* c);
1128
1129
1130 virtual bool isNameAvailable(const std::string& nameTag) const;
1131
1132
1133
1134 virtual const TupleNameTag& parseNameTag(TupleNameTag& what,
1135 const std::string& nameTag,
1136 bool WithIndices = false) const;
1137
1138
1139
1140
1141 virtual bool isRowWiseEnabled() const = 0;
1142 virtual bool isColumnWiseEnabled() const = 0;
1143 virtual bool isBlockWiseEnabled() const = 0;
1144 virtual bool isDiskResidentEnabled() const = 0;
1145 virtual bool isMemResidentEnabled() const = 0;
1146 virtual bool isSharedMemoryEnabled() const = 0;
1147 virtual bool isNwbuffEnabled(int nwbuff) const = 0;
1148 virtual bool isBuffLimitEnabled(int limit) const = 0;
1149 virtual bool isDemandBuffersEnabled() const = 0;
1150 virtual bool isCircularBufferEnabled() const = 0;
1151
1152
1153 virtual bool isCaseSensitive() const = 0;
1154
1155
1156
1157 virtual bool isTypeEnabled(ColumnData_t type,Block *bk) = 0;
1158 virtual bool isTypeEnabled(ColumnData_t type) = 0;
1159
1160 enum StorageGeometryName { ROW, COLUMN, BLOCK };
1161 enum BufferTypeName { CIRCULAR, DEMAND };
1162
1163 StorageGeometryName storageGeometry() const;
1164 BufferTypeName bufferType () const;
1165
1166
1167
1168
1169
1170 virtual bool setStorageGeometry(StorageGeometryName newStrategy);
1171 virtual bool setStorageLocation(unsigned char newLocation);
1172 virtual bool setSharedMemoryName(char sharedMemoryArea[]);
1173 virtual bool setNwbuffValue(int nwbuff);
1174 virtual bool setNrowsValue(int nrows);
1175 virtual bool setBuffLimitValue(int limit);
1176 virtual bool setBufferType(BufferTypeName type);
1177
1178
1179
1180
1181 std::vector<ColumnAttribs*> parseFormat(const std::string& chform);
1182
1183 virtual bool addBlock(Block *b);
1184 virtual bool addColumn(Column *c);
1185 virtual bool addColumn(Block *b,Column *c);
1186
1187
1188 void changedDefinition();
1189 bool isDefinitionChanged();
1190
1191
1192
1193 virtual bool book() = 0;
1194
1195
1196 virtual bool prepareBlockForStoring(Block* bk);
1197
1198
1199 virtual bool storeWholeRow() = 0;
1200 virtual bool storeSingleBlock(Block* bk) =0;
1201
1202
1203 virtual int readWholeRow(int irow) = 0;
1204 virtual int readWholeBlock(Block* bk, int irow) = 0;
1205 virtual int readSingleColumn(Column* col, int irow) = 0;
1206 virtual int readSingleColumn(Column* col, const std::string& indices,
1207 int irow, void * val) = 0;
1208 virtual int readSingleColumn(Column* col, int irow, void * val) = 0;
1209
1210
1211
1212
1213
1214
1215 virtual int readWholeColumn(Column* col, const std::string& indices,
1216 int start_row, int nrows,
1217 char * val, std::string::size_type size);
1218 virtual int readWholeColumn(Column* col,
1219 int start_row, int nrows,
1220 char * val, std::string::size_type size);
1221
1222
1223
1224
1225
1226
1227 int readBlock(Block *bk, int irow);
1228
1229
1230
1231
1232 typedef std::map<std::string, Column*,
1233 std::less<std::string> > columnsMap;
1234 typedef std::map<std::string, Block*,
1235 std::less<std::string> > blocksMap;
1236 blocksMap blocks;
1237 columnsMap columns;
1238
1239 bool _changedDefinition;
1240
1241
1242
1243 #ifdef NEVER
1244
1245 void silenceCompiler();
1246 #endif
1247
1248 private:
1249
1250
1251
1252
1253
1254
1255
1256
1257 StorageGeometryName _storageGeometry;
1258 unsigned char _storageLocation;
1259 char *_sharedMemoryAreaName;
1260 int _nwbuff;
1261 int _buffLimit;
1262 BufferTypeName _bufferType;
1263
1264 Block * _unspecifiedBlock;
1265
1266
1267
1268
1269 int _unspecifiedBlockNumber;
1270
1271
1272
1273
1274 bool _lockNoNewColumns;
1275
1276
1277
1278 mutable Column* _currentColumn;
1279
1280
1281 int _nrows;
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297 #ifdef COMMENT
1298 The following classes will change when we implement the exception
1299 mechanism, and will in particular become publicly derived from
1300 the ZMxGeneral base in HepNtuple class, which in turn is derived from
1301 the ZMexception base.
1302
1303 For now we keep it minimal to just compile; ZMthrow will lead to
1304 an exit.
1305 #endif
1306
1307 public:
1308 class ZMxGeneral;
1309 class ZMxProblem;
1310 class ZMxColumn;
1311 class ZMxNewColumn;
1312 class ZMxCapture;
1313
1314 #if (defined(__GNUC__) && (__GNUC__ < 3) && __GNUC_MINOR__ < 90) || defined(WIN32)
1315
1316
1317
1318
1319 #define HEPTUPLE_TEMPLATE_FRIENDS(TYPE) \
1320 friend bool captureF(const std::string& nametag, TYPE, HepNtuple* tuple); \
1321 friend bool captureArrF(const std::string& nametag, const TYPE val[], \
1322 int indexVal, \
1323 HepNtuple* tuple); \
1324 friend bool columnF(const std::string& nametag, TYPE value, TYPE defval, \
1325 HepNtuple* tuple); \
1326 friend bool columnAtF(const std::string& nametag, TYPE* value, TYPE defval, \
1327 HepNtuple* tuple); \
1328 friend bool columnViaF(const std::string& nametag, TYPE (*function)(), \
1329 TYPE defval, HepNtuple* tuple); \
1330 friend bool columnViaM(const std::string& nametag, ZMuseMethod<TYPE>* method, \
1331 TYPE defval, HepNtuple* tuple); \
1332 friend Column* newColumnF(const std::string& nametag, TYPE value, TYPE defval,\
1333 HepNtuple* tuple); \
1334 friend ColumnT<TYPE>* addNewColumnF(const std::string& nameTag, \
1335 TYPE defaultValue, \
1336 HepNtuple* tuple); \
1337 friend bool columnDefaultTmpl(const std::string& nametag, TYPE* def, \
1338 const HepNtuple* tuple); \
1339 friend bool setColumnDefaultTmpl(const std::string& nametag, TYPE def, \
1340 const HepNtuple* tuple); \
1341 friend bool readColumnF(int irow, const std::string& nametag, \
1342 TYPE* destination, HepNtuple *tuple); \
1343 friend int bulkReadColumnF(int irow, int nrows, const std::string& nametag, \
1344 TYPE* destination, HepNtuple *tuple); \
1345 friend int readColumnArrayF ( int irow, const std::string& nametag, \
1346 TYPE *destination, HepNtuple* tuple); \
1347 friend ColumnT<TYPE>* getColumnT(const std::string &nametag,HepNtuple *hep, \
1348 TYPE fortype); \
1349 friend ColumnT<TYPE>* getOrCreateColumnT(const std::string& nametag, \
1350 TYPE defVal, \
1351 HepNtuple *hep);
1352
1353 HEPTUPLE_TEMPLATE_FRIENDS(Int1)
1354 HEPTUPLE_TEMPLATE_FRIENDS(Int2)
1355 HEPTUPLE_TEMPLATE_FRIENDS(Int4)
1356 #ifdef Int8
1357 HEPTUPLE_TEMPLATE_FRIENDS(Int8)
1358 #endif
1359 HEPTUPLE_TEMPLATE_FRIENDS(Float4)
1360 HEPTUPLE_TEMPLATE_FRIENDS(Float8)
1361 #ifdef Float16
1362 HEPTUPLE_TEMPLATE_FRIENDS(Float16)
1363 #endif
1364 HEPTUPLE_TEMPLATE_FRIENDS(bool)
1365 HEPTUPLE_TEMPLATE_FRIENDS(void*)
1366
1367 #else
1368
1369 template <class TYPE> friend
1370 bool captureF(const std::string& nametag,TYPE, HepNtuple* tuple);
1371
1372 template <class TYPE> friend
1373 bool captureArrF(const std::string& nametag, const TYPE val[],
1374 int indexVal, HepNtuple* tuple);
1375
1376 template <class TYPE> friend
1377 bool columnF(const std::string& nametag, TYPE value,
1378 TYPE defval,HepNtuple* tuple);
1379
1380 template <class TYPE> friend
1381 bool columnAtF(const std::string& nametag, TYPE* value,
1382 TYPE defval,HepNtuple* tuple);
1383
1384 template <class TYPE> friend
1385 bool columnViaF(const std::string& nametag,
1386 TYPE (*function)(),TYPE defval, HepNtuple* tuple);
1387
1388 template <class TYPE> friend
1389 bool columnViaM(const std::string& nametag,
1390 ZMuseMethod<TYPE>* method,TYPE defval, HepNtuple* tuple);
1391
1392 template <class TYPE> friend
1393 Column* newColumnF(const std::string& nametag,
1394 TYPE value, TYPE defval,HepNtuple* tuple);
1395
1396 template <class TYPE> friend
1397 ColumnT<TYPE>* addNewColumnF(const std::string& nameTag,
1398 TYPE defaultValue, HepNtuple* tuple);
1399
1400 template <class TYPE> friend
1401 bool columnDefaultTmpl(const std::string& nametag, TYPE* def,
1402 const HepNtuple* tuple);
1403
1404 template <class TYPE> friend
1405 bool setColumnDefaultTmpl(const std::string& nametag, TYPE def,
1406 const HepNtuple* tuple);
1407
1408 template <class TYPE> friend
1409 bool readColumnF(int irow, const std::string& nametag,
1410 TYPE* destination, HepNtuple *tuple);
1411
1412 template <class TYPE> friend
1413 int bulkReadColumnF(int irow, int nrows,
1414 const std::string& nametag,TYPE* destination,
1415 HepNtuple *tuple);
1416
1417 template <class TYPE> friend
1418 int readColumnArrayF ( int irow, const std::string& nametag,
1419 TYPE *destination, HepNtuple* tuple);
1420
1421 template <class TYPE> friend
1422 ColumnT<TYPE>* getColumnT(const std::string& nametag,
1423 HepNtuple *hep,TYPE fortype);
1424
1425 template <class TYPE> friend
1426 ColumnT<TYPE>* getOrCreateColumnT(const std::string& nametag,TYPE defVal,
1427 HepNtuple *hep);
1428 #endif
1429 };
1430
1431
1432 ZM_END_NAMESPACE( zmht )
1433
1434
1435
1436
1437 #include "HepTuple/HepNtuple.icc"
1438
1439
1440 #ifdef COMMENT
1441
1442 NOTES
1443 -----
1444
1445 **[1]** Block and column name and tag
1446
1447 Column tags have no length limit but must be unique within any given block.
1448 (For HBook, column tags must be unique over the entire ntuple and the
1449 concatenation of all column tags in any block may not exceed 1300 characters.)
1450 A column may be defined with no specified block (for example defined by the
1451 direct capture routine column(tag[], value). What this means is that the user
1452 does not care what block this is grouped with, and does not intend to retrieve
1453 that data "by whole block."
1454
1455 Actually, all columns with no specified block which were defined between one
1456 row-store and another will end up in the same block.
1457
1458 Block names are treated as their first 8 characters. When a column is defined,
1459 you may use a longer form for its name than just its column tag -- the format
1460 is bname::ctag and we call this a nametag. For example, in the nametag
1461 "BLOCK5::PxDev" the column tag is PxDev and it is in block BLOCK5.
1462
1463 Unfortunately, one cannot use block names as a namespace mechanism to allow
1464 disjoint users to choose their column tags arbitrarily: The column tag must
1465 be unique across the entire HepNtuple when using the HBOOK manager.
1466 Some other form of column tag naming agreement must be reached for a given
1467 program.
1468
1469 Other than the un-named ("don't care") block, which can be assigned anew when
1470 new columns are added after a store has been done, the block name assigned
1471 is the block name used. We have abandoned the thought of automatically
1472 changing the block name under various conditions.
1473
1474 This has a manager-specific consequence for HBOOK:
1475
1476 Character string columns may have to be placed into distinct blocks from
1477 ordinary variables. The manual implies this is necessary. If so, it will be
1478 an error to mix character and numeric values in the same block if an HBOOK
1479 manager is used.
1480
1481 **[2]** Convenient syntax for column definition
1482
1483 You can combine definition of column nametag/designated variable, with
1484 refinements concerning packing, array dimensions, and so forth, in the
1485 following compact syntax:
1486
1487 HepNtuple *mytup; float whereItIs;
1488 mytup->columnAt
1489 ("mytag", &whereItIs).dimension(4,2).pack(0.1, 1.5, 12).index("JNUM");
1490
1491 That is why these methods return a HepNtuple* (this).
1492
1493 The one method which does double-duty as a capture method -- and therefore may
1494 be called thousands of times after the single column definition -- can still
1495 afford to return HepNtuple* (this). For now, it returns a bool but that may
1496 change.
1497
1498 **[3]** Example of designating an accessor function
1499
1500 Say you have a structure SpaceVector v, and you want to put r into the
1501 HepNtuple, but r is accessed by the method v.r().
1502
1503 class SpaceVector { public: float r();
1504 SpaceVector v;
1505 HepNtuple *mytup;
1506 mytup->columnVia ("ThisBLK::Radius", v.r());
1507
1508 mytup->capture("ThisBLK");
1509
1510
1511 Of course, now v had better stick around as long as ThisBLK is being captured,
1512 otherwise the call to v.r() will be invlaid. This is the same as always with
1513 designated variables: They must remain in scope if their block is to be
1514 captured.
1515
1516 **[4]** Arrays of columns, and Index variables
1517
1518 An array of columns is treated as a collection of separate columns. They all
1519 share the same array name, but the HBOOK column names, for example, will be
1520 like NAME(0,0) NAME(1,0) ... NAME(3,5), ... etc. You in fact can retrieve a
1521 column by that specific array element name (but you cannot capture just one
1522 element at a time). So for example, with columnwise storage you can get
1523 just X(3,2) for all rows stored, and do it very efficiently.
1524
1525 Note that indices are zero-based.
1526
1527 An index variable is how varying-length arrays are done. It delimits the
1528 slowest-varying dimension, which in C++ is the first dimension (a in
1529 X[a][b][c]) but in Fortran is the last one (c in X(a,b,c)). That first
1530 dimension of an indexed array is REPLACED in extent by the maximum set in
1531 the span of the index variable.
1532
1533 When the index variable is less than its maximum possible value the remaining
1534 columns may not have anything stored for them. HBOOK benefits from this
1535 optimization for column-wise Ntuples. Such un-captured columns, if read back,
1536 will give the default value.
1537
1538 **[5]** Array ordering
1539
1540 Because the most important implementation assigns column array element names
1541 using the Fortran convention X(0,0) X(1,0), ... X(M, 0), X(0,1), ... X(M,N)
1542 the HepTuple package will go along with that. This presents no problem at all
1543 on the side of filling the HepNtuple.
1544
1545 The confusion happens when a user knows he has stored an array shaped as
1546 x[40][20] in column array X, and wants to retrieve specific element -- he would
1547 have to say X(15,35) to get back the element which was in the C++ array as
1548 x[35][15]. That is what we get for mixing the two languages; further attempts
1549 to rectify the confusion will only make things worse. At least all our users
1550 KNOW to expect something cloudy whien this mixing goes on...
1551
1552 **[6]** Semantics of filling an Ntuple
1553
1554 The act of supplying data for one or more columns is called capturing that
1555 data. The act of adding the captured data for a row to the Ntuple is called
1556 storing the data. Data which is captured is not inevitably to be stored since
1557 the user can clearData for the row (for example when rejecting an event).
1558 Also, a subsequent capture for the same column will replace the earlier
1559 captured data.
1560
1561 For managers which can benefit from the knowledge of which blocks were not
1562 filled, by not storing a block for a particular row, the information is
1563 kept. A block which has been captured is "marked"; clearing the block will
1564 "unmark" it, as well as setting all values to their defaults.
1565
1566 The row number semantics for storing data is that of automatic append: The
1567 "active" row in an empty Ntuple would start at zero, and each time a row is
1568 stored, will increment. Thus you cannot overwrite a previously stored row, or
1569 leave a gap in row number.
1570
1571 Capture of data can be done on a per-column basis using the "Direct" forms
1572 column(tag, value, defval) or capture(tag, value). Another way is to capture
1573 data for an entire block or row by supplying designated variables. These are
1574 explained in note **[7]**.
1575
1576 The definition of the columns composing the HepNtuple may be extended
1577 after some data has been captured, and even after rows of data have been
1578 stored. The rules are:
1579
1580 * A column in an unnamed block may be defined at ANY time, as long
1581 as the column tag is unique. Adding colummns after data has been
1582 stored is even reasonably efficient for columns-wise storage, but
1583 can be quite time-consuming for row-wise HepNtuple with lots of
1584 data already stored.
1585
1586 * A column in a specific named block may be defined only if that block
1587 has not yet been stored. That is, if you capture a block (or data in a
1588 column in that block, then do storeCapturedData, then that block may no
1589 longer be added to.
1590
1591 * A column in a specific named block may be defined even if that block
1592 has been captured (but not stored). Of course, the value for that
1593 column would be the default value until it is captured.
1594
1595 * A column may not be defined with the same tag as some other column
1596 previously defined (even if they are in different blocks).
1597
1598 * The definition of a defined column may not be refined (adding packing
1599 information and so forth) after data has been captured for that column.
1600
1601 * For completeness: Storage strategy for the HepNtuple may be refined
1602 up until the first storeCapturedData is done, and no later.
1603
1604 The mode of operation where column(name, val) without a specified block name
1605 is done at arbitrary times for definition and Direct capture is a preferred
1606 mode of operation prefered at BaBar, where their framework allows different
1607 contributors to add their own information to a common Ntuple, but may not
1608 call every contributor for every event.
1609
1610 The act of adding a new column to an **EXISTING** ntuple, supplying data for
1611 each row for that column, is treated as part of the concept of manipulating
1612 ntuples, specifically, as a mode of combining two ntuples. This will be
1613 implemented later.
1614
1615 **[7]** Designated Variables and Destination Variables
1616
1617 HBOOK has the convenience of allowing (forcing for heterogeneous column-wise
1618 Ntuples) the user to designate variables meaning that, ""Here is where the data
1619 will be when I want to fill a block or row."" Those have to be in a COMMON
1620 block in HBOOK, to enforce a known pattern of word-alignment (namely, none).
1621
1622 HepTuple, of course, retains this convenience, but allows the designated
1623 variables to be in any struct or structs, not necessarily contiguous.
1624
1625 C++ compilers are free to word-align structs by adding padding. So even
1626 if all the designated variables are in one struct, there would be a need to
1627 specify the addresses of each. In HepTuple this is done either by columnAt(),
1628 or for a whole block at a time by the vector of addresses in block().
1629
1630 We distinguish designated variables for filling the HepNtuple, from destination
1631 variables for retrieval. To retrieve data other than one column or column
1632 array at a time, you must set up destinations for the data using
1633 destinationAt().
1634
1635 Don''t forget to keep the designated and destination variables in scope! If
1636 you don''t then either the HepTUple is being filled from meaningless data, or
1637 your retrival is putting data in a meaningless place!
1638
1639 **[8]** Possible error returns for Read routines
1640
1641 -1 Name not found
1642 -2 irow past end of Ntuple
1643 -3 No designated variables were established for desired block or row
1644 -4 Element of Column array read using tag without indices
1645 -5 Ordinary column read using readColumnArray
1646
1647 Since accessing an existing Ntuple is inherently subject to these problems, we
1648 choose (for now) to return a code RATHER THAN to throw exceptions. In
1649 particular, placing all access inside individual try constructs will be
1650 badly inefficient in an area that might matter.
1651
1652
1653 **[9]** Refining destination definitions
1654
1655 To specify a destination well enough for retrieval to proceed, you need to
1656 specify:
1657
1658 * The nametag and address, as in destinationAt().
1659
1660 You do not need to specify, because the HepNtuple knows about, the following:
1661
1662 - The dimensions of a column array
1663 - Packing information
1664 - The span of an index column
1665 - The tag of the column used as an index
1666
1667 It you do specify unneeded information, and it clashes in a meaningful way with
1668 the actual information, the specification routine will return 0 instead of a
1669 pointer to the HepNtuple. This should not be ignored; it probably means you
1670 will fou up badly if you try to retrive data into space tailored to your wrong
1671 information!
1672
1673 When an entire block is specified at a time, by blockDestinations(), the
1674 format supplied must match reality in tags, index variable, dimensions, and
1675 spans -- otherwise, there is too great a likelihood that reading into the
1676 supplied list of addresses will be blowing storage. For example, if you think
1677 index variable J has a span of 0-200 and it can really go to 210, you probably
1678 are allocating 200 words of space to hold a possible 210-word output.
1679
1680 Similarly, the number of columns in the format string must match the number of
1681 addressses in the list. But these do not have to match the total number of
1682 columns in the block, or be in the same order -- you can skip columns on
1683 retrieval. And packing information in the destination format string is
1684 ignored.
1685
1686 **[10]** SetMethods for destinations
1687
1688 This is for purists who wish to fill their structures (from retireved Ntuple
1689 data) via "mutator methods" rather than direcly writing to their data.
1690
1691 Say you have a structure SpaceVector v, and you have a method v.r(float) that
1692 would take one float value (IT MUST TAKE 1 VALUE FOR THIS FEATURE TO BE
1693 APPLICABLE) for r, and change the vector to keep the same theta and phi but use
1694 the new r. This is not just storing r in a place; the actual x, y, and z all
1695 change.
1696
1697 class SpaceVector { public: void r(float);
1698 SpaceVector v;
1699 HepNtuple *mytup;
1700 mytup->distinationVia ("ThisBLK::Radius", v.r());
1701
1702 mytup->readBlock("ThisBLK");
1703
1704
1705
1706 Of course, now v had better stick around as long as ThisBLK is being read,
1707 otherwise the call to v.r() will be invlaid.
1708
1709 (Frankly, v.r(x) can do anything it wants to with x. We just imagine it being
1710 used to modify some aspects of v.)
1711
1712 You can use this mechanism to work with a single column or an array of
1713 columns. In the latter case, you have mutator method which takes as an
1714 argument an float[] instead of a float.
1715
1716 **[11]** Memory resident information
1717
1718 The resident() method returns:
1719 'D' disk resident
1720 'M' memory resident
1721 'S' shared memory resident
1722 If shared memory resident, the method sharedAreaName returns the name of the
1723 shared section (otherwise, it returns a blank Std::String). If the Ntuple
1724 is not disk resident, either a circular buffer is being used, or demand
1725 strategy (where additional buffers are added as the Ntuple grows).
1726
1727 **[12]** Column data type identification
1728
1729 On a compliant compiler one could do
1730 type_info x = mytup.columnType_info(ncol);
1731 if ( x == typeid(double) ) doWhatever;
1732
1733 The alternative we supply is
1734 ColumnData_t x = mytup.columnDataType(ncol);
1735 if ( x == ColumnData_FLOAT8 ) doWhatever;
1736
1737 Actually, that alternative may be more than a kludge for the compliance-
1738 differently-abled, because our types (FLOAT8 vs FLOAT4 etc.) more directly
1739 correspond to the types used underneath, R*8, R*4 and so forth.
1740
1741 **[13]** Fixed-length character strings
1742
1743 These correspond to the HBOOK C*4, C*8, ... C*32 formats. They are different
1744 than ordinary char arrays in at least two ways:
1745
1746 - Even with columnwise storage, all 4 or 8 or ... or 32 bytes are stored
1747 together.
1748 - If there is any differnece in byte swap issues, the underlying manager will
1749 treat these as character strings and apply the proper swap for those.
1750
1751 Arrays of columns of fixed-length character strings -- e.g., the concept
1752 expressed by the format string X:C*16(3,4) -- are not supported.
1753
1754 By the way, what if you want a true array (of arbitrary length, perhaps with an
1755 index, maybe mulit-dimensional) of "integer*1" objects? Then you don''t invoke
1756 characters(), you invoke dimension().
1757
1758 The HBOOK implementation MAY NOT ??? ALLOW YOU TO MIX CHARACTER STD::STRINGS AND
1759 ORDINARY DATA IN THE SAME BLOCK.
1760
1761 **[14]** Direct capture of arrays of columns
1762
1763 Notice that although a 1-dimensional array can be defined without designated
1764 variables (the columnArray() method), multi-dimensional arrays will always have
1765 designated variables. Nonetheless, the
1766 capture (const string& nametag, float values[])
1767 method allows Direct capture; but if designated variables were assigned for
1768 that column array, one should be careful not to capture the block later lest
1769 the directly captured values be over-written.
1770
1771 **[15]** columnArray method for non-float data
1772
1773 In this method the default value is not required if float data is to be used --
1774 the signature without defval assumes float and sets defval=0. But for coulmns
1775 of int, double, or other non-float data, the default value must be supplied.
1776 And if a constant is supplied, the user must be careful that the constant
1777 is of the desired data type, as that is the only way the method caln tell what
1778 type of columns the user wants.
1779
1780 Similarly, columnDirect() requires a default value if non-float data is to
1781 be used, and the user must be careful that this is of the desired data type.
1782
1783 #endif
1784
1785 #endif
1786
Send problems or questions to cdfcode@fnal.gov