Пример #1
0
LIST list_CopyWithElement(const LIST List, POINTER (*CopyElement)(POINTER))
/**************************************************************
  INPUT:   A List and a copy function for the elements.
  RETURNS: The copy of the list.
  CAUTION: The entries of the list are NOT copied !
           The function needs time O(n*c), where <n> is the length
	   of the list and <c> is the time for a call of the
	   element copy function.
***************************************************************/
{
  LIST Copy;
  LIST Scan1,Scan2;

  if (list_Empty(List))
    return list_Nil();

  Copy  = list_List(CopyElement(list_Car(List)));
  Scan1 = Copy;
  Scan2 = list_Cdr(List);

  while (!list_Empty(Scan2)) {
    list_Rplacd(Scan1, list_List(CopyElement(list_Car(Scan2))));
    Scan1 = list_Cdr(Scan1);
    Scan2 = list_Cdr(Scan2);
  }
  return Copy;
}
Пример #2
0
cv::Mat EMat::combine(cv::Mat &src1, cv::Mat &src2, int rowstep, int colstep) {
    assert((rowstep >= 0) && (colstep >= 0) && (src1.type() == src2.type()));
    assert((src1.rows == src2.rows) && (src1.cols == src2.cols));
    assert((rowstep != 0) || (colstep != 0));

    create(src1.rows + src1.rows * (rowstep && 1), src1.cols + src1.cols * (colstep && 1), src1.type());
    uchar *tptr = data;

    int i, j, k, increment;
    cv::Mat *first = &src1;
    cv::Mat *second = &src2;
    for (i = 0; i < src1.rows; i++) {
        uchar *firstptr = first->ptr(i);
        uchar *secondptr = second->ptr(i);
        if (colstep != 0) {
            for (j = 0; j < src1.cols; j += colstep) {
                for (k = 0; k < colstep; k++) {
                    increment = CopyElement(firstptr, tptr);
                    tptr += increment;
                    firstptr += increment;
                }
                for (k = 0; k < colstep; k++) {
                    increment = CopyElement(secondptr, tptr);
                    tptr += increment;
                    secondptr += increment;
                }
            }
            if ((rowstep != 0) && ((i + 1) % rowstep)) {
                cv::Mat *tmp = first;
                first = second;
                second = tmp;
            }
        } else // Rowstep != 0 but colstep does
        {
            for (int j = 0; j < src1.cols; j++) {
                increment = CopyElement(firstptr, tptr);
                tptr += increment;
                firstptr += increment;
            }
            for (int j = 0; j < src2.cols; j++) {
                increment = CopyElement(secondptr, tptr);
                tptr += increment;
                secondptr += increment;
            }
        }
    }

    return *this;
}
Пример #3
0
//================================================================================================
//
//  DeviceRemoved
//
//  This routine will get called whenever any kIOGeneralInterest notification happens.  We are
//  interested in the kIOMessageServiceIsTerminated message so that's what we look for.  Other
//  messages are defined in IOMessage.h.
//
//================================================================================================
static void DeviceRemoved(void *refCon, io_service_t service, natural_t messageType, void *messageArgument) {
	kern_return_t kr;
	stDeviceListItem* deviceListItem = (stDeviceListItem *) refCon;
	DeviceItem_t* deviceItem = deviceListItem->deviceItem;

	if(messageType == kIOMessageServiceIsTerminated) {
		if(deviceListItem->deviceInterface) {
			kr = (*deviceListItem->deviceInterface)->Release(deviceListItem->deviceInterface);
		}

		kr = IOObjectRelease(deviceListItem->notification);


		ListResultItem_t* item = NULL;
		if(deviceItem) {
			item = CopyElement(&deviceItem->deviceParams);
			RemoveItemFromList(deviceItem);
			delete deviceItem;
		}
		else {
			item = new ListResultItem_t();
		}

		WaitForDeviceHandled();
		currentItem = item;
		isAdded = false;
		uv_async_send(&async_handler);
	}
}
Пример #4
0
cv::Mat EMat::operator()(cv::Range rowRange, cv::Range colRange, int rowstep, int colstep)
{
    assert((rowstep > 0) && (colstep > 0));

    cv::Mat ranged_mat = cv::Mat::operator()(rowRange, colRange);
    if ((rowstep == 1) && (colstep == 1))
        return ranged_mat;

    int new_cols = (ranged_mat.cols / colstep) + ((ranged_mat.cols % colstep) && 1);
    int new_rows = (ranged_mat.rows / rowstep) + ((ranged_mat.rows % rowstep) && 1);

    cv::Mat newmat(new_rows, new_cols, type());
    uchar *tptr = newmat.data;
    for (int i=0; i<ranged_mat.rows; i+=rowstep)
    {
        uchar *fptr = ranged_mat.ptr(i);
        for (int j=0; j<newmat.cols; j++)
        {
            int increment = CopyElement(fptr, tptr);
            tptr += increment;  fptr += increment; 
            fptr += ((colstep-1)*ranged_mat.elemSize());
        }
    }
    return newmat;
}
Пример #5
0
void XGArray::InsertElement(long index, void *ptr)
{
	long j;
	
	/*
	 *	Range check
	 */
	
	Assert((index >= 0) && (index <= fLength));
	
	/*
	 *	Change the allocation if needed
	 */
	
	j = fLength + 1;
	if (j % 16) j += 16 - (j % 16);
	if (j != fAlloc) {
		ChangeArray(j,fLength);
		fAlloc = j;
	}
	
	/*
	 *	Insert the element
	 */
	
	for (j = fLength; j > index; j--) {
		CopyArray(j,j-1);
	}
	CopyElement(index,ptr);
	fLength++;
}
Пример #6
0
cv::Mat EMat::shift(cv::Mat dst, int amount, bool row) {
    cv::Mat newmat(rows, cols, type());

    if (row) {
        assert(amount < cols);

        for (int i = 0; i < rows; i++) {
            uchar *fptr = ptr(i) + (amount * elemSize());
            uchar *tptr = newmat.ptr(i);
            for (int j = 0; j < cols; j++) {
                int increment = CopyElement(fptr, tptr);
                fptr += increment;
                tptr += increment;
            }

            // Start over our from pointer
            if (++amount > cols)
                fptr = ptr(i);
        }
    } else {
        assert(amount < rows);

        int offset = amount;
        for (int i = 0; i < rows; i++) {
            // wrap our rows
            if (offset + i >= rows)
                offset = -i;

            uchar *fptr = ptr(i);
            uchar *tptr = newmat.ptr(i + offset);

            for (int j = 0; j < cols; j++) {
                int increment = CopyElement(fptr, tptr);
                fptr += increment;
                tptr += increment;
            }
        }
    }

    // Add column code here later on (it's a bit messier)

    dst = newmat;
    return dst;
}
Пример #7
0
/*GoChildByPath
tpath - path of child element (ie. /parentelement[1]/childelement)
telement - on success, navigates to element specified by tpath
return True if element found
*/
Bool CXMLElement::GoChildByPath(char *tpath)
{
	if (!isinited()) return False;
	char *sptr = tpath;
	char *childpointer = NULL;
	CXMLElement telement;
	telement.CopyElement(this);
	if (*sptr == '/') sptr++; //skip first slash
	Bool foundmatch = False;
	char *endptr = sptr + strlen(sptr);
	while (sptr < endptr)
	{
		char *namestart,*nameend,*nextname,*numpointer;
		nextname = strchr(sptr, '/' );
		if (!nextname) nextname = endptr;
		namestart = sptr;
		nameend = nextname;

		bool t_is_text;
		t_is_text = (nameend == namestart) || (namestart[0] == '[');

		if (!telement.GoChild(NULL, t_is_text))
			return False;
		
		int whichchild = 1;
		numpointer = util_strchr(sptr,'[',nameend-sptr);
		if (numpointer)
		{
			whichchild = strtol((const char *)++numpointer, NULL, 10);
			nameend = numpointer-1;
		}
		
		Bool foundmatch = False;
		int childcounter = 0;
		do
		{
			if ((!t_is_text && util_strnicmp(telement.GetName(),namestart,nameend-namestart)==0) ||
				(t_is_text && telement.IsTextNode()))
			{
				childcounter++;
				if (childcounter == whichchild)
				{
					sptr = nextname+1;
					foundmatch = True;
				}
			}
		}
		while (!foundmatch && telement.GoNext(NULL, t_is_text));
		if (!foundmatch)
			return False;
	}
	CopyElement(&telement);
	return True;

}
Пример #8
0
void XGArray::Copy(const XGArray &a)
{
	long i;
	
	if (fAlloc != a.fAlloc) {
		ChangeArray(a.fAlloc,0);
		fAlloc = a.fAlloc;
	}
	fLength = a.fLength;
	for (i = 0; i < fLength; i++) {
		CopyElement(i,a.GetElement(i));
	}
}
Пример #9
0
BOOL KDicomDS::CopyDS(KDicomDS * pDS, BOOL bValue)
{
    KDicomElement * pSrc, * pDst;

    Reset();

    TransferSyntax = pDS->TransferSyntax;
    m_nTSOrg = pDS->m_nTSOrg;

    POSITION pos = pDS->m_listDE.GetHeadPosition();
    while(pos != NULL) {
        pSrc = pDS->m_listDE.GetNext(pos);
        pDst = AddElement(pSrc->GetTag());
        CopyElement(pDS, pSrc, pDst, bValue);
    }

    return TRUE;
}
Пример #10
0
unsigned int KDicomDS::CopyElement(KDicomDS * pSrcDS, KDicomElement * pSrc, KDicomElement * pDst, BOOL bValue)
{
    KD_TAG tag = pSrc->GetTag();

    if(pSrc->m_listDE.GetCount() > 0) {
        KDicomElement * pSrcChild, * pDstChild;
        POSITION pos = pSrc->m_listDE.GetHeadPosition();
        while(pos != NULL) {
            pSrcChild = pSrc->m_listDE.GetNext(pos);
            pDstChild = new KDicomElement(this);
            pDst->m_listDE.AddTail(pDstChild);
            CopyElement(pSrcDS, pSrcChild, pDstChild, bValue);
        }
    }

    // Tag
    pDst->SetTag(tag);

    // VR
    pDst->SetVR(pSrc->GetVR());
    pDst->SetchVR(pSrc->GetchVR());

    // Length
    if(pSrc->GetLength() == 0xFFFFFFFF) {
        pDst->SetLength(0xFFFFFFFF);
        return 0;
    }

    // Value
    if(bValue) {
        int length = pSrc->GetLength();
        if((length > 0) && (pSrc->GetTag().group != 0xFFFE) && (pSrc->GetVR() != SQ)) {
            unsigned char * temp;
            if((temp = pDst->ValueAlloc(length, 0)) != NULL) {
                memcpy(temp, pSrc->m_pValue, length);
            }
        }
        pDst->m_nVM = pSrc->m_nVM;
    }
    else {
        pDst->SetLength(0);
    }
    return 0;
}
Пример #11
0
/* ---------------------------------------------------------------------------
 * pastes the contents of the buffer to the layout. Only visible objects
 * are handled by the routine.
 */
bool
CopyPastebufferToLayout (Coord X, Coord Y)
{
  Cardinal i;
  bool changed = false;

#ifdef DEBUG
  printf("Entering CopyPastebufferToLayout.....\n");
#endif

  /* set movement vector */
  DeltaX = X - PASTEBUFFER->X, DeltaY = Y - PASTEBUFFER->Y;

  /* paste all layers */
  for (i = 0; i < max_copper_layer + 2; i++)
    {
      LayerType *sourcelayer = &PASTEBUFFER->Data->Layer[i];
      LayerType *destlayer = LAYER_PTR (i);

      if (destlayer->On)
	{
	  changed = changed ||
	    (sourcelayer->LineN != 0) ||
	    (sourcelayer->ArcN != 0) ||
	    (sourcelayer->PolygonN != 0) || (sourcelayer->TextN != 0);
	  LINE_LOOP (sourcelayer);
	  {
	    CopyLine (destlayer, line);
	  }
	  END_LOOP;
	  ARC_LOOP (sourcelayer);
	  {
	    CopyArc (destlayer, arc);
	  }
	  END_LOOP;
	  TEXT_LOOP (sourcelayer);
	  {
	    CopyText (destlayer, text);
	  }
	  END_LOOP;
	  POLYGON_LOOP (sourcelayer);
	  {
	    CopyPolygon (destlayer, polygon);
	  }
	  END_LOOP;
	}
    }

  /* paste elements */
  if (PCB->PinOn && PCB->ElementOn)
    {
      ELEMENT_LOOP (PASTEBUFFER->Data);
      {
#ifdef DEBUG
	printf("In CopyPastebufferToLayout, pasting element %s\n",
	      element->Name[1].TextString);
#endif
	if (FRONT (element) || PCB->InvisibleObjectsOn)
	  {
	    CopyElement (element);
	    changed = true;
	  }
      }
      END_LOOP;
    }

  /* finally the vias */
  if (PCB->ViaOn)
    {
      changed |= (PASTEBUFFER->Data->ViaN != 0);
      VIA_LOOP (PASTEBUFFER->Data);
      {
	CopyVia (via);
      }
      END_LOOP;
    }

  if (changed)
    {
      Draw ();
      IncrementUndoSerialNumber ();
    }

#ifdef DEBUG
  printf("  .... Leaving CopyPastebufferToLayout.\n");
#endif

  return (changed);
}
Пример #12
0
int  CombineButPMScaled() {
	//Connect to all existing histograms
	RootFileP = new TFile(Str_RootFilesButResultsP);
	TH1D *hP = (TH1D*)gROOT->FindObject("PhotonFluxLTCorrected");
	double SumP = hP->Integral();
	RootFileM = new TFile(Str_RootFilesButResultsM);
	TH1D *hM = (TH1D*)gROOT->FindObject("PhotonFluxLTCorrected");
	double SumM = hM->Integral();
	ScaleFactor = SumM/SumP;

	printf("Scale by: %f\n", ScaleFactor);

//	gROOT->cd();
	RootFile2 = new TFile(Str_RootFilesResultsSignal, "RECREATE");

	TH1D *hDiff = hM->Clone("PhotonFluxRatioT");
	hDiff->Divide(hP);

	if (DebugOptionScaleTargetMinusBeamtime) {
		printf("WARNING: Debug Option active: Scale Target Minus Beamtime.\n");
		ScaleFactor = ScaleFactor * ScaleTargetMinusBeamtime;
		hDiff->Scale(ScaleTargetMinusBeamtime);
		printf("Now: Scale by: %f\n", ScaleFactor);
	}

	if (DebugOptionAllChannelsRatioEqual) {
		printf("WARNING: Debug Option active: Flux Ratio is set to 1 for channels.\n");
		for (int i=1;i<=(hDiff->GetNbinsX());i++) {
			hDiff->SetBinContent(i,ScaleFactor);
			hDiff->SetBinError(i,0);
		}
	}
	//hDiff->Draw();


	Scale2D("MissingMassCombinedSignal", hDiff);
	CopyElement("CountNumberOfHistos");
	Scale1DSimple("hDroppedEvents", ScaleFactor);
	Scale1D("TaggerScalerAccum", hDiff);
	Scale2D("hTaggerTime", hDiff);
	Scale1DSimple("LiveTimeAccum", ScaleFactor);
	Scale2D("MissingMassCombinedSignalLTCorrected", hDiff);
	Scale2D("MissingMassCombinedSignalLTCorrectedFPrimeP", hDiff);
	Scale2D("MissingMassCombinedSignalLTCorrectedFPrimeM", hDiff);
	Scale2D("MissingMassCombinedSignalLTCorrectedTPrimeP", hDiff);
	Scale2D("MissingMassCombinedSignalLTCorrectedTPrimeM", hDiff);
	Scale1D("TaggerScalerAccumLTCorrectedInclDroppedEvents", hDiff);
	Scale1D("TaggerScalerAccumLTCorrected", hDiff);
	Scale1D("PhotonFluxLTCorrectedWOTaggEff", hDiff);
	Scale1D("PhotonFluxLTCorrected", hDiff);
	Scale2D("BeamPol", hDiff);
	Scale2D("TargetPolFPrime", hDiff);
	Scale2D("TargetPolTPrime", hDiff);
	Scale2D("TaggEffAbsTPrime", hDiff);
	Scale2D("TaggEffAbsFPrime", hDiff);
	Scale2D("TaggEffAbsAll", hDiff);

	//gROOT->cd();
	TH1D *hDiffAfter = hP->Clone("PhotonFluxRatioTAfter");
	hDiffAfter->Divide(hM);
	hDiffAfter->SetLineColor(kRed);
	//hDiffAfter->Draw("same");


	RootFileP->Close();
	RootFileM->Close();

	RootFile2->Write();
	RootFile2->Close();

	printf("Finished.\n");
}
Пример #13
0
cv::Mat EMat::padarray(int x_padsize, int y_padsize, pad_method method, pad_dir dir) {
    // Create a new matrix of the appropriate size and initialize it
    cv::Mat new_mat;
    if ((dir == pre) || (dir == post))
        new_mat.create(rows + y_padsize, cols + x_padsize, type());
    else
        new_mat.create(rows + (y_padsize * 2), cols + (x_padsize * 2), type());

    int padmult = 1;
    if (dir == both)
        padmult = 2;
    assert((new_mat.rows == (rows + (y_padsize * padmult))) && (new_mat.cols + (x_padsize * padmult)));

    int dsize = elemSize();
    // Mirror our matrix
    if (method == symmetric) {
        // for each line, we have a reverse, followed by a forward, etc.  We just have to find a good starting point

        // First find a direction:
        int start_x_dir, x_dir, y_dir;
        int start_x, cur_x, cur_y;

        // Now find our starting position in our source matrix
        if ((x_padsize / cols) % 2) // If we have an odd multiple (plus some), go Forward
        {
            start_x_dir = 1;
            start_x = cols - (x_padsize % cols) - 1;
        } else {
            start_x_dir = -1;
            start_x = (x_padsize % cols) - 1;
        }

        if ((y_padsize / rows) % 2) {
            y_dir = 1;
            cur_y = rows - (y_padsize % rows) - 1;
        } else {
            y_dir = -1;
            cur_y = (y_padsize % rows) - 1;
        }

        // Loop through every matrix of the old matrix
        uchar *fptr, *tptr;
        for (int i = 0; i < new_mat.rows; i++) {
            // Always reset initial conditions for x values
            cur_x = start_x;
            x_dir = start_x_dir;

            // New row for the to matrix
            tptr = new_mat.ptr(i);

            fptr = ptr(cur_y) + (cur_x * dsize);

            for (int j = 0; j < new_mat.cols; j++) {
                // Copy the element and increment applicable pointers
                CopyElement(fptr, tptr);
                tptr += dsize;

                // Handle incrementing from row ptr and reversing directions if necessary
                cur_x += x_dir;
                if ((cur_x == cols) || (cur_x < 0)) {
                    x_dir = x_dir * (-1); // reverse direction
                    cur_x += x_dir; // Go back into safe areas
                }
                fptr = ptr(cur_y) + (cur_x * dsize);
            }

            // Handle incrementing from matrix column and reversing if necessary
            cur_y += y_dir;
            if ((cur_y == rows) || (cur_y < 0)) {
                y_dir = y_dir * (-1); // reverse direction
                cur_y += y_dir; // Go back into safe areas
            }
        }
    } else if (method == circular)
        assert(0); // Not coded yet
    else if (method == replicate)
        assert(0); // Not coded yet
    else
        assert(0); // Probably should raise an exception here

    *this = new_mat;
    return new_mat;
}
Пример #14
0
int  ScalerFPosBinDebug() {
	//Connect to all existing histograms
	RootFileInput = new TFile(Str_RootFilesButInput);

	printf("Scale by: %f\n", ScaleFactor);

//	gROOT->cd();
	RootFileOutput = new TFile(Str_RootFilesButOutput, "RECREATE");

	CopyElement("MissingMassCombinedSignal");
	CopyElement("CountNumberOfHistos");
	CopyElement("hDroppedEvents");
	CopyElement("TaggerScalerAccum");
	CopyElement("hTaggerTime");
	CopyElement("LiveTimeAccum");
	CopyElement("MissingMassCombinedSignalLTCorrected");
	Scale2DSimple("MissingMassCombinedSignalLTCorrectedFP", ScaleFactor);
	CopyElement("MissingMassCombinedSignalLTCorrectedFM");
	CopyElement("MissingMassCombinedSignalLTCorrectedTP");
	CopyElement("MissingMassCombinedSignalLTCorrectedTM");
	CopyElement("TaggerScalerAccumLTCorrectedInclDroppedEvents");
	CopyElement("TaggerScalerAccumLTCorrected");
	CopyElement ("PhotonFluxLTCorrectedWOTaggEff");
	CopyElement("PhotonFluxLTCorrected");
	CopyElement("BeamPol");
	CopyElement("TargetPolF");
	CopyElement("TargetPolT");
	CopyElement("TaggEffAbsT");
	CopyElement("TaggEffAbsF");
	CopyElement("TaggEffAbsAll");

	RootFileInput->Close();

	RootFileOutput->Write();
	RootFileOutput->Close();

	printf("Finished.\n");
}
Пример #15
0
void RescaleH() {
	Char_t Name[256];
	Char_t *VarName;

	TH1D *h1PhotonFluxBut, *h1PhotonFluxH;
	TH1D *h1PhotonFluxCorrection;

	//Connect to all existing histograms
	RootFileButHistograms = new TFile(Str_RootFilesButResults);
	h1PhotonFluxBut = (TH1D*)gROOT->FindObject("PhotonFluxLTCorrected");

	RootFileHHistograms = new TFile(Str_RootFilesHResults);
	h2TempH = (TH2D*)gROOT->FindObject("MissingMassCombinedSignalLTCorrected");
	h1PhotonFluxH = (TH1D*)gROOT->FindObject("PhotonFluxLTCorrected");

	//Calculate
	RootFileHHistograms_Rescaled = new TFile(Str_RootFilesHResults_Rescaled,"RECREATE");

	//Ratio of Photon Flux betwen Combined But and H
	TH1D *hFluxRatio = (TH1D*)h1PhotonFluxBut->Clone("PhotonFluxRatio");
	hFluxRatio->Divide(h1PhotonFluxH);
	for (int i=1;i<=(hFluxRatio->GetNbinsX());i++) {
		if (hFluxRatio->GetBinContent(i) > 1E3) {
			hFluxRatio->SetBinContent(i,0);
			hFluxRatio->SetBinError(i,0);
		}
	}
	TF1 *AverageRatioFit = new TF1("AvgRatioFit","[0]",0,351);
	TFitResultPtr MyFitResult = hFluxRatio->Fit("AvgRatioFit", "0qFUW"); //0 = do not draw, q=quiet, R = respect range, f = special min finder, W=Set all weights to 1 for non empty bins; ignore error bars
	Int_t MyFitStatus = MyFitResult; //0 = alles okay, 4 fehler beim Fit, -1 = no data, 
					     //see: http://root.cern.ch/root/html/TH1.html#TH1:Fit%1
	double AverageRatio = 0;
	if (MyFitStatus == 0) {
		AverageRatio = AverageRatioFit->GetParameter(0);
		printf("Flux Ratio Fit result: %f +- %f\n", AverageRatioFit->GetParameter(0), AverageRatioFit->GetParError(0));
	} else {
		printf("ERROR: Fit did not converge.\n");
	}
	double ScaleFactor = 1/AverageRatio;
	hFluxRatio->Scale(ScaleFactor);

	if (DebugOptionAllChannelsRatioEqual) {
		printf("WARNING: Debug Option active: Flux Ratio is set to 1 for channels.\n");
		for (int i=1;i<=(hFluxRatio->GetNbinsX());i++) {
			hFluxRatio->SetBinContent(i,1);
			hFluxRatio->SetBinError(i,0);
		}
	}

	//Now Rescale the H-Results individually
	Scale2D("MissingMassCombinedSignal", hFluxRatio);
	CopyElement("CountNumberOfHistos");
	CopyElement("hDroppedEvents");
	Scale1D("TaggerScalerAccum", hFluxRatio);
	Scale2D("hTaggerTime", hFluxRatio);
	CopyElement("LiveTimeAccum");
	Scale2D("MissingMassCombinedSignalLTCorrected", hFluxRatio);
	Scale1D("TaggerScalerAccumLTCorrected", hFluxRatio);
	Scale1D("PhotonFluxLTCorrectedWOTaggEff", hFluxRatio);
	Scale1D("PhotonFluxLTCorrected", hFluxRatio);
	CopyElement("TaggEffAbsAll");

	RootFileHHistograms_Rescaled->Write();
	RootFileButHistograms->Close();
	RootFileHHistograms->Close();
	RootFileHHistograms_Rescaled->Close();

	printf("Finished.\n");
}