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
1824namespace 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
175238namespace o2 ::framework
0 commit comments