ATLAS Offline Software
InnerDetector
InDetCalibAlgs
TRT_CalibAlgs
scripts
TRTCalib_StrawStatus_merge.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
CxxUtils/checker_macros.h
"
6
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
;
7
8
#include <iostream>
9
#include <iomanip>
10
#include <string>
11
#include <fstream>
12
#include <sstream>
13
#include <map>
14
#include <set>
15
#include <vector>
16
#include <unistd.h>
17
#include <memory>
18
19
using namespace
std;
20
21
int
main
(
int
argc
,
char
*
argv
[])
22
{
23
24
int
nfiles =
argc
- 2;
25
cout <<
" TRT_StrawStatus_merge. nfiles= "
<< nfiles << endl;
26
27
// nBarrelStraws (= 1642) + nEndcapStraws (= 3840) = 5482
28
// 6 index refers to categories of accumulation: last index: 0 - all hits, 1 - hits on track, 2 - all HT (TR) hits, 3 - HT (TR) hits on track
29
// 32 refers to the phi coordinate index
30
//heap-allocated
31
std::unique_ptr<int[][5482][6]> accumulateHits(
new
int
[32][5482][6]);
32
33
int
nevents
= 0;
// we first need to read the first line in each file to get the total number of events
34
for
(
int
irun = 0; irun < nfiles; irun++)
35
{
36
std::string
filename
=
argv
[irun + 2];
37
printf(
"reading file %s \n"
,
filename
.c_str());
// debug printout
38
FILE *
f
= fopen(
filename
.c_str(),
"r"
);
39
if
(
f
==
nullptr
)
40
{
41
fprintf(
stderr
,
" - file %s missing\n"
,
filename
.c_str());
42
exit
(1);
43
}
44
int
tmp
[10]{};
45
int
nItems = fscanf(
f
,
"%d %d %d %d %d %d %d %d %d\n"
,
tmp
,
tmp
+ 1,
tmp
+ 2,
tmp
+ 3,
tmp
+ 4,
tmp
+ 5,
tmp
+ 6,
tmp
+ 7,
tmp
+ 8);
46
if
(nItems !=9){
47
std::cerr<<
"TRTCalib_StrawStatus_merge: Incorrect fline in "
<<
filename
<<std::endl;
48
continue
;
49
}
50
nevents
+=
tmp
[8];
51
fclose(
f
);
52
}
53
printf(
"read %d events from %d files\n"
,
nevents
, nfiles);
54
55
FILE *
fout
= fopen(
argv
[1],
"w"
);
// The output merged file.
56
if
(
fout
==
nullptr
)
57
{
58
fprintf(
stderr
,
"could not open file %s for writing, EXIT"
,
argv
[1]);
59
exit
(1);
60
}
61
printf(
"writing to merged file: %s\n"
,
argv
[1]);
62
for
(
int
i
= 0;
i
< 8;
i
++)
63
fprintf(
fout
,
"%d "
, 0);
64
fprintf(
fout
,
"%d\n"
,
nevents
);
// write total number of events in the first line
65
66
for
(
int
side
= 0;
side
< 2;
side
++)
67
{
// merge separately on the two sides
68
69
cout <<
" reset status for all straws on side "
<<
side
* 2 - 1 << endl;
70
for
(
int
j = 0; j < 32; j++)
71
for
(
int
k
= 0;
k
< 5482;
k
++)
72
for
(
int
m
= 0;
m
< 6;
m
++)
73
accumulateHits[j][
k
][
m
] = 0;
74
75
for
(
int
irun = 0; irun < nfiles; irun++)
76
{
// loop again over input files
77
char
filename
[1000];
78
snprintf(
filename
, 999,
"%s"
,
argv
[irun + 2]);
79
FILE *
f
= fopen(
filename
,
"r"
);
80
if
(!
f
)
81
continue
;
82
int
tmp
[10]{};
83
int
count
(0);
84
// read the first line in this file
85
int
nItems = fscanf(
f
,
"%d %d %d %d %d %d %d %d %d\n"
,
tmp
,
tmp
+ 1,
tmp
+ 2,
tmp
+ 3,
tmp
+ 4,
tmp
+ 5,
tmp
+ 6,
tmp
+ 7,
tmp
+ 8);
86
if
(nItems !=9){
87
std::cerr<<
"TRTCalib_StrawStatus_merge: Incorrect line in "
<<
filename
<<std::endl;
88
continue
;
89
}
90
// read the rest of the lines in this file
91
while
(fscanf(
f
,
"%d %d %d %d %d %d %d %d %d\n"
,
tmp
,
tmp
+ 1,
tmp
+ 2,
tmp
+ 3,
tmp
+ 4,
tmp
+ 5,
tmp
+ 6,
tmp
+ 7,
tmp
+ 8) == 9)
92
{
93
94
if
(
tmp
[0] < 0 &&
side
== 1)
95
continue
;
// only count A side
96
if
(
tmp
[0] > 0 &&
side
== 0)
97
continue
;
// only count C side
98
count
++;
99
100
for
(
int
k
= 0;
k
< 6;
k
++)
101
//coverity[tainted_data]
102
accumulateHits[
tmp
[1]][
tmp
[2]][
k
] +=
tmp
[3 +
k
];
103
}
104
fclose(
f
);
105
printf(
"read %7d lines from file %s \n"
,
count
,
argv
[irun + 2]);
106
}
// end loop over input files
107
108
// write counts to merged output file
109
for
(
int
j = 0; j < 32; j++)
110
for
(
int
k
= 0;
k
< 5482;
k
++)
111
{
112
int
bec
= 2 *
side
- 1;
113
if
(
k
>= 1642)
114
bec
*= 2;
115
fprintf(
fout
,
"%d %d %d"
,
bec
, j,
k
);
116
for
(
int
m
= 0;
m
< 6;
m
++)
117
fprintf(
fout
,
" %d"
, accumulateHits[j][
k
][
m
]);
118
fprintf(
fout
,
"\n"
);
119
}
120
}
// end loop over the two sides
121
122
fclose(
fout
);
123
printf(
"closed merged file: %s\n"
,
argv
[1]);
124
exit
(0);
125
}
ParticleGun_SamplingFraction.bec
int bec
Definition:
ParticleGun_SamplingFraction.py:89
main
int main(int argc, char *argv[])
Definition:
TRTCalib_StrawStatus_merge.cxx:21
get_generator_info.stderr
stderr
Definition:
get_generator_info.py:40
XMLtoHeader.count
count
Definition:
XMLtoHeader.py:84
TRT::Hit::side
@ side
Definition:
HitInfo.h:83
lumiFormat.i
int i
Definition:
lumiFormat.py:85
LArCellNtuple.argv
argv
Definition:
LArCellNtuple.py:152
dqt_zlumi_alleff_HIST.fout
fout
Definition:
dqt_zlumi_alleff_HIST.py:59
hist_file_dump.f
f
Definition:
hist_file_dump.py:140
DQHistogramMergeRegExp.argc
argc
Definition:
DQHistogramMergeRegExp.py:19
DeMoUpdate.tmp
string tmp
Definition:
DeMoUpdate.py:1167
calibdata.exit
exit
Definition:
calibdata.py:235
CaloCellTimeCorrFiller.filename
filename
Definition:
CaloCellTimeCorrFiller.py:23
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Definition:
TRTCalib_StrawStatus_merge.cxx:6
LArG4GenerateShowerLib.nevents
nevents
Definition:
LArG4GenerateShowerLib.py:19
checker_macros.h
Define macros for attributes used to control the static checker.
fitman.k
k
Definition:
fitman.py:528
python.SystemOfUnits.m
float m
Definition:
SystemOfUnits.py:106
Generated on Fri Nov 14 2025 21:22:18 for ATLAS Offline Software by
1.8.18