Exemple #1
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called once at the beginning of the job
void 
makemask::beginJob(Event& evt, Env& env)
{
	MsgLog(name(), debug, "beginJob()" );
	MsgLog(name(), info, "badPixelLowerBoundary = '" << p_badPixelLowerBoundary << "'" );	
	MsgLog(name(), info, "badPixelUpperBoundary = '" << p_badPixelUpperBoundary << "'" );
	MsgLog(name(), info, "mask file = '" << p_mask_fn << "'" );
	MsgLog(name(), info, "use mask correction = '" << p_useMask << "'" );
	MsgLog(name(), info, "takeOutThirteenthRow = '" << p_takeOutThirteenthRow << "'" );
	MsgLog(name(), info, "takeOutASICFrame = '" << p_takeOutASICFrame << "'" );

	//read mask, if a file was specified
	if (p_useMask){
		if (p_mask_fn != ""){
			delete p_mask;
			p_mask = new array1D<double>;
						
			array2D<double> *img2D = 0;
			int fail = io->readFromFile( p_mask_fn, img2D );
			create1DFromRawImageCSPAD( img2D, p_mask );
			delete img2D;
			
			
			MsgLog(name(), info, "histogram of mask read\n" << p_mask->getHistogramASCII(2) );
			if (fail){
				MsgLog(name(), warning, "Could not read mask, continuing without mask correction!");
				p_useMask = 0;	
			}
		}else{
				MsgLog(name(), warning, "No mask file specified in config file, continuing without mask correction!");
				p_useMask = 0;			
		}
	}		
}
/// Method which is called at the beginning of the run
void 
CSPadImageProducer::beginRun(Event& evt, Env& env)
{
  if( m_print_bits & 2 ) MsgLog(name(), info, "ImageCSPad::beginRun ");

  // get run number
  shared_ptr<EventId> eventId = evt.get();
  int run = 0;
  if (eventId.get()) {
    run = eventId->run();
  } else {
    MsgLog(name(), warning, "Cannot determine run number, will use 0.");
  }

  std::string calib_dir = (m_calibDir == "") ? env.calibDir() : m_calibDir;

  //m_cspad_calibpar = new PSCalib::CSPadCalibPars(); // get default calib pars from my local directory
                                                      // ~dubrovin/LCLS/CSPadAlignment-v01/calib-cxi35711-r0009-det/
  m_cspad_calibpar   = new PSCalib::CSPadCalibPars(calib_dir, m_typeGroupName, m_str_src, run);
  m_pix_coords_2x1   = new CSPadPixCoords::PixCoords2x1   ();
  m_pix_coords_quad  = new CSPadPixCoords::PixCoordsQuad  ( m_pix_coords_2x1,  m_cspad_calibpar, m_tiltIsApplied );
  m_pix_coords_cspad = new CSPadPixCoords::PixCoordsCSPad ( m_pix_coords_quad, m_cspad_calibpar, m_tiltIsApplied );

  if( m_print_bits & 1 ) m_cspad_calibpar  -> printCalibPars();
  //m_pix_coords_2x1  -> print_member_data();
  //m_pix_coords_quad -> print_member_data(); 

  this -> getQuadConfigPars(env);
}
Exemple #3
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called with event data, this is the only required 
/// method, all other methods are optional
void 
info::event(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "event()" );

	if (p_stopflag){
		stop();
		return;
	}

	//try to get the PV values
	map<string,pv>::iterator it;
	ostringstream osst;
	for (it = p_pvs.begin(); it != p_pvs.end(); it++){
		osst << setw(20) << it->first << " " << setw(26) << it->second.name; 
		try{
			it->second.value = env.epicsStore().value(it->second.name);
			it->second.valid = true;
			osst << " = " << setw(12) << it->second.value;
		}catch(...){
			it->second.valid = false;
			osst << setw(12) << " ---- ";
		}
		osst << " (" << it->second.desc << ")" << endl;
	}
	MsgLog(name(), info, "------list of read out PVs in event #" << p_count << "------\n" << osst.str() );

	//stop after a few events
	if (p_count >= 10){
		p_stopflag = true;
	}
		
	// increment event counter
	p_count++;
}
Exemple #4
0
PMINIRECORDCORE
CheckHost(char *_Host)
{
    PNAMEENTRY pRecord;
    char locbuf[512];
    sprintf(locbuf, "Checking Host for duplicate [%-100.100s]", _Host);
    MsgLog(locbuf);


    /* Get first item NAMES_CONTAINER Container */
    pRecord=(PNAMEENTRY)WinSendDlgItemMsg(sHwnd, sID,
                                          CM_QUERYRECORD,
                                          MPFROMP(0), /* pointer to reference record */
                                          MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));

    while (pRecord) {
        if (pRecord->pszHost[0] == _Host[0] && strcmp(pRecord->pszHost, _Host) == 0)
            return((PMINIRECORDCORE)pRecord);

        sprintf(locbuf, "pRecord [%100.100s] Next->%x", pRecord->pszHost, pRecord->Record.preccNextRecord);
        MsgLog(locbuf);

        pRecord=(PNAMEENTRY)WinSendDlgItemMsg(sHwnd, sID,
                                              CM_QUERYRECORD,
                                              MPFROMP(pRecord), /* pointer to reference record */
                                              MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));

//     pRecord = (PNAMEENTRY)pRecord->Record.preccNextRecord;

    } /* endwhile */
    return(0);
}
int DbDateDiff(const char* start, int delta, int sign, char* buffer, size_t buflen)
{
	int nchar;

    if (start == NULL) {
        return MsgLog(DBS_INVARG, "NULL input string to DbDateDiff");
    }

	if (sign == 1) {
		nchar = snprintf(buffer, buflen,
				"DATETIME('%s', '+%d SECONDS')", start, delta);
	}
	else if (sign == -1) {
		nchar = snprintf(buffer, buflen,
				"DATETIME('%s', '-%d SECONDS')", start, delta);
	}
	else {
        return MsgLog(DBS_INVARG, "Invalid sign to DbDateDiff");
    }

	if (nchar >= (int)buflen || nchar < 0) {
		return 1;
	}

	return 0;

}
int DbIntQuery(DB_HANDLE handle, int* value, const char* query)
{
	DB_RESULT	result;		/* Result object */
	DB_ROW		row = NULL; /* Row object */
    int			status;		/* Status return */

    status = DbExecuteSql(handle, query, &result);
    if (status == SQLITE_OK) {

        /* Get first row */
        status = DbFetchRow(result, &row);
		if (status == 0) {
            /* Got the row, so convert to integer */

            status = DbInt(row, 0, value);

			/* Query succeeded, but are there any more rows? */
        	if (DbFetchRow(result, &row) != -1) {
            	(void) MsgLog(DBS_TOOMANYROW, query);	/* Too much data */
        	}

        }
        else 
        {
			status = MsgLog(DBS_NORESULT);	/* Query did not return a result */
        }

		DbFreeResult(result);
		DbFreeRow(row);

    }

    return status;
}
Exemple #7
0
void correlate::updatePixelArrays(Event& evt)
{
	MsgLog(name(), trace, "updating pixel arrays");
	if (p_units == 1){
		MsgLog(name(), trace, "working in units of detector pixels");
		p_pix1_sp = evt.get(IDSTRING_PX_X_int);
		p_pix2_sp = evt.get(IDSTRING_PX_Y_int);
	}else if (p_units == 2){
		MsgLog(name(), trace, "working with micrometers on the detector");
		p_pix1_sp = evt.get(IDSTRING_PX_X_um);
		p_pix2_sp = evt.get(IDSTRING_PX_Y_um);
	}else if (p_units == 3){
		MsgLog(name(), trace, "working with q-values (in nm^-1)");
		p_pix1_sp = evt.get(IDSTRING_PX_X_q);
		p_pix2_sp = evt.get(IDSTRING_PX_Y_q);
	}else{
		MsgLog(name(), error, "No valid units for pixel arrays specified.");
	}

	if(p_pix1_sp && p_pix2_sp){
		MsgLog(name(), trace, "x: min = " << p_pix1_sp->calcMin() << ", max = " << p_pix1_sp->calcMax() );	
		MsgLog(name(), trace, "y: min = " << p_pix2_sp->calcMin() << ", max = " << p_pix2_sp->calcMax() );		
	}else{
		MsgLog(name(), error, "Could not retrieve new pixel arrays from event. "
			<< "pix1_sp=" << p_pix1_sp.get() << ", pix2_sp=" << p_pix2_sp.get() << "");
		throw;
	}
}
Exemple #8
0
int KsmDNSSECKeysStateCountInit(DB_RESULT* result, int policy_id, KSM_KEY_POLICY *key_policy, int state)
{
	int     where = 0;          /* WHERE clause value */
	char*   sql = NULL;         /* SQL query */
	int     status = 0;         /* Status return */

    /* Check arguments */
    if (key_policy == NULL) {
        return MsgLog(KSM_INVARG, "NULL key_policy");
    }

	/* Construct the query */

	sql = DqsCountInit("dnsseckeys");

	DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, key_policy->sm, where++);
	DqsConditionInt(&sql, "policy_id", DQS_COMPARE_EQ, policy_id, where++);
	DqsConditionInt(&sql, "size", DQS_COMPARE_EQ, key_policy->bits, where++);
	DqsConditionInt(&sql, "algorithm", DQS_COMPARE_EQ, key_policy->algorithm, where++);
	DqsConditionInt(&sql, "keytype", DQS_COMPARE_EQ, key_policy->type, where++);
	DqsConditionInt(&sql, "state", DQS_COMPARE_EQ, state, where++);


	/* Execute query and free up the query string */

	status = DbExecuteSql(DbHandle(), sql, result);

	DqsFree(sql);

	return status;
}
Exemple #9
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called once at the end of the job
void 
info::endJob(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "endJob()" );

	fout.close();
}
Exemple #10
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called at the beginning of the run
void 
makemask::beginRun(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "beginRun()" );
	
	p_outputPrefix = *( (shared_ptr<std::string>) evt.get(IDSTRING_OUTPUT_PREFIX) ).get();
}
int DbStringBuffer(DB_ROW row, int field_index, char* buffer, size_t buflen)
{
	char*	data = NULL;	/* Data returned from DbString */
	int		status;		    /* Status return */

	if (row && (row->magic == DB_ROW_MAGIC) && buffer && (buflen != 0)) {

		/* Arguments OK, get the information */

		status = DbString(row, field_index, &data);
		if (status == 0) {

            /* Success, copy the data into destination & free buffer 
               Note the StrStrncpy copes with data == NULL */

            StrStrncpy(buffer, data, buflen);
            DbStringFree(data);
		}
	}
	else {

		/* Invalid srguments, notify the user */

		status = MsgLog(DBS_INVARG, "DbStringBuffer");
	}

	return status;
}
Exemple #12
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called once at the beginning of the job
void 
info::beginJob(Event& evt, Env& env)
{
	MsgLog(name(), debug, "beginJob()" );
	
	p_pvs[pvDetPos].name = "CXI:DS1:MMS:06";
	p_pvs[pvDetPos].desc = "detector position";

	p_pvs[pvLambda].name = "SIOC:SYS0:ML00:AO192";
	p_pvs[pvLambda].desc = "wavelength [nm]";
		
	p_pvs[pvElEnergy].name = "BEND:DMP1:400:BDES";
	p_pvs[pvElEnergy].desc = "electron beam energy";
	
	p_pvs[pvNElectrons].name = "BPMS:DMP1:199:TMIT1H";
	p_pvs[pvNElectrons].desc = "particle N_electrons";

	p_pvs[pvRepRate].name = "EVNT:SYS0:1:LCLSBEAMRATE";
	p_pvs[pvRepRate].desc = "LCLS repetition rate [Hz]";
		
	p_pvs[pvPeakCurrent].name = "SIOC:SYS0:ML00:AO195";
	p_pvs[pvPeakCurrent].desc = "peak current after second bunch compressor";
	
	p_pvs[pvPulseLength].name = "SIOC:SYS0:ML00:AO820";
	p_pvs[pvPulseLength].desc = "pulse length";
	
	p_pvs[pvEbeamLoss].name = "SIOC:SYS0:ML00:AO569";
	p_pvs[pvEbeamLoss].desc = "ebeam energy loss converted to photon mJ";
	
	p_pvs[pvNumPhotons].name = "SIOC:SYS0:ML00:AO580";
	p_pvs[pvNumPhotons].desc = "calculated number of photons";
	
	p_pvs[pvPhotonEnergy].name = "SIOC:SYS0:ML00:AO541";
	p_pvs[pvPhotonEnergy].desc = "photon beam energy [eV]";

	//initialize the value and valid fields of the pv structs in the map
	for (map<string,pv>::iterator it = p_pvs.begin(); it != p_pvs.end(); it++){
		it->second.value = 0.;
		it->second.valid = false;
		it->second.changed = false;
	} 

	ostringstream header;
	header << "run ";
	map<string,pv>::iterator it;
	for(it = p_pvs.begin(); it != p_pvs.end(); it++){
		header << it->second.name << " ";
	}
	header << endl;
	header << "run ";
	for(it = p_pvs.begin(); it != p_pvs.end(); it++){
		header << it->second.desc << " ";
	}
	header << endl;
			
	std::ofstream headerfile("header.txt");
	headerfile << header.str() << endl;
}
/// Method which is called with event data, this is the only required 
/// method, all other methods are optional
void 
CSPadImageGetTest::event(Event& evt, Env& env)
{
  // this is how to gracefully stop analysis job
  ++m_count;
  //if (m_count >= m_maxEvents) stop();
  MsgLog(name(), debug, "Event: " << m_count);
  if (m_saveAll || m_count == m_eventSave) this -> saveImageInFile(evt);
}
void* MemRealloc(void *ptr, size_t size)
{
    void *ptr1 = realloc(ptr, size);
    if (ptr1 == NULL) {
		MsgLog(KSM_STMTALLOC, "realloc: Out of swap space");
        fprintf(stderr, "realloc: Out of swap space");
        exit(1);
    }
    return ptr1;
}
void* MemCalloc(size_t nmemb, size_t size)
{
    void *ptr = calloc(nmemb, size);
    if (ptr == NULL) {
		MsgLog(KSM_STMTALLOC, "calloc: Out of swap space");
        fprintf(stderr, "calloc: Out of swap space");
		exit(1);
    }
    return ptr;
}
Exemple #16
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called with event data, this is the only required 
/// method, all other methods are optional
void 
makemask::event(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "event()" );
	shared_ptr<array1D<double> > data_sp = evt.get(IDSTRING_CSPAD_DATA);
	
	if (data_sp){
		p_sum_sp->addArrayElementwise( data_sp.get() );	
		p_count++;
	}
}
int DbQuoteString(DB_HANDLE handle, const char* in, char* buffer, size_t buflen)
{

	(void) handle;

    if (in == NULL) {
        return MsgLog(DBS_INVARG, "NULL input string to DbQuoteString");
    }

	sqlite3_snprintf(buflen, buffer, "%q", in);

	return ( strlen(buffer) == 0 ) ? 1 : 0;
}
void 
CSPadImageGetTest::saveImageInFile(Event& evt)
{
  // Define the file name
  stringstream ssEvNum; ssEvNum << setw(6) << setfill('0') << m_count;
  string fname = m_fname + "-" + strRunNumber(evt) + "-" + strTimeStamp(evt) + ".txt";

  // In case if m_key == "Image2D" 

  shared_ptr< CSPadPixCoords::Image2D<double> > img2d = evt.get(m_str_src, m_key, &m_src);
  if (img2d.get()) {
    MsgLog(name(), info, "::saveImageInFile(...): Get image as Image2D<double> from event and save it in file");
    img2d -> saveImageInFile(fname,0);
  } // if (img2d.get())


  shared_ptr< ndarray<double,2> > img = evt.get(m_str_src, m_key, &m_src);
  if (img.get()) {
    MsgLog(name(), info, "::saveImageInFile(...): Get image as ndarray<double,2> from event and save it in file");
    CSPadPixCoords::Image2D<double> *img2d = new CSPadPixCoords::Image2D<double>(img->data(),img->shape()[0],img->shape()[1]);
    img2d -> saveImageInFile(fname,0);
  } // if (img2d.get())
}
int DbRowId(DB_ROW row, DB_ID* id)
{
	unsigned long	rowid;		/* ID of the row as a known type */
	int				status;		/* Status return */

    if (id == NULL) {
        status = MsgLog(DBS_INVARG, "NULL id");
        return -1;
    }

	status = DbUnsignedLong(row, 0, &rowid);
	*id = (DB_ID) rowid;		/* Do the conversion between types here */

	return status;
}
Exemple #20
0
/**
 *  Load the library for a package 
 */
void* 
DynLoader::loadPackageLib(const std::string& packageName) const
{
  // build library name
  std::string lib = "lib" + packageName + ".so";
  
  // load the library
  MsgLog(logger, trace, "loading library " << lib);
  void* ldh = dlopen(lib.c_str(), RTLD_NOW | RTLD_GLOBAL);
  if ( not ldh ) {
    throw ExceptionDlerror(ERR_LOC, "failed to load dynamic library "+lib);
  }
  
  return ldh;
}
int DbLastRowId(DB_HANDLE handle, DB_ID* id)
{

    if (id == NULL) {
        return MsgLog(DBS_INVARG, "NULL id");
    }

    /* TODO returns a sqlite_int64; can this be cast into an unsigned long?
     * do we need to check this for each platform? */
	*id = (DB_ID) sqlite3_last_insert_rowid((sqlite3*) handle);

	/*
	 * In sqlite, there is no error code; a value of 0 is returned if there
	 * is no matching row.  In this case, convert it to an error code.
	 */

	return (*id != 0) ? 0 : DBS_NOSUCHROW;
}
int DbExecuteSqlNoResult(DB_HANDLE handle, const char* stmt_str)
{
    DB_RESULT	result;     /* Pointer to result string */
    int         status;     /* Status return */

    status = DbExecuteSql(handle, stmt_str, &result);
    if (status == 0) {
        if (result) {

            /* Result given - get rid of it, we don't want it */

            status = MsgLog(DBS_UNEXRES, stmt_str);
            DbFreeResult(result);
        }
    }

    return status;
}
int DbInt(DB_ROW row, int field_index, int *value)
{
    char*   buffer = NULL;		/* Text buffer for returned string */
	int		status;		        /* Status return */

	/* Access the text in the field */

    status = DbString(row, field_index, &buffer);
	if (status == 0) {

		/* Got the string, can we convert it? */

		if (buffer != NULL) {

			/* Not best-efforts - ignore trailing non-numeric values */

			status = StrStrtoi(buffer, value);
			if (status == -1) {

				/* Could not translate the string to an integer */

				status = MsgLog(DBS_NOTINT, buffer);
				*value = 0;
			}
			DbStringFree(buffer);
		}
		else {

			/* Field is NULL, return 0 */
            /* TODO should we do something better here ? */

			*value = 0;
		}
	}

    return status;
}
Exemple #24
0
int KsmDNSSECKeysInSMCount(DB_RESULT result, int* count)
{
	int         status = 0;     /* Return status */
	DB_ROW      row = NULL;     /* Row data */

	/* Get the next row from the data */

	status = DbFetchRow(result, &row);
	if (status == 0) {

		/* Now copy the results into the output data */

		status = DbInt(row, DB_COUNT, count);
	}
    else if (status == -1) {}
        /* No rows to return (but no error) */
	else {
        status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
	}

    DbFreeRow(row);

	return status;
}
Exemple #25
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called once at the end of the job
void 
makemask::endJob(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "endJob()" );
	
	array1D<double> *mask = NULL;
	if (p_useMask){
		//allocate a mask (start from the one already read from file)
		mask = new array1D<double>( p_mask );
	}else{
		//allocate a mask. Initially, all pixels are GOOD
		mask = new array1D<double>( nMaxTotalPx );
		for (unsigned int i = 0; i<p_sum_sp->size(); i++){
			mask->set(i, GOOD);
		}
	}

	if ( p_count != 0 ){	
		//create average out of raw sum
		p_sum_sp->divideByValue( p_count );

		//	MsgLog(name(), info, "---complete histogram of averaged data---\n" << p_sum_sp->getHistogramASCII(50) );
		MsgLog(name(), info, "---partial histogram of averaged data---\n" << p_sum_sp->getHistogramInBoundariesASCII(100, -100, 400) );
			
		//set mask to 1 if pixel is valid, otherwise, leave 0
		for (unsigned int i = 0; i<p_sum_sp->size(); i++){
			if ( (p_sum_sp->get(i) < p_badPixelLowerBoundary) || (p_sum_sp->get(i) > p_badPixelUpperBoundary) ){
				//pixel seems bad: exclude this pixel
				mask->set(i, BAD);
			}
		}
	}else{
		MsgLog( name(), warning, "No events. No data-dependent masking (thresholding) possible." );
	}
			
	//go through data again: analytically take out certain areas
	//   - a whole ASIC, if specified in config file
	//   - first and last row on each ASIC
	//   - first and last column on each ASIC
	//   - row 13 on each ASIC
	for (int q = 0; q < nMaxQuads; q++){
		for (int s = 0; s < nMax2x1sPerQuad; s++){
			for (int c = 0; c < nColsPer2x1; c++){
				for (int r = 0; r < nRowsPer2x1; r++){
					int index = q*nMaxPxPerQuad + s*nPxPer2x1 + c*nRowsPer2x1 + r;
					
					if ( p_takeOutASICFrame && 
						(r==0 || r==nRowsPerASIC-1 || r==nRowsPerASIC || r==2*nRowsPerASIC-1 || c==0 || c==nColsPerASIC-1) ){
						mask->set( index, BAD );
					}//if takeOutASICFrame
					
					if ( p_takeOutThirteenthRow && 
						(r==nRowsPerASIC-13 || r==2*nRowsPerASIC-13) ){
							mask->set( index, BAD );
					}//if takeOutThirteenthRow
					
					if ( p_takeOutWholeSection == q*nMax2x1sPerQuad+s ){
						mask->set( index, BAD );
					}//if takeOutWholeSection
					
				}//for r
			}//for c
		}//for s
	}//for q
	
	MsgLog(name(), info, "---histogram of mask---\n" << mask->getHistogramASCII(2) );
	
	//output 2D
	array2D<double> *mask2D = new array2D<double>;
	createRawImageCSPAD( mask, mask2D );
	string ext = ".h5";
	io->writeToFile( p_outputPrefix+"_mask_raw2D"+ext, mask2D );
	delete mask2D;
	
	//output 1D
	//io->writeToEDF( p_outputPrefix+"_mask_1D.edf", mask );	
	
	delete mask;
}
Exemple #26
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called at the end of the run
void 
makemask::endRun(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "endRun()" );
}
Exemple #27
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called at the end of the calibration cycle
void 
makemask::endCalibCycle(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "endCalibCycle()" );
}
Exemple #28
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called once at the end of the job
void 
correlate::endJob(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "correlate::endJob()" );

	//normalize the running sums to get averages
	p_polarAvg_sp->divideByValue( p_count );
	p_corrAvg_sp->divideByValue( p_count );
	p_qAvg_sp->divideByValue( p_count );
	p_iAvg_sp->divideByValue( p_count );
	
	//compute the 'correlation of the average' in addition to the 'average of correlations'
	for (unsigned int i = 0; i < p_cc->polar()->size(); i++){
		p_cc->polar()->set_atIndex(i, p_polarAvg_sp->get_atIndex(i));			//feed the average polar coordinate map to cc
	}
	p_cc->calculateFluctuations();
	p_cc->calculateXCCA( p_startQ, p_stopQ );									//run correlation on average
	array2D<double> *corrOfAvg = p_cc->autoCorr();

	//compute the difference between the average of the correlations and the correlation of the average
	array2D<double> *diff = new array2D<double>( p_corrAvg_sp.get() );
	diff->subtractArrayElementwise( corrOfAvg );
	

	//the first output flag (h5Out, edfOut, tifOut), which is true, will determine the written data type
	string ext = "";
	if (p_h5Out){						//HDF5 output
		ext = ".h5";
	}else if (p_edfOut){				//EDF output
		ext = ".edf";
	}else if (p_tifOut){				//TIFF image output
		ext = ".tif";
		//convert 1D output to 2D, so they can be written to disk as TIFF images (with y-dim == 1)
		array2D<double> *qAvg2D = new array2D<double>;
		array2D<double> *iAvg2D = new array2D<double>;
		ns_arraydata::convertToArray2D( p_qAvg_sp.get(), qAvg2D, p_qAvg_sp->dim1(), 1);
		ns_arraydata::convertToArray2D( p_iAvg_sp.get(), iAvg2D, p_iAvg_sp->dim1(), 1);		
		io->writeToTiff( p_outputPrefix+"_avg_qAvg"+ext, qAvg2D, 1 );
		io->writeToTiff( p_outputPrefix+"_avg_iAvg"+ext, iAvg2D, 1 );
		delete qAvg2D;
		delete iAvg2D;
	}
	
	//write to file, file type is based on the extension
	if (p_autoCorrelateOnly){
		io->writeToFile( p_outputPrefix+"_avg_polar"+ext, p_polarAvg_sp.get() );
		io->writeToFile( p_outputPrefix+"_avg_xaca"+ext, p_corrAvg_sp.get() );
		io->writeToFile( p_outputPrefix+"_xacaOfAvg"+ext, corrOfAvg );
		io->writeToFile( p_outputPrefix+"_xacaDiff"+ext, diff );
	}else{
		MsgLog(name(), warning, "WARNING. No HDF5 output for 3D cross-correlation case implemented, yet!" );
	}
	io->writeToFile( p_outputPrefix+"_avg_qAvg"+ext, p_qAvg_sp.get() );
	io->writeToFile( p_outputPrefix+"_avg_iAvg"+ext, p_iAvg_sp.get() );	

	/*
	//HDF5 output
	if (p_h5Out){
		string ext = ".h5";
		if (p_autoCorrelateOnly){
			io->writeToHDF5( p_outputPrefix+"_avg_polar"+ext, p_polarAvg_sp.get() );
			io->writeToHDF5( p_outputPrefix+"_avg_xaca"+ext, p_corrAvg_sp.get() );
			io->writeToHDF5( p_outputPrefix+"_avg_xaca"+ext, polarOfAvg.get() );
			io->writeToHDF5( p_outputPrefix+"_avg_xaca"+ext, corrOfAvg.get() );
		}else{
			MsgLog(name(), warning, "WARNING. No HDF5 output for 3D cross-correlation case implemented, yet!" );
		}
		io->writeToHDF5( p_outputPrefix+"_avg_qAvg"+ext, p_qAvg_sp.get() );
		io->writeToHDF5( p_outputPrefix+"_avg_iAvg"+ext, p_iAvg_sp.get() );
	}
	//EDF output
	if (p_edfOut){
		string ext = ".edf";
		if (p_autoCorrelateOnly){
			io->writeToEDF( p_outputPrefix+"_avg_polar"+ext, p_polarAvg_sp.get() );
			io->writeToEDF( p_outputPrefix+"_avg_xaca"+ext, p_corrAvg_sp.get() );
		}else{
			MsgLog(name(), warning, "WARNING. No EDF output for 3D cross-correlation case implemented, yet!" );
		}
		io->writeToEDF( p_outputPrefix+"_avg_qAvg"+ext, p_qAvg_sp.get() );
		io->writeToEDF( p_outputPrefix+"_avg_iAvg"+ext, p_iAvg_sp.get() );
	}
	//TIFF image output
	if (p_tifOut){
		string ext = ".tif";
		if (p_autoCorrelateOnly){
			io->writeToTiff( p_outputPrefix+"_avg_polar"+ext, p_polarAvg_sp.get(), 1 );			// 0: unscaled, 1: scaled
			io->writeToTiff( p_outputPrefix+"_avg_xaca"+ext, p_corrAvg_sp.get(), 1 );			// 0: unscaled, 1: scaled
		}else{
			MsgLog(name(), warning, "WARNING. No tiff output for 3D cross-correlation case implemented, yet!" );
			//one possibility would be to write a stack of tiffs, one for each of the outer q values
		}
		
		//convert SAXS output to 2D, so they can be written to disk as TIFF images (with y-dim == 1)
		
		array2D<double> *qAvg2D = new array2D<double>;
		array2D<double> *iAvg2D = new array2D<double>;
		ns_arraydata::convertToArray2D( p_qAvg_sp.get(), qAvg2D, p_qAvg_sp->dim1(), 1);
		ns_arraydata::convertToArray2D( p_iAvg_sp.get(), iAvg2D, p_iAvg_sp->dim1(), 1);		
		io->writeToTiff( p_outputPrefix+"_avg_qAvg"+ext, qAvg2D, 1 );
		io->writeToTiff( p_outputPrefix+"_avg_iAvg"+ext, iAvg2D, 1 );
		delete qAvg2D;
		delete iAvg2D;
	}
*/	
}
Exemple #29
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called at the end of the run
void 
correlate::endRun(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "correlate::endRun()" );
}
Exemple #30
0
/// ------------------------------------------------------------------------------------------------
/// Method which is called at the end of the calibration cycle
void 
correlate::endCalibCycle(Event& evt, Env& env)
{
	MsgLog(name(), debug,  "correlate::endCalibCycle()" );
}