~mbogomilov/maus/devel3

« back to all changes in this revision

Viewing changes to bin/utilities/process_geometry.py

  • Committer: Durga Rajaram
  • Date: 2013-11-19 02:09:06 UTC
  • mfrom: (659.1.77 rc)
  • Revision ID: durga@fnal.gov-20131119020906-t2vxx4h2yr0f09tj
Tags: MAUS-v0.7.4
MAUS-v0.7.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
M. Littlefield
 
5
"""
 
6
#  This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
7
 
8
#  MAUS is free software: you can redistribute it and/or modify
 
9
#  it under the terms of the GNU General Public License as published by
 
10
#  the Free Software Foundation, either version 3 of the License, or
 
11
#  (at your option) any later version.
 
12
 
13
#  MAUS is distributed in the hope that it will be useful,
 
14
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#  GNU General Public License for more details.
 
17
 
18
#  You should have received a copy of the GNU General Public License
 
19
#  along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
#pylint: disable=W0611
 
22
import os
 
23
import shutil
 
24
import geometry
 
25
from geometry.GDMLtoCDB import Downloader
 
26
from geometry.GDMLtoMAUSModule import GDMLtomaus
 
27
from geometry.ConfigReader import Configreader
 
28
from geometry.GDMLFormatter import Formatter
 
29
from geometry.GDMLPacker import Unpacker
 
30
 
 
31
GDML_CACHE = 'gdml'
 
32
TMP_CACHE = 'tmp'
 
33
 
 
34
def main():
 
35
    """
 
36
    This is the code for the executable file which downloads the current valid
 
37
    geometry. It takes the arguments of the download directory. It will download
 
38
    the geometry from the database and translates the geometry into MAUS Module
 
39
    format.
 
40
    """
 
41
    # Read Config Arguments
 
42
    configuration = Configreader()
 
43
    dl_dir = configuration.geometry_download_directory
 
44
    # Set up target location for download
 
45
    gdml_cache = os.path.join(dl_dir, GDML_CACHE)
 
46
    try:
 
47
        os.mkdir(gdml_cache)
 
48
    except OSError:
 
49
        pass
 
50
    #Download file
 
51
    #geometry_downloader = Downloader()
 
52
    #if configuration.geometry_download_by == "run_number":
 
53
    #    geometry_downloader.download_geometry_by_run \
 
54
    #                   (configuration.geometry_download_run_number, gdml_cache)
 
55
    #elif configuration.geometry_download_by == "current":
 
56
    #    geometry_downloader.download_current(gdml_cache)
 
57
    #elif configuration.geometry_download_by == "id":
 
58
    #    geometry_downloader.download_geometry_by_id \
 
59
    #                     (configuration.geometry_download_id, gdml_cache)
 
60
    #else:
 
61
    #    raise KeyError("Didn't recognise 'geometry_download_by' option '"+\
 
62
    #            configuration.geometry_download_by+"'. Should be on of\n"+\
 
63
    #                       "run_number\ncurrent\nid\n")
 
64
    #Unzip file
 
65
    #zip_filename = os.path.join
 
66
    #               (gdml_cache, geometry.GDMLtoCDB.GEOMETRY_ZIPFILE)
 
67
    #zipped_geom = Unpacker(zip_filename, gdml_cache)
 
68
    # zipped_geom.unzip_file()
 
69
    # format files
 
70
    gdmls = Formatter(gdml_cache, dl_dir)
 
71
    gdmls.format()
 
72
    # convert to MAUS Modules
 
73
    maus_modules = GDMLtomaus(dl_dir)
 
74
    maus_modules.convert_to_maus(dl_dir)
 
75
    # clean up if required
 
76
    if configuration.geometry_download_cleanup:
 
77
        shutil.rmtree(gdml_cache)
 
78
    print "Download Complete"
 
79
 
 
80
if __name__ == "__main__":
 
81
    main()