@@ -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 {
440448bool 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
824834int 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
846857bool 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;
0 commit comments