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