void G4Init(const bool do_tracking = true, const bool do_pstof = true, const bool do_cemc = true, const bool do_hcalin = true, const bool do_magnet = true, const bool do_hcalout = true, const bool do_pipe = true, const bool do_plugdoor = false ) { // load detector/material macros and execute Init() function if (do_pipe) { gROOT->LoadMacro("G4_Pipe.C"); PipeInit(); } if (do_tracking) { gROOT->LoadMacro("G4_Tracking.C"); TrackingInit(); } if (do_pstof) { gROOT->LoadMacro("G4_PSTOF.C"); PSTOFInit(); } if (do_cemc) { gROOT->LoadMacro("G4_CEmc_Spacal.C"); CEmcInit(72); // make it 2*2*2*3*3 so we can try other combinations } if (do_hcalin) { gROOT->LoadMacro("G4_HcalIn_ref.C"); HCalInnerInit(); } if (do_magnet) { gROOT->LoadMacro("G4_Magnet.C"); MagnetInit(); } if (do_hcalout) { gROOT->LoadMacro("G4_HcalOut_ref.C"); HCalOuterInit(); } if (do_pipe) { gROOT->LoadMacro("G4_PlugDoor.C"); PlugDoorInit(); } }
void G4Init(bool do_svtx = true, bool do_preshower = false, bool do_cemc = true, bool do_hcalin = true, bool do_magnet = true, bool do_hcalout = true, bool do_pipe = true, bool do_bbc = true, bool do_global = true, bool do_FEMC = true, bool do_FHCAL = true) { gROOT->LoadMacro("G4_Bbc.C"); if (do_bbc) BbcInit(); gROOT->LoadMacro("G4_Pipe.C"); if (do_pipe) PipeInit(); // load detector macros and execute Init() function gROOT->LoadMacro("G4_Svtx.C"); // default //gROOT->LoadMacro("G4_Svtx_ladders.C"); // testing //gROOT->LoadMacro("G4_Svtx_ITS.C"); // testing if (do_svtx) SvtxInit(); if (do_preshower) { gROOT->LoadMacro("G4_PreShower.C"); // testing PreShowerInit(); } gROOT->LoadMacro("G4_CEmc_Spacal.C"); // if (do_cemc) CEmcInit(72); // make it 2*2*2*3*3 so we can try other combinations //gROOT->LoadMacro("G4_Hcal_ref.C"); // deprecated //gROOT->LoadMacro("G4_Hcal_cross.C"); // deprecated gROOT->LoadMacro("G4_HcalIn_ref.C"); // default if (do_hcalin) HCalInnerInit(); gROOT->LoadMacro("G4_Magnet.C"); if (do_magnet) MagnetInit(); gROOT->LoadMacro("G4_HcalOut_ref.C"); // default if (do_hcalout) HCalOuterInit(); gROOT->LoadMacro("G4_Global.C"); gROOT->LoadMacro("G4_Jets.C"); gROOT->LoadMacro("G4_FwdJets.C"); gROOT->LoadMacro("G4_FEMC.C"); if ( do_FEMC ) FEMCInit(); gROOT->LoadMacro("G4_FHCAL.C"); if ( do_FHCAL ) FHCALInit(); }
int main(int argc, char *argv[]) { TracePrintf(1, "\t===>pipe.c\n"); int pipe_id; int rc; if (PipeInit(&pipe_id) != 0) TracePrintf(1, "Failed to initialize pipe\n"); else TracePrintf(1, "Pipe Initialized. ID = %d\n", pipe_id); rc = Fork(); if (rc == 0) { char *to_write = (char *)malloc(5 * sizeof(char)); to_write[0] = 'a'; to_write[1] = 'b'; to_write[2] = 'c'; to_write[3] = 'd'; to_write[4] = 'e'; char *second_write = (char *)malloc(2 * sizeof(char)); second_write[0] = 'e'; second_write[1] = 'f'; int written; Pause(); TracePrintf(1, "\tCHILD: about to write to the lock\n"); written = PipeWrite(pipe_id, to_write, 4); TracePrintf(1, "\tCHILD: wrote %d characters to the lock\n", written); Pause(); TracePrintf(1, "\tCHILD: pausing once\n"); Pause(); written = PipeWrite(pipe_id, second_write, 2); TracePrintf(1, "\tCHILD: wrote to the pipe again (%d chars)\n", written); Pause(); Exit(0); } else { char *to_read = (char *)malloc(6 * sizeof(char)); int read; Pause(); Pause(); TracePrintf(1, "\tPARENT: reading 6 chars from the pipe (before it's ready\n"); read = PipeRead(pipe_id, to_read, 6); TracePrintf(1, "\tPARENT: read %d chars from the pipe. Results: %s\n", read, to_read); Pause(); Exit(0); } return 0; }
void SetupPipe( char * buff, struct PIPE * pipe, struct PRODUCER_CONTEXT * pc, struct CONSUMER_CONTEXT * cc, INDEX producer_watchdog, INDEX consumer_watchdog) { PIPE_READ reader; PIPE_WRITE writer; PipeInit( buff, BUFFER_LENGTH, pipe, &reader, &writer ); pc->WatchdogId = producer_watchdog; pc->Writer = writer; cc->WatchdogId = consumer_watchdog; cc->Reader = reader; }
void G4Init(bool do_svtx = true, bool do_preshower = false, bool do_cemc = true, bool do_hcalin = true, bool do_magnet = true, bool do_hcalout = true, bool do_pipe = false) { gROOT->LoadMacro("G4_Pipe.C"); if (do_pipe) PipeInit(); // load detector macros and execute Init() function gROOT->LoadMacro("G4_Svtx.C"); // default //gROOT->LoadMacro("G4_Svtx_ladders.C"); // testing //gROOT->LoadMacro("G4_Svtx_ITS.C"); // testing if (do_svtx) SvtxInit(); if (do_preshower) { gROOT->LoadMacro("G4_PreShower.C"); // testing PreShowerInit(); } gROOT->LoadMacro("G4_CEmc_Spacal.C"); // //gROOT->LoadMacro("G4_CEmc_cross.C"); // obselete //gROOT->LoadMacro("G4_CEmc_Alice.C"); // obselete //gROOT->LoadMacro("G4_CEmc_Alice_W.C"); // obselete if (do_cemc) CEmcInit(Cemc_slats_per_cell); //gROOT->LoadMacro("G4_Hcal_ref.C"); // deprecated //gROOT->LoadMacro("G4_Hcal_cross.C"); // deprecated gROOT->LoadMacro("G4_HcalIn_ref.C"); // default if (do_hcalin) HCalInnerInit(); gROOT->LoadMacro("G4_Magnet.C"); if (do_magnet) MagnetInit(); gROOT->LoadMacro("G4_HcalOut_ref.C"); // default if (do_hcalout) HCalOuterInit(); gROOT->LoadMacro("G4_Jets.C"); }
// Initialize all threads // pipe_path: the path of the pipe // id: the id of the pipe. // is_server: whether this opened pipe is a server. void *ExLocalInit(const char *pipe_path, int id, BOOL is_server) { Exchanger *ex = (Exchanger *)malloc(sizeof(Exchanger)); int flag = is_server ? 1 : 0; char buf[1000]; for (int i = 0; i < NUM_CHANNELS; ++i) { sprintf(buf, "%s/%s-%d-%d", pipe_path, PIPE_PREFIX, id, i); if (is_server) { // We need to remove the file first. remove(buf); } if (PipeInit(buf, flag, &ex->channels[i]) == -1) { free(ex); return NULL; } } ex->is_server = is_server; ex->wait_count = 0; ex->wait_count_max = 0; if (! is_server) return ex; ex->ctrl_flag = 0; ex->done = FALSE; ex->move_sent = 0; ex->board_received = 0; // Initialize queue. // queue_init(&ex->q, QUEUE_SIZE, sizeof(MBoard)); // For client, we don't need to do anything. // For server, we need to start a few threads. // Message thread: get all board messages and put them into a (priority) queue. // Ctrl thread: check all control messages (ctrl_c2s) and change the status of the exchanger accordingly. // Ack knowledge will be sent by the main thread (the main function). // pthread_create(&ex->message, NULL, threaded_message, ex); pthread_create(&ex->ctrl, NULL, threaded_ctrl, ex); return ex; }
void G4Init(bool do_svtx = true, bool do_preshower = false, bool do_cemc = true, bool do_hcalin = true, bool do_magnet = true, bool do_hcalout = true, bool do_pipe = true) { // load detector/material macros and execute Init() function if (do_pipe) { gROOT->LoadMacro("G4_Pipe.C"); PipeInit(); } if (do_svtx) { //gROOT->LoadMacro("G4_Svtx.C"); // default MIE projections gROOT->LoadMacro("G4_Svtx_pixels+strips.C"); // testing //gROOT->LoadMacro("G4_Svtx_pixels+tpc.C"); // testing //gROOT->LoadMacro("G4_Svtx_maps+strips.C"); // testing //gROOT->LoadMacro("G4_Svtx_maps+tpc.C"); // testing //gROOT->LoadMacro("G4_Svtx_ladders.C"); // testing //gROOT->LoadMacro("G4_Svtx_ITS.C"); // testing SvtxInit(); } if (do_preshower) { gROOT->LoadMacro("G4_PreShower.C"); PreShowerInit(); } if (do_cemc) { if ( fast_sim_flag == 1 ) gROOT->LoadMacro("G4_CEmc_BlackHole.C"); // super fast sim for electrons??? else if ( fast_sim_flag == 2 ) gROOT->LoadMacro("G4_CEmc_Galactic.C"); // super fast sim for pions??? else gROOT->LoadMacro("G4_CEmc_Spacal.C"); // actual GEANT simulation CEmcInit(72); // make it 2*2*2*3*3 so we can try other combinations } if (do_hcalin) { //gROOT->LoadMacro("G4_HcalIn_ref.C"); gROOT->LoadMacro("G4_HcalIn_Blackhole.C"); HCalInnerInit(); } if (do_magnet) { gROOT->LoadMacro("G4_Magnet.C"); MagnetInit(); } if (do_hcalout) { gROOT->LoadMacro("G4_HcalOut_ref.C"); HCalOuterInit(); } }
void G4Init(bool do_svtx = true, bool do_preshower = false, bool do_cemc = true, bool do_hcalin = true, bool do_magnet = true, bool do_hcalout = true, bool do_pipe = true, bool do_FEMC = true, bool do_FHCAL = true) { // load detector/material macros and execute Init() function if (do_pipe) { gROOT->LoadMacro("G4_Pipe.C"); PipeInit(); } if (do_svtx) { gROOT->LoadMacro("G4_Svtx.C"); //gROOT->LoadMacro("G4_Svtx_ladders.C"); // testing //gROOT->LoadMacro("G4_Svtx_ITS.C"); // testing SvtxInit(); } if (do_preshower) { gROOT->LoadMacro("G4_PreShower.C"); PreShowerInit(); } if (do_cemc) { gROOT->LoadMacro("G4_CEmc_Spacal.C"); CEmcInit(72); // make it 2*2*2*3*3 so we can try other combinations } if (do_hcalin) { gROOT->LoadMacro("G4_HcalIn_ref.C"); HCalInnerInit(); } if (do_magnet) { gROOT->LoadMacro("G4_Magnet.C"); MagnetInit(); } if (do_hcalout) { gROOT->LoadMacro("G4_HcalOut_ref.C"); HCalOuterInit(); } if (do_FEMC) { gROOT->LoadMacro("G4_FEMC.C"); FEMCInit(); } if (do_FHCAL) { gROOT->LoadMacro("G4_FHCAL.C"); FHCALInit(); } }
int main(int argc, char* argv[]){ // test 1 : pipe, lock and cvar int lock_id, cvar_id, pipe_id; int pid,status; int condition=0; char *test = "Yalnix Works"; char *buffer = (char*)malloc(1024); TracePrintf(1, "init main: test pipe, lock, cvar.\n"); LockInit(&lock_id); CvarInit(&cvar_id); PipeInit(&pipe_id); TracePrintf(1, "init main: Lockid %d.\n", lock_id); TracePrintf(1, "init main: Cvarid %d.\n", cvar_id); TracePrintf(1, "init main: Pipeid %d.\n", pipe_id); pid = Fork(); if (pid == 0) { TracePrintf(1,"init main: child \n"); Acquire(lock_id); TracePrintf(1,"init main: child acquire the lock\n"); condition=1; TracePrintf(1,"init main: child condition %d\n",condition); PipeWrite(pipe_id, &condition,sizeof(int)); TracePrintf(1,"init main: child change the condition and write it to pipe\n"); TracePrintf(1,"init main: child cvar signal\n"); CvarSignal(cvar_id); Release(lock_id); TracePrintf(1,"init main: child write to pipe: %s\n",test); PipeWrite(pipe_id,test,20); TracePrintf(1,"init main: child release the lock\n"); Exit(0); } else{ TracePrintf(1,"init main: parent\n"); Acquire(lock_id); TracePrintf(1,"init main: parent acquire the lock\n"); while(!condition){ TracePrintf(1,"init main: parent cvar wait, condition %d\n",condition); CvarWait(cvar_id,lock_id); PipeRead(pipe_id,&condition,sizeof(int)); TracePrintf(1,"init main: parent read the condition from pipe, condition %d\n",condition); } TracePrintf(1,"init main: parent wake up\n"); Release(lock_id); TracePrintf(1,"init main: parent release the lock\n"); PipeRead(pipe_id,buffer,20); TracePrintf(1,"init main: parent read from pipe: %s\n",buffer); } Reclaim(lock_id); Reclaim(cvar_id); Reclaim(pipe_id); Exit(0); }
int main(int argc, char **argv) { int pid, i, j, ret; int exit_status; char *exec_argv[] = { "haha", NULL }; int *a = (int *)calloc(3, sizeof(int)); int num_a = 100; char *str; unsigned int delay_ticks = 2; char buf[2 * TERMINAL_MAX_LINE + 2]; char pipe_buf[1025]; int pipe_fd; int lock_fd; int cvar_fd; #ifdef SWAP_TEST free(a); a = (void *)calloc(num_a, PAGESIZE); if (a == NULL) goto loop; if (Fork() == 0) { while (1) { Delay(2); a[0] = 1000; TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]); } } for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int))) a[i] = 100; if (Fork() == 0) { while (1) { Delay(2); a[0] = 2000; TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]); } } for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int))) a[i] = 100; if (Fork() == 0) { while (1) { Delay(2); a[0] = 3000; TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]); } } for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int))) a[i] = 100; if (Fork() == 0) { while (1) { Delay(2); a[0] = 4000; TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]); } } for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int))) a[i] = 100; if (Fork() == 0) { while (1) { Delay(2); a[0] = 5000; TtyPrintf(CONSOLE, "pid = %u, a[0] = %u\n", GetPid(), a[0]); } } for (i = 0; i < num_a * PAGESIZE / sizeof(int); i += (PAGESIZE / sizeof(int))) a[i] = 100; #endif #ifdef PIPE_TEST ret = PipeInit(&pipe_fd); pid = Fork(); bzero(pipe_buf, sizeof(pipe_buf)); if (pid != ERROR && !pid) { TtyPrintf(CONSOLE, "pipe_fd = %u\n", pipe_fd); j = 0; Delay(1); while (1) { for (i = 0; i < sizeof(pipe_buf); i++) pipe_buf[i] = (j % 26) + 'a'; TtyPrintf(CONSOLE, ">>>>>>>>>>> write pipe\n"); ret = PipeWrite(pipe_fd, pipe_buf, sizeof(pipe_buf)); TtyPrintf(CONSOLE, "write pipe ret = %d, pid = %u\n", ret, GetPid()); j++; } Exit(0); } while (1) { bzero(pipe_buf, sizeof(pipe_buf)); TtyPrintf(CONSOLE, ">>>>>>>>>>> read pipe\n"); ret = PipeRead(pipe_fd, pipe_buf, sizeof(pipe_buf) - 7); TtyPrintf(CONSOLE, "<<<<<<<<<<< read pipe ret = %d, pid = %u, %s\n", ret, GetPid(), pipe_buf); } Reclaim(pipe_fd); #endif #ifdef CVAR_TEST ret = LockInit(&lock_fd); ret = CvarInit(&cvar_fd); pid = Custom0(0, 0, 0, 0); if (pid != ERROR && !pid) { Acquire(lock_fd); while (!condition) CvarWait(cvar_fd, lock_fd); Delay(2); Release(lock_fd); Exit(7); } Acquire(lock_fd); condition = 1; CvarSignal(cvar_fd); Release(lock_fd); ret = Reclaim(lock_fd); if (ret) Exit(-1); #endif #ifdef TTY_TEST for (i = 0; i < sizeof(buf) - 1; i++) buf[i] = '9'; buf[i] = '\0'; TtyPrintf(CONSOLE, buf); TtyPrintf(CONSOLE, "\n"); a[0] = 10; a[2] = 100; TtyPrintf(CONSOLE, "Enter somthing:\n"); bzero(buf, sizeof(buf)); ret = TtyRead(CONSOLE, buf, sizeof(buf)); TtyPrintf(CONSOLE, "You just entered: %s (len = %d)\n", buf, ret); #endif #ifdef COW_TEST if (argc == 2) delay_ticks = atoi(argv[1]); pid = Fork(); if (pid == ERROR) { Delay(2); return ERROR; } else if (!pid) { GetPid(); delay_ticks = 5; TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid()); pid = Fork(); if (pid != ERROR && !pid) { GetPid(); delay_ticks = 8; TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid()); Delay(delay_ticks); Exec("exec_test", exec_argv); } pid = Wait(&exit_status); TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid()); TtyPrintf(CONSOLE, " wait child = %u, status = %d\n", pid, exit_status); Delay(delay_ticks); Exit(10); } pid = Fork(); if (pid != ERROR && !pid) { incursive_func(0); GetPid(); delay_ticks = 9; TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid()); Delay(delay_ticks); Exit(100); } TtyPrintf(CONSOLE, " delay_ticks = %u, pid = %u\n", delay_ticks, GetPid()); Delay(delay_ticks); GetPid(); Wait(&exit_status); Wait(&exit_status); GetPid(); #endif loop: while (1) Delay(delay_ticks); return 0; }