For each CWN, data and control information are stored in physical records. Each physical records contains logical records corresponding to variable buffers. The relation between logical record and variable buffer is
logical record = variable buffer + 15 words of ZEBRA headerEach physical record may contain more than one logical records depending on the size of record length and buffer size you set when you make a Ntuple. Because each logical record corresponding to one variable, one physical record may contain more than one variables. In CWN, data are retrieved by variable, which means each time a physical record is read into memory, only a logical record related to a variable is used. For example, if you use 4096 as your record length, and 1009 as your buffer size, then logical record length is 1009+15=1024, so a physical record may contain 4 logical records, each time 4096 words are read from disk to memory, only 1024 words are used, of which 1009 words are real data.
The highest I/O efficiency is achieved when physical record length is equal to logical record length. Then each time a physical record is read, it contains the variable data exactly what we want. In this case, it means we need to set buffer size equal to physical record length minus 15 words of ZEBRA header.
On the other side, use large physical record length reduces the total number of records in a CWN file. It reduces the number of I/O access times.
When you make a new CWN, you can control the record length and variable buffer size. You give the record length when you call HBOOK routine HROPEN, and you can call HBOOK routine HBSET to decide the buffer size, the default buffer size is 1024-15=1009 in which 15 is the ZEBRA header size. One thing worth notice is that in order for calling HBSET effective, you have to call it before calling routine HBNT which is used to book a new CWN. Otherwise, buffer size still use the default value 1009.
Now, you probably make a conclusion that increase buffer size and record length will give your CWN data better performance. But it also brings some side effects. One of the side effect is that it increases the file size a bit. The file size it increases depends on how many variables in your N-tuple. For example, if you have 300 variables in your CWN, and the original record length is 1024, we will increase the record length to 4096, then AT MOST it will increase a file size by:
(4096 - 1024) X 300 X 4 = 3.6 MBmultiply 4 converts words to bytes in 32 bits machine.
For a file which has size around 50MB, this increase is fine, but for a file which has size 3 MB, it is not worth increasing the record length and buffer size to a large value like 4096. You can decide if a file needs a larger record length and buffer size by simple calculation. The goal is to reduce the number of r/w times of I/O when you analyze the data.
The other side effect of increasing record length is that it requires larger memory both in making the new N-tuple and analyzing it. Fortunatly, when you analyze it, the memory increase is minor, only 12KB/variable in the above example. PAW and PIAF can afford this without any problem.
From the table, we can see for this perticular Ntuple, change record length to 4096 and buffer size to 4096-15 has reduced record seek time, read time and RZ key and cycle decoding time a lot. Ntuple I/O has been almost optimized. Increase buffer size further to 8191-15 wouldn't reduced I/O time to NONE.