ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCalib_StrawStatus_merge.cxx File Reference
#include "CxxUtils/checker_macros.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <unistd.h>
#include <memory>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Variables

 ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 21 of file TRTCalib_StrawStatus_merge.cxx.

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}
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
static TFile * fout
Definition listroot.cxx:40

Variable Documentation

◆ ATLAS_NO_CHECK_FILE_THREAD_SAFETY

ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Definition at line 6 of file TRTCalib_StrawStatus_merge.cxx.