+
+ // ------------------------------------------------------------------------
+ // Context conversion functions
+ // ------------------------------------------------------------------------
+
+ private static ITmfContext saveContext(ITmfContext context) {
+ if (context instanceof TmfExperimentContext) {
+ return saveExpContext(context);
+ }
+ TmfContext ctx = new TmfContext(context.getLocation(), context.getRank());
+ return ctx;
+ }
+
+ private static ITmfContext saveExpContext(ITmfContext context) {
+ TmfExperimentContext expContext = (TmfExperimentContext) context;
+ int size = expContext.getContexts().length;
+ ITmfContext[] trcCtxts = new TmfContext[size];
+ for (int i = 0; i < size; i++) {
+ ITmfContext ctx = expContext.getContexts()[i];
+ trcCtxts[i] = (ctx != null) ? new TmfContext(ctx.getLocation(), ctx.getRank()) : null;
+ }
+ TmfExperimentContext expCtx = new TmfExperimentContext(trcCtxts);
+ expCtx.setLocation(context.getLocation());
+ expCtx.setRank(context.getRank());
+ ITmfEvent[] trcEvts = expCtx.getEvents();
+ for (int i = 0; i < size; i++) {
+ ITmfEvent event = expContext.getEvents()[i];
+ trcEvts[i] = (event != null) ? event.clone() : null;
+ }
+ return expCtx;
+ }
+
+ private ITmfContext restoreContext(ITmfContext context) {
+ if (context instanceof TmfExperimentContext) {
+ return restoreExpContext(context);
+ }
+ ITmfContext ctx = fTrace.seekEvent(context.getLocation());
+ ctx.setRank(context.getRank());
+ return ctx;
+ }
+
+ private ITmfContext restoreExpContext(ITmfContext context) {
+ TmfExperimentContext expContext = (TmfExperimentContext) context;
+ int size = expContext.getContexts().length;
+ ITmfContext[] trcCtxts = new ITmfContext[size];
+ for (int i = 0; i < size; i++) {
+ ITmfTrace trace = ((TmfExperiment) fTrace).getTraces()[i];
+ ITmfContext ctx = expContext.getContexts()[i];
+ trcCtxts[i] = trace.seekEvent(ctx.getLocation());
+ trcCtxts[i].setRank(ctx.getRank());
+ }
+ TmfExperimentContext ctx = new TmfExperimentContext(trcCtxts);
+ ctx.setLocation(context.getLocation());
+ ctx.setRank(context.getRank());
+ ITmfEvent[] trcEvts = expContext.getEvents();
+ for (int i = 0; i < size; i++) {
+ ITmfEvent event = trcEvts[i];
+ ctx.getEvents()[i] = (event != null) ? event.clone() : null;
+ }
+ return ctx;
+ }
+