source: trunk/DataCheck/Archive/correctFileName.cxx@ 19979

Last change on this file since 19979 was 12750, checked in by lyard, 13 years ago
added ingest stuff
File size: 1.9 KB
Line 
1#include <string>
2#include <iostream>
3
4using namespace std;
5
6bool isNumber(char c)
7{
8 switch (c) {
9 case '0':
10 case '1':
11 case '2':
12 case '3':
13 case '4':
14 case '5':
15 case '6':
16 case '7':
17 case '8':
18 case '9':
19 return true;
20 break;
21 default:
22 return false;
23 };
24}
25
26int main(int argc, char** argv)
27{
28 if (argc != 2)
29 return 0;
30
31 string c(argv[1]);
32
33 //get the year, month and day from the path.
34 string year, month, day;
35 string runnumber;
36 string serviceName;
37 int count = c.size()-5;
38
39 while (count >= 0)
40 {
41 if (c[count+0] == '2' &&
42 c[count+1] == '0' &&
43 c[count+2] == '1' &&
44 c[count+3] == '1' &&
45 c[count+4] == '/')
46 {
47 year = "2011";
48 month = c.substr(count+5, 2);
49 day = c.substr(count+8, 2);
50 break;
51 }
52 count--;
53 }
54
55 //separate the runnumber from the rest of the filename
56 count = c.size()-6;
57 while (count >= 0)
58 {
59 if (c[count] == '_')
60 {
61 if (isNumber(c[count+1]) &&
62 isNumber(c[count+2]) &&
63 isNumber(c[count+3]))
64 {
65 runnumber=c.substr(count+1, 3);
66 break;
67 }
68 }
69 else
70 {
71 if (c[count+0] != '0' &&
72 c[count+1] == '0' &&
73 c[count+2] == '0' &&
74 c[count+3] == '0' &&
75 c[count+4] == '0' &&
76 c[count+5] == '0')
77 {
78 runnumber=c.substr(count+6, 3);
79 break;
80 }
81 }
82 count--;
83 }
84
85 //figure out the service name
86 count = c.size()-3;
87 while (count > 0)
88 {
89 if ((c[count] == '_' || c[count] == '.') &&
90 !isNumber(c[count+1]) &&
91 isNumber(c[count-1]))
92 {
93 serviceName = c.substr(count+1, c.size()-(count+6));
94 }
95 count--;
96 }
97 if (serviceName == "fits")
98 serviceName = "";
99
100
101 cout << year << month << day;
102 if (runnumber != "") cout << "_";
103 cout << runnumber;
104 if (serviceName != "") cout << ".";
105 cout << serviceName << ".fits";
106// cout << "year: " << year << " month: " << month << " day: " << day << endl;
107// cout << "run number: " << runnumber << " service name: " << serviceName << endl;
108
109return 0;
110
111}
Note: See TracBrowser for help on using the repository browser.