void ChecksumUpdater::buildStack(boost::shared_ptr<workflow::Node> node) { //std::cout << "Building stack of: " << node->getUuid() << std::endl; // Rebuild the stack without node, thus guaranteeing that node appears only once std::stack<boost::shared_ptr<workflow::Node> > oldStack; while (!nodesStack.empty()) { oldStack.push(nodesStack.top()); nodesStack.pop(); } while (!oldStack.empty()) { boost::shared_ptr<workflow::Node> n = oldStack.top(); if (n != node) nodesStack.push(n); oldStack.pop(); } nodesStack.push(node); // call build stack for all output nodes std::vector<boost::shared_ptr<workflow::Node> > dependentNodes; node->getDependentNodes(dependentNodes, true); for (unsigned i = 0; i < dependentNodes.size(); ++i) buildStack(dependentNodes[i]); }
bool isPalindrome(ListNode* head) { if(head == 0){ return true; } buildStack(head); return recursiveCompareForPalindrome(head); }
/* Crea un proceso */ int procCreate(char *name, process_t p, void *stack, void *heap, int fds[],int files, int argc, char **argv, int tty, int orphan, int priority){ int slot = getFreeSlot(); /* Obtengo un semaforo para controlar la salida de los hijos */ proc[slot].semChild = semGetID(0); proc[slot].semFather = semGetID(0); /* Obtengo un pid para el cual pid%MAX_PROCESS de el slot obtenido */ proc[slot].pid = proc[slot].pid + MAX_PROCESS; /* Si el proceso es huerfano, es hijo de INIT */ proc[slot].ppid = (orphan)? INIT_PROCESS : schedCurrentProcess(); /* Aumento en 1 la cantidad de hijos del padre */ proc[proc[slot].ppid%MAX_PROCESS].childCount++; strcpy(proc[slot].name, name); proc[slot].status = READY; /* No está implementado el uso del heap, pero se podría agregar muy * sencillamente asignando el heap, y luego a travez de un syscall * se pueda retornar, además un malloc podría administrar esta memoria * y en caso de que necesite más memoria podría pedir más páginas */ proc[slot].heapPages[0] = heap; proc[slot].usedheapPages = 0; /* Este proceso no tiene hijos */ proc[slot].childCount = 0; proc[slot].stackPages[0] = stack; proc[slot].usedstackPages = 1; proc[slot].attachedTTY = tty; proc[slot].retval = 0; memcpy(proc[slot].fds, fds, files*sizeof(int)); proc[slot].ESP = (byte*) buildStack(stack, p, argc, argv); /* Agregarlo al scheduler para que lo empiece a correr */ schedAdd(proc[slot].pid, name, priority); schedContinue(proc[slot].pid); return proc[slot].pid; }
void CutFlow::saveCutFlowPlot(AllSamples samples, Variable variable){ readCutFlowHistos(samples, variable); TH1D* data = samples.single_mu_data->histo; THStack *hs = buildStack(samples, variable); standardCutFlowPlot(data, hs, samples, variable); if(Globals::addRatioPlot){ ratioCutFlowPlot(data, hs, samples, variable); } writeTable(samples, variable); delete data; delete hs; }
int main(int argC,char* argV[]){ int i; tree t; if(argC==1) printf("Usage : %s <RPN expression enclosed by quotes> <optional parameter to trace the build process>",argV[0]); else{ buildStack(argV[1]); if(checkRPN()==0){ printf("\nInvalid RPN !"); return 0; } t = buildTree(getNextString(),argV[2]); printf("\nFinal infix expression : "); inorder(t); } return 0; }
void ChecksumUpdater::update(boost::shared_ptr<workflow::Node> node) { while(!nodesStack.empty()) nodesStack.pop(); boost::shared_ptr<workflow::Workflow> workflow = boost::dynamic_pointer_cast<workflow::Workflow>(node); if (workflow) { std::vector<boost::weak_ptr<workflow::Node> >& interfaceNodes = workflow->getInterfaceNodes(); for (unsigned i = 0; i < interfaceNodes.size(); ++i) { if (workflow->isOutputNode(interfaceNodes[i].lock())) buildStack(interfaceNodes[i].lock()); } } else { buildStack(node); } while (!nodesStack.empty()) { boost::shared_ptr<workflow::Node> currentNode = nodesStack.top(); nodesStack.pop(); // Update checksum + checksum from dependent stuff boost::crc_optimal<32, 0x04C11DB7> valueSum; boost::shared_ptr<workflow::Workflow> subworkflow = boost::dynamic_pointer_cast<workflow::Workflow>(currentNode); if (subworkflow) { ChecksumUpdater updater; updater.update(subworkflow); } else { assert(currentNode->getModule()); checksum_t dependentSum = 0; checksum_t selfSum = getChecksum(currentNode->getModule().get(), currentNode.get()); valueSum.process_bytes(&selfSum, sizeof(selfSum)); // std::cout << "Class name: " << currentNode->getModule()->getClassName() << std::endl; // if (currentNode->getModule()->getClassName() == "gml::convrbm4d::StackTensors") // std::cout << " Checksum: " << valueSum.checksum() << std::endl; std::vector<boost::shared_ptr<workflow::Node> > dependentNodes; currentNode->getDependentNodes(dependentNodes, true); // if (currentNode->getModule()->getClassName() == "gml::convrbm4d::StackTensors") // std::cout << " Dependent nodes: " << dependentNodes.size() << std::endl; for (unsigned i = 0; i < dependentNodes.size(); ++i) { // if (currentNode->getModule()->getClassName() == "gml::convrbm4d::StackTensors") { // std::cout << " " << dependentNodes[i]->getUuid() << std::endl; // std::cout << " In: " << dependentNodes[i]->getInputChecksum() << std::endl; // std::cout << " Out: " << dependentNodes[i]->getOutputChecksum() << std::endl; // } dependentSum = dependentNodes[i]->getInputChecksum(); valueSum.process_bytes(&dependentSum, sizeof(dependentSum)); // if (currentNode->getModule()->getClassName() == "gml::convrbm4d::StackTensors") { // std::cout << " Checksum: " << valueSum.checksum() << std::endl; // } } // if (currentNode->getModule()->getClassName() == "gml::convrbm4d::StackTensors") // std::cout << " Checksum: " << valueSum.checksum() << std::endl; currentNode->setInputChecksum(valueSum.checksum()); // if (currentNode->getModule()->getClassName() == "gml::convrbm4d::StackTensors") { // std::cout << " In: " << currentNode->getInputChecksum() << std::endl; // std::cout << " Out: " << currentNode->getOutputChecksum() << std::endl; // if (currentNode->getInputChecksum() != currentNode->getOutputChecksum()) // std::cout << currentNode->getUuid() << " changed!" << std::endl; // } } } if (workflow) { // accumulate checksums of output nodes // boost::crc_32_type valueSum; boost::crc_optimal<32, 0x04C11DB7> valueSum; std::vector<boost::weak_ptr<workflow::Node> >& interfaceNodes = workflow->getInterfaceNodes(); for (unsigned i = 0; i < interfaceNodes.size(); ++i) { if (workflow->isOutputNode(interfaceNodes[i].lock())) { checksum_t cs = interfaceNodes[i].lock()->getInputChecksum(); valueSum.process_bytes(&cs, sizeof(cs)); } } workflow->setInputChecksum(valueSum.checksum()); //if (workflow->getInputChecksum() != workflow->getOutputChecksum()) // std::cout << "checksum changed!" << std::endl; } }