// TODO this could be cleaned
@Override
	public void run(double frac) {
		logger.trace("run -> begin of method");
		try {
			workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1);
			ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>();
			ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>();
			for(TemporalObject iO : sourceDataset.temporalObjects()) {
				long inf = iO.getTemporalElement().asGeneric().getGranule().getInf();
				int i = 0;
				for(TemporalObject iB : currentBranches) {
					if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) {
		    			currentLeaves.get(i).add(iO);
		    			break;
					}
					i++;
				}
				if(i >= currentBranches.size()) {
			    	Granule newGranule = new Granule(inf,inf,granularities[0]); 
			    	Instant newTe = workingDataset.addInstant(newGranule);
			    	currentBranches.add(workingDataset.addTemporalObject(newTe));
			    	ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>();
			    	leaves.add(iO);
			    	currentLeaves.add(leaves);
				}
			}
			long[] roots = new long[currentBranches.size()];
			for(int i=0; i<currentBranches.size(); i++)
				roots[i] = currentBranches.get(i).getId();
			if (granularities.length > 1) {			
				for(int i=1; i<granularities.length;i++) {
					ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>();
					ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); 
					int whichChild = 0;
					for(int k=0; k<currentLeaves.size();k++) {
						ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k);
						while(iCurrentLeaves.size() > 0) {
							TemporalObject currentLeave = iCurrentLeaves.get(0);
							iCurrentLeaves.remove(0);
							TemporalObject targetBranch = null;
							long inf = currentLeave.getTemporalElement().asGeneric().getInf();
							long sup = currentLeave.getTemporalElement().asGeneric().getSup();
							whichChild = 0;
							for(int l=0; l<k; l++)
								whichChild += currentBranches.get(l).getChildCount();
							for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) {
								if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) {
									targetBranch = potentialBranch;
									break;
								}
								whichChild++;
							}
							if (targetBranch == null) {
								Granule newGranule = new Granule(inf,sup,granularities[i]); 
								Instant newTe = workingDataset.addInstant(newGranule);
								targetBranch = workingDataset.addTemporalObject(newTe);
								futureBranches.add(targetBranch);
								futureLeaves.add(new ArrayList<TemporalObject>());					    	
								whichChild = futureLeaves.size() - 1;
								currentBranches.get(k).linkWithChild(targetBranch);
							}
							futureLeaves.get(whichChild).add(currentLeave);
						}
					}
					if(i==granularities.length-1) {
						for(int j=0; j<futureBranches.size(); j++ ) {
							aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1);
						}
					} else {
						currentBranches = futureBranches;
						currentLeaves = futureLeaves;
					}
				}
				for(long iRoot : roots)
					aggregate(workingDataset.getTemporalObject(iRoot),0);
			} else {
				for(int i=0; i<roots.length; i++)
					aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0);
			}
			// TODO this could be cleaned
			for (long rootId : roots) {
			    workingDataset.getTemporalObject(rootId).setRoot(true);
			}
		} catch (TemporalDataException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0);
}
// TODO this could be cleaned
for (long rootId : roots) {
workingDataset.getTemporalObject(rootId).setRoot(true);
currentBranches = futureBranches;
currentLeaves = futureLeaves;
}
}
for(long iRoot : roots)
aggregate(workingDataset.getTemporalObject(iRoot),0);
} else {
for(int i=0; i<roots.length; i++)
aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0);
}
// TODO this could be cleaned
for (long rootId : roots) {
workingDataset.getTemporalObject(rootId).setRoot(true);
}
} catch (TemporalDataException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
currentBranches.get(k).linkWithChild(targetBranch);
}
futureLeaves.get(whichChild).add(currentLeave);
}
}
if(i==granularities.length-1) {
for(int j=0; j<futureBranches.size(); j++ ) {
aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1);
}
} else {
currentBranches = futureBranches;
currentLeaves = futureLeaves;
}
}
for(long iRoot : roots)
aggregate(workingDataset.getTemporalObject(iRoot),0);
} else {
for(int i=0; i<roots.length; i++)
aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0);
}
// TODO this could be cleaned
for (long rootId : roots) {
workingDataset.getTemporalObject(rootId).setRoot(true);
}
} catch (TemporalDataException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}