Skip to content

Commit f848b1d

Browse files
authored
Merge pull request #18 from sy-c/master
readout - minor upgrade
2 parents efce624 + 0d4f215 commit f848b1d

File tree

4 files changed

+97
-8
lines changed

4 files changed

+97
-8
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
This is the O2 Readout package.
2+
The documentation is in [the doc directory](doc/README.md)
3+
14
[![JIRA](https://img.shields.io/badge/JIRA-Report%20issue-blue.svg)](https://alice.its.cern.ch/jira/secure/CreateIssue.jspa?pid=11201&issuetype=1)

readout.cfg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,13 @@ monitoringURI=infologger://
132132
[consumer-rec]
133133
consumerType=fileRecorder
134134
enabled=0
135+
# the fileName value defines the path of the file to be created
136+
# it may include some runtime variables:
137+
# ${XYZ} -> get variable XYZ from environment
138+
# %t -> unix timestamp (seconds since epoch)
139+
# %T -> formatted date/time string, in the form YYYY_MM_DD__h_m_s__
135140
fileName=/tmp/data.raw
136-
141+
137142

138143

139144
# push to fairMQ device

src/ConsumerFileRecorder.cxx

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
#include "Consumer.h"
22
#include "ReadoutUtils.h"
3-
3+
#include <iomanip>
44

55
class ConsumerFileRecorder: public Consumer {
66
public:
7+
78
ConsumerFileRecorder(ConfigFile &cfg, std::string cfgEntryPoint):Consumer(cfg,cfgEntryPoint) {
89
counterBytesTotal=0;
910
fp=NULL;
1011

1112
fileName=cfg.getValue<std::string>(cfgEntryPoint + ".fileName");
1213
if (fileName.length()>0) {
13-
theLog.log("Recording to %s",fileName.c_str());
14-
fp=fopen(fileName.c_str(),"wb");
15-
if (fp==NULL) {
16-
theLog.log("Failed to create file");
17-
}
14+
theLog.log("Recording path = %s",fileName.c_str());
15+
createFile();
1816
}
1917
if (fp==NULL) {
2018
theLog.log("Recording disabled");
@@ -34,6 +32,86 @@ class ConsumerFileRecorder: public Consumer {
3432
closeRecordingFile();
3533
}
3634

35+
int createFile() {
36+
// create the file name according to specified path
37+
38+
// parse the string, and subst variables:
39+
// ${XXX} -> get variable XXX from environment
40+
// %t -> unix timestamp (seconds since epoch)
41+
// %T -> formatted date/time
42+
43+
std::string newFileName;
44+
45+
int parseError=0;
46+
for (std::string::iterator it=fileName.begin();it!=fileName.end();++it) {
47+
// subst environment variable
48+
if (*it=='$') {
49+
++it;
50+
int varNameComplete=0;
51+
if (it!=fileName.end()) {
52+
if (*it=='{') {
53+
std::string varName;
54+
55+
for (++it;it!=fileName.end();++it) {
56+
if (*it=='}') {
57+
varNameComplete=1;
58+
break;
59+
} else {
60+
varName+=*it;
61+
}
62+
}
63+
if (varNameComplete) {
64+
const char *val=getenv(varName.c_str());
65+
if (val!=nullptr) {
66+
newFileName+=val;
67+
//theLog.log((varName + " = " + val).c_str());
68+
}
69+
}
70+
}
71+
}
72+
if (!varNameComplete) {
73+
parseError++;
74+
}
75+
} else if (*it=='%') {
76+
// escape characters
77+
++it;
78+
if (it!=fileName.end()) {
79+
if (*it=='t') {
80+
newFileName+=std::to_string(std::time(nullptr));
81+
} else if (*it=='T') {
82+
std::time_t t = std::time(nullptr);
83+
std::tm tm = *std::localtime(&t);
84+
std::stringstream buffer;
85+
buffer << std::put_time(&tm, "%Y_%m_%d__%H_%M_%S__");
86+
newFileName+=buffer.str();
87+
} else {
88+
parseError++;
89+
}
90+
} else {
91+
parseError++;
92+
}
93+
} else {
94+
// normal char - copy it
95+
newFileName+=*it;
96+
}
97+
if (parseError) {
98+
break;
99+
}
100+
}
101+
if (parseError) {
102+
theLog.log("Failed to parse recording file path");
103+
return -1;
104+
}
105+
theLog.log(("Opening file for writing: " + newFileName).c_str());
106+
107+
fp=fopen(newFileName.c_str(),"wb");
108+
if (fp==NULL) {
109+
theLog.log("Failed to create file");
110+
return -1;
111+
}
112+
return 0;
113+
}
114+
37115
// fwrite function with partial write auto-retry
38116
int writeToFile(FILE *fp, void *data, size_t numberOfBytes) {
39117
unsigned char *buffer=(unsigned char *)data;

src/ReadoutEquipmentRORC.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
156156
params.setGeneratorLoopback(AliceO2::roc::LoopbackMode::fromString(cfgGeneratorLoopback));
157157
params.setGeneratorPattern(AliceO2::roc::GeneratorPattern::fromString(cfgGeneratorPattern));
158158
params.setGeneratorRandomSizeEnabled(cfgGeneratorRandomSizeEnabled);
159-
}
159+
} else {
160+
// for some unknown reason, one has to explicitely disable the loopback when not using the generator
161+
params.setGeneratorLoopback(AliceO2::roc::LoopbackMode::None);
162+
}
160163

161164
// card readout mode : experimental, not needed
162165
// params.setReadoutMode(AliceO2::roc::ReadoutMode::fromString(cfgReadoutMode));

0 commit comments

Comments
 (0)