Skip to content

Commit cf8bafe

Browse files
committed
DPL Analysis: percolate DataOrigin so that we can use it for multiple files reading.
1 parent d375e63 commit cf8bafe

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

Framework/AnalysisSupport/src/DataInputDirector.cxx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,22 @@ void DataInputDescriptor::addFileNameHolder(FileNameHolder* fn)
124124
mfilenames.emplace_back(fn);
125125
}
126126

127-
bool DataInputDescriptor::setFile(int counter)
127+
bool DataInputDescriptor::setFile(int counter, std::string_view origin)
128128
{
129129
// no files left
130130
if (counter >= getNumberInputfiles()) {
131131
return false;
132132
}
133133

134+
// In case the origin starts with a anything but AOD, we add the origin as the suffix
135+
// of the filename. In the future we might expand this for proper rewriting of the
136+
// filename based on the origin and the original file information.
137+
std::string filename = mfilenames[counter]->fileName;
138+
if (!origin.starts_with("AOD")) {
139+
filename = std::regex_replace(filename, std::regex("[.]root$"), fmt::format("_{}.root", origin));
140+
}
141+
134142
// open file
135-
auto filename = mfilenames[counter]->fileName;
136143
auto rootFS = std::dynamic_pointer_cast<TFileFileSystem>(mCurrentFilesystem);
137144
if (rootFS.get()) {
138145
if (rootFS->GetFile()->GetName() == filename) {
@@ -213,11 +220,11 @@ bool DataInputDescriptor::setFile(int counter)
213220
return true;
214221
}
215222

216-
uint64_t DataInputDescriptor::getTimeFrameNumber(int counter, int numTF)
223+
uint64_t DataInputDescriptor::getTimeFrameNumber(int counter, int numTF, std::string_view origin)
217224
{
218225

219226
// open file
220-
if (!setFile(counter)) {
227+
if (!setFile(counter, origin)) {
221228
return 0ul;
222229
}
223230

@@ -229,10 +236,10 @@ uint64_t DataInputDescriptor::getTimeFrameNumber(int counter, int numTF)
229236
return (mfilenames[counter]->listOfTimeFrameNumbers)[numTF];
230237
}
231238

232-
arrow::dataset::FileSource DataInputDescriptor::getFileFolder(int counter, int numTF)
239+
arrow::dataset::FileSource DataInputDescriptor::getFileFolder(int counter, int numTF, std::string_view origin)
233240
{
234241
// open file
235-
if (!setFile(counter)) {
242+
if (!setFile(counter, origin)) {
236243
return {};
237244
}
238245

@@ -246,7 +253,7 @@ arrow::dataset::FileSource DataInputDescriptor::getFileFolder(int counter, int n
246253
return {fmt::format("DF_{}", mfilenames[counter]->listOfTimeFrameNumbers[numTF]), mCurrentFilesystem};
247254
}
248255

249-
DataInputDescriptor* DataInputDescriptor::getParentFile(int counter, int numTF, std::string treename)
256+
DataInputDescriptor* DataInputDescriptor::getParentFile(int counter, int numTF, std::string treename, std::string_view origin)
250257
{
251258
if (!mParentFileMap) {
252259
// This file has no parent map
@@ -283,7 +290,7 @@ DataInputDescriptor* DataInputDescriptor::getParentFile(int counter, int numTF,
283290
mParentFile->mdefaultFilenamesPtr = new std::vector<FileNameHolder*>;
284291
mParentFile->mdefaultFilenamesPtr->emplace_back(makeFileNameHolder(parentFileName->GetString().Data()));
285292
mParentFile->fillInputfiles();
286-
mParentFile->setFile(0);
293+
mParentFile->setFile(0, origin);
287294
return mParentFile;
288295
}
289296

@@ -427,7 +434,8 @@ struct CalculateDelta {
427434
mTarget += (uv_hrtime() - start);
428435
}
429436

430-
void deactivate() {
437+
void deactivate()
438+
{
431439
active = false;
432440
}
433441

@@ -440,7 +448,8 @@ struct CalculateDelta {
440448
bool DataInputDescriptor::readTree(DataAllocator& outputs, header::DataHeader dh, int counter, int numTF, std::string treename, size_t& totalSizeCompressed, size_t& totalSizeUncompressed)
441449
{
442450
CalculateDelta t(mIOTime);
443-
auto folder = getFileFolder(counter, numTF);
451+
std::string origin = dh.dataOrigin.as<std::string>();
452+
auto folder = getFileFolder(counter, numTF, origin);
444453
if (!folder.filesystem()) {
445454
t.deactivate();
446455
return false;
@@ -473,7 +482,7 @@ bool DataInputDescriptor::readTree(DataAllocator& outputs, header::DataHeader dh
473482
if (!format) {
474483
t.deactivate();
475484
LOGP(debug, "Could not find tree {}. Trying in parent file.", fullpath.path());
476-
auto parentFile = getParentFile(counter, numTF, treename);
485+
auto parentFile = getParentFile(counter, numTF, treename, origin);
477486
if (parentFile != nullptr) {
478487
int parentNumTF = parentFile->findDFNumber(0, folder.path());
479488
if (parentNumTF == -1) {
@@ -817,8 +826,9 @@ arrow::dataset::FileSource DataInputDirector::getFileFolder(header::DataHeader d
817826
if (!didesc) {
818827
didesc = mdefaultDataInputDescriptor;
819828
}
829+
std::string origin = dh.dataOrigin.as<std::string>();
820830

821-
return didesc->getFileFolder(counter, numTF);
831+
return didesc->getFileFolder(counter, numTF, origin);
822832
}
823833

824834
int DataInputDirector::getTimeFramesInFile(header::DataHeader dh, int counter)
@@ -839,8 +849,9 @@ uint64_t DataInputDirector::getTimeFrameNumber(header::DataHeader dh, int counte
839849
if (!didesc) {
840850
didesc = mdefaultDataInputDescriptor;
841851
}
852+
std::string origin = dh.dataOrigin.as<std::string>();
842853

843-
return didesc->getTimeFrameNumber(counter, numTF);
854+
return didesc->getTimeFrameNumber(counter, numTF, origin);
844855
}
845856

846857
bool DataInputDirector::readTree(DataAllocator& outputs, header::DataHeader dh, int counter, int numTF, size_t& totalSizeCompressed, size_t& totalSizeUncompressed)
@@ -858,6 +869,7 @@ bool DataInputDirector::readTree(DataAllocator& outputs, header::DataHeader dh,
858869
didesc = mdefaultDataInputDescriptor;
859870
treename = aod::datamodel::getTreeName(dh);
860871
}
872+
std::string origin = dh.dataOrigin.as<std::string>();
861873

862874
auto result = didesc->readTree(outputs, dh, counter, numTF, treename, totalSizeCompressed, totalSizeUncompressed);
863875
return result;

Framework/AnalysisSupport/src/DataInputDirector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class DataInputDescriptor
6464

6565
void addFileNameHolder(FileNameHolder* fn);
6666
int fillInputfiles();
67-
bool setFile(int counter);
67+
bool setFile(int counter, std::string_view origin);
6868

6969
// getters
7070
std::string getInputfilesFilename();
@@ -74,9 +74,9 @@ class DataInputDescriptor
7474
int getNumberTimeFrames() { return mtotalNumberTimeFrames; }
7575
int findDFNumber(int file, std::string dfName);
7676

77-
uint64_t getTimeFrameNumber(int counter, int numTF);
78-
arrow::dataset::FileSource getFileFolder(int counter, int numTF);
79-
DataInputDescriptor* getParentFile(int counter, int numTF, std::string treename);
77+
uint64_t getTimeFrameNumber(int counter, int numTF, std::string_view origin);
78+
arrow::dataset::FileSource getFileFolder(int counter, int numTF, std::string_view origin);
79+
DataInputDescriptor* getParentFile(int counter, int numTF, std::string treename, std::string_view origin);
8080
int getTimeFramesInFile(int counter);
8181
int getReadTimeFramesInFile(int counter);
8282

Framework/Core/include/Framework/AnalysisSupportHelpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
namespace o2::framework
2222
{
23-
static constexpr std::array<header::DataOrigin, 3> AODOrigins{header::DataOrigin{"AOD"}, header::DataOrigin{"AOD1"}, header::DataOrigin{"AOD2"}};
24-
static constexpr std::array<header::DataOrigin, 5> extendedAODOrigins{header::DataOrigin{"AOD"}, header::DataOrigin{"AOD1"}, header::DataOrigin{"AOD2"}, header::DataOrigin{"DYN"}, header::DataOrigin{"AMD"}};
23+
static constexpr std::array<header::DataOrigin, 4> AODOrigins{header::DataOrigin{"AOD"}, header::DataOrigin{"AOD1"}, header::DataOrigin{"AOD2"}, header::DataOrigin{"EMB"}};
24+
static constexpr std::array<header::DataOrigin, 6> extendedAODOrigins{header::DataOrigin{"AOD"}, header::DataOrigin{"AOD1"}, header::DataOrigin{"AOD2"}, header::DataOrigin{"DYN"}, header::DataOrigin{"AMD"}, header::DataOrigin{"EMB"}};
2525
static constexpr std::array<header::DataOrigin, 4> writableAODOrigins{header::DataOrigin{"AOD"}, header::DataOrigin{"AOD1"}, header::DataOrigin{"AOD2"}, header::DataOrigin{"DYN"}};
2626

2727
class DataOutputDirector;

Framework/Core/src/AnalysisDataModelHelpers.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "Framework/AnalysisDataModelHelpers.h"
1313
#include "Framework/AnalysisDataModel.h"
14+
#include "Framework/AnalysisSupportHelpers.h"
1415
#include "Framework/StringHelpers.h"
1516
#include "Framework/Logger.h"
1617

@@ -27,7 +28,6 @@ namespace o2::aod::datamodel
2728
std::string getTreeName(header::DataHeader dh)
2829
{
2930
auto description = std::string(dh.dataDescription.str);
30-
auto origin = std::string(dh.dataOrigin.str);
3131
auto iver = (float)dh.subSpecification;
3232

3333
// lower case of first part of description
@@ -38,11 +38,15 @@ std::string getTreeName(header::DataHeader dh)
3838
}
3939

4040
// add prefix according to origin
41-
if (origin == "AOD") {
42-
treeName = "O2" + treeName;
41+
for (auto possibleOrigin : framework::AODOrigins) {
42+
if (dh.dataOrigin == possibleOrigin) {
43+
treeName = "O2" + treeName;
44+
break;
45+
}
4346
}
4447

4548
// exceptions from this
49+
auto origin = std::string(dh.dataOrigin.str);
4650
if (origin == "AOD" && description == "MCCOLLISLABEL") {
4751
treeName = "O2mccollisionlabel";
4852
}

Framework/TestWorkflows/src/o2TestHistograms.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace o2::framework::expressions;
2525

2626
namespace o2::aod
2727
{
28+
O2ORIGIN("EMB");
2829
namespace skimmedExampleTrack
2930
{
3031
DECLARE_SOA_COLUMN(Pt, pt, float); //!
@@ -49,7 +50,7 @@ struct EtaAndClsHistogramsSimple {
4950
}
5051
}
5152

52-
void process(soa::Filtered<aod::Tracks> const& tracks, aod::FT0s const&)
53+
void process(soa::Filtered<aod::Tracks> const& tracks, aod::FT0s const&, aod::StoredTracksFrom<o2::aod::Hash<"EMB"_h>> const& ortherTracks)
5354
{
5455
LOGP(info, "Invoking the simple one");
5556
for (auto& track : tracks) {
@@ -72,7 +73,7 @@ struct EtaAndClsHistogramsIUSimple {
7273
}
7374
}
7475

75-
void process(soa::Filtered<aod::TracksIU> const& tracks, aod::FT0s const&)
76+
void process(soa::Filtered<aod::TracksIU> const& tracks, aod::FT0s const&, aod::TracksIUFrom<o2::aod::Hash<"EMB"_h>> const& otherTracks)
7677
{
7778
LOGP(info, "Invoking the simple one IU");
7879
for (auto& track : tracks) {

0 commit comments

Comments
 (0)