EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MgridHeader.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MgridHeader.h
1 /* -------------------------------------------------------------------------- */
2 /* MgridHeader.h */
3 /* */
4 /* A.Kisselev, PNPI, St.Petersburg, Russia. */
5 /* e-mail: kisselev@hermes.desy.de */
6 /* -------------------------------------------------------------------------- */
7 
8 #include <3d.h>
9 
10 #include <MgridDirection.h>
11 #include <CoordSystem.h>
12 
13 // MgridHeader is filled with __u64 (or __s64) in order to allow
14 // compatibility with 64-bit machines (like Opterons); the problem
15 // is that Intel architecture requires alignment of variables, in
16 // particular elements in structures are aligned on 4-byte (32-bit
17 // arch) or 8-byte (64-bit arch) boundary; sizeof(double)=8 on both;
18 // so in order to avoid gaps on 64-bit architecture I'm forced to
19 // use 8-bit integeres in t_mgrid (and also to keep 'property'
20 // field of cells in a separate (char) array);
21 
22 #ifndef _MGRID_HEADER_H
23 #define _MGRID_HEADER_H
24 
25 // These 8 bytes are a usual magic signature; it
26 // is a sort of consistency check for a given file; to a
27 // certain extent it is also a check whether machine is a
28 // little or big endian (or something else); namely file
29 // created on i386 will NOT be recognized on mips; this is
30 // ok; if usage of a certain map file on a big endian
31 // machine becomes of interest, one can figure out machine
32 // endianness out of 'magic' bytes order and extend loading
33 // by appropriate byte swapping; I do not see this becomes
34 // necessary any time soon; usage on a 64-bit machine like
35 // AMD Opteron is certainly possible on the other hand;
36 // (as long as __u64 and double types match); different size
37 // of pointers does not matter since they are not used in
38 // either of t_mgrid or t_mgstack structures;
39 //#define _MFILE_MAGIC_ 0x91FA011B1122FE43
40 // Well, check please, that this "ull" suffix really works in I/O;
41 #define _MFILE_MAGIC_ 0x91FA011B1122FE43ull
42 
43 // Well, th eonly format version for now (and forever);
44 #define _MGRID_FORMAT_ID_ 0x00
45 
46 //
47 // NB: MgridHeader size should never change; format may vary, but
48 // then format_id variable should reflect this and I/O adjusted
49 // accordingly;
50 //
51 
52 // Please never change!; 128=8*16, so 8-byte alignment is Ok;
53 #define MGRID_NAME_LENGTH_MAX 128
54 
55 // Root node of a collection of daughter mgrids;
56 //#define _MGRID_HEAP_ 0x00
57 // 'Usual' 1..3 dim rectangular grid;
58 //#define _RECTANGULAR_MGRID_ 0x01
59 
61 
62 // Possible creation methods;
63 #define _FROM_SCRATCH_ 0x00
64 #define _ASCII_INPUT_ 0x01
65 #define _REGRID_ 0x02
66 
67 // Possible ways of field calculation in a _HEAP_;
68 // _SUPERPOSITION_ means fields from all daughters
69 // with ret=0 will be summed up; _FIRST_MATCH_ means
70 // the very first ret=0 will be taken (this may be useful
71 // for a collection of overlapping map pieces);
72 #define _SUPERPOSITION_ 0x00
73 #define _FIRST_MATCH_ 0x01
74 
75 //
76 // -> never change data fields order, etc in this class!;
77 //
78 
79 // This header will be dumped
80 // into a file; it is customed in a machine-independent way (as long as
81 // 1) __u64 and double size match, 2) 128-bit archs are not around,
82 // 3) there is no byte swapping; the latter which can be implemented
83 // if needed; never insert anything between magic_header and
84 // magic_trailer!; if extension needed, backward compatibility should
85 // be always preserved by adding more types of 'format_id&type';
86 // additional fields may be taken from reserved[] (in 8-byte portions!);
87 class MgridHeader {
88  friend class MgridInterpolation;
89 
90  public:
91  const char *getName() { return name;};
92  // Please, range check later;
93  void setCreationMethod(unsigned method) { creation_method = method;};
94 
95  protected:
96  // Well, even if a single mgrid is a part of a stack, want
97  // to keep this header in because prefer to keep single
98  // grids completely independent on the context (so that
99  // a very general function called with address of a single
100  // grid can figure out what it is and behave accordingly);
102  // Layout is not expected to change ever; if for wnatever reason
103  // one wants to do extensions, it is perfectly possible to increase
104  // format identifier in this field, use reserved[] space and put a
105  // switch() statement in the downloading code;
107 
108  // _MGRID_HEAP_, _RECTANGULAR_MGRID_; yes, want this __u64;
110 
111  // Well, it's the time of create_general_mgrid_header() call;
113  // Method (_FROM_SCRATCH_, _ASCII_INPUT_, etc);
115  // In case of regriding store parent name as well as it's type;
118 
119  // Grid name; NB: MGRID_NAME_LENGTH_MAX is a multiple of 8!;
121 
122  // Number of daughter-objects
124 
125  // Make life easier for now;
126  public:
127  // A way of calculating field in case of _MGRID_HEAP_
128  // (_SUPERPOSITION_/_FIRST_MATCH_);
130 
131  protected:
132  // This field describes which blocks are stored for this object;
134 
135  // Make life easier for now;
136  public:
137  // These bits describe what is actually kept in cells; options
138  // for now are 1) N field components, 2) N field component errors,
139  // 3) N chi^2's of the fits, 4) M cell coordinates; useful_cell_length
140  // is calculated based on this pattern and coord.coord_num,
141  // field.coord_num;
143 
144  // Describes what is actually stored in this grid;
145  // Actual number of *stored* field components (may be 2 for RZ-grid or
146  // even 1 if just one component was measured); once again: field
147  // calculation routines will always expand returned field value to
148  // dimension '3'; the way field will be expanded from the stored data
149  // is strictly defined by the combination of field coordinate system
150  // type, dimension and number of components;
152 
153  // '3': natural XYZ (RFZ) sequence; does not make sense to put this
154  // stuff into CoordSystem since it is not used for field components;
156 
157  protected:
158  // Shift of this object with respect to it's father reference system;
159  // Can not use ThreeDeeVector in this binary fixed format header!;
160  double shift[3];
161  // GEANT-like rotation parameters; this is probably not the most wise
162  // method to introduce 3 independent variables; but certainly these variables
163  // is easy to derive out of any other more convenient (say for fitting)
164  // parametrization, where one would like to have just 3 small rotations
165  // around X,Y,Z axes;
166  double theta[3], phi[3];
167 
168  // Reserve few bytes for possible further extensions; does not
169  // matter on a level of ~MB required to store the grid itself;
170  // NB: usage should proceed in 8-byte portions!;
171  unsigned char reserved[1024];
172 
173  // This is the last 'persistent' word in this structure;
174  // it will be kept into binary file including this word;
176 } ;
177 
178 #endif