-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdump-timelines.groovy
More file actions
106 lines (93 loc) · 2.96 KB
/
dump-timelines.groovy
File metadata and controls
106 lines (93 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// dump the contents of all the timeline plots for a given timeline HIPO file or timeline URL
import org.jlab.groot.data.TDirectory
def outFilePrefix = "out"
if(args.length<1) {
System.err.println """
USAGE: groovy ${this.class.getSimpleName()}.groovy [TIMELINE] [OUTPUT FILE PREFIX]
- [TIMELINE] may either be a timeline URL or a timeline HIPO file
- [OUTPUT FILE PREFIX] for the dumped timelines (default = $outFilePrefix)
"""
System.exit(101)
}
if(args.length>1) outFilePrefix = args[1]
def inSpec = args[0]
def inFiles = []
if(inSpec ==~ /^https.*clas12mon.jlab.org.*timeline.*/) {
def inDir = inSpec.replaceAll(/^.*jlab.org/, "/u/group/clas/www/clas12mon/html/hipo")
inDir = "/"+inDir.tokenize('/')[0..-2].join("/")
def inDirObj = new File(inDir)
inDirObj.traverse(type: groovy.io.FileType.FILES, nameFilter: ~/.*\.hipo/) {
if(it.size()>0) inFiles << inDir+"/"+it.getName()
}
} else {
inFiles << inSpec
}
System.out.println "inFiles:"
inFiles.each{System.out.println " - $it"}
System.out.println "outFilePrefix: $outFilePrefix"
def outFileNames = []
inFiles.each{ inFile ->
def inTdir = new TDirectory()
try {
inTdir.readFile(inFile)
} catch(Exception ex) {
System.err.println("ERROR: cannot read file $inFile; it may be corrupt")
System.exit(100)
}
def objList = inTdir.getCompositeObjectList(inTdir)
def timelines = []
def plots = []
def tlGraphs = []
objList.each { objN ->
tok = objN.tokenize('/')
if(tok[0] == "timelines") {
if( !(tok[1] ==~ /^plotLine.*/) && !(tok[1] ==~ /.*__bad$/) ) {
timelines << tok[1]
tlGraphs << inTdir.getObject(objN)
}
}
else {
if( ! tok[1].contains(":") ) {
plots << tok[1]
}
}
}
plots.unique()
inFileBase = inFile
.tokenize('/')[-2..-1]
.collect{ it.replaceAll(/.hipo$/,'') }[-1]
// System.out.println """
// > ${inFileBase}
// > timelines = $timelines
// > plots = $plots
// """
def numRunsCheck = tlGraphs.collect{ it.getDataSize(0) }.unique()
if(numRunsCheck.size()>1) {
System.err.println("ERROR: timelines have differing number of runs")
System.exit(100)
}
def numRuns = numRunsCheck[0]
System.out.println "numRuns: $numRuns"
def outFileName = "${outFilePrefix}_${inFileBase}.dat"
def outFile = new File(outFileName)
def outFileWriter = outFile.newWriter(false)
numRuns.times{
def runnum = tlGraphs[0].getDataX(it)
if(it==0) {
outFileWriter << "#runnum " << tlGraphs.collect{gr->"'${gr.getName()}'"}.join(' ') << '\n'
}
outFileWriter << runnum.toInteger() << ' '
tlGraphs.each{ gr ->
if(runnum != gr.getDataX(it)) {
System.err.println("ERROR: timelines have differing run numbers")
System.exit(100)
}
outFileWriter << gr.getDataY(it) << ' '
}
outFileWriter << '\n'
}
outFileWriter.close()
outFileNames << outFileName
}
System.out.println "DONE. Timelines dumped to:"
outFileNames.each{System.out.println " - $it"}