25 #define MODERATOR_HV_CHANNEL 4
26 #define SAMPLE_HV_CHANNEL 15
27 #define SPINROTATOR_VOLTAGE_CHANNEL 2
28 #define SPINROTATOR_CURRENT_CHANNEL 3
38 "/Experiment/Run Parameters",
39 "/Equipment/Trigger/Settings",
40 "/Equipment/Trigger/Vme_Statistics",
41 "/Equipment/Scaler/Settings",
42 "/Analyzer/Parameters/ScalerSumRate",
43 "/Equipment/HV/Settings",
44 "/Equipment/HV/Variables",
45 "/Equipment/HV Detectors/Settings",
46 "/Equipment/HV Detectors/Variables",
47 "/Equipment/Beamline/Settings",
48 "/Equipment/Beamline/Variables",
49 "/Equipment/ModCryo/Settings",
50 "/Equipment/ModCryo/Variables",
51 "/Equipment/SampleCryo/Settings",
52 "/Equipment/SampleCryo/Variables",
53 "/Equipment/LEMVAC/Settings",
54 "/Equipment/LEMVAC/Variables",
55 "/Equipment/SCS2001M/Variables",
56 "/Equipment/SlowControl/Variables/MEAN",
57 "/Analyzer/Parameters/TOFAnaModule",
58 "/Equipment/Danfysik_Spin_Rot/Variables",
59 "/Equipment/Omega/Variables",
103 void strcut(
char *result,
char *orgstr,
char *cutstr);
133 INT status, size, size1=0, i;
139 sprintf(odbkey,
"/Info");
140 db_find_key(
hDB, 0, odbkey, &
hKey);
142 status = db_get_record(
hDB,
hKey, &info, &size, 0);
143 if ( status != DB_SUCCESS ){
144 cm_msg(MERROR,
"open_odb_records",
"Could not open %s record.", odbkey);
152 if ( status != DB_SUCCESS ){
153 cm_msg(MERROR,
"open_odb_records",
"Could not find %s key.",
odbElements[i]);
158 case 0: size =
sizeof(RUNINFO);
break;
165 case 7: size =
sizeof(
HV_EVENT);
break;
178 case 19: size =
sizeof(
MEAN_BANK);
break;
188 if (status != DB_SUCCESS) {
189 cm_msg(MERROR,
"open_odb_records",
"Could not open %s record.",
odbElements[i]);
241 char dir[256], filebody[256];
246 if ( getenv(
"MIDAS_DATA") ){
247 strcpy(dir, getenv(
"MIDAS_DATA"));
248 strcat(dir, DIR_SEPARATOR_STR);
250 strcat(dir, DIR_SEPARATOR_STR);
253 #if defined (OS_UNIX)
254 strcpy(dir, getenv(
"HOME"));
255 #elif defined (OS_WINNT)
256 strcpy(dir, getenv(
"HOMEPATH"));
258 strcat(dir, DIR_SEPARATOR_STR);
259 cm_msg(MINFO,
"create_sum_filename",
260 "MIDAS_DATA path not defined, use home directory %s instead\n", dir);
264 tms = localtime(&now);
267 strcpy(filename, dir);
269 sprintf(filebody,
"%04d/lem%02d_%04d.summ", tms->tm_year+1900,
270 tms->tm_year%100, odb.
runinfo.run_number);
272 sprintf(filebody,
"%04d/lem%02d_%04d.summ", tms->tm_year+1900,
273 tms->tm_year%100, odb.
runinfo.run_number-1);
275 strcat(filename, filebody);
305 char beginComment[] =
306 "#BUC---- B e g i n of User Comment ------ Do not edit this line";
308 "#EUC---- E n d of User Comment ------ Do not edit this line";
309 char bucpattern[5] =
"#BUC";
310 char eucpattern[5] =
"#EUC";
311 char pattern[5], underline[
MAXLINE], previousfile[256];
313 BOOL prevfile=FALSE, cont=FALSE, dowrite=FALSE, running=FALSE;
327 file = fopen(filename,
"r");
332 sprintf(previousfile,
"%s.old", filename);
333 sprintf(cmd,
"cp %s %s", filename, previousfile);
335 fprevious = fopen(previousfile,
"r");
344 fprevious = fopen(previousfile,
"r");
345 if ( fprevious != NULL ){
358 file = fopen(filename,
"w");
360 cm_msg(MERROR,
"write_sum_file",
"Error opening summary file %s",
368 sprintf(
line,
"%s Run %04d started.\n", odb.
runinfo.start_time,
373 sprintf(
line,
"%s Run %04d stopped.\n\n", odb.
runinfo.stop_time,
376 sprintf(
line,
"%s Run %04d stopped.\n\n", odb.
runinfo.stop_time,
388 for ( i=0; i<len; i++)
391 sprintf(
line,
" %s\n\n", underline);
394 sprintf(
line,
"%s\n", beginComment);
408 for ( i = 0; i<4; i++ )
409 pattern[i] =
line[i];
411 if ( strcmp(pattern, bucpattern) == 0 )
413 if ( strcmp(pattern, eucpattern) == 0 )
418 unlink(previousfile);
422 sprintf(
line,
"\n\n%s\n\n\n", endComment);
426 sprintf(
line,
"\n\n\n");
459 void strcut(
char *result,
char *orgstr,
char *cutstr)
471 len = strlen(cutstr);
472 strcpy(tempstr, orgstr);
474 if ( strcmp(tempstr, cutstr) == 0 ){
476 while ( (result[j] = orgstr[j+len]) !=
'\0')
480 strcpy(result, orgstr);
490 char name0[32], name1[32];
491 char group[5] =
"FUG%";
493 sprintf(
line,
"\nTransport-HV:\n");
495 sprintf(
line,
"===============\n");
499 for ( i = 0; i<
N_FUG; i+=2){
502 sprintf(
line,
" %15s = %8.3f kV\t %15s = %8.3f kV\n",
507 sprintf(
line,
" Mean Moderator = %8.3f(%5.3f) kV\t Mean Sample = %8.3f(%5.3f) kV\n",
512 sprintf(
line,
" SR Current = %8.3f A\t\t SR Voltage = %8.3f V\n",
528 float eloss, implantation_energy;
530 sprintf(
line,
"\nMuon Energy:\n");
532 sprintf(
line,
"===============\n");
538 sprintf(
line,
" energy loss = %8.3f keV implantation energy = %8.3f keV\n",
539 eloss, implantation_energy);
552 sprintf(
line,
"\nCalculated t0's:\n");
554 sprintf(
line,
"===============\n");
566 sprintf(
line,
"\n ====================== E v e n t definition =========================\n\n");
574 sprintf(
line,
" Event 0: %d\t BC: %7d\t e+: %7d\n",
581 sprintf(
line,
" Event 1: %d\t BC: %7d\t e+: %7d\n",
588 sprintf(
line,
" Event 2: %d\t BC: %7d\t e+: 1\n",
594 sprintf(
line,
"\n Time windows: \n");
596 sprintf(
line,
" ============= \n");
598 sprintf(
line,
" Event 0: Data Window: %7d, TOF BC Window: %7d, TOF BC Pileup: %7d\n",
605 sprintf(
line,
" Event 1: Data Window: %7d, TOF M2 Window: %7d, TOF M2 Pileup: %7d\n",
612 sprintf(
line,
" Event 1: Data Window: %7d, TOF BC Window: %7d, TOF BC Pileup: %7d\n",
619 sprintf(
line,
" Event 2: Data Window: %7d, TOF BC Window: %7d, TOF BC Pileup: %7d\n",
626 sprintf(
line,
"\n Software delays: \n");
628 sprintf(
line,
" ================ \n");
630 sprintf(
line,
" Event 0: MCP1 : %7d, e+: %7d\n",
635 sprintf(
line,
" Event 1: Master: %7d, e+: %7d\n",
640 sprintf(
line,
" Event 2: TD : %7d, e+: %7d\n",
647 sprintf(
line,
"\n Event 1: Master TD: %d, TD Active: %d, Master M2: %d, M2 Active %d\n",
655 sprintf(
line,
"\n TD-MCP2 TOF cuts: \n");
657 sprintf(
line,
" ================= \n");
660 sprintf(
line,
" TOFcutMin : %7.0f, TOFcutMax: %7.0f\n",
666 sprintf(
line,
"\n MCP2 beamspot parameter: \n");
668 sprintf(
line,
" ======================== \n");
671 sprintf(
line,
" x Offset (mm) : %7.2f, y Offset (mm): %7.2f\n",
676 sprintf(
line,
" scale factor : %7.2f, rotation angle (degree): %7.2f\n",
689 char str0[32], str1[32];
691 sprintf(
line,
"\nBeamline:\n");
693 sprintf(
line,
"=========");
702 for ( i=0; i<nmax-1; i++){
707 sprintf(
line,
" %s\t DAC = %5.0f ADC = %7.3f\t %s\t DAC = %5.0f ADC = %7.3f\n",
799 const char *press[] = {
"MC_GJ ",
"MC_GJ2",
"TC_GJ ",
"SC_GJ ",
"SC_GJ2"};
800 const char *
xtc[] = {
"XTC_Th"};
804 sprintf(
line,
"\nEnvironment:\n");
806 sprintf(
line,
"============\n");
825 for ( i=0; i<size; i++){
826 for ( j=0; j<5; j++){
837 for ( i=0; i<size; i++){
838 for ( j=0; j<1; j++){
856 sprintf(
line,
"\t Trigger horizontal\t = %6.2f degree\n", info.
trigger.
angle);
870 const char *temp_mod[] = {
"ModCryo_CF_1",
"ModCryo_CF_2",
"ModCryo_Chimney",
"ModCryo_He_Shield"};
871 const char *temp_sample[] = {
"Sample_CF1",
"Sample_CF2",
"Sample_D0"};
875 sprintf(
line,
"\nTemperatures:\n");
877 sprintf(
line,
"============\n");
880 for ( i=0; i<size; i++){
881 for ( j=0; j<4; j++){
890 for ( i=0; i<size; i++){
891 for ( j=0; j<3; j++){
903 for ( i=0; i<size; i++){
928 sprintf(
line,
"\nControl Room Scalers:\n");
930 sprintf(
line,
"====================\n");
969 double scal_rate, norm, ip_norm, ip_rate, tdc_life;
971 const char *state[] = {
"",
"Stopped",
"Paused",
"Running" };
972 const char *dashline[] =
973 {
"--------------------------------------------------------------------------"};
975 {
" # Label Total Rate/mAs Rate/s "};
976 time_t now, difftime;
985 sprintf(
line,
"\n%s\n", dashline[0]);
988 sprintf(
line,
" Run Number: %10d started at: %s\n",
992 if ( odb.
runinfo.state == STATE_STOPPED){
993 sprintf(
line,
" Run State : %10s last update: %s\n",
998 sprintf(
line,
" Run State : %10s last update: %s\n",
999 state[odb.
runinfo.state], ctime(&now));
1002 sprintf(
line,
"\n%s\n", top[0]);
1004 sprintf(
line,
"%s\n\n", dashline[0]);
1006 db_find_key(
hDB, 0,
"/Equipment/Scaler/Variables/SSUM", &
hKey);
1007 size =
sizeof(ssum);
1008 db_get_data(
hDB,
hKey, &ssum, &size, TID_DOUBLE);
1013 if ( ssum[i] > 1e36 || (ssum[i] < 1e-36 && ssum[i] != 0.))
1015 norm = ssum[scal_ch]/scal_rate;
1016 ip_norm = ssum[ip_ch]/ip_rate;
1018 rate = ssum[i]/norm;
1022 rate_perIp = ssum[i]/ip_norm;
1027 if ( ssum[i] > 1e7 )
1028 sprintf(
line,
"%2d %-12s %15.5e\t %13.1f %16.1f\n", i,
1031 sprintf(
line,
"%2d %-12s %15.0f\t %13.1f %16.1f\n", i,
1045 rate_perIp = bc_sum/ip_norm;
1050 sprintf(
line,
" BC-Sum: %20.5e\t %13.1f %16.1f\n", bc_sum, rate_perIp, rate);
1052 sprintf(
line,
" BC-Sum: %20.0f\t %13.1f %16.1f\n", bc_sum, rate_perIp, rate);
1056 sprintf(
line,
"--- vme stats ----------\n");
1077 if ( ssum[
CLOCK] > 0 )
1088 sprintf(
line,
"%s\n", dashline[0]);
1091 if (odb.
runinfo.state == STATE_STOPPED)
1092 difftime = odb.
runinfo.stop_time_binary - odb.
runinfo.start_time_binary;
1094 difftime = now - odb.
runinfo.start_time_binary;
1096 sprintf(
line,
"Elapsed time: %dh%02dm%02ds\n",
1097 difftime/3600, difftime%3600/60,difftime%60);
1099 sprintf(
line,
"\nRates are a v e r a g e d rates\n");
1110 double rate, rate_perIp;
1113 rate = scaler_sum / norm;
1117 rate_perIp = scaler_sum / ip_norm;
1121 if ( scaler_sum > 1e7 )
1122 sprintf(
line,
"%-16s: %14.5e\t %13.1f %16.1f\n",
1123 label, scaler_sum, rate_perIp, rate);
1125 sprintf(
line,
"%-16s: %14.0f\t %13.1f %16.1f\n",
1126 label, scaler_sum, rate_perIp, rate);
1139 INT status, i, size;
1140 char host_name[HOST_NAME_LENGTH];
1141 char expt_name[HOST_NAME_LENGTH];
1152 cm_get_environment (host_name,
sizeof(host_name), expt_name,
sizeof(expt_name));
1155 for ( i=1; i<argc; i++){
1156 if ( argv[i][0] ==
'-' ){
1157 if ( i+1 >= argc || argv[i+1][0] ==
'-' )
1159 if ( argv[i][1] ==
'e' )
1160 strcpy(expt_name, argv[i+1]);
1161 else if ( argv[i][1] ==
'h' )
1162 strcpy(host_name, argv[i+1]);
1165 printf(
"\n usage: write_summary [-h Hostname] [-e Experiment]\n\n");
1175 status = cm_connect_experiment(host_name, expt_name,
"write_summary", NULL);
1176 if ( status != CM_SUCCESS)
1183 cm_get_experiment_database(&
hDB, NULL);
1196 if ( status == DB_SUCCESS ){
1199 sprintf(cmd,
"emacs %s",
sumfile);
1208 size =
sizeof(printcmd);
1209 if ( db_get_value(
hDB, 0,
"/Programs/print summary", &printcmd, &size, TID_STRING, FALSE)
1210 == DB_SUCCESS && odb.
runinfo.state == 1 ){
1212 if ( strstr( printcmd,
"print") ){
1213 sprintf(cmd,
"%s %s &", printcmd,
sumfile);
1220 cm_disconnect_experiment();
INT scaler_sum(EVENT_HEADER *, void *)
INT display_scaler(FILE *f)
float implantation_energy
double channelCounts[N_TDC_CHANNELS]
MODCRYO_EVENT moddy_event
void write_control_room_scaler(FILE *f)
MODCRYO_SETTINGS moddy_settings
UINT32 tof_bc_pileup_window
struct TRIGGER_SETTINGS::@20 event_2_settings
SAMPLECRYO_SETTINGS sample_settings
BEAMLINE_SETTINGS beamline_settings
DANFYSIK_SPIN_ROT_EVENT danfysik_spin_rot_event
HV_DETECTORS_SETTINGS hvdet_settings
INT write_trigger(FILE *f)
struct INFO::@298 trigger
void strcut(char *result, char *orgstr, char *cutstr)
OMEGA_EVENT oven_omega_event
char moderatorDATE[STR_SIZE]
struct INFO::@294 t0_parameter
BEAMLINE_EVENT beamline_event
INT create_sum_filename(char *filename, const char *flag)
INT write_beamline(FILE *f)
struct TRIGGER_SETTINGS::@17 events
struct TRIGGER_SETTINGS::@19 event_1_settings
TOFANAMODULE_PARAM tof_param
LEMVAC_SETTINGS lemvac_settings
struct INFO::@301 controlroom_scaler_info
INT write_temp(FILE *f, BOOL running)
char beamline_settings[132]
SCALER_SETTINGS scaler_settings
TRIGGER_SETTINGS trigger_settings
char sample_cryo[NAME_LENGTH]
INT write_sum_file(char *filename)
main(int argc, char *argv[])
SAMPLECRYO_EVENT sample_event
static INT rate[N_SCALER]
#define SPINROTATOR_VOLTAGE_CHANNEL
HV_DETECTORS_EVENT hvdet_event
#define N_SCALER
total number of scaler channels
#define SPINROTATOR_CURRENT_CHANNEL
#define CLOCK
TDC channel assignments.
struct INFO::@295 spinrot_parameter
#define N_DECAY_HISTS
number of LE-uSR npp decay histograms
INT open_odb_records(void)
LEMVAC_EVENT lemvac_event
SCALERSUMRATE_PARAM scaler_param
INT write_hvtrans(FILE *f)
SCS2001M_EVENT scs2001m_event
const char * odbElements[]
struct TRIGGER_SETTINGS::@18 event_0_settings
INT write_rates(FILE *f, double norm, double ip_norm, double scaler_sum, const char *label)
UINT32 tof_m2_pileup_window