@@ -124,15 +124,23 @@ 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+ std::cout << " Rewriting filename to " << filename << std::endl;
141+ }
142+
134143 // open file
135- auto filename = mfilenames[counter]->fileName ;
136144 auto rootFS = std::dynamic_pointer_cast<TFileFileSystem>(mCurrentFilesystem );
137145 if (rootFS.get ()) {
138146 if (rootFS->GetFile ()->GetName () == filename) {
@@ -213,11 +221,11 @@ bool DataInputDescriptor::setFile(int counter)
213221 return true ;
214222}
215223
216- uint64_t DataInputDescriptor::getTimeFrameNumber (int counter, int numTF)
224+ uint64_t DataInputDescriptor::getTimeFrameNumber (int counter, int numTF, std::string_view origin )
217225{
218226
219227 // open file
220- if (!setFile (counter)) {
228+ if (!setFile (counter, origin )) {
221229 return 0ul ;
222230 }
223231
@@ -229,10 +237,10 @@ uint64_t DataInputDescriptor::getTimeFrameNumber(int counter, int numTF)
229237 return (mfilenames[counter]->listOfTimeFrameNumbers )[numTF];
230238}
231239
232- arrow::dataset::FileSource DataInputDescriptor::getFileFolder (int counter, int numTF)
240+ arrow::dataset::FileSource DataInputDescriptor::getFileFolder (int counter, int numTF, std::string_view origin )
233241{
234242 // open file
235- if (!setFile (counter)) {
243+ if (!setFile (counter, origin )) {
236244 return {};
237245 }
238246
@@ -246,7 +254,7 @@ arrow::dataset::FileSource DataInputDescriptor::getFileFolder(int counter, int n
246254 return {fmt::format (" DF_{}" , mfilenames[counter]->listOfTimeFrameNumbers [numTF]), mCurrentFilesystem };
247255}
248256
249- DataInputDescriptor* DataInputDescriptor::getParentFile (int counter, int numTF, std::string treename)
257+ DataInputDescriptor* DataInputDescriptor::getParentFile (int counter, int numTF, std::string treename, std::string_view origin )
250258{
251259 if (!mParentFileMap ) {
252260 // This file has no parent map
@@ -283,7 +291,7 @@ DataInputDescriptor* DataInputDescriptor::getParentFile(int counter, int numTF,
283291 mParentFile ->mdefaultFilenamesPtr = new std::vector<FileNameHolder*>;
284292 mParentFile ->mdefaultFilenamesPtr ->emplace_back (makeFileNameHolder (parentFileName->GetString ().Data ()));
285293 mParentFile ->fillInputfiles ();
286- mParentFile ->setFile (0 );
294+ mParentFile ->setFile (0 , origin );
287295 return mParentFile ;
288296}
289297
@@ -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