Skip to content

Commit 2a95a68

Browse files
committed
Actually working
1 parent 2a1015d commit 2a95a68

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <cstring>
3636
#include <gsl/span> // IWYU pragma: export
3737
#include <limits>
38+
#include <iostream>
3839

3940
namespace o2::framework
4041
{
@@ -44,14 +45,18 @@ std::string cutString(std::string&& str);
4445
std::string strToUpper(std::string&& str);
4546
} // namespace o2::framework
4647

48+
struct TClass;
49+
4750
namespace o2::soa
4851
{
4952
void accessingInvalidIndexFor(const char* getter);
5053
void dereferenceWithWrongType(const char* getter, const char* target);
5154
void missingFilterDeclaration(int hash, int ai);
5255
void notBoundTable(const char* tableName);
56+
void* extractCCDBPayload(char *payload, size_t size, TClass const* cl, const char* what);
5357
} // namespace o2::soa
5458

59+
5560
namespace o2::soa
5661
{
5762
/// Generic identifier for a table type

Framework/Core/src/ASoA.cxx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#include "Framework/RuntimeError.h"
1515
#include <arrow/util/key_value_metadata.h>
1616
#include <arrow/util/config.h>
17+
#include <iostream>
18+
#include <TMemFile.h>
19+
#include <TClass.h>
20+
#include <TTree.h>
21+
#include <TH1.h>
22+
#include <TError.h>
1723

1824
namespace o2::soa
1925
{
@@ -149,6 +155,7 @@ arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, std::string_view lab
149155
return caseInsensitiveCompare(label, f->name());
150156
});
151157
if (field == table->schema()->fields().end()) {
158+
std::cout << table->ToString() << std::endl;
152159
o2::framework::throw_error(o2::framework::runtime_error_f("Unable to find column with label %s", label));
153160
}
154161
auto index = std::distance(table->schema()->fields().begin(), field);
@@ -170,6 +177,62 @@ void missingOptionalPreslice(const char* label, const char* key)
170177
throw o2::framework::runtime_error_f(R"(Optional Preslice with missing binding used: table "%s" (or join based on it) does not have column "%s")", label, key);
171178
}
172179

180+
void* extractCCDBPayload(char *payload, size_t size, TClass const* cl, const char* what)
181+
{
182+
Int_t previousErrorLevel = gErrorIgnoreLevel;
183+
gErrorIgnoreLevel = kFatal;
184+
// does it have a flattened headers map attached in the end?
185+
TMemFile file("name", (char*)payload, size, "READ");
186+
gErrorIgnoreLevel = previousErrorLevel;
187+
if (file.IsZombie()) {
188+
return nullptr;
189+
}
190+
191+
if (!cl) {
192+
return nullptr;
193+
}
194+
auto object = file.GetObjectChecked(what, cl);
195+
if (!object) {
196+
// it could be that object was stored with previous convention
197+
// where the classname was taken as key
198+
std::string objectName(cl->GetName());
199+
objectName.erase(std::find_if(objectName.rbegin(), objectName.rend(), [](unsigned char ch) {
200+
return !std::isspace(ch);
201+
}).base(),
202+
objectName.end());
203+
objectName.erase(objectName.begin(), std::find_if(objectName.begin(), objectName.end(), [](unsigned char ch) {
204+
return !std::isspace(ch);
205+
}));
206+
207+
object = file.GetObjectChecked(objectName.c_str(), cl);
208+
LOG(warn) << "Did not find object under expected name " << what;
209+
if (!object) {
210+
return nullptr;
211+
}
212+
LOG(warn) << "Found object under deprecated name " << cl->GetName();
213+
}
214+
auto result = object;
215+
// We need to handle some specific cases as ROOT ties them deeply
216+
// to the file they are contained in
217+
if (cl->InheritsFrom("TObject")) {
218+
// make a clone
219+
// detach from the file
220+
auto tree = dynamic_cast<TTree*>((TObject*)object);
221+
if (tree) {
222+
tree->LoadBaskets(0x1L << 32); // make tree memory based
223+
tree->SetDirectory(nullptr);
224+
result = tree;
225+
} else {
226+
auto h = dynamic_cast<TH1*>((TObject*)object);
227+
if (h) {
228+
h->SetDirectory(nullptr);
229+
result = h;
230+
}
231+
}
232+
}
233+
return result;
234+
}
235+
173236
} // namespace o2::soa
174237

175238
namespace o2::framework

Framework/TestWorkflows/src/o2TestAnalysisCCDB.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct DummyTimestampsTable {
4545
timestamps(1747442464000); // c2b3d801393540b7bddb949d600b199f, ecacb915-3d70-11f0-ac6f-808de0f5250c
4646
timestamps(1747442764000); // 0262dbd9d50aa79c3d4dcd5ec3ca67c3, ed5471c5-3d70-11f0-b0a3-808de0f524ee
4747
control->readyToQuit(QuitRequest::Me);
48+
control->endOfStream();
4849
std::cout << "Executed " << std::endl;
4950
}
5051
};

0 commit comments

Comments
 (0)