ATLAS Offline Software
Loading...
Searching...
No Matches
LArPhysWaveFromAscii.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10
13
14#include <fstream>
15#include <memory>
16
18
20{
21 ATH_MSG_INFO ( "... in stop()" );
22
23 // input file
24 std::ifstream inf(m_input_file_name);
25 if(!inf.is_open()){
26 ATH_MSG_ERROR("Could not open input file "<<m_input_file_name);
27 return StatusCode::FAILURE;
28 }
29
30 // Create new LArPhysWaveContainer
31 auto larPhysWaveContainerNew = std::make_unique<LArPhysWaveContainer>();
32 ATH_CHECK ( larPhysWaveContainerNew->setGroupingType(m_groupingType, msg()) );
33 ATH_CHECK ( larPhysWaveContainerNew->initialize() );
34
35 unsigned int hwid=0;
36 unsigned int lcounter=0;
37 float timdiff=0;
38 float lasttime=0;
39 // loop over lines
40 std::string line="";
41 std::vector<double> wave;
42 std::vector<double> wave_err;
43 std::vector<int> wave_trig;
44
45 unsigned lsize = m_hasIndex ? 4 : 3;
46
47 while ( ! std::getline(inf, line).eof() )
48 {
49 std::vector<std::string> strvec = CxxUtils::tokenize(line, ' ');
50 if(strvec.size() != lsize) {
51 ATH_MSG_WARNING("Wrong line: "<<line<<", skipped "<<strvec.size());
52 continue;
53 }
54 //check if we have new channel
55 if(!hwid) { // first line
56 if(std::stoi(strvec[1]) != 0) {
57 ATH_MSG_WARNING("Inconsistent first line of channel: "<<line);
58 continue;
59 }
60 hwid = std::stoi(strvec[0]);
61 lcounter=0;
62 timdiff=0;
63 lasttime=std::stof(strvec[lsize - 2]);
64 wave.push_back(std::stod(strvec[lsize - 1]));
65 wave_err.push_back(0);
66 wave_trig.push_back(1);
67 } else if(hwid != std::stoul(strvec[0])) { // new channels
68 // store previous wave
69 unsigned int skipped = 0;
70 unsigned int limit = wave.size();
72 std::vector<double> store_wave(limit,0);
73 std::vector<double> store_wave_err(limit,0);
74 std::vector<int> store_wave_trig(limit,1);
75 for ( unsigned int i = 0; i < limit; i++ ) {
76 if ( skipped >= m_skipPoints ) {
77 store_wave[i-m_skipPoints+m_prefixPoints]=wave[i];
78 store_wave_err[i-m_skipPoints+m_prefixPoints]=wave_err[i];
79 store_wave_trig[i-m_skipPoints+m_prefixPoints]=wave_trig[i];
80 }
81 else skipped++;
82 }
83
84 LArPhysWave newLArPhysWave(store_wave, store_wave_err, store_wave_trig, timdiff, 0, 0);
85 // Add physics wave to container
86 larPhysWaveContainerNew->setPdata(HWIdentifier(hwid), newLArPhysWave, (CaloGain::CaloGain)m_gain.value());
87
88 // reset vectors
89 wave.clear();
90 wave_err.clear();
91 wave_trig.clear();
92
93 if(m_hasIndex && std::stoi(strvec[1]) != 0) {
94 ATH_MSG_WARNING("Inconsistent first line of channel: "<<line);
95 continue;
96 }
97 hwid = std::stoi(strvec[0]);
98 lcounter=0;
99 timdiff=0;
100 lasttime=std::stof(strvec[lsize - 2]);
101 wave.push_back(std::stod(strvec[lsize - 1]));
102 wave_err.push_back(0);
103 wave_trig.push_back(1);
104
105 } else { // next line in channel
106 if(m_hasIndex && lcounter+1 != std::stoul(strvec[1])){ // wrong series ?
107 ATH_MSG_WARNING("Wrong next line: "<<line);
108 ATH_MSG_WARNING(lcounter+1 << " " << std::stoi(strvec[1]));
109 continue;
110 }
111 if(!timdiff) {
112 timdiff= std::stof(strvec[lsize - 2]) - lasttime;
113 } else {
114 if(int(timdiff) != int(std::stof(strvec[lsize - 2]) - lasttime)) {
115 ATH_MSG_WARNING("Non equal time bins ? "<<line);
116 ATH_MSG_WARNING(int(timdiff)<<" "<<int(std::stof(strvec[lsize - 2]) - lasttime)<<" "<<lasttime);
117 ++lcounter;
118 continue;
119 }
120 }
121 lasttime=std::stof(strvec[lsize - 2]);
122 wave.push_back(std::stod(strvec[lsize - 1]));
123 wave_err.push_back(0);
124 wave_trig.push_back(1);
125 ++lcounter;
126 }
127
128 }
129 // store last wave
130 unsigned int skipped = 0;
131 unsigned int limit = wave.size();
133 std::vector<double> store_wave(limit,0);
134 std::vector<double> store_wave_err(limit,0);
135 std::vector<int> store_wave_trig(limit,1);
136 for ( unsigned int i = 0; i < limit; i++ ) {
137 if ( skipped >= m_skipPoints ) {
138 store_wave[i-m_skipPoints+m_prefixPoints]=wave[i];
139 store_wave_err[i-m_skipPoints+m_prefixPoints]=wave_err[i];
140 store_wave_trig[i-m_skipPoints+m_prefixPoints]=wave_trig[i];
141 }
142 else skipped++;
143 }
144
145 LArPhysWave newLArPhysWave(store_wave, store_wave_err, store_wave_trig, timdiff, 0, 0);
146 // Add physics wave to container
147 larPhysWaveContainerNew->setPdata(HWIdentifier(hwid), newLArPhysWave, (CaloGain::CaloGain)m_gain.value());
148
149 ATH_CHECK( detStore()->record(std::move(larPhysWaveContainerNew),m_store_key) );
150 ATH_MSG_INFO ( "LArPhysWaveFromAscii finalized!" );
151 return StatusCode::SUCCESS;
152}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
const ServiceHandle< StoreGateSvc > & detStore() const
StringProperty m_groupingType
Grouping type. Default is Feedthrough.
virtual StatusCode stop() override final
UnsignedIntegerProperty m_skipPoints
the first m_skipPoints points of the waveform in the file are skipped
UnsignedIntegerProperty m_gain
which gain to store ?
StringProperty m_input_file_name
list of input ntuple file names
virtual ~LArPhysWaveFromAscii()
UnsignedIntegerProperty m_prefixPoints
make a PhysWave with the first m_prefixPoints as zeros
StringProperty m_store_key
key of the PhysWave collection
BooleanProperty m_hasIndex
has index in input data ?
TStreamerInfo * inf
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.