Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
srcs
sbnana
sbnanalysis
ana
SBNOscReco
uScript
main.cc
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
5
#include <iostream>
6
7
#include "
common.h
"
8
#include "
chunk.h
"
9
#include "
vm.h
"
10
#include "
compile.h
"
11
12
#include "
api.h
"
13
14
#include "../Data/RecoEvent.h"
15
#include "../Data/FlatInteraction.h"
16
17
static
void
repl
() {
18
numu::RecoEvent
event;
19
event
.
type
= (
numu::MCType
)1;
20
numu::CRTHit
hit
;
21
hit.
pes
= -5.6;
22
event
.in_time_crt_hits.push_back(hit);
23
24
numu::RecoSlice
slice;
25
slice.
flash_match
.
time
= 2.;
26
27
numu::TrueParticle
particle;
28
29
numu::flat::FlatInteraction
flat;
30
flat.
ptrack
.
start
[1] = 5.;
31
32
uscript::Compiler::Register<numu::TrueParticle>();
33
uscript::Compiler::Register<numu::RecoEvent>();
34
uscript::Compiler::Register<numu::RecoSlice>();
35
uscript::Compiler::Register<numu::flat::FlatInteraction>();
36
37
char
line[1024];
38
uscript::VM
vm;
39
while
(1) {
40
std::cout
<<
"> "
;
41
if
(!fgets(line,
sizeof
(line), stdin)) {
42
std::cout
<<
"\n"
;
43
break
;
44
}
45
uscript::Chunk
chunk =
uscript::compileChunk
(line);
46
if
(
uscript::Compiler::HadError
())
continue
;
47
vm.
SetChunk
(&chunk);
48
vm.
AddGlobal
(
"flat"
, &flat);
49
vm.
AddGlobal
(
"event"
, &event);
50
vm.
AddGlobal
(
"slice"
, &slice);
51
vm.
AddGlobal
(
"particle"
, &particle);
52
int
global = 5;
53
vm.
AddGlobal
(
"int"
, &global);
54
uscript::Value
v;
55
vm.
Run
(&v);
56
if
(!
IS_NIL
(v)) {
57
v.
Print
();
58
std::cout
<< std::endl;
59
}
60
}
61
}
62
63
static
char
*
readFile
(
const
char
*
path
) {
64
FILE*
file
= fopen(path,
"rb"
);
65
if
(file == NULL) {
66
std::cerr
<<
"Could not open file: "
<< path << std::endl;
67
return
NULL;
68
}
69
70
fseek(file, 0L, SEEK_END);
71
size_t
fileSize = ftell(file);
72
rewind(file);
73
74
char
* buffer = (
char
*)malloc(fileSize + 1);
75
if
(buffer == NULL) {
76
std::cerr
<<
"Not enough memory to read file\n"
;
77
return
NULL;
78
}
79
size_t
bytesRead = fread(buffer,
sizeof
(
char
), fileSize, file);
80
if
(bytesRead < fileSize) {
81
std::cerr
<<
"Could not read file.\n"
;
82
free(buffer);
83
return
NULL;
84
}
85
buffer[bytesRead] =
'\0'
;
86
87
fclose(file);
88
return
buffer;
89
}
90
91
static
int
runFile
(
const
char
*
path
) {
92
char
*
source
=
readFile
(path);
93
if
(source == NULL)
return
60;
94
uscript::VM
vm;
95
uscript::InterpretResult
result = vm.
Interpret
(source);
96
free(source);
97
98
if
(result ==
uscript::INTERPRET_COMPILE_ERROR
)
return
65;
99
if
(result ==
uscript::INTERPRET_RUNTIME_ERROR
)
return
70;
100
return
0;
101
}
102
103
int
main
(
int
argc,
const
char
* argv[]) {
104
if
(argc == 1) {
105
repl
();
106
}
107
else
if
(argc == 2) {
108
return
runFile
(argv[1]);
109
}
110
else
{
111
std::cout
<<
"Usage: uscript [path]\n"
;
112
return
64;
113
}
114
return
0;
115
}
116
117
numu::FlashMatch::time
float time
Time of flash [us].
Definition:
sbnana/sbnanalysis/ana/SBNOscReco/Data/FlashMatch.h:10
uscript::Compiler::HadError
static bool HadError()
Definition:
compile.h:139
numu::RecoEvent
Definition:
RecoEvent.h:47
uscript::VM::SetChunk
void SetChunk(const Chunk *_chunk)
Definition:
vm.cc:31
uscript::compileChunk
Chunk compileChunk(const char *source)
Definition:
api.h:45
numu::TrueParticle
Definition:
TrueParticle.h:23
api.h
cerr
BEGIN_PROLOG could also be cerr
Definition:
messageservice.fcl:10
numu::flat::FlatInteraction::ptrack
PrimaryTrack ptrack
Definition:
FlatInteraction.h:55
source
do source
Definition:
updateVersionList.sh:32
file
* file
Definition:
file_to_url.sh:69
repl
static void repl()
Definition:
main.cc:17
runFile
static int runFile(const char *path)
Definition:
main.cc:91
hit
process_name hit
Definition:
cheaterreco.fcl:51
uscript::VM
Definition:
vm.h:20
path
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
Definition:
magic_raw_to_triggeremu_icarus_Run1_data.fcl:108
uscript::VM::Interpret
InterpretResult Interpret(const char *source)
Definition:
vm.cc:14
uscript::Value
Definition:
value.h:29
numu::RecoSlice::flash_match
FlashMatch flash_match
Result of flash matching algorithm on this slice.
Definition:
RecoEvent.h:30
numu::CRTHit
Definition:
DetInfo.h:12
chunk.h
uscript::INTERPRET_COMPILE_ERROR
Definition:
vm.h:16
readFile
static char * readFile(const char *path)
Definition:
main.cc:63
uscript::VM::Run
InterpretResult Run(Value *ret=NULL)
Definition:
vm.cc:65
IS_NIL
#define IS_NIL(value)
Definition:
value.h:59
compile.h
uscript::InterpretResult
InterpretResult
Definition:
vm.h:14
numu::flat::FlatInteraction
Definition:
FlatInteraction.h:54
uscript::Value::Print
void Print() const
Definition:
value.cc:5
numu::RecoEvent::type
MCType type
Definition:
RecoEvent.h:53
numu::CRTHit::pes
float pes
Number of PE's in hit.
Definition:
DetInfo.h:15
uscript::Chunk
Definition:
chunk.h:45
uscript::VM::AddGlobal
void AddGlobal(const char *name, const TObj *object)
Definition:
vm.h:51
uscript::INTERPRET_RUNTIME_ERROR
Definition:
vm.h:17
numu::flat::PrimaryTrack::start
float start[3]
Definition:
FlatInteraction.h:25
common.h
vm.h
numu::MCType
MCType
Definition:
MCType.h:5
main
int main(int argc, char **argv)
Definition:
DetectorActivityRatePlots.cpp:996
cout
BEGIN_PROLOG could also be cout
Definition:
messageservice.fcl:10
numu::RecoSlice
Definition:
RecoEvent.h:24
Generated by
1.8.5