OpenMS
Loading...
Searching...
No Matches
QPXCollectionExport::Transaction Class Reference

Scope guard that leaves no partial QPX collection behind. More...

#include <OpenMS/FORMAT/QPXCollectionExport.h>

Public Member Functions

 Transaction (const std::string &directory)
 Start guarding a QPX collection directory.
 
 ~Transaction ()
 Remove the collection files this export created, unless commit() was called.
 
void commit ()
 Keep the collection: the export completed.
 
 Transaction (const Transaction &)=delete
 
Transaction & operator= (const Transaction &)=delete
 
 Transaction (Transaction &&)=delete
 
Transaction & operator= (Transaction &&)=delete
 

Private Attributes

std::string directory_
 
std::vector< std::string > preexisting_
 Collection files that were already on disk when the guard started; never removed.
 
bool committed_ {false}
 

Detailed Description

Scope guard that leaves no partial QPX collection behind.

requireExportable() cannot decide everything: a view can still refuse a row it only sees while building the table, and a write can fail on I/O. Either way the earlier files of the collection are already on disk, and a directory holding quantms.feature.parquet but no quantms.psm.parquet is indistinguishable from a complete export of a smaller dataset.

Construct this before the first write and call commit() once the last one has succeeded. On any other exit – a view returning false, a writer throwing, an early return – the destructor removes the collection files this export created, so the export is all-or-nothing. Enumerating the failure sites instead would silently miss the next one.

Files that already existed when the guard was constructed are never removed. Exporting into a directory that still holds an earlier collection is the normal way to re-run a pipeline, and a failed re-run must not take the previous result with it. Such a run does leave the directory mixed – the views that ran overwrote their files before the failure – so the destructor names the surviving files in its warning rather than pretending the directory is still coherent.

if (!ConsensusMapArrowExport::exportToParquet(cmap, out_qpx + "/quantms.feature.parquet")) { throw ...; }
if (!QPXFile::exportToParquet(prot_ids, pep_ids, out_qpx + "/quantms.psm.parquet")) { throw ...; }
if (!ProteinGroupArrowExport::exportToParquet(cmap, design, out_qpx + "/quantms.pg.parquet")) { throw ...; }
qpx.commit();
static bool exportToParquet(const ConsensusMap &cmap, const std::string &filename, const ParquetWriteConfig &config=ParquetWriteConfig{}, QPXIdentity::FeatureLinks *out_links=nullptr)
Export ConsensusMap to Parquet file.
static bool exportToParquet(const ConsensusMap &cmap, const ExperimentalDesign &design, const std::string &filename, const ParquetWriteConfig &config=ParquetWriteConfig{})
Export protein group data to Parquet file.
Scope guard that leaves no partial QPX collection behind.
Definition QPXCollectionExport.h:108
static bool exportToParquet(const std::vector< ProteinIdentification > &protein_identifications, const PeptideIdentificationList &peptide_identifications, const std::string &filename, bool export_all_psms=false, const ParquetWriteConfig &config=ParquetWriteConfig{}, const QPXIdentity::FeatureLinks *feature_links=nullptr)
Export PSM data to Parquet file.
Experimental classes:
This API is experimental and may change in future versions.

Constructor & Destructor Documentation

◆ Transaction() [1/3]

Transaction ( const std::string &  directory)
explicit

Start guarding a QPX collection directory.

Records which collection files already exist, so that only the ones this export creates can be removed again.

Parameters
[in]directoryOutput directory the three collection files are written to

◆ ~Transaction()

Remove the collection files this export created, unless commit() was called.

Never throws: it runs during stack unwinding when a writer threw, and a throwing destructor would replace a reported export failure with a call to std::terminate().

◆ Transaction() [2/3]

Transaction ( const Transaction &  )
delete

◆ Transaction() [3/3]

Transaction ( Transaction &&  )
delete

Member Function Documentation

◆ commit()

void commit ( )

Keep the collection: the export completed.

◆ operator=() [1/2]

Transaction & operator= ( const Transaction &  )
delete

◆ operator=() [2/2]

Transaction & operator= ( Transaction &&  )
delete

Member Data Documentation

◆ committed_

bool committed_ {false}
private

◆ directory_

std::string directory_
private

◆ preexisting_

std::vector<std::string> preexisting_
private

Collection files that were already on disk when the guard started; never removed.