/* * This program has HBOOK ntuple routine. * * YG ,Jul 1997 */ #include #include #include #include #include #include #include #include /** Hbook header **/ #include #include /*** DD header ***/ #include #include #include "/usr1/mvdonl/coda/dd/v2.5.2/usr/usr.h" #define PAWC_SIZE 5000000 #ifdef extname float pawc_[PAWC_SIZE]; #else float pawc_[PAWC_SIZE]; #endif main() { int i; int brc_flag; int status,run_nb; struct fifo_mode ntp_fmode; char ntp_fname[20],ntp_filename[100]; int dd_ctl[FIFO_HDR_CTL_LEN] = {-1,-1,-1,-1}; struct fifo_entry fev; int hid=10,istat=0,icycle=0; int record_size=1024; int end; struct data_event *phy_event; char dd_log_msg[50]; int buffer1,buffer2; float coda_hd[9],ornl_hd1[5],pre_dat1[32],pre_dat2[32]; float ornl_t1[2],ornl_hd2[5]; float post_dat1[32],post_dat2[32],ornl_t2[3]; /*********** initialise PAW ************/ HLIMIT(PAWC_SIZE); /*********** initialise DD consumer **********/ if ( ddu_attach() ) dds_create(); strcpy(ntp_fname,"NTUPLE"); ntp_fmode.mode = 0; ntp_fmode.wait = 0; ntp_fmode.prescale = 1; ntp_fmode.suser = FMODE_SINGLE_USER; ntp_fmode.p2ctl = dd_ctl; brc_flag = 1; /* -----> SIGNAL mode */ status = ddu_init(ntp_fname, ntp_fmode); if ( status ) { dd_log(DD_ERROR,"ddu_init failed!"); exit(1); } if (status = ddu_set_brc(brc_flag)) { dd_log(DD_ERROR,"ddu_set_brc failed!"); } fflush(stdout); /**************** prepare getting real physics events ***********/ if ( ddu_attached() ) { ddu_start(); if ( !ddu_get_fev(&fev) ) { if( fev.ctlw1 == PRESTART_EVENT ) { runagain: /*---> New run starts here! */ run_nb = *(fev.p2da + 3); sprintf(ntp_filename,"../hbook/run_%d",run_nb); strcat(ntp_filename,".ntp"); sprintf( dd_log_msg ," Prestart: run number = %d\n",run_nb); dd_log( DD_INFO, dd_log_msg ); /************************ Open and Initialise ntuple ***********************/ HROPEN(1,"LASER TEST",ntp_filename,"N",record_size,istat); HBNT(hid,"MVD DATA"," "); HBNAME(hid,"CODA_HD",coda_hd,"c_hd0,c_hd1,c_hd2,c_hd3, c_hd4,c_hd5,c_hd6,c_hd7,c_hd8"); HBNAME(hid,"ORLN_HD1",ornl_hd1,"o_hd10,o_hd11,o_hd12, o_hd13,o_hd14"); HBNAME(hid,"PRE_DA1",pre_dat1,"pre0,pre1,pre2,pre3,pre4,pre5,pre6, pre7,pre8,pre9,pre10,pre11,pre12,pre13,pre14,pre15,pre16, pre17,pre18,pre19,pre20,pre21,pre22,pre23,pre24,pre25,pre26, pre27,pre28,pre29,pre30,pre31"); HBNAME(hid,"PRE_DA2",pre_dat2,"pre32,pre33,pre34,pre35,pre36,pre37, pre38,pre39,pre40,pre41,pre42,pre43,pre44,pre45,pre46,pre47, pre48,pre49,pre50,pre51,pre52,pre53,pre54,pre55,pre56,pre57, pre58,pre59,pre60,pre61,pre62,pre63"); HBNAME(hid,"ORNL_TL1",ornl_t1,"o_t10,o_t11"); HBNAME(hid,"ORNL_HD2",ornl_hd2,"o_hd20,o_hd21,o_hd22,o_hd23,o_hd24"); HBNAME(hid,"POST_DA1",post_dat1,"post0,post1,post2,post3,post4,post5, post6,post7,post8,post9,post10,post11,post12,post13,post14, post15,post16,post17,post18,post19,post20,post21,post22,post23, post24,post25,post26,post27,post28,post29,post30,post31"); HBNAME(hid,"POST_DA2",post_dat2,"post32,post33,post34,post35,post36, post37,post38,post39,post40,post41,post42,post43,post44,post45, post46,post47,post48,post49,post50,post51,post52,post53,post54, post55,post56,post57,post58,post59,post60,post61,post62,post63"); HBNAME(hid,"ORNL_TL2",ornl_t2,"o_t20,o_t21,o_t22"); } else { dd_log( DD_ERROR,"prestart must be the first event!\n" ); } } else { dd_log( DD_ERROR,"ddu_get_fev failed!\n"); } if ( ( status = ddu_put_fev(fev) ) != 0 ) dd_log( DD_ERROR,"ddu_put_fev failed\n"); ddu_stop(); } /************** get events and fill ntuple for one run ***********/ end = 1; while ( ddu_attached() && end ) { if ( ddu_fifo_active( ntp_fname ) ) { ddu_start(); } if ( ddu_get_fev(&fev) ) { dd_log( DD_ERROR,"ddu_get_fev failed!\n"); } else { switch ( fev.ctlw1 ) { case GO_EVENT: dd_log ( DD_INFO,"Go: Data taking enable\n" ); ddu_put_fev(fev); break; case END_EVENT: sprintf ( dd_log_msg,"End run: run number = %d\n",run_nb); dd_log ( DD_INFO,dd_log_msg ); end = 0; /****** close ntuple ******/ HROUT(hid,icycle," "); HREND("LASER TEST"); ddu_put_fev(fev); ddu_stop(); break; case PAUSE_EVENT: ddu_put_fev(fev); ddu_stop(); break; case TEST_EVENT: phy_event = ( struct data_event* ) fev.p2da; for ( i = 0 ; i < 9 ; i++ ) { buffer1 = phy_event->coda_hd[i]; coda_hd[i] = (float)buffer1; } for ( i = 0 ; i < 5 ; i++ ) { buffer1 = phy_event->ornl_hd1[i]; buffer2 = phy_event->ornl_hd2[i]; ornl_hd1[i] = (float)buffer1; ornl_hd2[i] = (float)buffer2; } for ( i = 0 ; i < 32 ; i++ ) { buffer1 = phy_event->pre_data[i]; buffer2 = phy_event->post_data[i]; pre_dat1[i] = (float)buffer1; post_dat1[i] = (float)buffer2; } for ( i = 32 ; i < 64 ; i++ ) { buffer1 = phy_event->pre_data[i]; buffer2 = phy_event->post_data[i]; pre_dat2[i-32] = (float)buffer1; post_dat2[i-32] = (float)buffer2; } for ( i = 0 ; i < 2 ; i++ ) { buffer1 = phy_event->ornl_tl1[i]; ornl_t1[i] = (float)buffer1; } for ( i = 0 ; i < 3 ; i++ ) { buffer1 = phy_event->ornl_tl2[i]; ornl_t2[i] = (float)buffer1; } /* filling ntuple */ HFNT(hid); /* put back fev into DD for later use */ ddu_put_fev(fev); break; } } } /*********** waiting for new run or exit **********/ ddu_start(); if ( !ddu_get_fev(&fev) ) { if ( fev.ctlw1 == PRESTART_EVENT ) goto runagain; } else if ( ddu_attached() ) { ddu_close(); /* actually when dd_master closed */ } return; }