/***********************************************************************//** * @brief Sum effective area multiplied by livetime over zenith and * (optionally) azimuth angles * * @param[in] dir True sky direction. * @param[in] energy True photon energy. * @param[in] aeff Effective area. * * Computes * \f[\sum_{\cos \theta, \phi} T_{\rm live}(\cos \theta, \phi) * A_{\rm eff}(\log E, \cos \theta, \phi)\f] * where * \f$T_{\rm live}(\cos \theta, \phi)\f$ is the livetime as a function of * the cosine of the zenith and the azimuth angle, and * \f$A_{\rm eff}(\log E, \cos \theta, \phi)\f$ is the effective area that * depends on * the log10 of the energy (in MeV), * the cosine of the zenith angle, and * the azimuth angle. * This method assumes that \f$T_{\rm live}(\cos \theta, \phi)\f$ is * stored as a set of maps in a 2D array with \f$\cos \theta\f$ being the * most rapidely varying parameter and with the first map starting at * index m_num_ctheta (the first m_num_ctheta maps are the livetime cube * maps without any \f$\phi\f$ dependence). ***************************************************************************/ double GLATLtCubeMap::operator()(const GSkyDir& dir, const GEnergy& energy, const GLATAeff& aeff) const { // Get map index int pixel = m_map.dir2pix(dir); // Initialise sum double sum = 0.0; // Circumvent const correctness GLATAeff* fct = ((GLATAeff*)&aeff); // If livetime cube and response have phi dependence then sum over // zenith and azimuth. Note that the map index starts with m_num_ctheta // as the first m_num_ctheta maps correspond to an evaluation without // any phi-dependence. if (has_phi() && aeff.has_phi()) { for (int iphi = 0, i = m_num_ctheta; iphi < m_num_phi; ++iphi) { double p = phi(iphi); for (int itheta = 0; itheta < m_num_ctheta; ++itheta, ++i) { sum += m_map(pixel, i) * (*fct)(energy.log10MeV(), costheta(i), p); } } } // ... otherwise sum only over zenith angle else { for (int i = 0; i < m_num_ctheta; ++i) { sum += m_map(pixel, i) * (*fct)(energy.log10MeV(), costheta(i)); } } // Return sum return sum; }
int tetris_handler::cut_down(int diamonds_high, int height) { int i = 0; int j = 0; int count = 0; int map_col = m_map.get_cols(); for(; i < diamonds_high; ++i) { for(j = 1; j < (map_col-1) && m_map(height, j); ++j) { ; } // cut this line. if( (map_col-1) == j) { m_map.remove_line_at_height(height); ++count; } else { --height; } } return count; }
/***********************************************************************//** * @brief Return intensity of skymap * * @param[in] srcDir True photon arrival direction. * * Returns the intensity of the skymap at the specified sky direction * multiplied by the normalization factor. If the sky direction falls outside * the skymap, an intensity of 0 is returned. ***************************************************************************/ double GModelSpatialMap::eval(const GSkyDir& srcDir) const { // Get skymap intensity double intensity = m_map(srcDir); // Return intensity times normalization factor return (intensity * m_value.real_value()); }
void SparseMap<2>::markNonZero(size_t i, size_t j) { size_t& el = m_map(i, j); if (el == ZERO_ELEMENT) { el = m_numNonZeroElements; ++m_numNonZeroElements; } }
/***********************************************************************//** * @brief Return intensity of skymap and gradient * * @param[in] srcDir True photon arrival direction. * * Returns the intensity of the skymap at the specified sky direction * multiplied by the normalization factor. The method also sets the gradient * with respect to the normalization factor. If the sky direction falls * outside the skymap, an intensity of 0 is returned. ***************************************************************************/ double GModelSpatialMap::eval_gradients(const GSkyDir& srcDir) const { // Get skymap intensity double intensity = m_map(srcDir); // Compute partial derivatives of the parameter values double g_value = (m_value.isfree()) ? intensity * m_value.scale() : 0.0; // Set gradient to 0 (circumvent const correctness) const_cast<GModelSpatialMap*>(this)->m_value.gradient(g_value); // Return intensity times normalization factor return (intensity * m_value.real_value()); }
/***********************************************************************//** * @brief Create an array of non-zero pixel indices ***************************************************************************/ void GSkyRegionMap::set_nonzero_indices(void) { // Clear zero pixel array m_nonzero_indices.clear(); // Loop over map pixels and find non-zero pixels for (int i = 0; i < m_map.npix(); ++i) { if (m_map(i,0) != 0.0) { m_nonzero_indices.push_back(i); } } // Return return; }
/***********************************************************************//** * @brief Sum function multiplied by livetime over zenith angle * * @param[in] dir Sky direction. * @param[in] fct Function to evaluate. * * Computes * \f[\sum_{\cos \theta} T_{\rm live}(\cos \theta) f(\cos \theta)\f] * where * \f$T_{\rm live}(\cos \theta)\f$ is the livetime as a function of the * cosine of the zenith angle, and * \f$f(\cos \theta)\f$ is a function that depends on the cosine of the * zenith angle. * This method assumes that \f$T_{\rm live}(\cos \theta)\f$ is stored as a * set of maps. ***************************************************************************/ double GLATLtCubeMap::operator()(const GSkyDir& dir, _ltcube_ctheta fct) const { // Get map index int pixel = m_map.dir2pix(dir); // Initialise sum double sum = 0.0; // Loop over zenith angles for (int i = 0; i < m_num_ctheta; ++i) { sum += m_map(pixel, i) * (*fct)(costheta(i)); } // Return sum return sum; }
/***********************************************************************//** * @brief Check if a given direction is contained in this region * * @param[in] dir Sky direction. * @return True if sky direction is in region, false otherwise. * * Checks if sky direction is contained in the region map. ***************************************************************************/ bool GSkyRegionMap::contains(const GSkyDir& dir) const { // Initialize bool contain = false; // If direction is within map boundaries if (m_map.contains(dir)) { // Convert sky direction into pixel index int i = m_map.dir2inx(dir); // Set containment flag contain = (m_map(i,0) != 0.0); } // endif: map contains direction // Return value return contain; }
/***********************************************************************//** * @brief Sum function multiplied by livetime over zenith and azimuth angles * * @param[in] dir Sky direction. * @param[in] fct Function to evaluate. * * Computes * \f[\sum_{\cos \theta, \phi} T_{\rm live}(\cos \theta, \phi) * f(\cos \theta, \phi)\f] * where * \f$T_{\rm live}(\cos \theta, \phi)\f$ is the livetime as a function of * the cosine of the zenith and of the azimuth angle, and * \f$f(\cos \theta, \phi)\f$ is a function that depends on the cosine of * the zenith angle and of the azimuth angle. * This method assumes that \f$T_{\rm live}(\cos \theta, \phi)\f$ is * stored as a set of maps in a 2D array with \f$\cos \theta\f$ being the * most rapidely varying parameter and with the first map starting at * index m_num_ctheta (the first m_num_ctheta maps are the livetime cube * maps without any \f$\phi\f$ dependence). ***************************************************************************/ double GLATLtCubeMap::operator()(const GSkyDir& dir, _ltcube_ctheta_phi fct) const { // Get map index int pixel = m_map.dir2pix(dir); // Initialise sum double sum = 0.0; // Loop over azimuth and zenith angles. Note that the map index starts // with m_num_ctheta as the first m_num_ctheta maps correspond to an // evaluation without any phi-dependence. for (int iphi = 0, i = m_num_ctheta; iphi < m_num_phi; ++iphi) { double p = phi(iphi); for (int itheta = 0; itheta < m_num_ctheta; ++itheta, ++i) { sum += m_map(pixel, i) * (*fct)(costheta(itheta), p); } } // Return sum return sum; }
size_t SparseMap<2>::nonZeroElementIdx(size_t i, size_t j) const { return m_map(i, j); }
// Fork() Creating a child process from a parent uint64_t doFork() { PCB *pro = NULL; PCB *parent_process; //parent_process = get_curr_PCB(); parent_process = running; pro = create_pcb(); strcpy(pro->name, parent_process->name); m_map((uint64_t)pro, (uint64_t)(get_curr_PCB()), (uint64_t)(sizeof(struct pcb_t)), (uint64_t)(sizeof(struct pcb_t)) ); // Getting new pid ------------------------------------------------------------------------- if ((pro->pid = get_pid()) == 0) { printf("\n Error No Free PID found"); return -1; } pro->cr3 = map_pageTable(pro); // Storing Base Physical address of PML4e for new process pro->ppid = parent_process->pid; printf("\n PCR3:%x", pro->cr3); /// ----------------------------------------------------------------------------------------- //copy the user stack of the parent process //copyUST(pro); //checkUST(pro); //checkUST(running); //ckop(); copyPageTables(pro, parent_process); printf("PageTable copying done\n"); printf("Child PID=%p, pPID=%p\n", pro->pid, pro->ppid); printf("CP Cr3=%p Chid Cr3=%p\n", running->cr3, pro->cr3); // Add it to task linked list !! runnableTaskQ = addToTailTaskList(runnableTaskQ, pro); no_runnableQ++; // return 0 to the calling process //m_map( (uint64_t)pro->u_stack, (uint64_t)(parent_process->u_stack), (uint64_t)(4096), (uint64_t)(4096) ); printf("\n Trying to Fork()\n"); //copyOnWritePageTables(); _ptcr3(running->cr3); // update the cr3 to process->cr3 /*if ((pro->u_stack = process_stack()) == NULL) { printf("\n Cant allocate memory for process User stack"); //exit(); }*/ //check this function //m_map((uint64_t)pro->u_stack, (uint64_t)parent_process->u_stack, (uint64_t)(4096*8), (uint64_t)(4096*8) ); // Setting up the rax for both parent and child GREG *pp1 = (GREG *) &(running->kernel_stack[234]); GREG *cc1 = (GREG *) &(pro->kernel_stack[234]); pp1->rax = pro->pid; cc1->rax = 0x0; printf("\n Display :%x:%x", pp1->rax, cc1->rax); if (running->pid == pro->ppid) { printf("This is the parent ! Returning with pid=%p, parent/running pid=%p\n", pro->pid, running->pid); //Set everything for our child for it to execute in its registers //__asm volatile("sti"); //while(1); return pro->pid; } else { printf("This is the CHILD !!\n"); //__asm volatile("sti"); return 0; } }
/***********************************************************************//** * @brief Load skymap into the model class * * Loads skymap into the model class. After loading, the map is normalized * so that the total flux in the map amounts to 1 ph/cm2/s. Negative skymap * pixels are set to zero intensity. * * The method also initialises a cache for Monte Carlo sampling of the * skymap. This Monte Carlo cache consists of a linear array that maps a * value between 0 and 1 into the skymap pixel. ***************************************************************************/ void GModelSpatialMap::load_map(const std::string& filename) { // Initialise skymap and cache m_map.clear(); m_mc_cache.clear(); // Store filename of skymap (for XML writing). Note that we do not // expand any environment variable at this level, so that if we write // back the XML element we write the filepath with the environment // variable m_filename = filename; // Load skymap m_map.load(expand_env(m_filename)); // Determine number of skymap pixels int npix = m_map.npix(); // Continue only if there are skymap pixels if (npix > 0) { // Reserve space for all pixels in cache m_mc_cache.reserve(npix+1); // Set first cache value to 0 m_mc_cache.push_back(0.0); // Initialise cache with cumulative pixel fluxes and compute total // flux in skymap for normalization. Negative pixels are set to // zero intensity in the skymap. double sum = 0.0; for (int i = 0; i < npix; ++i) { double flux = m_map(i) * m_map.omega(i); if (flux < 0.0) { m_map(i) = 0.0; flux = 0.0; } sum += flux; m_mc_cache.push_back(sum); } // Normalize skymap and pixel fluxes in the cache so that the values // in the cache run from 0 to 1 if (sum > 0.0) { for (int i = 0; i < npix; ++i) { m_map(i) /= sum; m_mc_cache[i] /= sum; } } // Make sure that last pixel in the cache is >1 m_mc_cache[npix] = 1.0001; // Dump cache values for debugging #if defined(G_DEBUG_CACHE) for (int i = 0; i < npix+1; ++i) { std::cout << "i=" << i; std::cout << " c=" << m_mc_cache[i] << std::endl; } #endif } // endif: there were skymap pixels // Return return; }