Пример #1
0
void FileManager::findAllFiles(const std::string& pathToDirectory, bool iterateSubFolders)
{
    boost::filesystem::path dirPath_(pathToDirectory);

    if(boost::filesystem::exists(dirPath_) && boost::filesystem::is_directory(dirPath_))//check if the path exist and is a directory
    {
        if ( !exists( dirPath_ ) )
            std::cout << dirPath_.string() << " doesn't exist" << std::endl;

        boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end

        for ( boost::filesystem::directory_iterator itr( dirPath_ );
            itr != end_itr;
            ++itr )
        {
            //std::cout << "FOUND \t" <<itr->path().string() << std::endl;
        if ( is_directory(itr->status()))
        {
            if(iterateSubFolders)
                findAllFiles(itr->path().string(), iterateSubFolders);
        }
        else
            addToVector(*itr);
        }
    }
}
Пример #2
0
Product* getProduct(char* name, Vector* products) {

    int i = getProductId(name, products);

    if (i != -1) {
        return (Product*) getFromVector(products, i);
    }

    //this Product doesn't exist, let's add it
    Product* res;
    if ((res = malloc(sizeof(Product))) == NULL) {
        return NULL;
    }

    res->name = malloc((strlen(name) + 1) * sizeof(char));
    if (res->name == NULL) {
        free(res);
        return NULL;
    }
    strcpy(res->name, name);

    if ((i = addToVector(products, res)) == -1) {
        free(res);
        return NULL;
    }
    res->id = i;

    return res;
}
  void notify()
  {
    int fd;
    int wd;
    
    fd=inotify_init();
    if(fd<0)
      perror("inotify_init()");
    else
      printf("%d\n",fd);

    std::string path="/home/mcalpha/ROOT_Files_test";

    /* look for new files being moved into this directory */
    wd = inotify_add_watch(fd,path.c_str(),IN_MOVED_TO);
    if(wd<0)
      perror("inotify_add_watch");

    int safe = 200;
    int read_return1;
    ssize_t read_return2;
    
    std::string event_name;
    
    size_t nbytes = sizeof(struct inotify_event);
    struct inotify_event *ptr;
    ptr = (struct inotify_event *) malloc(sizeof(struct inotify_event)+safe);
    if(ptr==NULL)
      {
    	exit(1);
      }

    read_return1=read(fd,ptr,sizeof(struct inotify_event)+safe);
    int n=2;
    while(read_return1<0)
      {
	/* Resize the memory allocation for the event struct in case the name of the file is too long*/
	printf("Errno: %d %s\n",errno,strerror(errno));
	ptr = (struct inotify_event *) realloc(ptr,sizeof(struct inotify_event)+(n*safe));
	read_return1=read(fd,ptr,sizeof(struct inotify_event)+(n*safe));
	n++;
      }

    event_name.assign(ptr->name);
    addToVector(event_name);
    close(wd);
    close(fd);
    free(ptr);
  };
Пример #4
0
Vector* bootstrap_planes(Airline* self, ipc_t conn) {
    struct PlaneThread* t;
    Vector* threads = createVector();
    pthread_attr_t attr;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    for (size_t i = 0; i < self->numberOfPlanes; i++) {
        t = malloc(sizeof(struct PlaneThread));
        t->queue = message_queue_create();
        t->plane = &self->planes[i];
        t->conn = conn;
        t->done = 0;
        t->airline = self->id;
        pthread_create(&t->thread, &attr, (void*(*)(void*))run_plane, t);
        addToVector(threads, t);
    }

    pthread_attr_destroy(&attr);

    return threads;
}
Пример #5
0
// This is called by the root thread to do the work.
bool ShareDataClass::RunShareData(PolyObject *root)
{
    // We use a bitmap to indicate when we've visited an object to avoid
    // infinite recursion in cycles in the data.
    for (unsigned j = 0; j < gMem.npSpaces; j++)
    {
        PermanentMemSpace *space = gMem.pSpaces[j];
        if (!space->isMutable && space->hierarchy == 0)
        {
            if (! space->shareBitmap.Create(space->spaceSize()))
                return false;
        }
    }

    POLYUNSIGNED totalObjects = 0;
    POLYUNSIGNED totalShared  = 0;

    depthVectors = 0;
    depthVectorSize = 0;

    // Build the vectors from the immutable objects.
    bool success = true;

    try {
        ProcessAddToVector addToVector(this);
        addToVector.ProcessRoot(root);
    }
    catch (MemoryException &)
    {
        // If we ran out of memory we may still be able to process what we have.
        // That will also do any clean-up.
        success = false;
    }

    ProcessFixupAddress fixup;

    for (POLYUNSIGNED depth = 1; depth < depthVectorSize; depth++)
    {
        DepthVector *vec = &depthVectors[depth];
        fixup.FixupItems(vec);
        vec->Sort();

        POLYUNSIGNED n = vec->MergeSameItems();

        if ((debugOptions & DEBUG_SHARING) && n > 0)
            Log("Sharing: Level %4" POLYUFMT ", Objects %6" POLYUFMT ", Shared %6" POLYUFMT " (%1.0f%%)\n",
                vec->depth, vec->nitems, n, (float)n / (float)vec->nitems * 100.0);

        totalObjects += vec->nitems;
        totalShared  += n;
    }

      /*
       At this stage, we have fixed up most but not all of the forwarding
       pointers. The ones that we haven't fixed up arise from situations
       such as the following:

               X -> Y <-> Z

       i.e. Y and Z form a loop, and X is isomorphic to Z. When we assigned
       the depths, we have to arbitrarily break the loop between Y and Z.
       Suppose Y is assigned to level 1, and Z is assigned to level 2.
       When we process level 1 and fixup Y, there's nothing to do, since
       Z is still an ordinary object. However when we process level 2,
       we find that X and Z are isomorphic so we arbitrarily choose one
       of them and turn it into a "tombstone" pointing at the other. If
       we change Z into the tombstone, then Y now contains a pointer
       that needs fixing up. That's why we need the second fixup pass.

       Note also that if we had broken the loop the other way, we would have
       assigned Z to level 1, Y to level 2 and X to level 3, so we would
       have missed the chance to share Z and X. Perhaps that's why running
       the program repeatedly sometimes finds extra things to share?

      SPF 26/1/95
    */

    /* We have updated the addresses in objects with non-zero level so they point to
       the single occurrence but we need to do the same with level 0 objects
       (mutables, stacks and code). */
    if (depthVectorSize > 0)
    {
        DepthVector *v = &depthVectors[0];
        RestoreLengthWords(v);
        fixup.FixupItems(v);
        free(v->vector);
    }

    /* Previously we made a complete scan over the memory updating any addresses so
       that if we have shared two substructures within our root we would also
       share any external pointers.  This has been removed but we have to
       reinstate the length words we've overwritten with forwarding pointers because
       there may be references to unshared objects from outside. */
    for (POLYUNSIGNED d = 1; d < depthVectorSize; d++)
    {
        DepthVector *v = &depthVectors[d];
        RestoreLengthWords(v);
        free(v->vector);
    }

    free(depthVectors);
    depthVectors = 0;

    if (debugOptions & DEBUG_SHARING)
        Log ("Sharing: Total Objects %6" POLYUFMT ", Total Shared %6" POLYUFMT " (%1.0f%%)\n",
            totalObjects, totalShared, (float)totalShared / (float)totalObjects * 100.0);

    return success; // Succeeded.
}
Пример #6
0
/* ----------------------------------------------
 *
 >>>>>>                                           */
return_t qpDUNES_setupStageQP(	qpData_t* const qpData,
								interval_t* const interval,
								boolean_t refactorHessian
								)
{
	return_t statusFlag;


	/* presolve first QP */
	if ( interval->qpSolverSpecification == QPDUNES_STAGE_QP_SOLVER_CLIPPING ) {
		/* (a) use clipping stage QP solver */
		interval->qpSolverSpecification = QPDUNES_STAGE_QP_SOLVER_CLIPPING;

		/* (b) prepare clipping QP solver */
		if ( refactorHessian == QPDUNES_TRUE ) {	/* only first Hessian needs to be factorized in LTI case, others can be copied; last one might still be different, due to terminal cost, even in LTI case */
			factorizeH( qpData, &(interval->cholH), &(interval->H), interval->nV );
		}

		/* (c) solve unconstrained local QP for g and initial lambda guess: */
		/*	   - get (possibly updated) lambda guess */
		if (interval->id > 0) {		/* lambdaK exists */
			qpDUNES_updateVector( &(interval->lambdaK), &(qpData->lambda.data[((interval->id)-1)*_NX_]), _NX_ );
		}
		if (interval->id < _NI_) {		/* lambdaK1 exists */
			qpDUNES_updateVector( &(interval->lambdaK1), &(qpData->lambda.data[(interval->id)*_NX_]), _NX_ );
		}

		/*     - update first order term */
		qpDUNES_setupZeroVector( &(interval->q), interval->nV );	/* reset q; qStep is added in qpDUNES_solve, when bounds are known */
		clippingQpSolver_updateStageData( qpData, interval, &(interval->lambdaK), &(interval->lambdaK1) );
		addToVector( &(interval->qpSolverClipping.qStep), &(interval->g), interval->nV );	/* Note: qStep is rewritten in line before */
		/*     - solve */
		statusFlag = directQpSolver_solveUnconstrained( qpData, interval, &(interval->qpSolverClipping.qStep) );
		if ( statusFlag != QPDUNES_OK ) {
			int kk = 1234567890;	/* TODO: get right interval number!*/
			qpDUNES_printError( qpData, __FILE__, __LINE__, "QP on interval %d infeasible!", kk );
			if (qpData->options.logLevel >= QPDUNES_LOG_ITERATIONS )	qpDUNES_logIteration( qpData, &(qpData->log.itLog[0]), qpData->options.QPDUNES_INFTY, _NI_ );
			return statusFlag;
		}

		qpDUNES_setupZeroVector( &(interval->qpSolverClipping.zUnconstrained), interval->nV );	/* reset zUnconstrained */
	}
	else
	{
		#ifndef __SIMPLE_BOUNDS_ONLY__
		/* (a) use qpOASES */
		interval->qpSolverSpecification = QPDUNES_STAGE_QP_SOLVER_QPOASES;

		/* (b) prepare first order term: initial lambda guess and g */
		/*	   - get primal first order term */
		qpDUNES_copyVector( &(interval->q), &(interval->g), interval->nV );
		/*	   - get (possibly updated) lambda guess */
		if (interval->id > 0) {		/* lambdaK exists */
			qpDUNES_updateVector( &(interval->lambdaK), &(qpData->lambda.data[((interval->id)-1)*_NX_]), _NX_ );
		}
		if (interval->id < _NI_) {		/* lambdaK1 exists */
			qpDUNES_updateVector( &(interval->lambdaK1), &(qpData->lambda.data[(interval->id)*_NX_]), _NX_ );
		}
		qpOASES_updateStageData( qpData, interval, &(interval->lambdaK), &(interval->lambdaK1) );

		/* (c) initialize qpOASES and run initial homotopy (i.e., solve first QP) */
		statusFlag = qpOASES_setup( qpData, interval->qpSolverQpoases.qpoasesObject, interval,
									&(interval->H), &(interval->qpSolverQpoases.qFullStep), /*&(interval->g),*/
									&(interval->zLow), &(interval->zUpp),
									&(interval->D), &(interval->dLow), &(interval->dUpp));
		#else
			qpDUNES_printError( qpData, __FILE__, __LINE__, "The flag '__SIMPLE_BOUNDS_ONLY__' was set at compile time.\n          Hence, no QPs with dense Hessian or affine constraints are supported." );
			return QPDUNES_ERR_INVALID_ARGUMENT;
		#endif /* __SIMPLE_BOUNDS_ONLY__ */
	}

	return statusFlag;
}
Пример #7
0
void closureTestCSv2(int dataUnfold=0, int compareToTheory=0)
{
  TVersion_t inpVer=_verEl2skim3;
  TString inpVerTag=versionName(inpVer);
  TString csOutFName="csClosure_DYee_13TeV_" + inpVerTag + ".root";

  const TString tag_UseData="data";
  const TString tag_UseTheory="theory";
  const TString tag_UseUnity="unity";
  const TString tag_UseZero="zero";
  const TString tag_Load="combine:";
  std::vector<TString> dataInput, theoryInput;
  addToVector(dataInput, "cs_DYee_13TeV_El2.root  h1Yield  h1Bkg");
  addToVector(theoryInput, "theory13TeVmm.root h1cs_theory");

  std::map<TVaried_t,TString> inpHistoNames;

  TCSType_t csType= _csPreFsrFullSp;
  TString inpFName="dyee_test_dressed_El2skim3.root";
  inpHistoNames[_varYield] = "h1recoSel_MWPU";
  //inpHistoNames[_varBkg] = tag_UseZero;
  inpHistoNames[_varDetRes]= "rooUnf_detResRespPU";
  inpHistoNames[_varRho] = tag_UseUnity;
  inpHistoNames[_varEffAcc] = "h1EffPUAcc";
  inpHistoNames[_varFSRRes] = "rooUnf_fsrResp";
  inpHistoNames[_varLast] = "h1_preFsr_Mweighted";

  if (1) inpHistoNames[_varEffAcc] = "h1EffPUEleMatchAcc";

  if (dataUnfold) {
    inpHistoNames[_varYield] = "data";
    //inpHistoNames[_varRho] = "h1rho";
    //inpHistoNames[_varRho] = "h1rho_inPostFsrAcc";
  }

  TH1D *h1Zero= new TH1D("h1Zero","h1Zero",DYtools::nMassBins,DYtools::massBinEdges);
  h1Zero->SetDirectory(0);
  TH1D *h1Unity= cloneHisto(h1Zero,"h1Unity","h1Unity");
  for (int ibin=1; ibin<=h1Unity->GetNbinsX(); ibin++) {
    h1Unity->SetBinContent(ibin,1.);
  }

  CrossSection_t cs("cs",inpVerTag,csType,inpVer);


  for (std::map<TVaried_t,TString>::const_iterator it=inpHistoNames.begin();
       it!=inpHistoNames.end(); it++) {
    TH1D *h1tmp=NULL, *h1tmp2=NULL;
    std::cout << "load " << variedVarName(it->first) << " named " << it->second << "\n";
    switch(it->first) {
    case _varYield:
      if (it->second == tag_UseData) {
	h1tmp= loadHisto(dataInput[0],dataInput[1], "h1Yield",1,h1dummy);
	h1tmp2=loadHisto(dataInput[0],dataInput[2], "h1Bkg",1,h1dummy);
	double lumi=2316.97;
	if (h1tmp && h1tmp2) {
	  h1tmp->Scale(1/lumi);
	  h1tmp2->Scale(1/lumi);
	}
      }
      else {
	h1tmp= loadHisto(inpFName,it->second, "h1Yield",1,h1dummy);
	h1tmp2=h1Zero;
      }
      if (!h1tmp || !h1tmp2) return;
      cs.h1Yield(h1tmp);
      cs.h1Bkg(h1tmp2);
      break;
    case _varDetRes: {
      RooUnfoldResponse *r= loadRooUnfoldResponse(inpFName,it->second,"detRes");
      if (!r) return;
      cs.detRes(*r);
    }
      break;
    case _varRho:
      if (it->second == tag_UseUnity) {
	h1tmp= h1Unity;
      }
      else {
	h1tmp= loadHisto(inpFName,it->second, "h1Rho",1,h1dummy);
      }
      if (!h1tmp) return;
      cs.h1Rho(h1tmp);
      break;
    case _varEff:
      h1tmp= loadHisto(inpFName,it->second, "h1Eff",1,h1dummy);
      if (!h1tmp) return;
      cs.h1Eff(h1tmp);
      break;
    case _varEffAcc:
      h1tmp= loadHisto(inpFName,it->second, "h1EffAcc",1,h1dummy);
      if (!h1tmp) return;
      cs.h1EffAcc(h1tmp);
      break;
    case _varAcc:
      h1tmp= loadHisto(inpFName,it->second, "h1Acc",1,h1dummy);
      if (!h1tmp) return;
      cs.h1Acc(h1tmp);
      break;
    case _varFSRRes: {
      RooUnfoldResponse *r= loadRooUnfoldResponse(inpFName,it->second,"fsrRes");
      if (!r) return;
      cs.fsrRes(*r);
    }
      break;
    case _varLast:
      h1tmp2= loadHisto(inpFName,it->second, "h1theory",1,h1dummy);
      if (!h1tmp2) return;
      h1tmp= perMassBinWidth(h1tmp2);
      cs.h1Theory(h1tmp);
      break;
    default:
      std::cout << "unprepared case " << variedVarName(it->first) << "\n";
      return;
    }
  }


  TH1D* h1cs= cs.calcCrossSection();
  printRatio(h1cs,cs.h1Theory());
  cs.plotCrossSection();

  if (1) {
    // unfold in 1 step
    TH1D* h1reco=cloneHisto(cs.h1Yield(),"h1reco","h1reco");
    RooUnfoldResponse *rFull= loadRooUnfoldResponse(inpFName,"rooUnf_detResEffAccFsrResp","fullResponse");
    if (!h1reco || !rFull) return;
    RooUnfoldBayes bayesFull( rFull, h1reco, 4);
    TH1D *h1UnfFull=perMassBinWidth((TH1D*)bayesFull.Hreco());
    histoStyle(h1UnfFull,kOrange,5,1);
    plotHistoSame(h1UnfFull,"cs","LPE1","fullUnf");
    printRatio(h1UnfFull,cs.h1Theory());
    std::cout << "\n\ndifferent unfoldings\n";
    printRatio(h1UnfFull,cs.h1PreFsrCS());
  }

  //cs.save(csOutFName);
}