| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64event/hdql-augments.hh" | ||
| 2 | #include "na64calib/dispatcher.hh" | ||
| 3 | #include "na64detID/TBName.hh" | ||
| 4 | #include "na64detID/trackID.hh" | ||
| 5 | #include "na64detID/wireID.hh" | ||
| 6 | #include "na64event/data/calo.hh" | ||
| 7 | #include "na64event/data/f1.hh" | ||
| 8 | #include "na64event/data/sadc.hh" | ||
| 9 | #include "na64event/data/stwTDC.hh" | ||
| 10 | #include "na64event/data/track.hh" | ||
| 11 | #include "na64event/hdql-assets.hh" | ||
| 12 | #include "na64util/str-fmt.hh" | ||
| 13 | #include <hdql/helpers/compounds.hh> | ||
| 14 | #include <hdql/value.h> | ||
| 15 | |||
| 16 | #if defined(hdql_FOUND) && hdql_FOUND | ||
| 17 | |||
| 18 | #include <hdql/attr-def.h> | ||
| 19 | #include <hdql/compound.h> | ||
| 20 | #include <hdql/types.h> | ||
| 21 | #include <hdql/operations.h> | ||
| 22 | #include <hdql/context.h> | ||
| 23 | #include <hdql/function.h> | ||
| 24 | |||
| 25 | namespace na64dp { | ||
| 26 | |||
| 27 | void | ||
| 28 | 1 | DetIDSelection::handle_update(const nameutils::DetectorNaming & nm) { | |
| 29 | 1 | calib::Handle<nameutils::DetectorNaming>::handle_update(nm); | |
| 30 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if( _expression.empty() ) return; |
| 31 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if( ! _detSelect ) { |
| 32 | ✗ | _detSelect = new DetSelect( _expression.c_str() | |
| 33 | , util::gDetIDGetters | ||
| 34 |
2/2✓ Branch 3 taken 1 times.
✓ Branch 6 taken 1 times.
|
3 | , nm ); |
| 35 | //std::cout << "xxx DetIDSelection instantiated" << std::endl; // XXX | ||
| 36 | } else { | ||
| 37 | ✗ | _detSelect->reset_context( nm ); | |
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | bool | ||
| 42 | 8 | DetIDSelection::matches(DetID id) const { | |
| 43 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if(_expression.empty()) return true; |
| 44 | //std::cout << "xxx DetIDSelection match()" << std::endl; // XXX | ||
| 45 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
8 | if(!_detSelect) { |
| 46 | // TODO: may be wrong | ||
| 47 | throw std::runtime_error("Can't use detector selection within HDQLang" | ||
| 48 |
1/1✓ Branch 2 taken 1 times.
|
1 | " expression as detectors naming has not being updated."); |
| 49 | } | ||
| 50 | |||
| 51 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | assert(!_expression.empty()); |
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | assert(_detSelect); |
| 53 | 7 | return _detSelect->matches(id); | |
| 54 | } | ||
| 55 | |||
| 56 | 2 | DetIDSelection::DetIDSelection(const char * expression_ | |
| 57 | , calib::Dispatcher & cdsp | ||
| 58 | 2 | , const std::string & detNameClass) | |
| 59 | : calib::Handle<nameutils::DetectorNaming>(detNameClass, cdsp) | ||
| 60 |
1/1✓ Branch 1 taken 2 times.
|
2 | , _expression(expression_) |
| 61 | 4 | , _detSelect(nullptr) {} | |
| 62 | |||
| 63 | namespace event { | ||
| 64 | |||
| 65 | void | ||
| 66 | 9 | create_event_id_compound( hdql::helpers::CompoundTypes & compoundTypes | |
| 67 | , hdql_Context * context ) { | ||
| 68 | // This customized compound interface provides breakdown of encoded event | ||
| 69 | // ID into runNo/spillNo/eventInSpillNo properties. Additionally, a full | ||
| 70 | // event ID is available as id | ||
| 71 | // TODO: for now it is just an empty compound definition | ||
| 72 |
1/1✓ Branch 1 taken 9 times.
|
9 | hdql_Compound * compound = hdql_compound_new("EventID", context); |
| 73 | // runNo attribute | ||
| 74 | // ... | ||
| 75 | // spillNo attribute | ||
| 76 | // ... | ||
| 77 | // eventInSpillNo attribute | ||
| 78 | // ... | ||
| 79 | // id attribute | ||
| 80 | // ... | ||
| 81 |
1/1✓ Branch 1 taken 9 times.
|
9 | compoundTypes.emplace(typeid(EventID), compound); |
| 82 | 9 | } | |
| 83 | |||
| 84 | void | ||
| 85 | 9 | create_timepair_compound( hdql::helpers::CompoundTypes & compoundTypes | |
| 86 | , hdql_Context * context ) { | ||
| 87 | // This customized compound interface provides breakdown of encoded event | ||
| 88 | // ID into runNo/spillNo/eventInSpillNo properties. Additionally, a full | ||
| 89 | // event ID is available as id | ||
| 90 | // TODO: for now it is just an empty compound definition | ||
| 91 |
1/1✓ Branch 1 taken 9 times.
|
9 | hdql_Compound * compound = hdql_compound_new("EventTime", context); |
| 92 | // runNo attribute | ||
| 93 | // ... | ||
| 94 | // spillNo attribute | ||
| 95 | // ... | ||
| 96 | // eventInSpillNo attribute | ||
| 97 | // ... | ||
| 98 | // id attribute | ||
| 99 | // ... | ||
| 100 |
1/1✓ Branch 1 taken 9 times.
|
9 | compoundTypes.emplace(typeid(std::pair<time_t, uint32_t>), compound); |
| 101 | 9 | } | |
| 102 | |||
| 103 | } // namespace ::na64dp::event | ||
| 104 | |||
| 105 | namespace { | ||
| 106 | |||
| 107 | // | ||
| 108 | // Custom key types | ||
| 109 | |||
| 110 | // | ||
| 111 | // TrackID | ||
| 112 | |||
| 113 | int | ||
| 114 | ✗ | copy_track_id( hdql_Datum_t dest | |
| 115 | , const hdql_Datum_t src | ||
| 116 | , size_t byteLen | ||
| 117 | , hdql_Context_t | ||
| 118 | ) { | ||
| 119 | ✗ | assert(byteLen == sizeof(TrackID)); | |
| 120 | ✗ | memcpy(dest, src, byteLen); | |
| 121 | ✗ | return 0; | |
| 122 | } | ||
| 123 | |||
| 124 | int | ||
| 125 | ✗ | get_track_id_as_string( const hdql_Datum_t d_, char * buf, size_t bufSize, hdql_Context_t) { | |
| 126 | ✗ | throw std::runtime_error("TODO: TrackID to string"); | |
| 127 | } | ||
| 128 | |||
| 129 | int | ||
| 130 | ✗ | set_track_id_from_string(hdql_Datum_t d_, const char * strexpr, hdql_Context_t) { | |
| 131 | ✗ | throw std::runtime_error("TODO: TrackID from string"); | |
| 132 | } | ||
| 133 | |||
| 134 | int | ||
| 135 | 9 | add_track_id_type(hdql_ValueTypes * vt) { | |
| 136 | hdql_ValueInterface vti; | ||
| 137 | 9 | vti.name = "TrackID"; | |
| 138 | 9 | vti.init = NULL; | |
| 139 | 9 | vti.destroy = NULL; | |
| 140 | 9 | vti.size = sizeof(TrackID); | |
| 141 | 9 | vti.copy = ©_track_id; | |
| 142 | 9 | vti.get_as_logic = NULL; | |
| 143 | 9 | vti.set_as_logic = NULL; | |
| 144 | 9 | vti.get_as_int = NULL; | |
| 145 | 9 | vti.set_as_int = NULL; | |
| 146 | 9 | vti.get_as_float = NULL; | |
| 147 | 9 | vti.set_as_float = NULL; | |
| 148 | 9 | vti.get_as_string = get_track_id_as_string; | |
| 149 | 9 | vti.set_from_string = set_track_id_from_string; | |
| 150 |
1/1✓ Branch 1 taken 9 times.
|
18 | return hdql_types_define(vt, &vti); |
| 151 | } | ||
| 152 | |||
| 153 | // | ||
| 154 | // DetID | ||
| 155 | |||
| 156 | int | ||
| 157 | ✗ | copy_det_id( hdql_Datum_t dest | |
| 158 | , const hdql_Datum_t src | ||
| 159 | , size_t byteLen | ||
| 160 | , hdql_Context_t | ||
| 161 | ) { | ||
| 162 | ✗ | assert(byteLen == sizeof(DetID)); | |
| 163 | ✗ | memcpy(dest, src, byteLen); | |
| 164 | ✗ | return 0; | |
| 165 | } | ||
| 166 | |||
| 167 | int | ||
| 168 | ✗ | get_det_id_as_string( const hdql_Datum_t d_ | |
| 169 | , char * buf | ||
| 170 | , size_t bufSize | ||
| 171 | , hdql_Context_t context | ||
| 172 | ) { | ||
| 173 | ✗ | std::string name = util::get_naming_handle(context)[*reinterpret_cast<DetID*>(d_)]; | |
| 174 | ✗ | strncpy(buf, name.c_str(), bufSize); | |
| 175 | ✗ | return 0; | |
| 176 | } | ||
| 177 | |||
| 178 | int | ||
| 179 | ✗ | set_det_id_from_string( hdql_Datum_t d_ | |
| 180 | , const char * strexpr | ||
| 181 | , hdql_Context_t context | ||
| 182 | ) { | ||
| 183 | ✗ | *reinterpret_cast<DetID*>(d_) = util::get_naming_handle(context)[strexpr]; | |
| 184 | ✗ | return 0; | |
| 185 | } | ||
| 186 | |||
| 187 | int | ||
| 188 | 9 | add_det_id_type(hdql_ValueTypes * vt) { | |
| 189 | hdql_ValueInterface vti; | ||
| 190 | 9 | vti.name = "DetID"; | |
| 191 | 9 | vti.init = NULL; | |
| 192 | 9 | vti.destroy = NULL; | |
| 193 | 9 | vti.size = sizeof(DetID); | |
| 194 | 9 | vti.copy = ©_det_id; | |
| 195 | 9 | vti.get_as_logic = NULL; | |
| 196 | 9 | vti.set_as_logic = NULL; | |
| 197 | 9 | vti.get_as_int = NULL; | |
| 198 | 9 | vti.set_as_int = NULL; | |
| 199 | 9 | vti.get_as_float = NULL; | |
| 200 | 9 | vti.set_as_float = NULL; | |
| 201 | 9 | vti.get_as_string = get_det_id_as_string; | |
| 202 | 9 | vti.set_from_string = set_det_id_from_string; | |
| 203 |
1/1✓ Branch 1 taken 9 times.
|
18 | return hdql_types_define(vt, &vti); |
| 204 | } | ||
| 205 | |||
| 206 | // | ||
| 207 | // PlaneKey | ||
| 208 | |||
| 209 | int | ||
| 210 | ✗ | copy_plane_key( hdql_Datum_t dest | |
| 211 | , const hdql_Datum_t src | ||
| 212 | , size_t byteLen | ||
| 213 | , hdql_Context_t | ||
| 214 | ) { | ||
| 215 | ✗ | assert(byteLen == sizeof(PlaneKey)); | |
| 216 | ✗ | memcpy(dest, src, byteLen); | |
| 217 | ✗ | return 0; | |
| 218 | } | ||
| 219 | |||
| 220 | int | ||
| 221 | ✗ | plane_key_as_string( const hdql_Datum_t d_, char * buf, size_t bufSize, hdql_Context_t context) { | |
| 222 | ✗ | std::string name = util::get_naming_handle(context)[*reinterpret_cast<PlaneKey*>(d_)]; | |
| 223 | ✗ | strncpy(buf, name.c_str(), bufSize); | |
| 224 | ✗ | return 0; | |
| 225 | } | ||
| 226 | |||
| 227 | int | ||
| 228 | ✗ | set_plane_key_from_string(hdql_Datum_t d_, const char * strexpr, hdql_Context_t context) { | |
| 229 | ✗ | *reinterpret_cast<PlaneKey*>(d_) = PlaneKey(util::get_naming_handle(context)[strexpr]); | |
| 230 | ✗ | return 0; | |
| 231 | } | ||
| 232 | |||
| 233 | int | ||
| 234 | 9 | add_plane_key_type(hdql_ValueTypes * vt) { | |
| 235 | hdql_ValueInterface vti; | ||
| 236 | 9 | vti.name = "PlaneKey"; | |
| 237 | 9 | vti.init = NULL; | |
| 238 | 9 | vti.destroy = NULL; | |
| 239 | 9 | vti.size = sizeof(DetID); | |
| 240 | 9 | vti.copy = ©_plane_key; | |
| 241 | 9 | vti.get_as_logic = NULL; | |
| 242 | 9 | vti.set_as_logic = NULL; | |
| 243 | 9 | vti.get_as_int = NULL; | |
| 244 | 9 | vti.set_as_int = NULL; | |
| 245 | 9 | vti.get_as_float = NULL; | |
| 246 | 9 | vti.set_as_float = NULL; | |
| 247 | 9 | vti.get_as_string = plane_key_as_string; | |
| 248 | 9 | vti.set_from_string = set_plane_key_from_string; | |
| 249 |
1/1✓ Branch 1 taken 9 times.
|
18 | return hdql_types_define(vt, &vti); |
| 250 | } | ||
| 251 | |||
| 252 | } // empty ns | ||
| 253 | |||
| 254 | void | ||
| 255 | 9 | init_root_hdql_context( hdql::helpers::CompoundTypes *& compoundTypesPtr | |
| 256 | , calib::Dispatcher & cdsp | ||
| 257 | ) { | ||
| 258 | int rc; | ||
| 259 | // emit the event data structure definitions and set the root context | ||
| 260 | // pointer | ||
| 261 | // NOTE, the meaning of the flags: | ||
| 262 | // * HDQL_CTX_PRINT_PUSH_ERROR -- makes any error in HDQL context-related | ||
| 263 | // routines to be duplicate printout to `stderr` | ||
| 264 | // Root HDQL execution context is a base for evaluation clauses and should | ||
| 265 | // be provided as global arg to HDQL evaluation routines as reentrant base, | ||
| 266 | // saving some performance for common stuff initialization. | ||
| 267 | 9 | hdql_Context_t context = hdql_context_create(HDQL_CTX_PRINT_PUSH_ERROR); // TODO: configurable | |
| 268 | 9 | compoundTypesPtr = new hdql::helpers::CompoundTypes(context); | |
| 269 | 9 | auto & compoundTypes = *compoundTypesPtr; | |
| 270 | // Registers event data atomic and compound types, adds standard math | ||
| 271 | // and conversion functions. | ||
| 272 | // NOTE: upon (of very rare) creation/deletion of new top-tier type within | ||
| 273 | // the event structure, the list of compounds in these function must be modified. | ||
| 274 | |||
| 275 | // reentrant table with type interfaces | ||
| 276 | 9 | hdql_ValueTypes * valTypes = hdql_context_get_types(context); | |
| 277 | // add standard (int, float, etc) types | ||
| 278 | 9 | hdql_value_types_table_add_std_types(valTypes); | |
| 279 | // add na64sw-specific types | ||
| 280 | 9 | add_det_id_type(valTypes); | |
| 281 | 9 | add_plane_key_type(valTypes); | |
| 282 | 9 | add_track_id_type(valTypes); | |
| 283 | |||
| 284 | // create and operations table | ||
| 285 | 9 | hdql_Operations * operations = hdql_context_get_operations(context); | |
| 286 | // add std types arithmetics | ||
| 287 | 9 | hdql_op_define_std_arith(operations, valTypes); | |
| 288 | |||
| 289 | // add track id as key-compound object with to-arithmetic interface | ||
| 290 | // ... (TODO) | ||
| 291 | |||
| 292 | // add event compounds, in order: | ||
| 293 | // - add event compounds; these functions are generated automatically along | ||
| 294 | // with changed event structure definitions. One function per single .yaml | ||
| 295 | // definition tier | ||
| 296 | 9 | event::create_event_id_compound(compoundTypes, context); | |
| 297 | 9 | event::create_timepair_compound(compoundTypes, context); | |
| 298 | |||
| 299 | // list of compounds here should be modified manually upon top-tier | ||
| 300 | // compound type creation/deletion | ||
| 301 | 9 | event::define_sadc_hdql_compounds(compoundTypes, context); | |
| 302 | 9 | event::define_apv_hdql_compounds(compoundTypes, context); | |
| 303 | 9 | event::define_f1_hdql_compounds(compoundTypes, context); | |
| 304 | 9 | event::define_stwTDC_hdql_compounds(compoundTypes, context); | |
| 305 | 9 | event::define_track_hdql_compounds(compoundTypes, context); | |
| 306 | 9 | event::define_calo_hdql_compounds(compoundTypes, context); | |
| 307 | // ... | ||
| 308 | 9 | event::define_event_hdql_compounds(compoundTypes, context); | |
| 309 | |||
| 310 | // add standard functions | ||
| 311 | 9 | hdql_functions_add_standard_math(hdql_context_get_functions(context)); | |
| 312 | // add standard math consts (pi, e) | ||
| 313 | 9 | hdql_constants_define_standard_math(hdql_context_get_constants(context)); | |
| 314 | // add standard type conversions | ||
| 315 | 9 | hdql_converters_add_std(hdql_context_get_conversions(context), hdql_context_get_types(context)); | |
| 316 | |||
| 317 | // | ||
| 318 | // HDQLang context custom data | ||
| 319 | |||
| 320 | // - context custom data: calib dispatcher | ||
| 321 | 9 | rc = hdql_context_custom_data_add(context, "na64sw/calib-dispatcher-ptr", &cdsp); | |
| 322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | assert(HDQL_ERR_CODE_OK == rc); |
| 323 | // - common detector naming class used for HDQL expressions | ||
| 324 | // (TODO: fwd as external as parameter?) | ||
| 325 | 9 | char * detNamingClass = strdup("default"); | |
| 326 | 9 | rc = hdql_context_custom_data_add(context, "na64sw/det-ID-class-name", detNamingClass); | |
| 327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | assert(HDQL_ERR_CODE_OK == rc); |
| 328 | |||
| 329 | // create and associate detector naming handle to be used in | ||
| 330 | // detID-filtering expressions | ||
| 331 |
2/3✓ Branch 2 taken 9 times.
✓ Branch 5 taken 9 times.
✗ Branch 10 not taken.
|
18 | auto namingHandle = new calib::Handle<nameutils::DetectorNaming>(detNamingClass, cdsp); |
| 332 | 9 | rc = hdql_context_custom_data_add(context, "na64sw/det-naming-handle", namingHandle); | |
| 333 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | assert(HDQL_ERR_CODE_OK == rc); |
| 334 | // ... | ||
| 335 | 9 | } | |
| 336 | |||
| 337 | void | ||
| 338 | 9 | destroy_root_hdql_context(hdql::helpers::CompoundTypes *& compoundTypes) { | |
| 339 | 9 | hdql_Context_t context = compoundTypes->context_ptr(); | |
| 340 | |||
| 341 | { | ||
| 342 | 9 | auto detNameClass_ = hdql_context_custom_data_get(context, "na64sw/det-ID-class-name"); | |
| 343 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if(detNameClass_) { |
| 344 | 9 | free(reinterpret_cast<char *>(detNameClass_)); | |
| 345 | 9 | hdql_context_custom_data_erase(context, "na64sw/det-ID-class-name"); | |
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | { | ||
| 350 | 9 | auto namingHandle_ = hdql_context_custom_data_get(context, "na64sw/det-naming-handle"); | |
| 351 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if(namingHandle_) { |
| 352 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | delete reinterpret_cast< calib::Handle<nameutils::DetectorNaming>* >(namingHandle_); |
| 353 | 9 | hdql_context_custom_data_erase(context, "na64sw/det-naming-handle"); | |
| 354 | } | ||
| 355 | } | ||
| 356 | 9 | hdql_context_custom_data_erase(context, "na64sw/calib-dispatcher-ptr"); | |
| 357 | |||
| 358 | 9 | hdql_context_destroy(context); | |
| 359 |
2/2✓ Branch 5 taken 252 times.
✓ Branch 6 taken 9 times.
|
261 | for(auto & ce : *compoundTypes) { |
| 360 |
1/1✓ Branch 1 taken 252 times.
|
252 | hdql_compound_destroy(ce.second, context); |
| 361 | } | ||
| 362 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | delete compoundTypes; |
| 363 | 9 | compoundTypes = nullptr; | |
| 364 | 9 | } | |
| 365 | |||
| 366 | |||
| 367 | // | ||
| 368 | // HDQLAssets | ||
| 369 | |||
| 370 | namespace util { | ||
| 371 | |||
| 372 | HDQLAssets * HDQLAssets::_self = nullptr; | ||
| 373 | |||
| 374 | ✗ | HDQLAssets::HDQLAssets() : _compounds(nullptr) {} | |
| 375 | |||
| 376 | HDQLAssets & | ||
| 377 | ✗ | HDQLAssets::self() { | |
| 378 | ✗ | if(!_self) _self = new HDQLAssets(); | |
| 379 | ✗ | return *_self; | |
| 380 | } | ||
| 381 | |||
| 382 | hdql::helpers::CompoundTypes & | ||
| 383 | ✗ | HDQLAssets::compounds() { | |
| 384 | ✗ | if(!_compounds) { | |
| 385 | ✗ | NA64DP_RUNTIME_ERROR("Handlers HDQL compounds collection is not initialized."); | |
| 386 | } | ||
| 387 | ✗ | return *_compounds; | |
| 388 | } | ||
| 389 | |||
| 390 | const nameutils::DetectorNaming & | ||
| 391 | ✗ | get_naming_handle(hdql_Context_t context) { | |
| 392 | ✗ | void * namingHandle_ = hdql_context_custom_data_get(context, "na64sw/det-naming-handle"); | |
| 393 | ✗ | if(NULL == namingHandle_) { | |
| 394 | ✗ | throw std::runtime_error("No item \"detNaming\" bound to context"); | |
| 395 | } | ||
| 396 | ✗ | return reinterpret_cast<calib::Handle<nameutils::DetectorNaming>*>(namingHandle_)->get(); | |
| 397 | } | ||
| 398 | |||
| 399 | } // namespace ::na64dp::util | ||
| 400 | } // namespace na64dp | ||
| 401 | |||
| 402 | #endif // defined(hdql_FOUND) && hdql_FOUND | ||
| 403 | |||
| 404 |