@@ -126,103 +126,135 @@ void CcdbDatabase::storeMO(std::shared_ptr<o2::quality_control::core::MonitorObj
126126 long from = getCurrentTimestamp ();
127127 long to = getFutureTimestamp (60 * 60 * 24 * 365 * 10 );
128128
129- ccdbApi.storeAsTFile (mo.get (), path, metadata, from, to);
129+ // extract object and metadata from MonitorObject
130+ TObject* obj = mo->getObject ();
131+ metadata[" qc_detector_name" ] = mo->getDetectorName ();
132+ metadata[" qc_task_name" ] = mo->getTaskName ();
133+ metadata[" ObjectType" ] = mo->getObject ()->IsA ()->GetName (); // ObjectType says TObject and not MonitorObject due to a quirk in the API. Once fixed, remove this.
134+
135+ ccdbApi.storeAsTFileAny <TObject>(obj, path, metadata, from, to);
130136}
131137
132- std::shared_ptr<TObject> CcdbDatabase::retrieveTObject (std::string path, long timestamp )
138+ void CcdbDatabase::storeQO (std::shared_ptr<QualityObject> qo )
133139{
140+ // metadata
134141 map<string, string> metadata;
142+ // QC metadata (prefix qc_)
143+ metadata[" qc_version" ] = Version::GetQcVersion ().getString ();
144+ metadata[" qc_quality" ] = std::to_string (qo->getQuality ().getLevel ());
145+ metadata[" qc_detector_name" ] = qo->getDetectorName ();
146+ metadata[" qc_check_name" ] = qo->getCheckName ();
147+
148+ // other attributes
149+ string path = qo->getPath ();
150+ long from = getCurrentTimestamp ();
151+ long to = getFutureTimestamp (60 * 60 * 24 * 365 * 10 );
152+
153+ ccdbApi.storeAsTFileAny <QualityObject>(qo.get (), path, metadata, from, to);
154+ }
155+
156+ TObject* CcdbDatabase::retrieveTObject (std::string path, std::map<std::string, std::string> const & metadata, long timestamp, std::map<std::string, std::string>* headers)
157+ {
135158 long when = timestamp == 0 ? getCurrentTimestamp () : timestamp;
136159
137160 // we try first to load a TFile
138- TObject * object = ccdbApi.retrieveFromTFile (path, metadata, when);
161+ auto * object = ccdbApi.retrieveFromTFileAny <TObject> (path, metadata, when, headers );
139162 if (object == nullptr ) {
140163 // We could not open a TFile we should now try to open an object directly serialized
141164 object = ccdbApi.retrieve (path, metadata, when);
142- ILOG (Debug) << " We could retrieve the object " << path << " as a streamed object." << ENDM ;
143165 if (object == nullptr ) {
166+ ILOG (Error) << " We could NOT retrieve the object " << path << " ." << ENDM ;
144167 return nullptr ;
145168 }
146169 }
147- std::shared_ptr<TObject> result ( object) ;
148- return result ;
170+ ILOG (Debug) << " Retrieved object " << path << ENDM ;
171+ return object ;
149172}
150173
151174std::shared_ptr<core::MonitorObject> CcdbDatabase::retrieveMO (std::string taskName, std::string objectName, long timestamp)
152175{
153176 string path = taskName + " /" + objectName;
154- std::shared_ptr<TObject> obj = retrieveTObject (path, timestamp);
155- std::shared_ptr<MonitorObject> mo = std::dynamic_pointer_cast<MonitorObject>(obj);
156- if (mo == nullptr ) {
157- ILOG (Error) << " Could not cast the object " << taskName << " /" << objectName << " to MonitorObject" << ENDM ;
177+ long when = timestamp == 0 ? getCurrentTimestamp () : timestamp;
178+ map<string, string> headers;
179+ map<string, string> metadata;
180+ TObject* obj = retrieveTObject (path, metadata, when, &headers);
181+ Version objectVersion (headers[" qc_version" ]); // retrieve headers to determine the version of the QC framework
182+
183+ std::shared_ptr<MonitorObject> mo;
184+ if (objectVersion == Version (" 0.0.0" ) || objectVersion < Version (" 0.25" )) {
185+ ILOG (Debug) << " Version of object " << taskName << " /" << objectName << " is < 0.25" << ENDM ;
186+ // The object is either in a TFile or is a blob but it was stored with storeAsTFile as a full MO
187+ mo.reset (dynamic_cast <MonitorObject*>(obj));
188+ if (mo == nullptr ) {
189+ ILOG (Error) << " Could not cast the object " << taskName << " /" << objectName << " to MonitorObject" << ENDM ;
190+ }
191+ } else {
192+ // Version >= 0.25 -> the object is stored directly unencapsulated
193+ ILOG (Debug) << " Version of object " << taskName << " /" << objectName << " is >= 0.25" << ENDM ;
194+ mo = make_shared<MonitorObject>(obj, headers[" qc_task_name" ], headers[" qc_detector_name" ]);
195+ // TODO should we remove the headers we know are general such as ETag and qc_task_name ?
196+ mo->addMetadata (headers);
158197 }
159198 return mo;
160199}
161200
162201std::shared_ptr<QualityObject> CcdbDatabase::retrieveQO (std::string qoPath, long timestamp)
163202{
164- std::shared_ptr<TObject> obj = retrieveTObject (qoPath, timestamp);
165- std::shared_ptr<QualityObject> qo = std::dynamic_pointer_cast<QualityObject>(obj);
203+ long when = timestamp == 0 ? getCurrentTimestamp () : timestamp;
204+ map<string, string> headers;
205+ map<string, string> metadata;
206+ TObject* obj = retrieveTObject (qoPath, metadata, when, &headers);
207+ std::shared_ptr<QualityObject> qo (dynamic_cast <QualityObject*>(obj));
166208 if (qo == nullptr ) {
167- LOG ( ERROR ) << " Could not cast the object " << qoPath << " to QualityObject" ;
209+ ILOG (Error ) << " Could not cast the object " << qoPath << " to QualityObject" << ENDM ;
168210 }
211+ // TODO should we remove the headers we know are general such as ETag and qc_task_name ?
212+ qo->addMetadata (headers);
169213 return qo;
170214}
171215
172216std::string CcdbDatabase::retrieveQOJson (std::string qoPath, long timestamp)
173217{
174- return retrieveJson (qoPath, timestamp);
218+ map<string, string> metadata;
219+ return retrieveJson (qoPath, timestamp, metadata);
175220}
176221
177222std::string CcdbDatabase::retrieveMOJson (std::string taskName, std::string objectName, long timestamp)
178223{
179224 string path = taskName + " /" + objectName;
180- return retrieveJson (path, timestamp);
225+ map<string, string> metadata;
226+ return retrieveJson (path, timestamp, metadata);
181227}
182228
183- std::string CcdbDatabase::retrieveJson (std::string path, long timestamp)
229+ std::string CcdbDatabase::retrieveJson (std::string path, long timestamp, const std::map<std::string, std::string>& metadata )
184230{
185- auto tobj = retrieveTObject (path, timestamp);
231+ map<string, string> headers;
232+ auto tobj = retrieveTObject (path, metadata, timestamp, &headers);
233+
186234 if (tobj == nullptr ) {
187235 return std::string ();
188236 }
189- TObject* toConvert = 0 ;
190- if (tobj->IsA () == MonitorObject::Class ()) {
191- std::shared_ptr<MonitorObject> mo = std::dynamic_pointer_cast<MonitorObject>(tobj);
237+
238+ TObject* toConvert = nullptr ;
239+ if (tobj->IsA () == MonitorObject::Class ()) { // a full MO -> pre-v0.25
240+ std::shared_ptr<MonitorObject> mo (dynamic_cast <MonitorObject*>(tobj));
192241 toConvert = mo->getObject ();
193- mo->setIsOwner (true );
242+ mo->setIsOwner (false );
194243 } else if (tobj->IsA () == QualityObject::Class ()) {
195- toConvert = dynamic_cast <QualityObject*>(tobj.get ());
196- } else {
197- ILOG (Error) << " Unknown type of object : " << path << " -> " << tobj->ClassName () << ENDM ;
198- return std::string ();
244+ toConvert = dynamic_cast <QualityObject*>(tobj);
245+ } else { // something else but a TObject
246+ toConvert = tobj;
199247 }
200248 if (toConvert == nullptr ) {
201249 ILOG (Error) << " Unable to get the object to convert" << ENDM ;
202250 return std::string ();
203251 }
204252 TString json = TBufferJSON::ConvertToJSON (toConvert);
253+ delete toConvert;
205254
206255 return json.Data ();
207256}
208257
209- // Quality Object
210- void CcdbDatabase::storeQO (std::shared_ptr<QualityObject> qo)
211- {
212- // metadata
213- map<string, string> metadata;
214- // QC metadata (prefix qc_)
215- metadata[" qc_version" ] = Version::GetQcVersion ().getString ();
216- metadata[" qc_quality" ] = std::to_string (qo->getQuality ().getLevel ());
217-
218- // other attributes
219- string path = qo->getPath ();
220- long from = getCurrentTimestamp ();
221- long to = getFutureTimestamp (60 * 60 * 24 * 365 * 10 );
222-
223- ccdbApi.storeAsTFile (qo.get (), path, metadata, from, to);
224- }
225-
226258void CcdbDatabase::disconnect ()
227259{
228260 // NOOP for CCDB
0 commit comments