Project

General

Profile

FNAL Redmine tricks » History » Version 1

Katherine Lato, 07/14/2016 03:19 PM

1 1 Katherine Lato
h1. FNAL Redmine tricks
2 1 Katherine Lato
3 1 Katherine Lato
{{>toc}}
4 1 Katherine Lato
5 1 Katherine Lato
h2. Empty page - for testing
6 1 Katherine Lato
7 1 Katherine Lato
An empty page for your tests: [[LArSoft Redmine sandbox]]; remember to clean up after yourself!
8 1 Katherine Lato
9 1 Katherine Lato
h2. Calling macros
10 1 Katherine Lato
11 1 Katherine Lato
A macro can be called by enclosing its name in double braces; for example:
12 1 Katherine Lato
<pre>{{hello_world(arg="argument text")
13 1 Katherine Lato
  block of text
14 1 Katherine Lato
}}</pre>
15 1 Katherine Lato
16 1 Katherine Lato
bq. {{hello_world(arg="argument text")
17 1 Katherine Lato
  block of text
18 1 Katherine Lato
}}
19 1 Katherine Lato
20 1 Katherine Lato
21 1 Katherine Lato
h2. Syntax highlight for code
22 1 Katherine Lato
23 1 Katherine Lato
The standard way to get some syntax highlight is to switch to HTML mode with.
24 1 Katherine Lato
25 1 Katherine Lato
Class names are
26 1 Katherine Lato
27 1 Katherine Lato
| C       | @c@       | |
28 1 Katherine Lato
| C++     | @cpp@     | (does not know C++11 keywords) |
29 1 Katherine Lato
| python  | @python@  | |
30 1 Katherine Lato
| ruby    | @ruby@    | |
31 1 Katherine Lato
| JSON    | @json@    | |
32 1 Katherine Lato
| bash    | n/a       | |
33 1 Katherine Lato
| FHiCL   | n/a       | (try with @python@) |
34 1 Katherine Lato
35 1 Katherine Lato
{{collapse(Example with C++ code (class: "cpp"))
36 1 Katherine Lato
<pre><code class="cpp">
37 1 Katherine Lato
  /**
38 1 Katherine Lato
   * @file   ServiceUtils.h
39 1 Katherine Lato
   * @brief  Utility functions in `lar` namespace to interface with art services
40 1 Katherine Lato
   * @author me@fnal.gov
41 1 Katherine Lato
   * @date   October 9th, 2015
42 1 Katherine Lato
   */
43 1 Katherine Lato
  #ifndef COREUTILS_SERVICEUTILS_H
44 1 Katherine Lato
  #define COREUTILS_SERVICEUTILS_H
45 1 Katherine Lato
46 1 Katherine Lato
  // framework libraries
47 1 Katherine Lato
  #include "art/Framework/Services/Registry/ServiceHandle.h"
48 1 Katherine Lato
  #include "art/Utilities/Exception.h"
49 1 Katherine Lato
  #include "cetlib/demangle.h"
50 1 Katherine Lato
  
51 1 Katherine Lato
  // C/C++ standard libraries
52 1 Katherine Lato
  #include <typeinfo>
53 1 Katherine Lato
  #include <type_traits> // std::is_copy_assignable<>, ...
54 1 Katherine Lato
  
55 1 Katherine Lato
  namespace lar {
56 1 Katherine Lato
    
57 1 Katherine Lato
    /**
58 1 Katherine Lato
     * @brief  Returns a constant pointer to the provider of specified service
59 1 Katherine Lato
     * @tparam SERVICE the class of the service that is needed
60 1 Katherine Lato
     * @return a constant, non-null pointer to the service provider
61 1 Katherine Lato
     * @throw  art::Exception if service returns a null pointer
62 1 Katherine Lato
     *
63 1 Katherine Lato
     * The service class is required to have a `provider_type` and a `provider()`
64 1 Katherine Lato
     * members defined.
65 1 Katherine Lato
     */
66 1 Katherine Lato
    template <typename SERVICE>
67 1 Katherine Lato
    SERVICE const* providerFrom() {
68 1 Katherine Lato
      // if you get a compilation error here,
69 1 Katherine Lato
      // the service class your code is asking for does not comply with LArSoft
70 1 Katherine Lato
      // service class requirements
71 1 Katherine Lato
      static_assert(
72 1 Katherine Lato
           !std::is_copy_constructible<typename SERVICE::provider_type>::value
73 1 Katherine Lato
        && !std::is_move_constructible<typename SERVICE::provider_type>::value
74 1 Katherine Lato
        && !std::is_copy_assignable<typename SERVICE::provider_type>::value
75 1 Katherine Lato
        && !std::is_move_assignable<typename SERVICE::provider_type>::value,
76 1 Katherine Lato
        "LArSoft service provider classes must not be copyable nor moveable!");
77 1 Katherine Lato
      SERVICE const* pProv = art::ServiceHandle<SERVICE>()->provider();
78 1 Katherine Lato
      if (!pProv) {
79 1 Katherine Lato
        throw art::Exception(art::errors::NotFound)
80 1 Katherine Lato
          << "Service " << cet::demangle(typeid(SERVICE).name())
81 1 Katherine Lato
          << " returned a null provider!";
82 1 Katherine Lato
      }
83 1 Katherine Lato
      return pProv;
84 1 Katherine Lato
    } // providerFrom()
85 1 Katherine Lato
    
86 1 Katherine Lato
  } // namespace lar
87 1 Katherine Lato
88 1 Katherine Lato
  #endif // COREUTILS_SERVICEUTILS_H
89 1 Katherine Lato
</code></pre>
90 1 Katherine Lato
}}
91 1 Katherine Lato
92 1 Katherine Lato
{{collapse(Example with C code (class: "c"))
93 1 Katherine Lato
<pre><code class="c">
94 1 Katherine Lato
  #include <stdio.h>
95 1 Katherine Lato
  
96 1 Katherine Lato
  int main() {
97 1 Katherine Lato
    int const n = 10;
98 1 Katherine Lato
    for (int i = 0; i < n; ++i) {
99 1 Katherine Lato
      printf ("Loop: %d\n", i);
100 1 Katherine Lato
    } /* for */
101 1 Katherine Lato
    return 0;
102 1 Katherine Lato
  } /* main() */
103 1 Katherine Lato
</code></pre>
104 1 Katherine Lato
}}
105 1 Katherine Lato
106 1 Katherine Lato
{{collapse(Example with python code (class: "python"))
107 1 Katherine Lato
<pre><code class="python">
108 1 Katherine Lato
  import sys
109 1 Katherine Lato
  
110 1 Katherine Lato
  if __name__ == "__main__":
111 1 Katherine Lato
    print "%s got %d command line arguments: '%s'." \
112 1 Katherine Lato
      % (sys.argv[0], len(sys.argv) - 1, "', '".join(sys.argv[1:]))
113 1 Katherine Lato
    sys.exit(0)
114 1 Katherine Lato
  # main
115 1 Katherine Lato
</code></pre>
116 1 Katherine Lato
}}
117 1 Katherine Lato
118 1 Katherine Lato
{{collapse(Example with FHiCL code (class: not supported but "python" may do))
119 1 Katherine Lato
<pre><code class="python">
120 1 Katherine Lato
#include "services.fcl"
121 1 Katherine Lato
122 1 Katherine Lato
BEGIN_PROLOG
123 1 Katherine Lato
my_service: { 
124 1 Katherine Lato
  service_provider: "ReallyMyService"
125 1 Katherine Lato
  
126 1 Katherine Lato
  lower_limit: 10
127 1 Katherine Lato
  upper_limit: 20
128 1 Katherine Lato
  
129 1 Katherine Lato
} # my service
130 1 Katherine Lato
END_PROLOG
131 1 Katherine Lato
132 1 Katherine Lato
services: {
133 1 Katherine Lato
  IMyService: @local::my_service
134 1 Katherine Lato
}
135 1 Katherine Lato
136 1 Katherine Lato
services.IMyService.upper_limit: 30
137 1 Katherine Lato
services.IMyService.upper_limit: @erase
138 1 Katherine Lato
</code></pre>
139 1 Katherine Lato
}}
140 1 Katherine Lato
141 1 Katherine Lato
{{collapse(Example with BASH code (class: not supported))
142 1 Katherine Lato
<pre><code>
143 1 Katherine Lato
#!/usr/bin/env bash
144 1 Katherine Lato
#
145 1 Katherine Lato
# Print the full patch of each argument
146 1 Katherine Lato
#
147 1 Katherine Lato
148 1 Katherine Lato
function ExpandPath() {
149 1 Katherine Lato
  local Path="$1"
150 1 Katherine Lato
  readlink -f "$Path"
151 1 Katherine Lato
} # ExpandPath()
152 1 Katherine Lato
153 1 Katherine Lato
154 1 Katherine Lato
for Param in "$@" ; do
155 1 Katherine Lato
  ExpandPath "$Param"
156 1 Katherine Lato
done
157 1 Katherine Lato
158 1 Katherine Lato
</code></pre>
159 1 Katherine Lato
}}
160 1 Katherine Lato
161 1 Katherine Lato
162 1 Katherine Lato
163 1 Katherine Lato
164 1 Katherine Lato
h2. Custom macro test
165 1 Katherine Lato
166 1 Katherine Lato
_(this is currently incorrect or not working)_
167 1 Katherine Lato
168 1 Katherine Lato
macro :my_macro, :desc => 'This is a custom macro' do |obj, args|
169 1 Katherine Lato
  # args is an array
170 1 Katherine Lato
  # and this macro does not accept a block of text
171 1 Katherine Lato
end
172 1 Katherine Lato
173 1 Katherine Lato
{{my_macro}}
174 1 Katherine Lato
175 1 Katherine Lato
176 1 Katherine Lato
h2. Collapsing text
177 1 Katherine Lato
178 1 Katherine Lato
The following macro creates a collapsible window with the specified text as short description.
179 1 Katherine Lato
The extended text can contain macros; e.g.:
180 1 Katherine Lato
<pre>{{collapse(View details...)
181 1 Katherine Lato
  bq. {{child_pages}}
182 1 Katherine Lato
  This is a block of text that is collapsed by default.
183 1 Katherine Lato
  It can be expanded by clicking a link.
184 1 Katherine Lato
}}</pre>
185 1 Katherine Lato
186 1 Katherine Lato
{{collapse(View details...)
187 1 Katherine Lato
  bq. {{child_pages}}
188 1 Katherine Lato
  This is a block of text that is collapsed by default.
189 1 Katherine Lato
  It can be expanded by clicking a link.
190 1 Katherine Lato
}}
191 1 Katherine Lato
192 1 Katherine Lato
193 1 Katherine Lato
h2. Mathematical formulas with LaTeX
194 1 Katherine Lato
195 1 Katherine Lato
<pre>{{latex($\beta\tau\Theta\theta$)}}</pre>
196 1 Katherine Lato
197 1 Katherine Lato
bq. {{latex($\beta\tau\Theta\theta$)}}
198 1 Katherine Lato
199 1 Katherine Lato
200 1 Katherine Lato
h2. DOT graphs
201 1 Katherine Lato
202 1 Katherine Lato
This seems not to work...
203 1 Katherine Lato
<pre>{{graphviz( a -> b ;)}}</pre>
204 1 Katherine Lato
205 1 Katherine Lato
bq. {{graphviz( a -> b ;)}}
206 1 Katherine Lato
207 1 Katherine Lato
208 1 Katherine Lato
h2. List of supported macros
209 1 Katherine Lato
210 1 Katherine Lato
The following list can be rendered by running the @{{macro_list}}@ macro:
211 1 Katherine Lato
212 1 Katherine Lato
--- 
213 1 Katherine Lato
214 1 Katherine Lato
{{macro_list}}
215 1 Katherine Lato
216 1 Katherine Lato
---