Skip to content

Commit fc9ad2a

Browse files
committed
Catch problems with corrupted CTF files
1 parent dd8940b commit fc9ad2a

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

Detectors/CTF/workflow/src/CTFReaderSpec.cxx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class CTFReaderSpec : public o2::framework::Task
8585
std::unique_ptr<TTree> mCTFTree;
8686
bool mRunning = false;
8787
int mCTFCounter = 0;
88+
int mNFailedFiles = 0;
89+
int mFilesRead = 0;
8890
long mLastSendTime = 0L;
8991
long mCurrTreeEntry = 0;
9092
size_t mSelIDEntry = 0; // next CTFID to select from the mInput.ctfIDs (if non-empty)
@@ -110,7 +112,7 @@ void CTFReaderSpec::stopReader()
110112
if (!mFileFetcher) {
111113
return;
112114
}
113-
LOG(INFO) << "CTFReader stops processing";
115+
LOGP(INFO, "CTFReader stops processing, {} files read, {} files failed", mFilesRead - mNFailedFiles, mNFailedFiles);
114116
LOGP(INFO, "CTF reading total timing: Cpu: {:.3f} Real: {:.3f} s for {} TFs in {} loops",
115117
mTimer.CpuTime(), mTimer.RealTime(), mCTFCounter, mFileFetcher->getNLoops());
116118
mRunning = false;
@@ -137,14 +139,24 @@ void CTFReaderSpec::init(InitContext& ic)
137139
///_______________________________________
138140
void CTFReaderSpec::openCTFFile(const std::string& flname)
139141
{
140-
mCTFFile.reset(TFile::Open(flname.c_str()));
141-
if (!mCTFFile->IsOpen() || mCTFFile->IsZombie()) {
142-
LOG(ERROR) << "Failed to open file " << flname;
143-
throw std::runtime_error("failed to open CTF file");
144-
}
145-
mCTFTree.reset((TTree*)mCTFFile->Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
146-
if (!mCTFTree) {
147-
throw std::runtime_error("failed to load CTF tree");
142+
try {
143+
mFilesRead++;
144+
mCTFFile.reset(TFile::Open(flname.c_str()));
145+
if (!mCTFFile || !mCTFFile->IsOpen() || mCTFFile->IsZombie()) {
146+
throw std::runtime_error("failed to open CTF file");
147+
}
148+
mCTFTree.reset((TTree*)mCTFFile->Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
149+
if (!mCTFTree) {
150+
throw std::runtime_error("failed to load CTF tree from");
151+
}
152+
} catch (const std::exception& e) {
153+
LOG(ERROR) << "Cannot process " << flname << ", reason: " << e.what();
154+
mCTFTree.reset();
155+
mCTFFile.reset();
156+
mNFailedFiles++;
157+
if (mFileFetcher) {
158+
mFileFetcher->popFromQueue(mInput.maxLoops < 1);
159+
}
148160
}
149161
mCurrTreeEntry = 0;
150162
}

0 commit comments

Comments
 (0)