int aida2tree::readDataPack_first_sync(char *blockData, int di)
{
    clearMidas(); //refesh
    unsigned int word0; //each word contains 32 bit
    unsigned int word1;
    word0 = (blockData[di] & 0xFF)  | (blockData[di+1] & 0xFF) << 8 |
      (blockData[di+2] & 0xFF) << 16 | (blockData[di+3] & 0xFF) << 24;
    word1 = (blockData[di+4] & 0xFF) | (blockData[di+5] & 0xFF) << 8 |
      (blockData[di+6] & 0xFF) << 16 | (blockData[di+7] & 0xFF) << 24;
    //Terminate data reading  when there is end of block word
        //AIDA format: only one FFFFFFFF word in end of block
    if( (word0 & 0xFFFFFFFF) == 0xFFFFFFFF || (word1 & 0xFFFFFFFF) == 0xFFFFFFFF){
        return 0;
    }
    // After getting two word, try to extract data
    midas.dataType= (word0 >> 30) & 0x3; //mask at bit 31+30
    // Information data needed for getting MSB time stamp,
    // sync100 syncronization and timestamp colleration scaler
    if(midas.dataType == 0x2){//information data
        midas.feeId = (word0 >> 24) & 0x0000003F; //bits 24:29
        midas.infoField= word0 & 0x000FFFFF; //bits 0:19
        midas.infoCode= (word0 >> 20) & 0x0000000F; //bits 20:23
        //if (midas.infoField==95084&&midas.infoCode==4) std::cout<<"FIRE!!!!"<<std::hex<<midas.infoField<<"--"<<word0<<"-FeeId-"<<std::dec<<midas.feeId<<std::endl;
        midas.timestampLsb = word1 & 0x0FFFFFFF;  //bits 0:27

        //get first sync
        if (midas.infoCode==2||midas.infoCode==3||midas.infoCode==4){ //get msb of module
            if (first_sync_flag[midas.feeId]==0){ //get first dantum with time stamp msb info
                my_tm_stp_msb=(midas.infoField & 0x000FFFFF);
                tm_stp_msb_modules[midas.feeId]=(midas.infoField & 0x000FFFFF);
                std::cout<<"Got you first sync pulse on Fee module No."<<midas.feeId<<" MSB of timestamp= "<<std::hex<<"0x"<<tm_stp_msb_modules[midas.feeId]<<std::dec<<std::endl;
                sync_flag_modules[midas.feeId]=true;//this could help debug?
            }
            first_sync_flag[midas.feeId]++;
        }

        //get first EXT timestamp
        else if (midas.infoCode==8){
            int my_MBS_index;
            long long my_MBS_bits;
            my_MBS_index=(midas.infoField & 0x000F0000) >>16; //-> Bit 19:16 is information index
            my_MBS_bits=midas.infoField & 0x0000FFFF; //-> Bit 15:0 with EXT scaler data (0 1 2 index) (LUPO?)
            if (my_MBS_index==0 || my_MBS_index==1){ //Get low bits of EXT time stamp
                MBS_hit[midas.feeId][my_MBS_index]=true;
                MBS_bits[midas.feeId][my_MBS_index]=my_MBS_bits; // LSB of the ext data (bit 15:0 or 31:16) with ch number
                MBS_tm_stp_lsb[midas.feeId][my_MBS_index]=midas.timestampLsb; //Get timestamp of this information
            }
            else if(my_MBS_index==2){ //get higher bits of EXT timestamp (assume other low bits info already come
                if (MBS_hit[midas.feeId][0]&&MBS_hit[midas.feeId][1]){ // when we have enough 2 hits in time stamp scaler
                    unsigned long t1=midas.timestampLsb;
                    unsigned long t2=MBS_tm_stp_lsb[midas.feeId][1];
                    unsigned long t3=MBS_tm_stp_lsb[midas.feeId][0];
                    //std::cout<<"aaaa"<<std::endl;
                    //Another condition to check if t1 is in coincidence with t2 t3 within 1 us window (so the information come from 1 burse) (100 pulses)
                    if (checkCoincidence(t1,t2,t3,100)){
                        //note my_MBS_bits<<32 is now in index 2 which is bit 32-47
                        // Just get only first dantum!!!
                        if (first_sync_flag[midas.feeId]>0){
                            if (first_corr_scaler_datum==0) {

                                first_corr_scaler_timestamp=my_MBS_bits <<32 | MBS_bits[midas.feeId][1] <<16 | MBS_bits[midas.feeId][0];
                                //get offset time from here!!!
                                long long timestamp_temp=(long long)(tm_stp_msb_modules[midas.feeId] << 28 ) | (midas.timestampLsb & 0x0FFFFFFF); //caution this conversion!
                                my_time_offset=first_corr_scaler_timestamp*tm_stp_scaler_ratio-timestamp_temp;
                                std::cout<<my_MBS_bits<<std::endl;
                                std::cout<<"Got you first offset bw AIDA-LUPO! ="<<std::dec<<my_time_offset<<"-- Timestamp LUPO="<<first_corr_scaler_timestamp*tm_stp_scaler_ratio<<"| Timestamp AIDA="<<timestamp_temp<<std::endl;
                                //CAUTION:IF FOR SOME REASON WE MISS SYNC THEN THIS OFFSET MAKE NON SENSE
                            }
                            first_corr_scaler_datum++;
                        }

                    }else{
                        std::cout<<"MBS info is OUT of Sync FEE#"<<int(midas.feeId)<<", MBS info(info, time-stamp)= ("
                                << my_MBS_bits<<", "<<midas.timestampLsb<<"), ("
                                << MBS_bits[midas.feeId][1]<<", "<<MBS_tm_stp_lsb[midas.feeId][1]<<"), ("
                                << MBS_bits[midas.feeId][0]<<", "<<MBS_tm_stp_lsb[midas.feeId][0]<<")"
                                <<std::endl;
                    }
                    //reset MBS hit and tmp stamp
                    MBS_hit[midas.feeId][0]= false;
                    MBS_hit[midas.feeId][1]= false;
                    MBS_tm_stp_lsb[midas.feeId][0]=0;
                    MBS_tm_stp_lsb[midas.feeId][1]=0;
                    MBS_bits[midas.feeId][0]=0;
                    MBS_bits[midas.feeId][1]=0;
                }
            }
        }// if (midas.infoCode==8)
示例#2
0
//===========================================================================
void Intersector::compute(bool compute_at_boundary)
//===========================================================================
{
    // Purpose: Compute the topology of the current intersection

    // Make sure that no "dead intersection points" exist in the pool,
    // i.e. points that have been removed when compute() has been run
    // on sibling subintersectors.
    int_results_->synchronizePool();

    // Make sure that all intersection points at the
    // boundary/boundaries of the current object are already computed
    if (compute_at_boundary)
	getBoundaryIntersections();

    // Remove inner points in constant parameter intersection
    // links
    // (vsk, 0609) and isolated points identical to the existing ones
    int_results_->cleanUpPool();
    int nmb_orig = int_results_->numIntersectionPoints();

    if (getenv("DEBUG") && *(getenv("DEBUG")) == '1') {
	try {
	    printDebugInfo();
	} catch (...) {
	    MESSAGE("Failed printing debug info, continuing.");
	}
    }

    // Check if any intersections are possible in the inner of the
    // objects
    int status_intercept = performInterception();

    // Branch on the outcome of the interseption test
    if (status_intercept == 0) {
	// No intersection is possible
    } else if (status_intercept == 2) {
	// Both objects are too small for further processing.
	// Handle micro case
	microCase();
    } else if (degTriangleSimple()) {
	// This situation is currently relevant only for intersections
	// between two parametric surfaces. It will probably at some
	// stage be relevant for two-parametric functions.
	// All the necessary connections are made
    } else if (checkCoincidence()) {
	// The two objects coincide. The representation is already
	// updated according to this situation
    } else {
	// status_intercept == 1

	// Intersections might exist. Check for simple case. 0 = Maybe
	// simple case; 1 = Confirmed simple case.
	int status_simplecase = simpleCase();

	if (status_simplecase == 1) {
	    // Confirmed simple case.
	    // Compute intersection points or curves according to the
	    // properties of this particular intersection
	    updateIntersections();
	} else if (isLinear()) {
	    // Linearity is a simple case, but it is important to
	    // check for coincidence before trying to find/connect
	    // intersections as the simple case criteria is not
	    // satisfied
	    updateIntersections();
	}
	else if (complexIntercept())
	{
	    // Interception by more complex algorithms is performed
	    // (implicitization). No further intersectsions are found
	    // to be possible
	}
	else if (complexSimpleCase())
	{
	    // Simple case test by more complex algorithms is performed
	    // (implicitization). A simple case is found.
	    updateIntersections();
	} else if (!complexityReduced()) {
	    // For the time being, write documentation of the
	    // situation to a file
	    handleComplexity();
	} else {
	    // It is necessary to subdivide the current objects
	    doSubdivide();
	    
	    int nsubint = int(sub_intersectors_.size());
	    for (int ki = 0; ki < nsubint; ki++) {
		sub_intersectors_[ki]->getIntPool()
		    ->includeCoveredNeighbourPoints();
		sub_intersectors_[ki]->compute();
	    }
	}
    }

//     // Write intersection point diagnostics
//     if (numParams() == 4) {
// 	writeIntersectionPoints();
//     }

    if (prev_intersector_ && prev_intersector_->numParams() > numParams())
    {
	// Remove inner points in constant parameter intersection
	// links
	// (vsk, 0609) and isolated points identical to the existing ones
	int_results_->cleanUpPool(nmb_orig);

	// No more recursion at this level. Post iterate the intersection points
	doPostIterate();
    }

    // Prepare output intersection results
    if (prev_intersector_ == 0 || prev_intersector_->isSelfIntersection())
    {
	/*if (getenv("DEBUG_FINISH") && *(getenv("DEBUG_FINISH")) == '1') {
	    cout << "Status after cleaning up pool:" << endl;
	    writeIntersectionPoints();
	    }*/

	// Remove loose ends of intersection links in the inner
	//int_results_->weedOutClutterPoints();
	if (getenv("DEBUG_FINISH") && *(getenv("DEBUG_FINISH")) == '1') 
	{
	    cout << "Status after removing clutter points:" << endl;
	    writeIntersectionPoints();
	    int_results_->writeDebug();
	}

	// Remove loose ends of intersection links in the inner
	//int_results_->weedOutClutterPoints();
	int_results_->cleanUpPool(0);

	if (true /*getenv("DO_REPAIR") && *(getenv("DO_REPAIR")) == '1'*/) 
	{
	    if (getenv("DEBUG_FINISH") && *(getenv("DEBUG_FINISH")) == '1') 
	    {
		cout << "Starting repair" << endl;
	    }
	    repairIntersections();

	    if (getenv("DEBUG_FINISH") && *(getenv("DEBUG_FINISH")) == '1') 
	    {
		cout << "Status after repairing intersections:" << endl;
		writeIntersectionPoints();
	    }
	}
    }

    if (prev_intersector_ == 0) {
	// Top level intersector
	/*if (getenv("DEBUG_FINISH") && *(getenv("DEBUG_FINISH")) == '1') {
	    cout << "Status after removing clutter points:" << endl;
	    writeIntersectionPoints();
	    }*/

// 	if (/*true */getenv("DO_REPAIR") && *(getenv("DO_REPAIR")) == '1') {
// 	    repairIntersections();

// 	    if (getenv("DEBUG_FINISH") && *(getenv("DEBUG_FINISH")) == '1') {
// 		cout << "Status after repairing intersections:" << endl;
// 		writeIntersectionPoints();
// 	    }
// 	}

	if (getenv("DEBUG_FINISH") && *(getenv("DEBUG_FINISH")) == '1') {
	    int_results_->writeDebug();
	}

	int_results_->makeIntersectionCurves();
    }
}