001 /* 002 * $RCSfile: FileListToolkit.java,v $ 003 * 004 * Created on April 18, 2003, 6:53 PM 005 * 006 * This file is part of the STAR Scheduler. 007 * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory 008 * 009 * STAR Scheduler is free software; you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as published by 011 * the Free Software Foundation; either version 2 of the License, or 012 * (at your option) any later version. 013 * 014 * STAR Scheduler is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with STAR Scheduler; if not, write to the Free Software 021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 022 */ 023 024 package gov.bnl.star.offline.scheduler.util; 025 026 import gov.bnl.star.offline.scheduler.catalog.PhysicalFile; 027 import gov.bnl.star.offline.scheduler.policy.PassivePolicy; 028 029 import java.io.PrintStream; 030 import java.util.Collection; 031 import java.util.Iterator; 032 import java.util.Map; 033 034 /** 035 * Used to format and write out the file list. 036 * 037 * @author Gabriele Carcassi & Pavel Jakl & Levente Hajdu 038 * @version $Revision: 1.13 $ $Date: 2006/11/21 00:41:29 $ 039 */ 040 public class FileListToolkit { 041 042 043 044 static public void createPathsFileList(PrintStream out, Collection col, Map variables) { 045 046 String nameBuffer; 047 int nFile = 0; 048 Iterator iter = col.iterator(); 049 050 while (iter.hasNext()) { 051 PhysicalFile file = (PhysicalFile) iter.next(); 052 nameBuffer = file.getPath() + "/" + file.getFilename(); 053 variables.put("INPUTFILE" + nFile, nameBuffer); 054 out.println(nameBuffer); 055 nFile ++; 056 } 057 } 058 059 static public void createLocalRemoteFileList(PrintStream out, Collection col, Map variables, boolean isXrootdAllowed) { 060 061 String nameBuffer; 062 int nFile = 0; 063 Iterator iter = col.iterator(); 064 065 while (iter.hasNext()) { 066 PhysicalFile file = (PhysicalFile) iter.next(); 067 nameBuffer = getRootName(file, isXrootdAllowed); 068 out.print(nameBuffer); 069 if (file.getAtribute("events") != null) { 070 out.print(" "); 071 out.print(file.getAtribute("events")); 072 //nameBuffer = nameBuffer + " " + file.getAtribute("events"); 073 } 074 out.println(); 075 variables.put("INPUTFILE" + nFile, nameBuffer); 076 nFile ++; 077 078 } 079 } 080 081 private static String getRootName(PhysicalFile file, boolean isXrootdAllowed) { 082 if (file.getStorage().equals("NFS")) { 083 return file.getPath() + "/" + file.getFilename(); 084 } else if (isXrootdAllowed) { 085 return "root://" + PassivePolicy.getXrootdRedirectorName() + ":" + PassivePolicy.getXrootdPort() + "/" + file.getPath() + "/" + file.getFilename(); 086 } 087 return "root://" + file.getNode() + "/" + file.getPath() + "/" + file.getFilename(); 088 } 089 090 091 092 093 094 095 096 097 098 }