Warning, /rcdaq/doc/rcdaq_doc.tex is written in an unsupported language. File is not indexed.
0001 \documentclass{article}[11pt]
0002 %
0003 %
0004 %
0005 %-------------------------------------------------------------------
0006 \parindent 0pt
0007 \parskip 0.75ex
0008 \renewcommand{\baselinestretch}{1.03}
0009 \renewcommand{\topfraction}{0.9}
0010 \renewcommand{\textfraction}{0.01}
0011 \renewcommand{\floatpagefraction}{0.99}
0012 \addtolength{\textwidth}{6mm}
0013 \addtolength{\textheight}{1cm}
0014 \usepackage{graphicx}
0015 \usepackage{hyperref}
0016 \usepackage{color}
0017 \usepackage{pifont}
0018
0019
0020 \newcommand{\pointout}[1]{
0021 \vskip 3mm
0022 \begin{minipage}[c]{\linewidth}
0023 \hrule
0024 \vskip 2mm
0025 \begin{minipage}[c]{0.1\linewidth}
0026 {\Huge\color{red}\ding{43}}
0027 \end{minipage}
0028 \begin{minipage}[c]{0.9\linewidth}
0029 #1
0030 \end{minipage}
0031 \vskip 2mm
0032 \hrule
0033 \end{minipage}
0034 \vskip 3mm
0035 }
0036
0037 \newcommand{\warning}[1]{
0038 \vskip 3mm
0039 \begin{minipage}[c]{\linewidth}
0040 \hrule
0041 \vskip 2mm
0042 \begin{minipage}[c]{0.1\linewidth}
0043 {\Huge\color{red}{\fontencoding{U}\fontfamily{futs}\selectfont\char 66\relax}}
0044 \end{minipage}
0045 \begin{minipage}[c]{0.9\linewidth}
0046 #1
0047 \end{minipage}
0048 \vskip 2mm
0049 \hrule
0050 \end{minipage}
0051 \vskip 3mm
0052 }
0053
0054
0055
0056
0057 \makeatletter
0058 \def\verbatim{\footnotesize\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
0059 \makeatother
0060
0061 \definecolor{darkred}{rgb}{0.6,0.2,0}
0062
0063
0064 \begin{document}
0065
0066
0067
0068 \title{RCDAQ, a lightweight yet powerful data acquisition system}
0069 \author{Martin L. Purschke}
0070 \maketitle
0071
0072 \tableofcontents
0073
0074 \newpage
0075
0076 \section{Changelog}
0077
0078 \subsection{November 2022}
0079 \begin{itemize}
0080 \item I brought the old file rollover feature from the AML days
0081 back. So far the second section field in fle names had not been used
0082 by RCDAQ. This is controlled by the \verb|daq_set_rollover| command
0083 and takes units of gigabytes (GB).
0084
0085 \end{itemize}
0086
0087 \subsection{February 2022}
0088 \begin{itemize}
0089 \item I cleaned up some of the documentation that was still mentioning
0090 the \verb|daq_open_server| command (this was short-lived and was replaced
0091 with \verb|daq_set_server|).
0092 \item I replaced the somewhat klunky "convert the setup file name to a
0093 full path" commands with \verb|readlink|. Updated here and in the
0094 \verb|setup.sh| example (see pg.~\pageref{setupexample}). Much easier.
0095
0096 \end{itemize}
0097
0098 \subsection{August 2021}
0099 \begin{itemize}
0100 \item I resurrected the remote logging capability to a server (called
0101 the \emph{Super Fast Server}, SFS) for RCDAQ running in large
0102 eperiments (such as sPHENIX). Most of the changes are invisible to
0103 you, and there is no change in operations if you are not using this
0104 way of logging.
0105
0106 \end{itemize}
0107
0108 \subsection{February 20, 2020}
0109 \begin{itemize}
0110 \item I added a command \verb|daq_get_lastfilename| (see
0111 chapter~\ref{CommandOverview}) that returns the most recent (or
0112 current) filename, if any. If you took a run without logging, the
0113 name will be empty. The purpose of this command is for automated,
0114 scripted measurements. You can obtain the last filename \emph{after}
0115 the run has ended, so you can use it to start some analysis on the
0116 file right away after the run ends. Before it was hard to get at
0117 that filename in a script.
0118
0119 \end{itemize}
0120
0121 \subsection{February 13, 2019}
0122 \begin{itemize}
0123 \item I added a new built-in pseudo device \verb|device_gauss|. Its
0124 only role is to provide data to monitor for the tutorial of the
0125 companion ``pmonitor'' manual. I provide a
0126 \verb|setup_pmonitor_tutorial.sh| script that sets all up properly if you want
0127 to run all parts of the tutorial.
0128 \end{itemize}
0129
0130
0131 \subsection{March 13, 2018}
0132 \begin{itemize}
0133 \item I added a new built-in pseudo device \verb|device_rtclock|. It
0134 allows you to measure the event timing, and the distance in time to
0135 the most recent event. See chaper~\ref{eventtiming}
0136 \end{itemize}
0137
0138 \subsection{February 22, 2017}
0139 \begin{itemize}
0140 \item I added the concept of a named RCDAQ instance. We found that we
0141 are often running multiple RCDAQ systems (such as the main DAQ and
0142 the wirechamber readout at Fermilab). This has sometimes led to
0143 confusion which instance you are interacting with. The name
0144 defaults to the hostname, and can be set with
0145 \verb|rcdaq_client daq_setname|, and retrieved with
0146 \verb|rcdaq_client daq_getname|. The aliases have also been
0147 updated to make the command shortcuts, and the GUIs show the name
0148 now, too.
0149 \item The \verb|daq_status| used to show ``logging enabled'', and nothing if
0150 disabled. So the absence of the ``enabled'' message indicated
0151 that we are not logging. That has led to a number of operator
0152 errors. \verb|daq_status| now shows ``enabled'' or ``disabled''.
0153 \item I have added the start of the web service on the standard port
0154 8899 in the template setup script ``\verb|setup.sh|''. If this port
0155 is taken on your system, you need to change it.
0156
0157 \end{itemize}
0158
0159 \subsection{August 30, 2016}
0160 \begin{itemize}
0161 \item Added documentation about the newly implemented web-based controls.
0162 \end{itemize}
0163
0164 \subsection{February 28, 2016}
0165 \begin{itemize}
0166 \item expanded the chapter~\ref{installation} with many more details
0167 and step-by-step instructions
0168 \item added a chapter about the PSI DRS4 evaluation board
0169 \end{itemize}
0170
0171 \subsection{August 27, 2015}
0172 \begin{itemize}
0173 \item added two new devices \verb|device_file_delete| and
0174 \verb|device_filenumbers_delete|, which
0175 delete the file after it has been read. See page~\pageref{delete} for a description and application.
0176 \end{itemize}
0177
0178 \subsection{August 15, 2015}
0179 \begin{itemize}
0180 \item the \verb|rcdaq_server| process now defines a number of environmental
0181 variables, principally for the benefit of \verb|device_command|. The
0182 resulting process, usually a script, can use the variables to obtain important
0183 information it might need. See page~\pageref{environment}.
0184 \end{itemize}
0185
0186 \newpage
0187
0188 \section{Introduction}
0189
0190
0191 \subsection{What This is About}
0192
0193 RCDAQ is a data acquisition package which is used in the R\&D efforts
0194 of the PHENIX and sPHENIX experiments at the Relativistic Heavy Ion
0195 Collider. The experiment has its main data acquisition which fills a
0196 room about size of a squash court. For a variety of R\&D efforts, it
0197 was necessary to get a smaller, portable, and lightweight data
0198 acquisition system which would support test beams, electronics
0199 developments, cosmic ray tests, and the like.
0200
0201 Meanwhile, the system is in use for a number of other projects, such
0202 as a number of PET scanners for medical imaging applications, the
0203 readout of a GEM detector, and for tests and the characterization of
0204 Silicon Photomultipliers.
0205
0206
0207 The development of RCDAQ was governed by a number of design principles:
0208
0209 \begin{description}
0210
0211 \item {\bf format-compatible with the main PHENIX data acquisition
0212 system.} In this way, the readout of a new device needs to get
0213 implemented and debugged only once, and is ready to go once the new
0214 component is integrated in the main DAQ system. This also allows to
0215 reuse most tools, such as online monitoring components, during the
0216 running of the main experiment.
0217
0218 \item {\bf compatible with the PHENIX online monitoring and analysis
0219 framework.} This allows to reuse the code developed during the R\&D
0220 phase and test beams once the new detector or component is installed
0221 in PHENIX. The online monitoring of several new detectors has its
0222 roots in the online monitoring used and refined in a test beam.
0223
0224 \item {\bf lightweight and able to run on most modern Linux distributions.}
0225 You do not have to devote your system to the task of running the
0226 DAQ. (As a rule of thumb, if your system has a working version of the
0227 root package, you will be able to install RCDAQ and the assorted
0228 components). RCDAQ is also able to build and run on a Raspberry Pi.
0229
0230 \item {\bf powerful and fast.} The most demanding device supported by
0231 RCDAQ produces sustained data rates of 400\,MB/s.
0232
0233 \item {\bf client-server based.} This will allow you to work in a
0234 network-transparent way, for example, control the main DAQ running on
0235 a powerful server natively from your desktop or laptop.
0236
0237 \item {\bf based on a plugin concept.} In order to make the package
0238 adaptable to a large number of tasks, most of the actual readout
0239 capabilities and support for the readout of particular devices is
0240 added through plugins. In this way, we are able to make the core
0241 package available outside the PHENIX collaboration because no
0242 proprietary or commercial libraries or drivers (which are needed for
0243 some PHENIX hardware) need to be distributed.
0244
0245 \item {\bf extensive support for automated, scripted acquisitions.}
0246
0247 \item {\bf no configuration \emph{files}}. By definition,
0248 configuration files require you to learn their syntax. In most
0249 cases, configuration file formats, say, XML, do not support loops,
0250 conditions, formal parameters, or error handling, which is why most
0251 systems have moved away from the much-hyped XML format. We already
0252 have the best parser for configuration input -- the Unix shell. It
0253 fulfills all of the above requirements (loops, conditions, parameters,
0254 and error handling). Each interaction with RCDAQ is a Unix shell
0255 command. In this way, there are no configuration files, but
0256 configuration \emph{scripts} which you execute to configure your
0257 system.
0258
0259 \item {\bf Elog Support}. RCDAQ natively supports the \emph{elog}
0260 electronic logbook, developed and maintained by Stefan Ritt at the
0261 Paul-Scherrer Institute in Switzerland. RCDAQ can be configured to
0262 make automated elog entries to help you keep track of the data you
0263 acquire. You can add to the automatically generated entries, for
0264 example, detailing that the High Voltage tripped during the
0265 acquisition, or attach plots or other image files. It gives you an
0266 easily accessible timeline of your data taking efforts.
0267
0268 \end{description}
0269
0270 In the following discussions, you will see the term \emph{``Run''} a
0271 lot. A Run is a collection of events, say, a certain time interval
0272 worth of data, or data taken with a given settings of some
0273 parameters. It is identified by a Run Number that should always
0274 increase during the course of your acquisition. The combination of run
0275 number and event number in that run uniquely identifies an Event that
0276 was read out.
0277
0278 \subsection{What? No configuration files?}
0279 In my opinion, the above-mentioned fact that there are no
0280 configuration files, only scripts, is one of the most versatile
0281 features of this DAQ system. \emph{Each} instruction is a separate command
0282 executed on the shell. Besides the facts that you do not need to learn
0283 a new command interpreter, have loops, conditions, etc, at your
0284 fingertips, the most important feature is that you are not trapped
0285 within the always limited command set of an application. You can freely
0286 interleave RCDAQ commands with other shell commands, and so write
0287 a scripted data acquisition protocol tailored to your needs.
0288
0289 To the best of my knowledge, a group from the Physics Department at
0290 Stony Brook has so far designed the most versatile application of this
0291 concept. The task at hand was to certify a readout plane of a GEM
0292 detector. It involved connecting a probe to a specific pad on the
0293 plane, taking some data, and verify that the correct channel did see the
0294 signal, then moving on to the next pad. It was hard to take either the
0295 probe or your eyes off the board without losing the position.
0296
0297 The group came up with a script that would loop through the pads,
0298 \emph{reading} the pad coordinates and other commands to the operator
0299 by way of a text-to-speech program (festival), so the operator was
0300 free to keep the eyes (and the probe) on the plane at all times. This
0301 is possible because you never leave the shell to interact with RCDAQ.
0302
0303
0304 \section{Data Format Basics}
0305
0306 The PHENIX raw data format defines a number of data structures, most
0307 importantly the concept of \emph{Events} and \emph{Packets}.
0308
0309 Think of a Packet as the data from a given readout device, such as an
0310 ADC board, a digitizer, or something similar. Typically, modern
0311 readout devices provide their data in some form of compact data
0312 structure, which needs to be unpacked later. All that RCDAQ does is to
0313 store the data unmodified with what we call \emph{envelope
0314 information}. That envelope information, here the Packet header,
0315 holds a packet id which uniquely identifies \emph{what} is being read
0316 out.
0317
0318 That id is a number chosen by you more or less arbitrarily, as long
0319 you keep that assignment the same. For example, a typical event in
0320 PHENIX consists of data from about 600 different readout devices
0321 (which we call FEM, Front-End Module), and the same number of packets
0322 in one event. We chose to assign the ids by ``subsystem number''. The
0323 PHENIX Pad Chamber, Subsystem number 4, gets Packet IDs 4001, 4002,
0324 and so on. A given Packet id is meant to identify a particular set of
0325 channels on the detector (those connected to the FEM), and it is your
0326 responsibility to make sure that a given id assignment remains the
0327 same. It is not uncommon in PHENIX to refer to a given Front-End
0328 Module by its never-changing Packet id (``Last night we had trouble
0329 with Pad Chamber Packets 4036 and 4037, and had to adjust the supply
0330 voltage slightly'').
0331
0332 The Packet id, however, does not specify \emph{how} the data are
0333 stored within the Packet. That is done by another field, historically
0334 called the \emph{hitformat}, which indicates what kind of data is kept
0335 in that Packet. This is the field that in the end identifies a
0336 decoding algorithm for the data, and which assures that your analysis
0337 code is shielded from changes in the low-level data format of a given
0338 FEM or other readout device. You do not get to set the hitformat value
0339 yourself -- if you define a device, it then adds its data structure
0340 tagged with the right value.
0341
0342 Over the course of the operation of the PHENIX detector, the low-level
0343 data formats of the FEMs of a given subsystem have changed several
0344 times, usually to make the data more compact by improving the
0345 bit-packing of data, or by removing redundancy in the data which was
0346 initially needed to test and certify the data integrity. Packets with
0347 data in such a different format are simply tagged with a different
0348 hitformat number, which in turn selects a different decoding
0349 algorithm. Your analysis code is never exposed to those internals. In
0350 this way we are free to change the FEM data formats without ever
0351 breaking existing analysis code.
0352
0353 An \emph{Event} structure is simply a collection/concatenation of such
0354 packets, with the next layer of envelope information, this time the
0355 Event header. This header holds an Event number, event type, a timestamp,
0356 length, and similar bookkeeping information.
0357
0358 Events and Packets are the only objects you will likely encounter in
0359 the course of analyzing data taken with RCDAQ. The raw data files
0360 group a number of Events in what we call a \emph{Buffer}, although
0361 this is just a storage-technology concept and mostly invisible to
0362 you. I say ``mostly'' because the design is such that, although your
0363 code is shielded from internals such as buffers and hitformat
0364 differences, the interface libraries still make it easy to access this
0365 kind of information for debugging purposes.
0366
0367 The raw data files are lightweight, and have a number of convenient
0368 features, most notably the fact that one can concatenate two valid
0369 raw data files and obtain again a valid file.
0370
0371 All interfaces to the raw data are provided in what we call the
0372 \emph{Event Library}, which loads in root and teaches root how to deal
0373 with our data format. Although it is rare to write an actual main
0374 program, the library also exists without root bindings.
0375
0376 There is a ton of documentation on the PHENIX web pages about the software, to be
0377 found at
0378 \url{http://www.phenix.bnl.gov/~phoncs/oncs/code_documentation/Event/index.html}.
0379
0380 You should definitely familiarize yourself with the concepts and read
0381 the ``Events and Packets'' chapter
0382 \url{http://www.phenix.bnl.gov/~phoncs/oncs/code_documentation/Event/Eventsandpackets.html},
0383 and also learn about the indispensable data inspection tools such as
0384 \verb|dlist| and \verb|ddump| in
0385 \url{http://www.phenix.bnl.gov/~phoncs/oncs/code_documentation/Event/dlistddumpanddpipe.html}.
0386
0387
0388
0389 \section{RCDAQ Principles of Operation}
0390
0391 The rcdaq main process is formally a server running in the
0392 background. It writes a very modest amount of output to a log file,
0393 but does not accept any kind of input directly.
0394
0395 All control is performed by clients connecting to the RCDAQ process
0396 and instructing it to perform a particular task, such as loading a
0397 plugin, start or stop taking data, setting parameters, and the
0398 like. The underlying protocol is a \emph{Remote Procedure Call} (RPC),
0399 a network protocol for client-server interaction. It is widely used
0400 and stable because the extremely common Network File system (NFS) is
0401 based on the RPC protocol, and is available on virtually any operating
0402 system.
0403
0404 At the core of the readout is the \emph{readlist}. This is a list of
0405 devices registered with RCDAQ to be read out. When an external trigger
0406 arrives (more about this is a minute), RCDAQ goes through the
0407 readlist, and each defined readout device adds a Packet to the Event
0408 structure under construction.
0409
0410 The RPC protocol makes the interaction with RCDAQ
0411 network-transparent. Your client doesn't need to run on the same
0412 machine (of course it can); in fact, it can be anywhere as long as
0413 the RPC protocol is able to traverse the routers and firewalls.
0414
0415
0416 \section{Running RCDAQ}
0417 \label{running}
0418
0419 Let's take RCDAQ for a quick spin. RCDAQ knows a built-in ``pseudo
0420 device'' which pretends to be reading out some kind of ADC or TDC,
0421 except that it fills in some random numbers. I made this ``device'' in
0422 order to allow to test-drive RCDAQ without the need for any actual
0423 acquisition hardware.
0424
0425 \pointout{I provide a guaranteed-to-work setup script ``{\tt setup.sh}'' with
0426 the RCDAQ source code. It exercises a number of features that will be
0427 presented in the next chapters. It uses the pseudo devices we will see
0428 in a minute. This script allows you to test the proper working of a
0429 RCDAQ installation.}
0430
0431
0432 For now, get yourself two terminal windows on the machine that has
0433 RCDAQ installed. We will run the RCDAQ server and clients
0434 interactively. Later, you will likely run the actual server in the
0435 background that writes to a logfile.
0436
0437 In terminal 1 (after the one sole command we will leave this alone), type
0438 \begin{verbatim}
0439 rcdaq_server
0440 \end{verbatim}
0441
0442 Just to see that we communicate to the just-started server, we type,
0443 in terminal 2,
0444 \begin{verbatim}
0445 rcdaq_client daq_status
0446 \end{verbatim}
0447
0448 and you should see the answer ``Stopped''. In a moment, we will see
0449 how to make those unwieldy ``rcdaq\_client ....'' commands more
0450 convenient, but for now, we will continue with this style for a few
0451 more commands.
0452
0453 The ``-l'' switch we will see in the next command stands for
0454 ``long''. Multiple ``-l'' switches will accumulate, although
0455 at this stage there is no more information to be had. Later we will look
0456 at a ``double-ell'' -- ``-ll'' -- switch output.
0457
0458 \begin{verbatim}
0459 $ daq_status -l
0460 Stopped
0461 Logging disabled
0462 Filerule: rcdaq-%08d-%04d.evt
0463 Buffer Sizes: 32832 KB adaptive buffering: 15 s
0464 Web control Port: 8899
0465 Elog: not defined
0466 -- defined Run Types: (none)
0467 No Plugins loaded
0468 \end{verbatim}
0469
0470 The last line says that we have not acquainted RCDAQ with any particular
0471 hardware -- as I said in the introduction, except for a very small
0472 number of natively built-in ``devices'', all support for actual
0473 readout hardware is loaded by the assorted plugin.
0474
0475 The ``Buffer Sizes'' and their setting are of interest and can be
0476 tweaked in a number of situations; we will ignore this for now.
0477
0478 The Filerule will govern the generation of data file names later. It
0479 is used as a ``printf''-style format statement, where the printf takes
0480 two integer parameters. The ``\%08d'' and ``\%04d'' formats make an 8-
0481 and 4-digit number field padded with leading zeroes:
0482
0483 \begin{verbatim}
0484 $ printf rcdaq-%08d-%04d.evt 1333 0
0485 rcdaq-00001333-0000.evt
0486 \end{verbatim}
0487
0488 The first number is the current run number, and the second is a ``file
0489 sequence number''. This number is used when files are rolled over after the
0490 previous file reached its pre-set rollover limit.
0491
0492 The file rule can be changed at any time. The next data file will be
0493 named according to the current rule.
0494
0495 Note that the rule above with the zero-padded fields will prevent
0496 spaces in file names, but the rule can really be set to anything. You
0497 must check that your rule generates valid and useful file names. You
0498 would normally choose a full path, such as
0499
0500 \begin{verbatim}
0501 /data/rcdaq/beamdata-%08d-%04d.evt
0502 \end{verbatim}
0503
0504
0505 Finally we create a new readout device that fills our pretend-ADC data
0506 with random numbers:
0507
0508 \begin{verbatim}
0509 rcdaq_client create_device device_random 1 1001 32 0 2048 1
0510 \end{verbatim}
0511
0512 The command ``create\_device'' takes the device type (device\_random),
0513 the event type in which it is read out (1), the packet id (1001), how
0514 many ``channels'' we want our device to have (32), the lower and upper
0515 bounds of the random number distribution (0 - 2048). In general, the
0516 parameters past the packet id are highly device-specific and will
0517 configure the device as in this example. The final ``1'' means that
0518 we designate this device as the one which actually generates the
0519 trigger for the DAQ. We might have multiple devices which are
0520 trigger-capable, so we need to specify this. If you do not specify any
0521 trigger device, you will not get any events.
0522
0523 As a convention (which you can ignore, of course), most RCDAQ users
0524 use packet ids above 1000 in devices read in data events, and in the
0525 800 or 900 block for other event types (which we haven't mentioned
0526 yet). It's just a convention.
0527
0528
0529 We can look at the defined readlist with
0530
0531 \begin{verbatim}
0532 $ rcdaq_client daq_list_readlist
0533 Random Device Event Type: 1 Subevent id: 1001 n_words: 32 range: 0 - 2048 ** Trigger enabled
0534 $
0535 \end{verbatim}
0536
0537 which gives a brief description of the device and the parameters.
0538
0539 Now we start a run with number 1 (but keep in mind that we have not
0540 specified that we want to write any data to disk yet):
0541
0542 \begin{verbatim}
0543 $ rcdaq_client daq_begin 1
0544 Run 1 started
0545 \end{verbatim}
0546
0547 After a moment, we look at the status:
0548
0549 \begin{verbatim}
0550 $ rcdaq_client daq_status
0551 Run 1 Event: 1054 Volume: 0.176605
0552 \end{verbatim}
0553
0554 It now indicates that we have a run 1, and we are currently at event
0555 1054. The volume is given in megabytes.
0556
0557 After a while we end the run:
0558
0559 \begin{verbatim}
0560 $ rcdaq_client daq_end
0561 Run 1 ended
0562 \end{verbatim}
0563
0564 When we start the next run without a number, the next number will be used:
0565
0566 \begin{verbatim}
0567 $ rcdaq_client daq_begin
0568 Run 2 started
0569 $ rcdaq_client daq_end
0570 Run 2 ended
0571 \end{verbatim}
0572
0573 Now we specify that we want to actually write data to disk, start a
0574 run (number 3), and look at the ``long'' status:
0575
0576 \begin{verbatim}
0577 $ rcdaq_client daq_open
0578 $ rcdaq_client daq_begin
0579 Run 3 started
0580 $ daq_status -l
0581 Running
0582 Run Number: 3
0583 Event: 836
0584 Run Volume: 0.357658 MB
0585 Filerule: rcdaq-%08d-%04d.evt
0586 Duration: 18 s
0587 Buffer Sizes: 32832 KB adaptive buffering: 15 s
0588 Web control Port: 8899
0589 Elog: not defined
0590 -- defined Run Types: (none)
0591 No Plugins loaded
0592 \end{verbatim}
0593
0594 We see that in addition to the file rule, we now also see the actual
0595 open file name that was derived from the rule.
0596
0597 After you end the run, you will find (in this case with the default
0598 file rule) that file in the directory where you started the
0599 rcdaq\_server.
0600
0601 Let's take a quick peek at the data file. Without going into all the
0602 details, let's run ``dlist'', which lists the packets found in a data
0603 event:
0604
0605 \begin{verbatim}
0606 $ dlist -i rcdaq-00000003-0000.evt
0607 -- Event 2 Run: 3 length: 44 type: 1 (Data Event) 1363583279
0608 Packet 1001 68 -1 (sPHENIX Packet) 6 (ID4EVT)
0609 $
0610 \end{verbatim}
0611
0612 ddump will inspect a packet and print out its content in an
0613 interpreted fashion. ddump is a versatile utility which allows to
0614 inspect the data in a myriad of ways. Here is one:
0615
0616 \begin{verbatim}
0617 $ ddump -i rcdaq-00000003-0000.evt
0618 -- Event 2 Run: 3 length: 44 type: 1 (Data Event) 1363583279
0619 Packet 1001 68 -1 (sPHENIX Packet) 6 (ID4EVT)
0620
0621 0 | 5dd 512 403 152
0622 4 | 160 51d 380 399
0623 8 | 6d8 12 557 19d
0624 c | 672 4f4 525 48
0625 10 | 759 33a 759 51a
0626 14 | 6aa 7fd 270 c8
0627 18 | 4bd 4df 22a 6cf
0628 1c | 1cb 7ff 3fa 653
0629 $
0630 \end{verbatim}
0631
0632 This says it is event number 2. We can look at event 3 with the ``-e 3'' switch:
0633
0634 \begin{verbatim}
0635 $ ddump -i -e 3 rcdaq-00000003-0000.evt
0636 -- Event 3 Run: 3 length: 44 type: 1 (Data Event) 1363583279
0637 Packet 1001 68 -1 (sPHENIX Packet) 6 (ID4EVT)
0638
0639 0 | b0 529 22 306
0640 4 | 77e 4e1 3a0 bd
0641 8 | 1c0 7ce 717 6a0
0642 c | 1dd 343 4db 3e0
0643 10 | 5e5 4e9 761 179
0644 14 | 324 50f 705 3a6
0645 18 | f7 17 c8 178
0646 1c | 127 16 409 11a
0647 $
0648 \end{verbatim}
0649
0650 This is just to show that the next event has different (random) numbers.
0651
0652
0653 \section{Making the commands more convenient}
0654 \label{convenience}
0655
0656 We have so far used the ``long'' versions of each rcdaq command, such as
0657
0658 \begin{verbatim}
0659 $ rcdaq_client daq_begin 1
0660 \end{verbatim}
0661
0662 That is a lot of typing, and so we provide a script which you can source and
0663 which sets up each command as a short-hand alias, for example,
0664 \verb|daq_begin| will be an alias for \verb|rcdaq_client daq_begin|.
0665
0666 There are two versions of the script, one for the bash shell (aliases.sh), and
0667 one for csh and its derivatives. You simple execute (note the back-ticks)
0668
0669 \begin{verbatim}
0670 $ source `which aliases.sh`
0671 \end{verbatim}
0672
0673 or
0674
0675 \begin{verbatim}
0676 > source `which aliases.csh`
0677 \end{verbatim}
0678
0679 depending on your preferred shell.
0680
0681 In scripts you should \emph{always} use the long form of the commands.
0682
0683 Here are the aliases that you get:
0684
0685 \begin{verbatim}
0686 alias daq_begin='rcdaq_client daq_begin'
0687 alias daq_end='rcdaq_client daq_end'
0688 alias daq_setrunnumberfile='rcdaq_client daq_setrunnumberfile'
0689 alias daq_define_runtype='rcdaq_client daq_define_runtype'
0690 alias daq_set_runtype='rcdaq_client daq_set_runtype'
0691 alias daq_get_runtype='rcdaq_client daq_get_runtype'
0692 alias daq_list_runtypes='rcdaq_client daq_list_runtypes'
0693 alias daq_setfilerule='rcdaq_client daq_setfilerule'
0694 alias daq_set_server='rcdaq_client daq_set_server'
0695 alias daq_open='rcdaq_client daq_open'
0696 alias daq_close='rcdaq_client daq_close'
0697 alias daq_fake_trigger='rcdaq_client daq_fake_trigger'
0698 alias daq_list_readlist='rcdaq_client daq_list_readlist'
0699 alias daq_clear_readlist='rcdaq_client daq_clear_readlist'
0700 alias daq_status='rcdaq_client daq_status'
0701 alias daq_set_maxevents='rcdaq_client daq_set_maxevents'
0702 alias daq_set_maxvolume='rcdaq_client daq_set_maxvolume'
0703 alias daq_set_maxbuffersize='rcdaq_client daq_set_maxbuffersize'
0704 alias daq_set_rolloverlimit='rcdaq_client daq_set_rolloverlimit'
0705 alias daq_setname='rcdaq_client daq_setname'
0706 alias daq_set_adaptivebuffering='rcdaq_client daq_set_adaptivebuffering'
0707 alias daq_shutdown='rcdaq_client daq_shutdown'
0708 alias daq_webcontrol='rcdaq_client daq_webcontrol'
0709 alias daq_get_lastfilename="rcdaq_client daq_get_lastfilename"
0710 \end{verbatim}
0711
0712 If you routinely use a specific account for rcdaq work, you should add the
0713 respective source command to the login files.
0714
0715
0716 \section{Event types and what they are good for}
0717
0718 A program able to read the data from your detector and writing the data
0719 to a file does not yet qualify as a data acquisition - what is needed
0720 are features that allow you to automate acquisitions, and add
0721 arbitrary ``outside'' data to your data stream. It also needs to
0722 support your online monitoring needs.
0723
0724 Let's say that you want to perform a gain scan by varying some HV
0725 setting for your detector in a number of steps. In the old days, you
0726 would probably have made a table in a paper logbook:
0727
0728 \begin{center}
0729
0730 \begin{tabular}{|c|r|r|}
0731 \hline
0732 Run Number & HV & Gain \\
0733 \hline
0734 \hline
0735 2001 & 1710 & \\ \hline
0736 2002 & 1720 & \\ \hline
0737 2003 & 1730 & \\ \hline
0738 2004 & 1740 & \\ \hline
0739 2005 & 1750 & \\ \hline
0740 \dots & \dots & \\ \hline
0741 \hline
0742 \end{tabular}
0743 \end{center}
0744
0745 In the analysis phase, you would need to communicate
0746 these values to your analysis process somehow, probably ending up with
0747 a text file which tabulates HV and gain values with some error
0748 information which you use to finally produce the desired plot.
0749
0750 This looks like a lot of tedious, manual, and error-prone labor -- it
0751 is easy to make a mistake transcribing the HV values to the table, or
0752 ``slip'' an entry and get the alignment of the columns wrong. It is
0753 also largely not automated. In my experience, you will re-do the
0754 analysis of such data sets many times over, and automation of the
0755 procedure will help save a lot of time.
0756
0757 One of the most powerful features of RCDAQ, which is at the core of
0758 those acquisitions and later analysis of the data ``on autopilot'', are
0759 different \emph{Event Types}. You would typically think of a data
0760 acquisition as something that ``reads out your detector'' -- the ADCs
0761 and TDCs and whatever it is you want to read out. In addition,
0762 however, there is often the need to read other devices at different times.
0763
0764 Here is a real-world example from a previous DAQ of mine at the
0765 CERN-SPS, which has also been used at BNL's AGS. Both accelerators
0766 feature an extraction cycle -- the ring gets filled, the beam
0767 accelerated, and then the beam is extracted and delivered to your
0768 beamline. The SPS cycle is about 14s, 10s of acceleration followed by
0769 about 4s of extracted beam. The accelerator furnishes you with two
0770 signals, one that indicates that the extraction is imminent (``Spill
0771 on''), the other saying that the extraction has ended (``Spill
0772 off''). During the extraction, you obviously want to ``read your
0773 detector'', but most likely you will also need to know what the
0774 intensity of each extraction (spill) was, in order to make
0775 intensity-dependent corrections later, or study the effects on the
0776 detector's gain by the delivered beam intensity. In order to do that,
0777 you will need to read out some scalers which count the signals from
0778 your beam counter, and likely other signals as well.
0779
0780 At CERN and at the AGS, I used the accelerator signals to trigger
0781 special ``spill on'' and ``spill off'' events.\footnote{At this point
0782 in time, spill-on or -off special events can only be generated if
0783 you use a CAEN V1718 VME-USB bridge. } They get assigned different
0784 event types, and when those events are generated, they traverse
0785 different readlists. You would typically set the different readlists
0786 up in a way that the spill-on event doesn't actually read anything,
0787 but simply resets the scalers. The readlist of the spill-off event has
0788 then the actual readout of the scaler. This setup allows you to know
0789 the intensity of each spill. Remember -- different event types mean
0790 different readlists.
0791
0792 In addition, two more special events are automatically generated in
0793 each run. One is the \emph{Begin-Run Event}, the other the
0794 \emph{End-Run Event}. You cannot prevent the generation of those
0795 events, and all the promised benefits come with these two event types.
0796
0797 Let me convince you that the begin- and end-run events are actually present in
0798 the data file we just took. dlist and dpipe, by default, only look at
0799 data events, and we have to explicitly ask to see special events:
0800
0801 \begin{verbatim}
0802 $ dlist -i -t S rcdaq-00000003-0000.evt
0803 -- Event 1 Run: 3 length: 8 type: 9 (Begin Run Event) 1363583279
0804 $ dlist -i -t 12 rcdaq-00000003-0000.evt
0805 -- Event 23125 Run: 3 length: 8 type: 12 (End Run Event) 1363583519
0806 $
0807 \end{verbatim}
0808
0809 Since we have not specified any devices to be read in the begin- or end-run event,
0810 no packets are listed. Those events are present but empty.
0811
0812 Before I explain why those special events are so tremendously useful,
0813 let me first list the defined event types. You should \emph{not}
0814 invent new event types, since those are not known and understood by the
0815 analysis software (never mind that RCDAQ cannot generate them anyway,
0816 unless you modify the code).
0817
0818 \begin{center}
0819 \begin{tabular}{|r|l|l|}
0820 \hline
0821 Event type & meaning & comment \\
0822 \hline
0823 \hline
0824 1 & Data Event & Readout of detector hardware\\ \hline
0825 2 & Streaming Data Event & Streaming Readout of detector hardware\\ \hline
0826 3 \dots 7 & Data Events & Not normally used by RCDAQ \\ \hline
0827 8 & Spill-On Event & \\ \hline
0828 9 & Begin-Run Event & Automatically generated by RCDAQ \\ \hline
0829 12 & End-Run Event & Automatically generated by RCDAQ \\ \hline
0830 14 & Scaler Event & Not normally used by RCDAQ \\ \hline
0831 16 & Spill-Off Event & \\ \hline
0832 \hline
0833 \end{tabular}
0834 \end{center}
0835
0836 You may notice that the events which can be triggered by a hardware
0837 signal ( Data, spill-on, spill-off) have numbers which are powers of
0838 2. The historic reason for this is that you typically use some kind of
0839 input register to distinguish the source of a hardware trigger, and
0840 the binary value of such a register then reads 1,2,4,8,... for the different
0841 inputs.
0842
0843 At long last, here's why those special events (the ones
0844 actually generated by RCDAQ) are so useful.
0845
0846 \begin{itemize}
0847 \item it is guaranteed that the begin-run event is the first event of
0848 a given run in the data stream. Similarly, the end-run event will be
0849 the last event in the run. If you have a continuous data stream that
0850 keeps on delivering events, such as the stream that feeds your
0851 online monitoring processes, those events can serve as convenient
0852 markers that a run has started or ended. On receipt of the begin-run
0853 event, you would typically clear your monitoring histograms and start
0854 histogramming the data from the new run. When you recognize the
0855 end-run event, you might choose to save the histograms for later
0856 review.
0857
0858 \item you can add information such as the aforementioned HV setting to
0859 the begin-run event (this is not actually specific to special
0860 events, but it will probably only make sense here). I will show you
0861 in the next chapter how to accomplish this. In the begin-run event
0862 you will then find some packets that contain the data which you are
0863 interested in.
0864
0865 \end{itemize}
0866
0867 Lets now see how you would go about adding some arbitrary information to your data
0868 stream.
0869
0870 \subsection{Pseudo Devices}
0871
0872 ``Pseudo Devices'' are those which do not connect to any actual
0873 readout hardware, or just perform some action without reading any
0874 data. The ``device\_random'' we have used before is in this group.
0875
0876 The most prominent pseudo devices are
0877 \begin{description}
0878
0879 \item[\bf device\_file] this device absorbs the contents of another
0880 (small\footnote{Without going into all the details: if your file is
0881 expected to be larger than 128KB, you need to say how big it
0882 is. RCDAQ needs to calculate the worst-case maximum event size per
0883 event type, although virtually all events will be smaller due to
0884 zero-suppression. RCDAQ knows the maximum sizes of each device
0885 except this one.}) file as its readout. In this way, you can add the
0886 contents of any other file to your data stream. You can use this to
0887 add a description, or add automatically generated files, or even an
0888 image to the data stream. If the file does not exist, no packet is
0889 generated. You can see on page~\pageref{packet900} how we use this
0890 feature to self-document the RCDAQ setup itself. It is not uncommon
0891 to have a large number of such file devices in the begin-run event
0892 -- at a recent test beam we had about 60 of them to capture all
0893 relevant detector settings for each run.
0894
0895 \item[\bf device\_file\_delete] \label{delete}like device\_file,
0896 except that this device also deletes the file after it has been
0897 read. {\bf Use this device with caution.} This device was added to
0898 allow you to \emph{occasionally} add some information to the data
0899 stream. Let's say that you want some ``slow'' readout added, for
0900 eample, a temperature reading. Since no packet is generated if the
0901 file does not exist, you can define a device\_file\_delete to the
0902 readout of data events, and most events will not have the
0903 packet. But every few minutes, an external process, such as a cron
0904 job, could generate the file with the temperature information. It
0905 will be added as a packet in the next event and subsequently
0906 deleted, so it would be added to one event only. In this way you
0907 could track the temperature over time.
0908
0909
0910 \item[\bf device\_filenumbers] this device reads a text file and looks for
0911 (integer) numbers on a line all by themselves. While the
0912 device\_file adds the original text, device\_filenumbers discards
0913 the text and adds those numbers in binary form. This makes them
0914 much easier accessible in the later analysis.
0915
0916 \item[\bf device\_filenumbers\_delete] like device\_filenumbers, except
0917 that this device also deletes the file after it has been read. See
0918 the explanation of device\_file\_delete above.
0919
0920 \item[\bf device\_command] this device does not add any data but executes
0921 an arbitrary command. This way, you can trigger actions at certain
0922 times. {\bf You must not call rcdaq\_client commands from the
0923 command, as this leads to a deadlock.} As a convenience, rcdaq
0924 defines a number of environmental variables to the process executing
0925 the command, which make it easier for a script to obtain dynamic
0926 information. The variables defined are \label{environment}
0927 \begin{description}
0928 \item[DAQ\_RUNNUMBER] The current runnumber
0929
0930 \item[DAQ\_FILERULE] The current file rule that generates the file names
0931
0932 \item[DAQ\_STARTTIME] The starttime of the run as a Unix timestamp value
0933
0934 \item[DAQ\_FILENAME] The current file name. If logging is not
0935 enabled, this variable will be empty. In this way you can find out
0936 if we are logging.
0937
0938 \item[DAQ\_ELOGHOST, DAQ\_ELOGPORT, DAQ\_ELOGLOGBOOK] the coordinates
0939 of the elog server. This allows you to add or edit elog entries
0940 from a script. If no Elog is defined, the variables are empty.
0941 \end{description}
0942
0943 \item[\bf device\_random] we have already seen the random
0944 number-generating device in the example above.
0945
0946
0947 \item[\bf device\_deadtime] this device can add a configurable amount
0948 of artificial deadtime anywhere in the traversal of the readlist. I
0949 could envision a few applications in actual data taking, but mostly
0950 this is a debugging tool that can be used to slow down the data
0951 rate, but also to make the event loop run as fast as possible
0952 (enable this device to trigger but set zero deadtime) for benchmarks
0953 or debugging. It can optionally pretend to generate adjustable
0954 amounts of data. Different from daq\_device\_random, it wastes no
0955 time to fill in any meaningful values. If you then enable writing,
0956 one can benchmark the ``empty'' DAQ speed. See
0957 chapter~\ref{speedtests} for details.
0958
0959 \item[\bf device\_rtclock] this device records the current
0960 high-resolution system clock value, as well as the same value from
0961 the most-recent event where this ``device'' was read. See
0962 chapter~\ref{eventtiming} for an example how to use this.
0963
0964 \item[\bf device\_gauss] is here mainly for convenience as the
0965 companion ``pmonitor'' manual references it for its tutorial
0966 section. I provide a \verb|setup_pmonitor_tutorial.sh| script that
0967 sets everything up to run the monitoring part of the tutorial.
0968
0969 \end{description}
0970
0971 \pointout{Be sure to read to the end of the chapter where, after the following
0972 explanations, I point out a nice self-documentation feature.}
0973
0974 Now let's go and get the HV setting of our detector added to the data
0975 stream. We typically have some kind of command interface to the HV
0976 system. I use the PHENIX hvclient here in the example, but let me
0977 stress that any such utility which can print some output to the screen
0978 will fit the bill.
0979
0980 We add two devices to the begin-run event:
0981
0982 \begin{verbatim}
0983 $ rcdaq_client create_device device_file 9 910 hv_readback.txt
0984 $ rcdaq_client create_device device_filenumbers 9 911 hv_readings.txt
0985 \end{verbatim}
0986
0987 Out readlist now looks like this:
0988
0989 \begin{verbatim}
0990 $ rcdaq_client daq_list_readlist
0991 Random Device Event Type: 1 Subevent id: 1001 n_words: 32 range: 0 - 2048 ** Trigger enabled
0992 File Device Event Type: 9 Subevent id: 910 reading from hv_readback.txt
0993 File Number Reader Event Type: 9 Subevent id: 911 reading from hv_readings.txt
0994 $
0995 \end{verbatim}
0996
0997
0998 I then capture the output of the HV command interface in the
0999 ``hv\_readback.txt'' file:
1000
1001 \begin{verbatim}
1002 $ hvclient -b -s BB dv > hv_readback.txt
1003 $ cat hv_readback.txt
1004 HV_BB_S-1 1461 -1724.2 -1725.7 -2443.8 1 1 13
1005 HV_BB_S-2 1461 -2057.4 -2059 -2578.3 1 1 13
1006 HV_BB_S-3 1461 -1809.8 -1811.5 -2886.6 1 1 13
1007 HV_BB_S-4 1461 -2227.1 -2227.6 -3157.1 1 1 13
1008 HV_BB_S-5 1461 -2170.4 -2171.2 -3075.6 1 1 13
1009 HV_BB_S-6 1461 -1563.2 -1563.7 -1938.1 1 1 13
1010 HV_BB_S-7 1461 -1739.4 -1738.8 -2785 1 1 13
1011 HV_BB_S-8 1461 -2080.9 -2081.8 -2955.1 1 1 13
1012 HV_BB_N-1 1461 -1641.6 -1641.8 -2276 1 1 13
1013 HV_BB_N-2 1461 -2494.2 -2494.5 -3089.6 1 1 13
1014 HV_BB_N-3 1461 -1779.7 -1781.3 -2839.2 1 1 13
1015 HV_BB_N-4 1461 -1956.6 -1957.9 -2711.5 1 1 13
1016 HV_BB_N-5 1461 -1492.8 -1493.2 -2107.1 1 1 13
1017 HV_BB_N-6 1461 -2220.2 -2221.1 -2754.8 1 1 13
1018 HV_BB_N-7 1461 -1998.8 -1999.2 -3192.7 1 1 13
1019 HV_BB_N-8
1020 $
1021 \end{verbatim}
1022
1023 This gives the name of the HV channel, the hardware (LeCroy 1461), the
1024 demand voltage, the actual voltage, and so on. This file will end up
1025 in packet 910 as normal text.
1026
1027 Now we process the file to take the 4th column (the actual voltage),
1028 multiply by 100 to get an integer with the right range, and write to a
1029 new file ``hv\_readings.txt'':
1030
1031 \begin{verbatim}
1032 $ cat hv_readback.txt | awk '{print $4 , "*100"}' | bc | sed 's/\..*//' > hv_readings.txt
1033 $ cat hv_readings.txt
1034 -172570
1035 -205900
1036 -181150
1037 -222760
1038 -217120
1039 -156370
1040 -173880
1041 -208180
1042 -164180
1043 -249450
1044 -178130
1045 -195790
1046 -149320
1047 -222110
1048 -199920
1049 -175350
1050 \end{verbatim}
1051
1052 Each number on a line will be added to packet 911 in binary.
1053
1054 Now we start and end a run:
1055
1056 \begin{verbatim}
1057 $ rcdaq_client daq_begin
1058 Run 4 started
1059 $ daq_status -l
1060 Running
1061 Run Number: 4
1062 Event: 381
1063 Run Volume: 0.163261 MB
1064 Filerule: rcdaq-%08d-%04d.evt
1065 Duration: 8 s
1066 Buffer Sizes: 32832 KB adaptive buffering: 15 s
1067 Web control Port: 8899
1068 Elog: not defined
1069 -- defined Run Types: (none)
1070 No Plugins loaded
1071 $ rcdaq_client daq_end
1072 Run 4 ended
1073 $
1074 \end{verbatim}
1075
1076 If we now look what the begin-run event has, we see
1077
1078 \begin{verbatim}
1079 $ dlist -i -t 9 rcdaq-00000004-0000.evt
1080 -- Event 1 Run: 4 length: 324 type: 9 (Begin Run Event) 1363614653
1081 Packet 910 296 -1 (sPHENIX Packet) 4 (IDCSTR)
1082 Packet 911 20 -1 (sPHENIX Packet) 6 (ID4EVT)
1083 $
1084 \end{verbatim}
1085
1086 We see packet 910, which says it is a "IDCSTR" packet, meaning it
1087 contains text, and 911, which is of type "I4EVT" (the same as our
1088 random-number packet), which contains a vector of integer
1089 numbers. Let's look inside:
1090
1091
1092 \begin{verbatim}
1093 $ ddump -i -t 9 -p 910 rcdaq-00000004-0000.evt
1094 -- Event 1 Run: 4 length: 324 type: 9 (Begin Run Event) 1363614653
1095 HV_BB_S-1 1461 -1724.2 -1725.7 -2443.8 1 1 13
1096 HV_BB_S-2 1461 -2057.4 -2059 -2578.3 1 1 13
1097 HV_BB_S-3 1461 -1809.8 -1811.5 -2886.6 1 1 13
1098 HV_BB_S-4 1461 -2227.1 -2227.6 -3157.1 1 1 13
1099 HV_BB_S-5 1461 -2170.4 -2171.2 -3075.6 1 1 13
1100 HV_BB_S-6 1461 -1563.2 -1563.7 -1938.1 1 1 13
1101 HV_BB_S-7 1461 -1739.4 -1738.8 -2785 1 1 13
1102 HV_BB_S-8 1461 -2080.9 -2081.8 -2955.1 1 1 13
1103 HV_BB_N-1 1461 -1641.6 -1641.8 -2276 1 1 13
1104 HV_BB_N-2 1461 -2494.2 -2494.5 -3089.6 1 1 13
1105 HV_BB_N-3 1461 -1779.7 -1781.3 -2839.2 1 1 13
1106 HV_BB_N-4 1461 -1956.6 -1957.9 -2711.5 1 1 13
1107 HV_BB_N-5 1461 -1492.8 -1493.2 -2107.1 1 1 13
1108 HV_BB_N-6 1461 -2220.2 -2221.1 -2754.8 1 1 13
1109 HV_BB_N-7 1461 -1998.8 -1999.2 -3192.7 1 1 13
1110 HV_BB_N-8 1461 -1752.2 -1753.5 -2485.3 1 1 13
1111 $ ddump -t 9 -p 911 -g -d rcdaq-00000004-0000.evt
1112 Packet 911 20 -1 (sPHENIX Packet) 6 (ID4EVT)
1113
1114 0 | -172570 -205900 -181150 -222760 -217120 -156370
1115 6 | -173880 -208180 -164180 -249450 -178130 -195790
1116 12 | -149320 -222110 -199920 -175350
1117 $
1118 \end{verbatim}
1119
1120 Mission (almost) accomplished. If you run an HV scan from a script
1121 that steps through a number of HV settings, it is easy to add the
1122 HV-capturing commands to that script. However, if you are in a mode
1123 where you start and stop runs manually, it is easy to forget to update
1124 the files each time.
1125
1126 This is where our final pseudo device is coming in, the
1127 ``device\_command''. We will use this to automatically execute the
1128 HV-capturing commands at begin-run. Since especially the second
1129 command has a large number of characters which would need to be
1130 escaped when used on the command line, we sidestep all those issues
1131 and put the two commands into a script, and then just execute the
1132 script.
1133
1134 \begin{verbatim}
1135 $ cat hvcapture.sh
1136 #! /bin/sh
1137 hvclient -b -s BB dv > hv_readback.txt
1138 cat hv_readback.txt | awk '{print $4 , "*100"}' | bc | sed 's/\..*//' > hv_readings.txt
1139 $
1140 \end{verbatim}
1141
1142 First, we need to start over with our readlist, because we have to make it so that the
1143 new command is executed \emph{before} the files are accessed. We delete the readlist:
1144
1145 \begin{verbatim}
1146 $ rcdaq_client daq_clear_readlist
1147 Readlist cleared
1148 $
1149 \end{verbatim}
1150
1151 Now we add the command, and the two file-reading devices. You need to make sure
1152 that the script is executable and properly found by the server process. You would probably
1153 want to specify an absolute path to the script later.
1154
1155 \begin{verbatim}
1156 $ rcdaq_client create_device device_command 9 0 './hvcapture.sh'
1157 $ rcdaq_client create_device device_file 9 910 hv_readback.txt
1158 $ rcdaq_client create_device device_filenumbers 9 911 hv_readings.txt
1159 $ rcdaq_client daq_list_readlist
1160 Command Device Event Type: 9 executing ./hvcapture.sh
1161 File Device Event Type: 9 Subevent id: 910 reading from hv_readback.txt
1162 File Number Reader Event Type: 9 Subevent id: 911 reading from hv_readings.txt
1163 $
1164 \end{verbatim}
1165
1166 Now all this is on autopilot, and we will always have the current HV
1167 readback in the data file.
1168
1169
1170 \subsection{Self-documenting your setup}
1171
1172 Let me quickly point out a trick that allows you to go back to your
1173 raw data and see how RCDAQ was configured in the first place.
1174
1175 We have seen the commands
1176
1177 \begin{verbatim}
1178 rcdaq_client create_device device_file 9 910 hv_readback.txt
1179 rcdaq_client create_device device_filenumbers 9 911 hv_readings.txt
1180 \end{verbatim}
1181
1182 which we gave, ostensibly from the command line, to configure rcdaq.
1183
1184 Of course, in almost all cases, you are not going to type this in on
1185 the fly, but put this into a script, such as this ``setup.sh'':
1186
1187 \begin{verbatim}
1188 #! /bin/sh
1189
1190 rcdaq_client create_device device_file 9 910 hv_readback.txt
1191 rcdaq_client create_device device_filenumbers 9 911 hv_readings.txt
1192 \end{verbatim}
1193
1194 Now you could (but wait!) just add another device
1195
1196 \begin{verbatim}
1197 #! /bin/sh
1198
1199 rcdaq_client create_device device_file 9 900 "$0"
1200 rcdaq_client create_device device_file 9 910 hv_readback.txt
1201 rcdaq_client create_device device_filenumbers 9 911 hv_readings.txt
1202 \end{verbatim}
1203
1204 You see packet 900 with ``\$0''? That of course refers to the name of
1205 the script itself, ``setup.sh'', and it will then be added and
1206 captured in packet 900 in the begin-run, so you can later see how
1207 rcdaq was configured to begin with.
1208
1209 However, there is one small problem. You will likely invoke the script as
1210
1211 \begin{verbatim}
1212 ./setup.sh
1213 \end{verbatim}
1214
1215 so the ``\$0'' parameter will be ``./setup.sh''. If the rcdaq server
1216 process is not run from the exact same directory where that script
1217 resides, it will not be able to find the script.
1218
1219 You could either be disciplined enough to \emph{always} invoke the
1220 script by its full pathname (not very likely to succeed), or you could
1221 rewrite it as follows:
1222 \label{setupexample}
1223 \begin{verbatim}
1224 #! /bin/sh
1225
1226 MYSELF=$(readlink -f $0)
1227
1228 rcdaq_client create_device device_file 9 900 "$MYSELF"
1229 rcdaq_client create_device device_file 9 910 hv_readback.txt
1230 rcdaq_client create_device device_filenumbers 9 911 hv_readings.txt
1231 \end{verbatim}
1232
1233 In the standard setup is a full-blown example script (\verb|setup.sh|) which you can use
1234 as a template.
1235
1236
1237 \section{Command overview}
1238 \label{CommandOverview}
1239
1240 The command \verb|rcdaq_client| without parameters lists all available rcdaq commands:
1241
1242 \begin{verbatim}
1243 help show this help text
1244 daq_status [-s] [-l] display status [short] [long]
1245 daq_open enable logging
1246 daq_set_server hostname [port] choose logging to a SFS server, or "None" to choose local file
1247 daq_begin [run-number] start taking data for run-number, or auto-increment
1248 daq_end end the run
1249 daq_close disable logging
1250 daq_setfilerule file-rule set the file rule default rcdaq-%08d-%04d.evt
1251
1252 daq_list_readlist display the current readout list
1253 daq_clear_readlist clear the current readout list
1254
1255 daq_define_runtype type file-rule define a run type, such as "calibration"
1256 daq_set_runtype type activate a predefined run type
1257 daq_get_runtype [-l] list the active runtype (if any)
1258 daq_list_runtypes [-s] list defined run types
1259 daq_get_lastfilename return the last file name written, if any
1260
1261 daq_set_maxevents nevt set automatic end at so many events
1262 daq_set_maxvolume n_MB set automatic end at n_MB MegaByte
1263 daq_set_rolloverlimit n_GB set file rollover limit at n_BG GigaByte
1264
1265 load shared_library_name load a "plugin" shared library
1266 create_device [device-specific parameters]
1267
1268 daq_setname <string> define an identifying string for this RCDAQ instance
1269 daq_setrunnumberfile file define a file to maintain the current run number
1270 daq_set_maxbuffersize n_KB adjust the size of buffers written to n KB
1271 daq_set_adaptivebuffering seconds enable adaptive buffering at n seconds (0 = off)
1272
1273 daq_webcontrol <port number> restart web controls on a new port (default 8080)
1274
1275 elog elog-server port specify coordinates for an Elog server
1276
1277 daq_shutdown terminate the rcdaq backend
1278 \end{verbatim}
1279
1280 The ``short'' versions of the commands (with the \verb|-s| flag, which
1281 at some point actually stood for ``script'') are generally there for
1282 the benefit of scripts (typically the GUIs, which are written in
1283 Python or Perl/Tk). The output is usually easy to parse by a script, but less easy
1284 to digest by humans, such as
1285
1286 \begin{verbatim}
1287 $ daq_status -s
1288 -1 0 0 0 0 0
1289 \end{verbatim}
1290
1291 Let's go through the commands:
1292
1293 \begin{description}
1294
1295
1296 \item[daq\_status] This displays the status of RCDAQ.
1297 The \verb|-l| flags accumulate and increase the detail of the status
1298 report.
1299
1300 \item[daq\_open] This enables the writing out of data to disk. You may
1301 wonder why one would choose to not log the data, but there are many
1302 situations where you are timing in your trigger, test the readout
1303 speed, or exercise the DAQ without cluttering your storage with
1304 files taken with ever-changing settings. Also keep in mind that you
1305 can still get at the events through your online monitoring.
1306
1307 \item[daq\_set\_server] This enables the writing out of data to a
1308 dedicated server named \verb|sfs|. This is used in the sPHENIX
1309 eperiment to log the data to a dedicated file server, and is
1310 something to consider if you would be logging the data to a
1311 NFS-mounted volume through the network. The \verb|sfs| has much less
1312 overhead than the NFS protocol, and allows you to log your data
1313 faster.
1314
1315 \item[daq\_begin] Start taking data. If you supply a run number,
1316 this run number will be used. Without a run number, the last run
1317 number will be incremented. Also see the \verb|daq_setrunnumberfile|
1318 command which allows you to make run numbers persistent between
1319 restarts of the rcdaq\_server.
1320
1321 \item[daq\_close] Disables logging.
1322
1323 \item[daq\_end] Ends the run.
1324
1325 \item[daq\_setfilerule file-rule] Set the file rule. You should always
1326 set a specific rule because with the default rule,
1327 \verb|rcdaq-%08d-%04d.evt|, the data files will end up in the same
1328 area where rcdaq was started from. Be sure to have a look at the 4 commands
1329 managing run types, such as \verb|daq_define_runtype|, which allows
1330 you to pre-set a few file rules, and switch between them quickly.
1331
1332 \item[daq\_list\_readlist] Displays the current readout list.
1333
1334 \item[daq\_clear\_readlist] Clears the current readout list.
1335
1336 \item[daq\_define\_runtype] This command, which takes a
1337 ``mnemonic'' and a file rule as parameters, allows you to pre-set an
1338 arbitrary number of different file rules. You will be able to switch
1339 between them quickly. In chapter~\ref{GUI} we show a convenient GUI
1340 to quickly switch between what I call \emph{run types}, which uses
1341 the following example. Here I define
1342
1343 \begin{verbatim}
1344 rcdaq_client daq_define_runtype pedestal /data/rcdaq/pedestal/pedestal_%010d-%04d.evt
1345 rcdaq_client daq_define_runtype beam /data/rcdaq/beam/beam_%010d-%04d.evt
1346 rcdaq_client daq_define_runtype calibration /data/rcdaq/calibration/calibration_%010d-%04d.evt
1347 rcdaq_client daq_define_runtype junk /data/rcdaq/junk/junk_%010d-%04d.evt
1348 \end{verbatim}
1349
1350 and then quickly switch between them, making the data appear in the
1351 specified location. This allows you to keep, say, pedestal or
1352 calibration runs apart from actual beam runs, and have more meaningful
1353 file names. There is no practical limit to the number of such
1354 types. However, it is no more than a convenient shortcut to set file
1355 rules. You can still manually set a file rule which is different from
1356 any of the defined ones.
1357
1358 \item[daq\_set\_runtype type] This sets the file rule to the
1359 predefined file rule, such as (from the example above)
1360
1361 \begin{verbatim}
1362 rcdaq_client daq_set_runtype beam
1363 \end{verbatim}
1364
1365 \item[daq\_get\_runtype] This lists the active run type (if any
1366 -- if the file rule is not set to any of the predefined ones, it
1367 will return nothing). It takes the ``long'' \verb|-l|
1368 switch. Without it, it will just list the type, with the long flag
1369 it will also list the rule.
1370
1371 \item[daq\_list\_runtypes] Lists the defined run types,
1372 the short version just the names, else also the rules.
1373
1374 \item[daq\_set\_maxevents nevt] Set an automatic end of a run at
1375 so many events. Setting it to 0 resets the event limit.
1376
1377 \item[daq\_set\_maxvolume nMB] Set an automatic end of a run
1378 after so many megabytes of data have been accumulated. Setting it to
1379 0 resets the size limit.
1380
1381 \item[load shared\_library\_name] This loads a "plugin" shared
1382 library. Since rcdaq doesn't really know about any meaningful
1383 devices to read, you will have to load at least one plugin for
1384 serious work.
1385
1386 \item[create\_device]
1387 This sets up a device to be read out. The parameters past the packet
1388 id are very device-specific.
1389
1390 \item[daq\_setrunnumberfile filename] This defines a file where
1391 rcdaq maintains the current run number. Normally, the rcdaq server
1392 remembers the most recent run number, and it gets incremented for each run.
1393 When the server is started, however, the run number defaults to 0, and for the
1394 first run, you have to set it manually. This mechanism lets you make that
1395 process persistent across restarts of the server. Example:
1396
1397 \begin{verbatim}
1398 rcdaq_client daq_setrunnumberfile $HOME/.last_rcdaq_runnumber.txt
1399 \end{verbatim}
1400
1401 \item[daq\_set\_rollover n\_GB] This will make RCDAQ ``roll over'' the
1402 output files after the given number of GigaBytes have been reached.
1403 This increments the usual second number field in the output files, such as
1404 \begin{verbatim}
1405 rcdaq-00000001-0000.evt
1406 rcdaq-00000001-0001.evt
1407 rcdaq-00000001-0002.evt
1408 ...
1409 \end{verbatim}
1410
1411 \item[daq\_set\_maxbuffersize n\_KB] Adjust the size of buffers to n
1412 KB. With the advent of ``adaptive buffering'' (next command), this
1413 can largely be ignored. This command was available mostly for the
1414 benfit of the online monitoring, since the monitoring receives one
1415 buffer at a time. If you have a low data rate (think a cosmics
1416 telescope) and small events, it can take several minutes (or even
1417 hours) for a large buffer to be filled and the monitoring to receive
1418 data. This was the reason why one could reduce the buffer size, to
1419 feed the online monitoring a more steady data stream. This was very
1420 sub-optimal, because the data taking efficiency is lower with
1421 smaller buffers, so one (small) size does not fit all. This brings
1422 us to the next command:
1423
1424 \item[daq\_set\_adaptivebuffering seconds] This is a much better
1425 solution for the above problem. By default, adaptive buffering is
1426 enabled and preset to 15 seconds. A buffer is now flushed when it
1427 is either full or the time period has elapsed, and there are no more
1428 rate-dependent adjustments. Unless there there is a specific reason,
1429 you should leave the adaptive buffering switched on. Setting the
1430 time to 0 disables adaptive buffering.
1431
1432 \item[daq\_get\_lastfilename] This returns the filename of the last
1433 written file, if any (if logging was disabled in the most recent
1434 run, you get an empty string). The purpose of this command is for
1435 automated, scripted measurements. You can obtain the last filename
1436 \emph{after} the run has ended, so you can use it to start some
1437 analysis on the file right away after the run ends. Here is an example:
1438
1439 \begin{verbatim}
1440 while (some_condition) ; do
1441 rcdaq_client daq_begin
1442 wait_for_run_end.sh # wait until the run automatically ends
1443 FILE=$(rcdaq_client daq_get_lastfilename) # get the filename, if any
1444 # if there was a file, start the analysis, presumably in the background
1445 [ -n "$FILE" ] && start_analysis $FILE
1446 done
1447 \end{verbatim}
1448
1449 \item[daq\_webcontrol port\_number ] Start the web-based controls on
1450 the given port number (defaults to port 8899 if omitted). See
1451 chapter~\ref{webcontrols} for details.
1452
1453 \item[elog elog-server port logbook] Specify the whereabouts for an
1454 Elog server where rcdaq can make automated entries.
1455
1456 \item[daq\_shutdown] Ask the rcdaq\_server to gracefully shut
1457 down. It will not shut down if a run is in progress.
1458
1459 \end{description}
1460
1461 \section{Standard GUIs}
1462 \label{GUI}
1463 There are 4 standard GUIs which come with rcdaq. There is a control
1464 GUI, a status display (essentially the control GUI without the action
1465 buttons), a ``Run Type Chooser'' GUI, and a configuration GUI which
1466 will take a bit more explanation.
1467
1468 The most important design concept is that all standard GUIs are
1469 \emph{stateless}. You can start a run from the control GUI, end it via
1470 the command, or have multiple copies of the same GUI and click
1471 ``Start'' in one and ``Stop'' in the other. All GUIs and buttons will
1472 (with a minimal time lag of about one second) always adapt to the
1473 state of the DAQ. A particular GUI does not remember that it was it
1474 which started the run, etc.
1475
1476 The GUIs are resilient and deal with a shutdown of the rcdaq\_server
1477 gracefully, so you can let them sit on the screen and they will always
1478 reflect the status of the DAQ.
1479
1480 \subsection{The Control Gui}
1481
1482 This is the workhorse GUI which allows to control the ``operational''
1483 aspects of RCADQ - \verb|daq_open|, \verb|daq_begin|, \verb|daq_end|,
1484 and \verb|daq_close|. It will also display some useful information, such
1485 as the run number, duration of the run, the currently open file, if
1486 any, and so on.
1487
1488 You start the GUI with
1489
1490 \begin{verbatim}
1491 rcdaq_control.pl &
1492 \end{verbatim}
1493
1494 The GUI is shown here in different states; first with logging disabled,
1495 stopped and running; and logging enabled, stopped and running. You can see the
1496 different information displayed.
1497
1498 \begin{center}
1499 \begin{tabular}{cc}
1500 \includegraphics[height=2in]{rcdaqcontrol_idle.png} &
1501 \includegraphics[height=2in]{rcdaqcontrol_no_logging.png}\\
1502 \includegraphics[height=2in]{rcdaqcontrol_loggingenabled.png} &
1503 \includegraphics[height=2in]{rcdaqcontrol_logging.png}\\
1504 \end{tabular}
1505 \end{center}
1506
1507 \subsection{The Status GUI}
1508
1509 This GUI is essentially a stripped-down version of the control GUI. It
1510 does not have the action buttons. If you just want to keep an eye on
1511 the status, there is no danger that you inadvertently click a button and
1512 interfere with the data taking.
1513
1514 You start it with
1515
1516 \begin{verbatim}
1517 rcdaq_status.pl &
1518 \end{verbatim}
1519
1520 and get
1521
1522 \begin{center}
1523 \label{rcdaqstatus}\includegraphics[height=2in]{rcdaqstatus.png}
1524 \end{center}
1525
1526 Since this is a completely passive GUI, you can also use it to display
1527 the status on an overhead monitor which is found in many control
1528 rooms. For that reason, it supports three options, \verb|--large|,
1529 \verb|--display=<display>|, and \verb|--geometry=<geometry>|. The
1530 \verb|--large| option enlarges the GUI so that you can see it from a
1531 distance, and the other options allow you to send it to a remote
1532 display and position it properly, for example
1533
1534 \begin{verbatim}
1535 rcdaq_status.pl --display=phnxtv1.phenix.bnl.gov:0.0 --geometry=+100+100 --large &
1536 \end{verbatim}
1537
1538 \subsection{The Run Type Chooser GUI}
1539
1540 If you have run types defined, say, along the example from before
1541
1542 \begin{verbatim}
1543 $ daq_list_runtypes
1544 beam - /data/rcdaq/beam/beam_%010d-%04d.evt
1545 calibration - /data/rcdaq/calibration/calibration_%010d-%04d.evt
1546 junk - /data/rcdaq/junk/junk_%010d-%04d.evt
1547 pedestal - /data/rcdaq/pedestal/pedestal_%010d-%04d.evt
1548 \end{verbatim}
1549
1550 then you can easily select the type with this GUI. Type
1551
1552 \begin{verbatim}
1553 rcdaq_runtypechooser.pl &
1554 \end{verbatim}
1555
1556 and you will get
1557
1558 \begin{center}
1559 \includegraphics[height=2in]{rcdaqruntypechooser.png}
1560 \end{center}
1561
1562 Each defined type brings up a button which allows you to select the run type
1563 easily.
1564
1565 Despite appearances, this GUI is stateless, too. The buttons merely
1566 set the run type in the rcdaq\_server, but the display is updated not
1567 from the button click but from information from the server, so the GUI
1568 will reflect the changes if you change the run type from the command line.
1569
1570 This GUI will gracefully deal with a shutdown of the server, however,
1571 it will get confused if you change the list of run types. I think this
1572 is a small inconvenience, because the run types are usually pretty
1573 static. If they do change, this GUI needs to be restarted.
1574
1575 \subsection{The Configuration GUI}
1576
1577 This brings us to our last GUI, which is a bit more complex. We are
1578 supporting setups where the researchers are used to selecting the
1579 setup from a long scroll-down list of pre-made standard
1580 configurations, depending on what the experiment of the day is. This
1581 in itself is not so difficult, but soon you run into a complication
1582 in defining what such a ``setup'' actually is.
1583
1584 You will likely find the area teeming with a number of shell or perl
1585 scripts for different purposes, along with the top-level scripts which
1586 define the various setups. It is good practice to have those
1587 individual setup scripts call more generic other scripts with the
1588 proper parameters, in order to avoid a proliferation of ``flat''
1589 all-in-one scripts. This immediately leads to the need to identify the
1590 actual top-level scripts which are meant to be listed in that
1591 GUI. Attempts to seclude those in a particular area only have, quite
1592 predictably, not worked.
1593
1594 For this reason, we invented a scheme in which we identify those
1595 ``GUI-grade'' scripts by certain tags, which are comments in the
1596 script.
1597
1598 If you look at the \verb|setup.sh| example script in the main rcdaq
1599 source directory, you will see the following comments:
1600
1601 \begin{verbatim}
1602 #! /bin/sh
1603
1604 # the following line identifies this script as one to be
1605 # listed in the configuration GUI
1606
1607 # --RCDAQGUI
1608
1609 # lines starting with the "--SC" tag are short comments
1610 # (can be only one, later ones override earlier ones)
1611
1612 # --SC Top Level setup script with a random device
1613
1614 # lines starting with the "--SC" tag are long comments
1615
1616 # --LC This setup script is part of the RCDAQ distribution.
1617 # --LC It uses the random device (i.e. no particular hardware)
1618 # --LC and can run on any machine to give RCDAQ a spin.
1619 # --LC It can serve as a template to develop your own setups.
1620 \end{verbatim}
1621
1622 The \verb|--RCDAQGUI| tag identifies this script as one to be listed
1623 in the GUI. Then there are ``short comments'', which act as tooltip
1624 help (when you hover the mouse), and ``long comments'', which are
1625 displayed once you select the GUI.
1626
1627 If you run
1628
1629 \begin{verbatim}
1630 rcdaq_configmenu.pl &
1631 \end{verbatim}
1632
1633 in the directory where this \verb|setup.sh| script resides, you will see
1634
1635 \begin{center}
1636 \includegraphics[height=2in]{rcdaqconfigmenu1.png}
1637 \end{center}
1638
1639 (in this case there is only one such script, but all ``GUI-enabled'' scripts will be
1640 shown but not any others. If you hover the mouse, you will see the tooltip with the
1641 ``short comment'' (which can only be one line):
1642
1643 \begin{center}
1644 \includegraphics[height=2in]{rcdaqconfigmenu2.png}
1645 \end{center}
1646
1647 Selecting this then displays the longer help text, and you can see if
1648 this script is what you wanted:
1649
1650 \begin{center}
1651 \includegraphics[height=2in]{rcdaqconfigmenu3.png}
1652 \end{center}
1653
1654 Once selected, you can then choose to execute the script, or cancel.
1655
1656 \section{Web-based Controls}
1657 \label{webcontrols}
1658
1659 The GUIs shown in the previous chapter are based on the ``Tk''
1660 graphics widget set and are implemented in Perl. While extremely
1661 versatile, Perl-Tk is not readily available on every platform, and
1662 requires additional libraries to be installed. On several Linux
1663 flavors in widespread use, such as RedHat and Scientific Linux, Tk can
1664 be installed but is not part of the software management system, and
1665 needs to be installed from source. In addition, the Tk system requires
1666 the availability of the X11 graphics system, which eliminates all
1667 platforms that do no support X11, such as iPads and iPhones. On other
1668 platforms like Windows and most smart phones and tablets, the ``Tk''
1669 component is extremely difficult to install or is not available at
1670 all.
1671
1672 Recent advances in web technologies have converted the web browser
1673 into a viable platform for slow controls, with the advantage that the
1674 underlying technologies are available in most modern browsers on
1675 virtually any platform, including smart phones and tablets.
1676
1677 By adding a GUI technology that uses web-based controls, it is
1678 possible to implement the RCDAQ GUIs in a truly platform-independent
1679 fashion. This makes them available on platforms which could not
1680 support the GUIs before, such as smart phones, tablets, and even
1681 iPads, which have the most restrictive execution environment of all
1682 platforms.
1683
1684
1685 \subsection{The Web-based RCDAQ Control GUI}
1686
1687 \begin{figure}[htb]
1688 \begin{center}
1689 \includegraphics[width=0.47\columnwidth]{webcontrol_idle.png}
1690 \includegraphics[width=0.47\columnwidth]{webcontrol_running.png}
1691 \includegraphics[width=0.47\columnwidth]{webcontrol_logging.png}
1692 \includegraphics[width=0.47\columnwidth]{webcontrol_shutdown.png}
1693 \end{center}
1694 \caption{\label{webcontrol-idle}The new web-based control GUI for the RCDAQ system
1695 in various states of the RCDAQ operation. The upper left shows the GUI in the idle state,
1696 then in the running state, while logging, and when the RCDAQ server has been shut down.}
1697 \end{figure}
1698
1699 The web-based control interface acts like a web server running on the
1700 chosen port. The default port is 8899, but you can choose any port
1701 number that is available on your system.
1702
1703 The service starts automatically on port 8899. You can re-start it on a different port with the command
1704 \begin{verbatim}
1705 rcdaq_client daq_webcontrol <port number>
1706 \end{verbatim}
1707
1708 For example,
1709 \begin{verbatim}
1710 rcdaq_client daq_webcontrol
1711 \end{verbatim}
1712 starts the interface on the default port number 8899. You can then access the
1713 web-based controls on your local machine where RCDAQ is running as
1714 \begin{verbatim}
1715 http://localhost:8899
1716 \end{verbatim}
1717 or on another system as
1718 \begin{verbatim}
1719 http://your.daq.machine:8899
1720 \end{verbatim}
1721
1722 \warning{If you select another port number, keep in mind that RCDAQ is
1723 running without special privileges and cannot use any privileged
1724 ports such as the ``http'' port 80. If you use a port number
1725 different from the default, you \emph{must} use a non-privileged
1726 port higher than 1024, and it is recommended that you use a port
1727 number above 8000.}
1728
1729 At this point in time, only the equivalent of the standard control GUI
1730 has been implemented as a web-based control. The web-based equivalent
1731 of the ``Status'' GUI, shown on page~\pageref{rcdaqstatus}, will be
1732 implemented in an upcoming version.
1733
1734 Over time, the web controls will make it easy to add other amenities
1735 such as ready-made strip charts of the system performance, such as
1736 ``events taken per minute'' or ``data volume as a function of time''.
1737
1738 \begin{figure}[htb]
1739 \begin{center}
1740 \includegraphics[width=0.85\columnwidth]{android.png}
1741 \end{center}
1742 \caption{\label{android}The new web-based controls for the RCDAQ system
1743 running in the web browser on an Android phone.}
1744 \end{figure}
1745
1746 To show the enhanced possibilities of the web-based controls,
1747 Fig.~\ref{android} shows a screen shot of the controls running in the
1748 browser on my Android phone. In the same way, it is now possible to
1749 run the controls on iPads and basically any platform with a modern web
1750 browser.
1751
1752 \subsection{Sending information to an operator via the GUIs}
1753
1754 Let me mention an application of the \verb|daq_setname| facility that
1755 we use a lot when we are making position scans of a detector, for
1756 example in a test beam. The ``name'' of an RCDAQ instance defaults to
1757 the hostname of the machine that the server is running on. Often you
1758 run multiple RCDAQ instances on different machines, and this helps you
1759 keep the GUIs apart.
1760
1761 However, you can change the name to whatever you like (you have space
1762 for about 30 characters in the GUIs). When you are running an
1763 automated script to make a position (or any other) scan, you can
1764 change the name to give some information about the progress on the GUI.
1765
1766 Consider this script snippet:
1767
1768 \begin{verbatim}
1769 for ypos in {0..9} ; do
1770 for xpos in {0..9} ; do
1771 # some commands to move your detector to $xpos, $ypos
1772 rcdaq_client daq_setname "running at position $xpos,$ypos"
1773 rcdaq_client daq_begin
1774 wait_for_run_end.sh
1775 done
1776 done
1777 \end{verbatim}
1778
1779
1780 \begin{figure}[htb]
1781 \begin{center}
1782 \includegraphics[width=0.45\columnwidth]{GUI_name.png}
1783 \end{center}
1784 \caption{\label{GUIname}A GUI that displays information about the
1785 current status of a position scan.}
1786 \end{figure}
1787
1788 Fig.~\ref{GUIname} shows the effect of the above script.
1789
1790 \section{Installation}
1791 \label{installation}
1792
1793 If you want to give RCDAQ and the assorted analysis tools a quick look
1794 (and potentially want my help at some point), it is easiest if you
1795 follow these steps.
1796
1797 While there is nothing wrong with installing only the actual RCDAQ
1798 component (and on a Raspberry Pi, it is rather difficult to go beyond
1799 that), you typically want the analysis tools, too, in order to be able
1800 to look at the data.
1801
1802 Obviously you can name your installation areas whatever you want, and
1803 also install everything in the standard system areas. However, to get
1804 started and make it easy for me to help you if needed, you might just
1805 install it in the way I describe here so I can find my way around.
1806
1807 Especially the use of the environmental variable \verb|ONLINE_MAIN| is
1808 convenient in the sense that it allows you to install all
1809 sub-components (and later all plugins you wish to build) into the same
1810 area easily. Still, if you are an expert user and proficient with the
1811 UNIX auto-tools, nothing will prevent you from installing it in a way
1812 that makes the most sense to you.
1813
1814 Here is how I recommend to begin:
1815
1816 Make a directory {\tt \$HOME/softwarerepo}, and ``cd'' there:
1817
1818 \begin{verbatim}
1819 mkdir $HOME/softwarerepo
1820 cd $HOME/softwarerepo
1821 \end{verbatim}
1822
1823 git clone the rcdaq and online\_distribution components:
1824
1825 \begin{verbatim}
1826 git clone https://github.com/sPHENIX-Collaboration/rcdaq.git
1827 git clone https://github.com/sPHENIX-Collaboration/online_distribution.git
1828 \end{verbatim}
1829
1830 Define an environmental variable \verb|ONLINE_MAIN|:
1831
1832 \begin{verbatim}
1833 export ONLINE_MAIN=$HOME/softwarepo/install
1834 \end{verbatim}
1835
1836 Generate the various build areas:
1837
1838 \begin{verbatim}
1839 mkdir -p build/rcdaq
1840 mkdir -p build/online_distribution/{eventlibraries,pmonitor}
1841 \end{verbatim}
1842
1843 and move to respective area, configure, and install:
1844
1845 \begin{verbatim}
1846 cd build/rcdaq
1847 ../../rcdaq/autogen.sh --prefix=$ONLINE_MAIN
1848 make install
1849 \end{verbatim}
1850
1851 \begin{verbatim}
1852 cd ../online_distribution/eventlibraries
1853 ../../../online_distribution/eventlibraries/autogen.sh --prefix=$ONLINE_MAIN
1854 make install
1855 \end{verbatim}
1856
1857 \begin{verbatim}
1858 cd ../online_distribution/pmonitor
1859 ../../../online_distribution/pmonitor/autogen.sh --prefix=$ONLINE_MAIN
1860 make install
1861 \end{verbatim}
1862
1863
1864 After the installation is complete, you should add the
1865 \verb|$ONLINE_MAIN/bin| area to the \verb|PATH|, and define
1866 \verb|$ONLINE_MAIN/lib| as \verb|LD_LIBRARY_PATH| (or add to an
1867 existing definition).
1868
1869 You can then add the following lines to your
1870 \verb|$HOME/.bash_login| or equivalent file for your shell:
1871
1872 \begin{verbatim}
1873 export ONLINE_MAIN=$HOME/softwarerepo/install
1874 PATH=$PATH:$ONLINE_MAIN/bin
1875 export LD_LIBRARY_PATH=$ONLINE_MAIN/lib
1876
1877 source $ONLINE_MAIN/bin/aliases.sh
1878
1879 export ROOT_INCLUDE_PATH=$ONLINE_MAIN/include:$ONLINE_MAIN/include/Event:$ONLINE_MAIN/include/pmonitor
1880 \end{verbatim}
1881
1882 The second-last line sets up the aliases as described in
1883 chapter~\ref{convenience}. The last line is required if you are using
1884 ROOT version 6 for your analysis. It defines where ROOT is looking for
1885 the include files.
1886
1887
1888
1889 \section{System Requirements}
1890
1891 RCDAQ runs without special privileges. The only system service it
1892 needs is \verb|rpcbind|, which typically gets started at boot time of
1893 your system. The only modification to the usual way the rpcbind
1894 service is run is that it \emph{may} need the ``-i'' flag. Test first
1895 if all works without it before you change anything.
1896
1897 The end result must be that rpcbind is running, as shown here with the
1898 ``-i'' flag:
1899
1900 \begin{verbatim}
1901 $ ps ax | grep rpcbind
1902 2273 ? Ss 0:00 /sbin/rpcbind -i
1903 5626 pts/0 S+ 0:00 grep --colour=auto rpcbind
1904 $
1905 \end{verbatim}
1906
1907 Should you system require the -i flag, the way that is accomplished varies
1908 a lot between Linux distributions. Here are a few of the more
1909 mainstream ones:
1910
1911 \begin{description}
1912
1913 \item[Gentoo] Create or edit the file \verb|/etc/conf.d/rpcbind|. Add a line
1914
1915 \begin{verbatim}
1916 RPCBIND_OPTS="-i"
1917 \end{verbatim}
1918
1919 \item[Scientific Linux] Create or edit the file \verb|/etc/sysconfig/rpcbind|. Add a line
1920
1921 \begin{verbatim}
1922 RPCBIND_ARGS="-i"
1923 \end{verbatim}
1924
1925 \item[Ubuntu] Create or edit the file \verb|/etc/default/rpcbind|. Add a line
1926
1927 \begin{verbatim}
1928 OPTIONS="-i"
1929 \end{verbatim}
1930
1931 \end{description}
1932
1933
1934
1935 \appendix
1936
1937 \section{Examples}
1938
1939 I show a few examples of real-life setups that were used in the past.
1940
1941 I will expand on this chapter as time progresses.
1942
1943 \subsection{Running Speed Tests}
1944 \label{speedtests}
1945 Let's say that you want to see how fast your system can take data when
1946 you pull out all the stops. Actually reading out devices later will
1947 invariably slow you down, but it is good to know where the limits of
1948 your disk, CPU, and network are.
1949
1950 I mentioned the \verb|daq_device_deadtime| pseudo-device. It may sound
1951 odd that you can use a device that adds artificial deadtime for a
1952 speed test, but here is how it works.
1953
1954 Let me first show how to actually generate artificial deadtime. At the
1955 time I write this at the FermiLab Test Beam Facility, it is unclear if
1956 we will need this for the benefit of a MWPC, which may be able run at
1957 only 100Hz (remains to be seen). Then we would add, say, 150 microseconds
1958 deadtime:
1959
1960 \begin{verbatim}
1961 rcdaq_client create_device device_deadtime 1 0 150
1962 \end{verbatim}
1963
1964 The 3rd parameter is the deadtime added in units of the Unix \verb|usleep|
1965 system call, which is meant to be microseconds, but you may have to calibrate and
1966 adjust the unit on your system a little bit.
1967
1968 With the above parameters, it will not add anything to the data stream
1969 (that's why the packet id is set to 0). It can, however, add an
1970 adjustable amount of data to the event (and generate a packet,
1971 obviously). And it can also provide the system trigger. That allows
1972 you to dial in any desired data rate. Here is how you run the speed
1973 test: You set the deadtime to 0 (no deadtime), set a packet id (I
1974 chose 1005 here), have the device add 64 (32-bit) words to the event,
1975 and provide the system trigger (the last ``1''). Since this is now the
1976 only device defined in a data event, it will run as fast as it can:
1977
1978 \begin{verbatim}
1979 rcdaq_client create_device device_deadtime 1 1005 0 64 1
1980 \end{verbatim}
1981
1982 You can reduce the number of words to test the inner mechanics of
1983 RCDAQ on your PC (how fast it can go through the paces to kick off the
1984 event reading), or increase the number to test the limits of your
1985 storage system.
1986
1987 Be warned, though, that the artificial data do not have meaningful
1988 values. Different from the \verb|device_random|, this device wastes
1989 no time filling in any actual values; it just says that it has added
1990 so many words, no matter what the contents of the packet payload are.
1991
1992 \subsection{Measuring Event Timing}
1993 \label{eventtiming}
1994
1995 Especially under test beam conditions, it is often useful to see what
1996 the ``spacing'' in time between events is. Ideally, you would expect a
1997 somewhat balanced distribution with events being apart in time by
1998 roughly the same amount, but very often you find that there is a
1999 macroscopic structure in that distribution for a myriad of reasons.
2000
2001 If you see that in a beam setting, you should definitely find out why
2002 that is. This usually points to some undesired feature in the beam,
2003 which might have a microstructure, or some other structure.
2004
2005 A trivial way of getting such an artificial structure is to have a
2006 really slow file system to write the data to, such as a USB stick or
2007 something similarly slow. Then the time it takes to write out a buffer to
2008 storage is much longer than the time it takes to fill it. RCDAQ uses a
2009 double-buffering scheme so one buffer is getting filled while
2010 another one is being written to disk. In modern solid-state disks and
2011 especially in today's RAID systems, the writing is virtually always
2012 faster than the filling. However, if the writing is slow, the readout
2013 needs to wait for the writing to complete before that buffer becomes
2014 available again, and the busy goes up.
2015
2016 In order to measure the distance between events, the system offers a
2017 built-in pseudo device \verb|device_rtclock|. This device uses the
2018 \verb|clock_gettime| system service and retrieves the
2019 \verb|CLOCK_MONOTONIC_RAW| system clock, which is strictly continuous
2020 and not affected by ``jumps'' due to NTP-driven or manual time
2021 adjustments. The clock reports clock ticks in units of nanoseconds,
2022 but that may need a system-dependent calibration. Still, it provides a
2023 ``heartbeat'' to gauge the relative timing of events.
2024
2025 The device records both the current clock value, as well as the same
2026 value from the last event where the ``device'' was read out. This
2027 makes it easy to compute the relative timing of events.
2028
2029 Here is an example how to set up such a pseudo device in a data event:
2030
2031 \begin{verbatim}
2032 rcdaq_client create_device device_rtclock 1 1010
2033 \end{verbatim}
2034
2035 It does not take any configuration parameters, only the event type and
2036 the packet id.
2037
2038 \subsection{Adding a webcam picture to a packet}
2039
2040 In this setup we use a detector that gets positioned with a step
2041 motor. While we save the motor positions in the begin-run event, it is
2042 nice to have a visual confirmation that the detector is in the right
2043 place, or actually moves in the direction we expect it to. To get
2044 this, we add a webcam picture to the begin-run event. The webcam looks
2045 at the detector with a ruler in the background, so you get a rough
2046 verification that the detector at least moves in the right direction.
2047
2048 While there are many ways to get a webcam picture, the most flexible
2049 solution is to run the ``\verb|motion|'' utility on the
2050 system. \verb|motion| is a surveillance tool designed to monitor a
2051 video stream and record video whenever \emph{motion} is detected in
2052 the feed, where motion can be defined in a highly flexible manner. In
2053 addition, the utility provides a web interface to a live video stream,
2054 and has the ability to take snapshots in predefined intervals
2055 independent of detected motion in the picture. All streams and
2056 pictures carry a time stamp.
2057
2058 I usually adjust the threshold for motion recognition rather high so
2059 no actual video gets recorded, although that of course depends on your
2060 setup. The sequence of snapshot files later provides a rough
2061 timeline of events if needed. The web interface allows you to remotely
2062 monitor the camera at any time. For getting a picture from the camera,
2063 I provide a simple perl script in the distribution which reads the web
2064 live stream and extracts and saves one frame.
2065
2066 The script is called ``\verb|motion_cam_parse.pl|'' and takes the URL
2067 of the webcam feed as an argument. Assuming that motion runs on the
2068 local machine and the live feed appears on the standard port 8081, we can
2069 get one picture:
2070
2071 \begin{verbatim}
2072 motion_cam_parse.pl http://localhost:8081 > cam_picture.jpg
2073 \end{verbatim}
2074
2075 I usually wrap this into a shell script ``\verb|capture_picture.sh|'':
2076
2077 \begin{verbatim}
2078 #! /bin/sh
2079 # this captures a picture to the provided filename,
2080 # or cam_picture.jpg
2081
2082 FILE="$1"
2083 [ -z "$FILE" ] && FILE=cam_picture.jpg
2084 motion_cam_parse.pl > "$FILE"
2085
2086 \end{verbatim}
2087
2088 and then we configure rcdaq as follows:
2089 \label{packet900}
2090
2091 \begin{verbatim}
2092 #! /bin/sh
2093
2094 D=`dirname "$0"`
2095 B=`basename "$0"`
2096 MYSELF="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B"
2097 rcdaq_client create_device device_file 9 900 "$MYSELF"
2098
2099 # add the camera picture
2100 rcdaq_client create_device device_command 9 0 "/home/eic/capture_picture.sh /home/eic/cam_picture.jpg"
2101 rcdaq_client create_device device_file_delete 9 940 /home/eic/cam_picture.jpg
2102
2103 # .. lines deleted...
2104 \end{verbatim}
2105
2106 We use \verb|device_file_delete| so it is impossible to add a stale
2107 picture if there is a problem getting the current one.
2108
2109 \subsection{The GEM Detector Readout at the FermiLab Test Beam, February 2014}
2110
2111 This setup is building on the previous example in the sense that
2112 we are adding a lot of configuration information and two camera
2113 snapshots to the begin-run event. We also have 5 different run types defined.
2114
2115 First, we let the main RCDAQ configuration script figure out if there
2116 is a \verb|rcdaq_server| running by issuing a \verb|daq_status|
2117 command and testing its return status. If that fails, we need to start
2118 the server. At this point, we also define the Elog whereabouts.
2119
2120 \begin{verbatim}
2121 #! /bin/sh
2122
2123 if ! rcdaq_client daq_status > /dev/null 2>&1 ; then
2124 echo "No rcdaq_server running, starting..."
2125 rcdaq_server > $HOME/log/rcdaq.log 2>&1 &
2126 sleep 2
2127 ELOG=$(which elog 2>/dev/null)
2128 [ -n "$ELOG" ] && rcdaq_client elog localhost 666 RCDAQLog
2129 fi
2130 \end{verbatim}
2131
2132 This is the ``make an absolute path'' routine you already know:
2133
2134 \begin{verbatim}
2135 # we need the $0 as absolute path b/c we pass it on to a "file" device further down
2136 D=`dirname "$0"`
2137 B=`basename "$0"`
2138 MYSELF="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B"
2139 \end{verbatim}
2140
2141 We make the current run number persistent:
2142
2143 \begin{verbatim}
2144 rcdaq_client daq_setrunnumberfile $HOME/.last_rcdaq_runnumber.txt
2145 \end{verbatim}
2146
2147 And we find out if the SRS plugin is loaded already:
2148
2149 \begin{verbatim}
2150 if ! rcdaq_client daq_status -l | grep -q "SRS Plugin" ; then
2151 echo "SRS plugin not loaded yet, loading..."
2152 rcdaq_client load librcdaqplugin_srs.so
2153 fi
2154 \end{verbatim}
2155
2156
2157 And now we assemble the pieces that we want to add to the begin-run event.
2158 \begin{itemize}
2159 \item Packet 900 will hold the configuration script itself
2160 \item we execute the command \verb|srs_control readapv > $HOME/apv.txt|. It extracts
2161 most of the relevant setup parameters from the SRS crate and writes it to the file.
2162 \item we execute \verb|/home/eic/rcdaq_setup/prepare_run.sh|. This script
2163
2164 \begin{itemize}
2165 \item reaches out to the motor rotation controller, queries the current
2166 position, and writes the value into \verb|current_position.txt|;
2167 \item turns on a small light underneath the turntable for a moment and
2168 takes a picture from a webcam which looks at the scale for visual confirmation; the picture goes into an image file called
2169 ``\verb|snapshot.jpg|'';
2170 \item it makes a similar snapshot from a permanently mounted overhead camera as ``\verb|overhead_snapshot.jpg|''.
2171 \end{itemize}
2172
2173 \item we then add the ``\verb|apv.txt|'' file as packet 910;
2174 \item we add ``\verb|current_position.txt|'' as packet 940;
2175 \item we add ``\verb|snapshot.jpg|'' as packet 941;
2176 \item and we add ``\verb|overhead_snapshot.jpg|'' as packet 942.
2177 \end{itemize}
2178
2179 \begin{verbatim}
2180 # we add this very file to the begin-run event
2181 rcdaq_client create_device device_file 9 900 $MYSELF
2182
2183 rcdaq_client create_device device_command 9 0 "srs_control readapv > $HOME/apv.txt"
2184 rcdaq_client create_device device_command 9 0 "/home/eic/rcdaq_setup/prepare_run.sh"
2185
2186 rcdaq_client create_device device_file 9 910 $HOME/apv.txt
2187 rcdaq_client create_device device_file 9 940 $HOME/current_position.txt
2188 rcdaq_client create_device device_file 9 941 $HOME/snapshot.jpg 128000
2189 rcdaq_client create_device device_file 9 942 $HOME/overhead_snapshot.jpg 128000
2190 \end{verbatim}
2191
2192 The remainder of the set up script is straightforward; we set up the run types,
2193 set ``junk'' as default, and finally define the readout of the SRS crate:
2194
2195 \begin{verbatim}
2196 rcdaq_client daq_define_runtype beam /data/gem/beam/beam_%010d-%04d.evt
2197 rcdaq_client daq_define_runtype noSi /data/gem/noSi/no_si_%010d-%04d.evt
2198 rcdaq_client daq_define_runtype junk /data/gem/junk/junk_%010d-%04d.evt
2199 rcdaq_client daq_define_runtype calibration /data/gem/calibration/calibration_%010d-%04d.evt
2200 rcdaq_client daq_define_runtype pedestal /data/gem/pedestal/pedestal_%010d-%04d.evt
2201 rcdaq_client daq_setruntype junk
2202
2203 rcdaq_client create_device device_srs 1 1010 10.0.0.2 1
2204 \end{verbatim}
2205
2206 And here is the composition of the begin-run event:
2207
2208 \begin{verbatim}
2209 $ dlist -i -t 9 beam_0000000451-0000.evt
2210 -- Event 1 Run: 451 length: 17431 type: 9 (Begin Run Event) 1392306649
2211 Packet 900 614 -1 (sPHENIX Packet) 4 (IDCSTR)
2212 Packet 910 142 -1 (sPHENIX Packet) 4 (IDCSTR)
2213 Packet 940 7 -1 (sPHENIX Packet) 4 (IDCSTR)
2214 Packet 941 3643 -1 (sPHENIX Packet) 4 (IDCSTR)
2215 Packet 942 13017 -1 (sPHENIX Packet) 4 (IDCSTR)
2216 \end{verbatim}
2217
2218 If we now want to find out the position of the turntable, we can have a
2219 look at packet 940:
2220
2221 \begin{verbatim}
2222 $ ddump -t 9 -p 940 /media/psf/Home/srs/GEM/beam/beam_0000000472-0000.evt
2223 -0000020
2224 $
2225 \end{verbatim}
2226
2227 ( -20 is actually the ``zero'' position, 80 ticks mean one degree, the the zero marks are aligned at this value.)
2228
2229 Here is another run:
2230
2231 \begin{verbatim}
2232 $ ddump -t 9 -p 940 /media/psf/Home/srs/GEM/beam/beam_0000000474-0000.evt
2233 +0002380
2234 $
2235 \end{verbatim}
2236
2237 which is at 2380 (+20) ticks (30 degrees).
2238
2239 In case there seems something wrong, one can extract the webcam snapshots:
2240
2241 \begin{verbatim}
2242 $ ddump -t 9 -p 941 beam_0000000472-0000.evt > 472.jpg
2243 $ ddump -t 9 -p 942 beam_0000000472-0000.evt > 472_overhead.jpg
2244 $ ddump -t 9 -p 941 beam_0000000474-0000.evt > 474.jpg
2245 $ ddump -t 9 -p 942 beam_0000000474-0000.evt > 474_overhead.jpg
2246 \end{verbatim}
2247
2248 Here you can see these snapshots:
2249
2250 \includegraphics[height=2in]{472.jpg}
2251 \includegraphics[height=2in]{474.jpg}
2252
2253 \includegraphics[height=2in]{472_overhead.jpg}
2254 \includegraphics[height=2in]{474_overhead.jpg}
2255
2256 This is great for potential forensics and a visual conformation that the detector
2257 was at the right position.
2258
2259
2260
2261 \section{A Selection of Currently Implemented Readout Devices}
2262
2263 \subsection{The PSI DRS4 Evaluation Board}
2264 \label{instructions}
2265
2266 The DRS4 chip is a switched capacitor array capable of sampling at a
2267 speed of up to 5\,Gigasamples/s. This device supports sampling rates
2268 of 0.7, 1, 2, and 5\,GS/s.
2269
2270 The PSI DRS4 evaluation board is one of the workhorse systems in small
2271 setups. It offers 4 waveform digitizing channels with sample rates of
2272 up to 5GS/s. Since it is a USB-based device, it can be run on
2273 virtually any Linux system without the need for special
2274 interfaces. Fig.~\ref{drsevalboard} shows pictures of the board.
2275
2276 This is the only device implemented in RCDAQ so far that is capable of
2277 being read out with a Raspberry Pi. The RCDAQ core will work on a Pi
2278 just fine, but most of the other readout devices will not be
2279 supported, because the required vendor-supplied libraries are usually
2280 not available. The DRS4 evaluation board is the exception. I have
2281 personally used the board with a Pi for a long-term cosmic calibration
2282 measurement, where I didn't want to commit a more powerful PC to
2283 acquire the data.
2284
2285 To start, you need to make sure that your system has all the libraries
2286 needed to interface with the DRS4 evaluation board in the first
2287 place. Follow the instructions on the PSI website what to install and
2288 configure. You should be able to run the \verb|drsosc|
2289 ``oscilloscope'' application, shown in Fig.~\ref{drsosc}, on your
2290 system \emph{before} you start with RCDAQ.
2291
2292 \begin{figure}
2293 \centering
2294 \includegraphics[width=0.4\columnwidth]{drsfront.jpg}
2295 \includegraphics[width=0.4\columnwidth]{drsback.jpg}
2296 \caption{\label{drsevalboard}The PSI DRS4 Evaluation Board.}
2297 \end{figure}
2298
2299 The installation of the plugin follows the recipe outlined in
2300 chapter~\ref{installation} exactly. Go back to the place where you
2301 already installed RCDAQ, in my example from above
2302 \verb|$HOME/softwarerepo|. Then get the software:
2303
2304 \begin{verbatim}
2305 git clone https://github.com/sPHENIX-Collaboration/drs4.git
2306 \end{verbatim}
2307
2308 and you will have a new directory ``drs4''. Now go to your build area,
2309 \verb|$HOME/softwarerepo/build| in the example, make a new directory ``drs4'',
2310 and configure:
2311
2312 \begin{verbatim}
2313 $ mkdir drs4
2314 $ cd drs4
2315 $ ../../drs4/autogen.sh --prefix=$HOME/softwarerepo/install
2316 $ make install
2317 \end{verbatim}
2318
2319 This will install \verb|librcdaqplugin_drs.so| in your
2320 \verb|$ONLINE_MAIN/lib| area, which is the plugin that teaches RCDAQ how
2321 to read the Evaluation Board.
2322
2323 This is the way how you install every other plugin as well, just
2324 replace the name accordingly.
2325
2326 You can now load the plugin, and see the effect with the
2327 \verb|daq_status -ll| command:
2328
2329 {\footnotesize
2330 \begin{verbatim}
2331 $ rcdaq_client load librcdaqplugin_drs.so
2332 $ daq_status -ll
2333 Stopped
2334 Logging enabled
2335 have a trigger object
2336 Filerule: rcdaq-%08d-%04d.evt
2337 Buffer Sizes: 32832 KB adaptive buffering: 15 s
2338 Web control Port: 8899
2339 Elog: not defined
2340 -- defined Run Types: (none)
2341 List of loaded Plugins:
2342 - DRS Plugin, provides -
2343 - device_drs (evttype, subid, triggerchannel, triggerthreshold[mV], slope[n/p], delay[ns],
2344 speed, start_ch, nch, baseline[mV]) - DRS4 Eval Board
2345 - device_drs_by_serialnumber (evttype, subid, serialnumber, triggerchannel,
2346 triggerthreshold[mV], slope[n/p], delay[ns],
2347 speed, start_ch, nch, baseline[mV]) - DRS4 Eval Board
2348 \end{verbatim}
2349 }
2350
2351 \begin{figure}
2352 \centering
2353 \includegraphics[width=0.95\columnwidth]{drsosc.png}
2354 \caption{\label{drsosc}A screenshot of the drsosc application. Make
2355 sure that you can sucessfully run this application before you
2356 start setting up RCDAQ.}
2357 \end{figure}
2358
2359 The only slightly complicated setting is the \verb|triggerchannel|
2360 parameter, which is a bit-mapped value. You will usually see some
2361 value such as \verb|0x21| here. The 5 least significant bits denote
2362 the 4 inputs and the external trigger as triggers for the board.
2363
2364 Keep in mind that there are two different triggers here -- one is
2365 triggering the board itself, and the other is whether or not this
2366 board also provides the system trigger for RCDAQ (see
2367 chapter~\ref{running} for the explanation). So bits 0-4 switch on or
2368 off the 5 possible sources of board triggers, and bit 5 says if this
2369 board generates the system trigger. So \verb|0x21| -- bits 0 and 5 are
2370 set -- is saying that channel 1 triggers the board, and the board also
2371 makes the system trigger. \verb|0x30| means the system trigger, and
2372 the external trigger triggers the board. Keep in mind that if you
2373 choose to \emph{not} make the system trigger here, you need another
2374 device to do that; you will not get any events else.
2375
2376 There is another specialty in the standard Linux parameter
2377 parsing that you need to think of and which is shown in this setup
2378 example:
2379
2380 \begin{verbatim}
2381 rcdaq_client create_device device_drs -- 1 1001 0x21 -150 negative 438 2
2382 \end{verbatim}
2383
2384 Since we need to prevent the parser from interpreting the \verb|-150|
2385 as options ( -1, -5, -0), you need to tell it to stop the option
2386 parsing with the the ``double-dash'' -- \verb|--|. This is standard
2387 Unix shell behavior, but you need to remember that.
2388
2389 The above line sets the board up to trigger on channel 1, negative trigger
2390 with a -150\,mV threshold, an internal delay of 438 ticks (that's how
2391 far we ``look back'' in the waveform before the trigger), and 2GS/s
2392 speed. The final ``2'' parameter happens to mean 2GS/s, but this
2393 parameter is enumerated:
2394
2395 \begin{center}
2396 \begin{tabular}{|c|c|}
2397 \hline
2398 parameter & speed \\
2399 \hline
2400 \hline
2401 0 & 700\,MS/s \\ \hline
2402 1 & 1\,GS/s \\ \hline
2403 2 & 2\,GS/s \\ \hline
2404 3 & 5\,GS/s \\ \hline
2405 \end{tabular}
2406 \end{center}
2407
2408 By the way: The way I derive the delay and speed parameters is to run
2409 \verb|drsosc|, adjust everything the way I want it, and then
2410 transcribe the parameters from \verb|drsosc| to the setup command. If
2411 you look at Fig.~\ref{drsosc}, you will see that I used the same
2412 settings (2\,GS/s and a delay of 438 ticks) in the setup example
2413 above.
2414
2415 There are two more ``hidden'' parameters which assume default values
2416 when omitted. The above setup command is equivalent to
2417
2418 \begin{verbatim}
2419 rcdaq_client create_device device_drs -- 1 1001 0x21 -150 negative 438 2 0 1024
2420 \end{verbatim}
2421
2422 where the last two parameters mean ``start channel'' and ``number of
2423 samples''. Setting the former to a non-zero value will cut out the
2424 early part of the waveform. I \emph{strongly} advise against using
2425 this parameter, since this will actually slow down your system as it
2426 involves copying the desired part of the waveform to the right place.
2427 You can virtually always accomplish the same by adjusting the delay
2428 value (or delaying the hardware trigger). It is here more
2429 out of a sense of completeness.
2430
2431 With the ``number of samples'' parameter you can cut out the later
2432 part of the waveform. For example, if your signal is confined to the
2433 first 250 samples in your waveform, you can store just those first 250
2434 samples. This will only save storage space and not gain any
2435 significant readout speed, since we still need to read the full
2436 waveform and only discard the unwanted tail end. Different from
2437 discarding the front part, the tail end can be discarded without an
2438 expensive copy operation.
2439
2440
2441 \subsection{The CAEN DRS4 1742V System}
2442
2443
2444 The CAEN V1742 module, shown in Fig.~\ref{caen1742v}, is one of the
2445 more complex modules implemented in RCDAQ. At its core, it has 4 DRS4
2446 chips inside, providing 32 primary input channels, plus one ``side''
2447 channel per chip. Two of those can be used to digitize the NIM input
2448 signal if so desired.
2449
2450 Different from the evaluation board, it supports sampling speeds of 1,
2451 2.5, and 5\,GS/s.
2452
2453
2454 The assorted RCDAQ plugin, \verb|librcdaqplugin_CAENdrs.so|, provides
2455 two different devices to readout the V1742. One, called
2456 \verb|device_CAENdrs|, uses the preconfigured V1742 as-is, without
2457 changing any ``non-essential'' registers. This device makes the full
2458 configuration space available that the V1742 has to offer. It comes
2459 with a companion utility \verb|caen_client|, which can be used to
2460 adjust any available register as needed. I said ``non-essential''
2461 registers, because RCDAQ still sets up the registers that govern the
2462 actual readout the way it needs it; there is not much choice in that
2463 matter. Still, in this way one can set up any conceivable trigger
2464 mode, readout length, sample, rate, and so on, essentially any
2465 configuration parameter. Here is a list of parameters that the
2466 \verb|caen_client| utility can set and read:
2467
2468 \begin{figure}
2469 \centering
2470 \includegraphics[angle=90,width=0.8\columnwidth]{1742v.jpg}
2471 \caption{\label{caen1742v}The CAEN V1742 module.}
2472 \end{figure}
2473
2474
2475 \begin{verbatim}
2476 $ caen_client status
2477 MaxNumEventsBLT: 1
2478 ExtTriggerInputMode: 3 (ACQ_AND_EXTOUT)
2479 FastTriggerDigitizing: 0 (Disabled)
2480 FastTriggerMode: 0 (Disabled)
2481 OutputSignalMode: 0 (TRIGGER)
2482 Sampling Frequency: 2 (DRS4_1GHz)
2483 RecordLength: 1024 samples
2484 PostTriggerSize: 0
2485 IOLevel() 0 (NIM)
2486 AcquisitionMode 0 (software controlled)
2487 GroupEnableMask 0xf
2488 TriggerPolarity (F - falling edge / R - rising edge) :
2489 R R R R R R R R
2490 R R R R R R R R
2491 R R R R R R R R
2492 R R R R R R R R
2493
2494 ChannelDCOffset:
2495 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00
2496 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00
2497 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00
2498 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00 0x8f00
2499 \end{verbatim}
2500
2501 This pretty much covers the entire configuration space of the device.
2502
2503 The other device you can define is \verb|device_CAENdrs_std|, which is
2504 a no-frills standard configuration. It can also be adjusted by using
2505 \verb|device_CAENdrs| and \verb|caen_client|, but for a novice user it
2506 provides a guaranted-to-work way to configure the device. This device
2507 will not obey the \verb|caen_client| changes but re-set everything to
2508 its defaults at each begin-run. It takes a NIM signal on the
2509 trigger line, and adjusts the offsets to a range of $\pm 500$\,mV.
2510
2511 The syntax is
2512
2513 \begin{verbatim}
2514 device_CAENdrs_std evttype subid trigger speed delay
2515 \end{verbatim}
2516
2517 where "trigger" means whether or not the device provides the system trigger.
2518
2519
2520
2521 \end{document}
2522
2523