1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright 1997-2002, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: Scatter_logger_stop.comp
*
* %I
*
* Written by: Erik B Knudsen, Peter K Willendrup & Esben Klinkby
* Date: January 2013
* Origin: DTU Physics / DTU Nutech
*
* Stop logging iteractions of neutrons with components
*
* %D
* Component which marks the end of the region where SCATTER events should be logged.
*
* %P
* Input parameters:
*
* logger: [] The Scatter_logger.comp which began the logging region. This is necessary to allow communication between the components.
*
* %E
*******************************************************************************/
DEFINE COMPONENT Scatter_logger_stop
SETTING PARAMETERS (string logger)
SHARE
%{
#define SCATTER0\
do {mcDEBUG_SCATTER(mcnlx, mcnly, mcnlz, mcnlvx, mcnlvy, mcnlvz, \
mcnlt,mcnlsx,mcnlsy,mcnlsz, mcnlp); mcScattered++;} while(0)
%}
DECLARE
%{
int bounce_store_index;
int bounce_store_overrun;
%}
INITIALIZE
%{
#ifndef logger
fprintf(stderr,"Error(%s): Logger undefined - can't stop noexisting logger\n", NAME_CURRENT_COMP);
#endif
%}
TRACE
%{
#undef SCATTER
#define SCATTER SCATTER0
#undef mcabsorb
#define mcabsorb mcabsorbAll
scatter_logger_stop:
if (bounce_store_index<BOUNCE_LOG_SIZE){
struct Generalized_State_t *bp;
bp=&(Bounce_store[bounce_store_index]);
bp->_x=0;
bp->_y=0;
bp->_z=0;
bp->_vx=0;
bp->_vy=0;
bp->_vz=0;
bp->_sx=0;
bp->_sy=0;
bp->_sz=0;
bp->_t=0;
bp->_p=-1;
bp->_nid=0;
bp->_comp=0;
bounce_store_index++;
} else if (bounce_store_index==BOUNCE_LOG_SIZE && !bounce_store_overrun) {
printf("Warning (%s): Scatter_log overrun - cannot set stop bit. Aborting\n",NAME_CURRENT_COMP);
exit(1);
}
%}
FINALLY
%{
/*If we are a logger stop we should also free the memory*/
int i;
struct Generalized_State_t *bp;
for (i=0;i<BOUNCE_LOG_SIZE;i++){
bp=&(Bounce_store[i]);
/* maybe this should be in the share block - must be able to discern between different loggers*/
/* printf("SCATTERLOG: %d %lld %g %g %g %g %g %g %g %g %g %g %g %d\n", \*/
/* i,bp->_nid,bp->_x,bp->_y,bp->_z, bp->_vx, bp->_vy, bp->_vz, bp->_t, \*/
/* bp->_sx, bp->_sy, bp->_sz, bp->_p, bp->_comp);*/
}
free(Bounce_store);
%}
END
|