示例#1
0
文件: ROMETree.cpp 项目: cjpl/rome
//______________________________________________________________________________
Long64_t ROMETree::AutoSave(Option_t *option)
{
   Long64_t ret = 0;
   if (fAutoSaveSize > 0 && isWrite() && fTree && fTree->GetCurrentFile()) {
      ret = fTree->AutoSave(option);
#if (ROOT_VERSION_CODE > ROOT_VERSION(4,4,2))
      fLastSaveSize = fTree->GetCurrentFile()->GetBytesWritten();
#else
      fLastSaveSize = static_cast<Long64_t>(fTree->GetCurrentFile()->GetBytesWritten());
#endif
      TString opt = option;
      opt.ToLower();
   }
   return ret;
}
示例#2
0
文件: ROMETree.cpp 项目: cjpl/rome
//______________________________________________________________________________
Bool_t ROMETree::CheckAutoSave()
{
   Long64_t currentSize;
   if (fAutoSaveSize > 0 && isWrite() && fTree && fTree->GetCurrentFile()) {
#if (ROOT_VERSION_CODE > ROOT_VERSION(4,4,2))
      currentSize = fTree->GetCurrentFile()->GetBytesWritten();
#else
      currentSize = static_cast<Long64_t>(fTree->GetCurrentFile()->GetBytesWritten());
#endif
      if (currentSize < fLastSaveSize) {
         // probably new file is created.
         fLastSaveSize = 0;
      }
      if (currentSize > fLastSaveSize + fAutoSaveSize) {
         return kTRUE;
      }
   }
   return kFALSE;
}
示例#3
0
bool isSubTypeOf(const TypePtr& subType, const TypePtr& superType) {

	// quick check - reflexivity
	if (*subType == *superType) {
		return true;
	}

	// check for recursive types
	if (subType->getNodeType() == NT_RecType || superType->getNodeType() == NT_RecType) {

		// since they are not equivalent we have to compare the unrolled version of the sub with the super type
		if (subType->getNodeType() == NT_RecType) {
			return isSubTypeOf(subType.as<RecTypePtr>()->unroll(), superType);
		}

		if (superType->getNodeType() == NT_RecType) {
			assert(subType->getNodeType() != NT_RecType);
			return isSubTypeOf(subType, superType.as<RecTypePtr>()->unroll());
		}

		assert(false && "How could you get here?");
	}

	// check whether the sub-type is generic
	if (subType->getNodeType() == NT_GenericType || subType->getNodeType() == NT_StructType) {
		// use the delta algorithm for computing all the super-types of the given sub-type
		return isSubTypeOfInternal(subType, superType);
	}

	// check for vector types
	if (subType.isa<VectorTypePtr>() ) {
		VectorTypePtr vector = static_pointer_cast<const VectorType>(subType);
		// potential super type is an array of the same element type
		IRBuilder builder(vector->getNodeManager());
		return *superType == *builder.arrayType(vector->getElementType());
	}

	// for all other relations, the node type has to be the same
	if (subType->getNodeType() != superType->getNodeType()) {
		return false;
	}

	// check function types
	if (subType->getNodeType() == NT_FunctionType) {
		FunctionTypePtr funTypeA = static_pointer_cast<const FunctionType>(subType);
		FunctionTypePtr funTypeB = static_pointer_cast<const FunctionType>(superType);

		// check kind of functions
		if (funTypeA->getKind() != funTypeB->getKind()) {
			// only closure to plain conversion is allowed
			if (!(funTypeB->isClosure() && funTypeA->isPlain())) {
				return false;
			}
		}

		bool res = true;
		res = res && funTypeA->getParameterTypes().size() == funTypeB->getParameterTypes().size();
		res = res && isSubTypeOf(funTypeA->getReturnType(), funTypeB->getReturnType());
		for(std::size_t i = 0; res && i<funTypeB->getParameterTypes().size(); i++) {
			res = res && isSubTypeOf(funTypeB->getParameterTypes()[i], funTypeA->getParameterTypes()[i]);
		}
		return res;
	}

	// check reference types
	if (subType->getNodeType() == NT_RefType) {
		const auto& basic = subType->getNodeManager().getLangBasic();

		// check source / sink
		auto srcRef = subType.as<RefTypePtr>();
		auto trgRef = superType.as<RefTypePtr>();

		// check read/write privileges
		if (trgRef.isRead() && !srcRef.isRead()) return false;
		if (trgRef.isWrite() && !srcRef.isWrite()) return false;

		// check element type
		auto srcElement = subType.as<RefTypePtr>()->getElementType();
		auto trgElement = superType.as<RefTypePtr>()->getElementType();

		// if element types are identical => it is fine
		//if (srcElement == trgElement) return true;
		if(core::analysis::compareTypes(srcElement, trgElement)) return true;

		// if sub-type is ref<any> it is ok
		if (basic.isAny(trgElement)) {
			return true;
		}

		// support nested references
		if (srcElement.isa<RefTypePtr>() && trgElement.isa<RefTypePtr>()) {
			return isSubTypeOf(srcElement, trgElement);
		}

		// a ref<vector<X,Y>> is a sub-type of a ref<array<X,1>>
		if (trgElement.isa<ArrayTypePtr>() && srcElement.isa<VectorTypePtr>()) {
			IRBuilder builder(srcElement.getNodeManager());
			auto one = builder.concreteIntTypeParam(1);

			// array needs to be 1-dimensional and both have to have the same element type
			return trgElement.as<ArrayTypePtr>()->getDimension() == one &&
				   trgElement.as<ArrayTypePtr>()->getElementType() == srcElement.as<VectorTypePtr>()->getElementType();
		}

		// also support references of derived classes being passed to base-type pointer
		if (core::analysis::isObjectType(srcElement) && core::analysis::isObjectType(trgElement)) {
			if (isSubTypeOf(srcElement, trgElement)) {
				return true;
			}
		}

	}

	// no other relations are supported
	return false;
}