For any comments, suggestion and questions, contact to akio@bnl.gov
This is a very simple unix filesystem based database which will be used for calibration. Unix file system directory structure is used to distinguish different calibration constants files. The name of the file include data and time to keep time dependent constants. There are utilities to get correct file names and find proper file to the requested date and time. The users (or each detectors) can call these functions to get file names, and save/load their calibration constants with these file names in any format as they like. This database is considered as a short term solution for calibration system and when the objectivity DB comes and start working, this will be replaced.
There are two C functions available for users. This will be included in STAF executable after next release, and any PAMs can just call them.
User may call this to get file name and then save calibration constants with this name. The first argument is domain_name, the second is file_name, third is date and time for this calibration data in time_t (time in second since 00:00:00 UTC, January 1, 1970. See "man -s 2 time"). The return value is a pointer to the fullpath file name. This gives back NULL on failure. Note that it's users responsibility to FREE the allocated space for returned character array.
This searches the directories described above, looking at files in it, and pick up most recent calibration data file for the requested time and date(2nd argument) (when last argument is 0). The first and second arguments are pointer to domain_name and file_name. The third is requested time (i.e., time of the event). Fourth is time which the founded calibration constant is expired(i.e. time of next calibration file). The fifth is the option.
1---2---3--*--4---5--->time (* is the requested date/time) option=0 gives back most recent file (file 3) option=-1 gives second recent file (file 2) option=1 gives next file (file 4)If the requested time is earlier than the first file, it gives the first file. If the requested time is later than the last file, expiration date is 2147483647(22:14:07, January 18, 2038). Return value is a pointer to the filename with fullpath and gives back NULL on failure. Note that it's users responsibility to FREE the allocated space for returned character array.
SEE ALSO : time(2), mktime(3C)
The program searches the calibration data files at $PWD/calb/domain_name/ and then, $STAR_CALB/domain_name/ at last, $STAR_ROOT/calb/domain_name/In STAR_LOGIN.csh, $STAR_CALB is equivalent to $STAR_ROOT/calb. The last one is where we will have official calibration constants. Each user can have their own files in first two places. Note that domain_name can contain more than a level of directory(for example, domain_name can be emc/pedestal)
file_name.YYYYMMDD.hhmmssT (for example, bemc_pedA.19980221.1616060)
where Y=year, M=month, D=date, h=hour, m=minit, s=second. T=0 means normal time(winter time) and T=1 means summer time(day light saving time). (Do we need to add time zone?)
void main(void){ char* file; int option=0; time_t expire, justnow = time(0); file=cal_filename("emc/pedestal","bemc_pedA",t); printf("%s\n",file); free(file); file=find_cal_file("emc/pedestal","bemc_pedA",justnow,expire,option); printf("%s\n",file); free(file); } > ls ./emc/pedestal bemc_pedA.19980221.1616060 bemc_pedA.19980226.1116060 bemc_pedA.19980227.1616060 bemc_pedA.19980223.1616060 bemc_pedA.19980226.1616060 bemc_pedA.19980228.1616060 bemc_pedA.19980225.1616060 bemc_pedA.19980226.2116060 >a.out /star/u2d/akio/staf/cal/emc/pedestal/bemc_pedA.19980226.2120190 /star/u2d/akio/staf/cal/emc/pedestal/bemc_pedA.19980226.2116060
static time_t expire; runloop{ expire=0; ... eventloop; ... } eventloop{ ... if(time > expire){ file=find_cal_file(domainname,filename,time,expire,option); read_cal_const(file); } ... } calibration{ ... file=cal_filename(domainname,filename,time); save_cal_const(file); } <\pre>