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
12
13#include <boost/algorithm/string/split.hpp>
14#include <boost/algorithm/string/classification.hpp>
15#include <fstream>
16#include <memory>
17
19
21{
22 ATH_MSG_INFO ( "... in stop()" );
23
24 // input file
25 std::ifstream inf(m_input_file_name);
26 if(!inf.is_open()){
27 ATH_MSG_ERROR("Could not open input file "<<m_input_file_name);
28 return StatusCode::FAILURE;
29 }
30
31 // Create new LArPhysWaveContainer
32 auto larPhysWaveContainerNew = std::make_unique<LArPhysWaveContainer>();
33 ATH_CHECK ( larPhysWaveContainerNew->setGroupingType(m_groupingType, msg()) );
34 ATH_CHECK ( larPhysWaveContainerNew->initialize() );
35
36 unsigned int hwid=0;
37 unsigned int lcounter=0;
38 float timdiff=0;
39 float lasttime=0;
40 // loop over lines
41 std::string line="";
42 std::vector<double> wave;
43 std::vector<double> wave_err;
44 std::vector<int> wave_trig;
45
46 unsigned lsize = m_hasIndex ? 4 : 3;
47
48 while ( ! std::getline(inf, line).eof() )
49 {
50 std::vector<std::string> strvec;
51 boost::split(strvec, line, boost::is_any_of(" "));
52 if(strvec.size() != lsize) {
53 ATH_MSG_WARNING("Wrong line: "<<line<<", skipped "<<strvec.size());
54 continue;
55 }
56 //check if we have new channel
57 if(!hwid) { // first line
58 if(std::stoi(strvec[1]) != 0) {
59 ATH_MSG_WARNING("Inconsistent first line of channel: "<<line);
60 continue;
61 }
62 hwid = std::stoi(strvec[0]);
63 lcounter=0;
64 timdiff=0;
65 lasttime=std::stof(strvec[lsize - 2]);
66 wave.push_back(std::stod(strvec[lsize - 1]));
67 wave_err.push_back(0);
68 wave_trig.push_back(1);
69 } else if(hwid != std::stoul(strvec[0])) { // new channels
70 // store previous wave
71 unsigned int skipped = 0;
72 unsigned int limit = wave.size();
74 std::vector<double> store_wave(limit,0);
75 std::vector<double> store_wave_err(limit,0);
76 std::vector<int> store_wave_trig(limit,1);
77 for ( unsigned int i = 0; i < limit; i++ ) {
78 if ( skipped >= m_skipPoints ) {
79 store_wave[i-m_skipPoints+m_prefixPoints]=wave[i];
80 store_wave_err[i-m_skipPoints+m_prefixPoints]=wave_err[i];
81 store_wave_trig[i-m_skipPoints+m_prefixPoints]=wave_trig[i];
82 }
83 else skipped++;
84 }
85
86 LArPhysWave newLArPhysWave(store_wave, store_wave_err, store_wave_trig, timdiff, 0, 0);
87 // Add physics wave to container
88 larPhysWaveContainerNew->setPdata(HWIdentifier(hwid), newLArPhysWave, (CaloGain::CaloGain)m_gain.value());
89
90 // reset vectors
91 wave.clear();
92 wave_err.clear();
93 wave_trig.clear();
94
95 if(m_hasIndex && std::stoi(strvec[1]) != 0) {
96 ATH_MSG_WARNING("Inconsistent first line of channel: "<<line);
97 continue;
98 }
99 hwid = std::stoi(strvec[0]);
100 lcounter=0;
101 timdiff=0;
102 lasttime=std::stof(strvec[lsize - 2]);
103 wave.push_back(std::stod(strvec[lsize - 1]));
104 wave_err.push_back(0);
105 wave_trig.push_back(1);
106
107 } else { // next line in channel
108 if(m_hasIndex && lcounter+1 != std::stoul(strvec[1])){ // wrong series ?
109 ATH_MSG_WARNING("Wrong next line: "<<line);
110 ATH_MSG_WARNING(lcounter+1 << " " << std::stoi(strvec[1]));
111 continue;
112 }
113 if(!timdiff) {
114 timdiff= std::stof(strvec[lsize - 2]) - lasttime;
115 } else {
116 if(int(timdiff) != int(std::stof(strvec[lsize - 2]) - lasttime)) {
117 ATH_MSG_WARNING("Non equal time bins ? "<<line);
118 ATH_MSG_WARNING(int(timdiff)<<" "<<int(std::stof(strvec[lsize - 2]) - lasttime)<<" "<<lasttime);
119 ++lcounter;
120 continue;
121 }
122 }
123 lasttime=std::stof(strvec[lsize - 2]);
124 wave.push_back(std::stod(strvec[lsize - 1]));
125 wave_err.push_back(0);
126 wave_trig.push_back(1);
127 ++lcounter;
128 }
129
130 }
131 // store last wave
132 unsigned int skipped = 0;
133 unsigned int limit = wave.size();
135 std::vector<double> store_wave(limit,0);
136 std::vector<double> store_wave_err(limit,0);
137 std::vector<int> store_wave_trig(limit,1);
138 for ( unsigned int i = 0; i < limit; i++ ) {
139 if ( skipped >= m_skipPoints ) {
140 store_wave[i-m_skipPoints+m_prefixPoints]=wave[i];
141 store_wave_err[i-m_skipPoints+m_prefixPoints]=wave_err[i];
142 store_wave_trig[i-m_skipPoints+m_prefixPoints]=wave_trig[i];
143 }
144 else skipped++;
145 }
146
147 LArPhysWave newLArPhysWave(store_wave, store_wave_err, store_wave_trig, timdiff, 0, 0);
148 // Add physics wave to container
149 larPhysWaveContainerNew->setPdata(HWIdentifier(hwid), newLArPhysWave, (CaloGain::CaloGain)m_gain.value());
150
151 ATH_CHECK( detStore()->record(std::move(larPhysWaveContainerNew),m_store_key) );
152 ATH_MSG_INFO ( "LArPhysWaveFromAscii finalized!" );
153 return StatusCode::SUCCESS;
154}
#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