@@ -1207,55 +1207,107 @@ uint8_t AODProducerWorkflowDPL::getTRDPattern(const o2::trd::TrackTRD& track)
12071207 return pattern;
12081208}
12091209
1210+ template <typename TCaloHandler, typename TCaloCursor, typename TCaloTRGCursor>
1211+ void AODProducerWorkflowDPL::addToCaloTable (const TCaloHandler& caloHandler, const TCaloCursor& caloCellCursor, const TCaloTRGCursor& caloTRGCursor,
1212+ int eventID, int bcID, int8_t caloType)
1213+ {
1214+ auto inputEvent = caloHandler.buildEvent (eventID);
1215+ auto cellsInEvent = inputEvent.mCells ; // get cells belonging to current event
1216+ for (auto & cell : cellsInEvent) { // loop over all cells in collision
1217+ caloCellCursor (0 ,
1218+ bcID,
1219+ CellHelper::getCellNumber (cell),
1220+ truncateFloatFraction (CellHelper::getAmplitude (cell), mCaloAmp ),
1221+ truncateFloatFraction (CellHelper::getTimeStamp (cell), mCaloTime ),
1222+ cell.getType (),
1223+ caloType); // 1 = emcal, -1 = undefined, 0 = phos
1224+
1225+ // todo: fix dummy values in CellHelper when it is clear what is filled for trigger information
1226+ if (CellHelper::isTRU (cell)) { // Write only trigger cells into this table
1227+ caloTRGCursor (0 ,
1228+ bcID,
1229+ CellHelper::getFastOrAbsID (cell),
1230+ CellHelper::getLnAmplitude (cell),
1231+ CellHelper::getTriggerBits (cell),
1232+ caloType);
1233+ }
1234+ }
1235+ }
1236+
12101237// fill calo related tables (cells and calotrigger table)
1211- template <typename TEventHandler, typename TCaloCells, typename TCaloTriggerRecord, typename TCaloCursor, typename TCaloTRGTableCursor >
1212- void AODProducerWorkflowDPL::fillCaloTable (TEventHandler* caloEventHandler, const TCaloCells& calocells , const TCaloTriggerRecord& caloCellTRGR ,
1213- const TCaloCursor& caloCellCursor, const TCaloTRGTableCursor& caloCellTRGTableCursor ,
1214- const std::map< uint64_t , int >& bcsMap, int8_t caloType )
1238+ template <typename TCaloCursor, typename TCaloTRGCursor >
1239+ void AODProducerWorkflowDPL::fillCaloTable (const TCaloCursor& caloCellCursor , const TCaloTRGCursor& caloTRGCursor ,
1240+ const std::map< uint64_t , int >& bcsMap ,
1241+ const o2::globaltracking::RecoContainer& data )
12151242{
1216- uint64_t globalBC = 0 ; // global BC ID
1217- uint64_t globalBCRel = 0 ; // BC id reltive to minGlBC (from FIT)
1243+ // get calo information
1244+ auto caloEMCCells = data.getEMCALCells ();
1245+ auto caloEMCCellsTRGR = data.getEMCALTriggers ();
1246+
1247+ auto caloPHOSCells = data.getPHOSCells ();
1248+ auto caloPHOSCellsTRGR = data.getPHOSTriggers ();
1249+
1250+ if (!mInputSources [GIndex::PHS]) {
1251+ caloPHOSCells = {};
1252+ caloPHOSCellsTRGR = {};
1253+ }
1254+
1255+ if (!mInputSources [GIndex::EMC]) {
1256+ caloEMCCells = {};
1257+ caloEMCCellsTRGR = {};
1258+ }
1259+
1260+ o2::emcal::EventHandler<o2::emcal::Cell> emcEventHandler;
1261+ o2::phos::EventHandler<o2::phos::Cell> phsEventHandler;
12181262
12191263 // get cell belonging to an eveffillnt instead of timeframe
1220- caloEventHandler-> reset ();
1221- caloEventHandler-> setCellData (calocells, caloCellTRGR );
1264+ emcEventHandler. reset ();
1265+ emcEventHandler. setCellData (caloEMCCells, caloEMCCellsTRGR );
12221266
1223- // loop over events
1224- for (int iev = 0 ; iev < caloEventHandler->getNumberOfEvents (); iev++) {
1225- auto inputEvent = caloEventHandler->buildEvent (iev);
1226- auto cellsInEvent = inputEvent.mCells ; // get cells belonging to current event
1227- auto interactionRecord = inputEvent.mInteractionRecord ; // get interaction records belonging to current event
1267+ phsEventHandler.reset ();
1268+ phsEventHandler.setCellData (caloPHOSCells, caloPHOSCellsTRGR);
1269+
1270+ int emcNEvents = emcEventHandler.getNumberOfEvents ();
1271+ int phsNEvents = phsEventHandler.getNumberOfEvents ();
1272+
1273+ std::vector<std::tuple<uint64_t , int8_t , int >> caloEvents; // <bc, caloType, eventID>
1274+
1275+ caloEvents.reserve (emcNEvents + phsNEvents);
12281276
1229- globalBC = interactionRecord.toLong ();
1277+ for (int iev = 0 ; iev < emcNEvents; ++iev) {
1278+ uint64_t bc = emcEventHandler.getInteractionRecordForEvent (iev).toLong ();
1279+ caloEvents.emplace_back (std::make_tuple (bc, 1 , iev));
1280+ }
1281+
1282+ for (int iev = 0 ; iev < phsNEvents; ++iev) {
1283+ uint64_t bc = phsEventHandler.getInteractionRecordForEvent (iev).toLong ();
1284+ caloEvents.emplace_back (std::make_tuple (bc, 0 , iev));
1285+ }
1286+
1287+ std::sort (caloEvents.begin (), caloEvents.end (),
1288+ [](const auto & left, const auto & right) { return std::get<0 >(left) < std::get<0 >(right); });
1289+
1290+ // loop over events
1291+ for (int i = 0 ; i < emcNEvents + phsNEvents; ++i) {
1292+ uint64_t globalBC = std::get<0 >(caloEvents[i]);
1293+ int8_t caloType = std::get<1 >(caloEvents[i]);
1294+ int eventID = std::get<2 >(caloEvents[i]);
12301295 auto item = bcsMap.find (globalBC);
12311296 int bcID = -1 ;
12321297 if (item != bcsMap.end ()) {
12331298 bcID = item->second ;
12341299 } else {
12351300 LOG (warn) << " Error: could not find a corresponding BC ID for a calo point; globalBC = " << globalBC << " , caloType = " << (int )caloType;
12361301 }
1237-
1238- // loop over all cells in collision
1239- for (auto & cell : cellsInEvent) {
1240- caloCellCursor (0 ,
1241- bcID,
1242- CellHelper::getCellNumber (cell),
1243- truncateFloatFraction (CellHelper::getAmplitude (cell), mCaloAmp ),
1244- truncateFloatFraction (CellHelper::getTimeStamp (cell), mCaloTime ),
1245- cell.getType (),
1246- caloType); // 1 = emcal, -1 = undefined, 0 = phos
1247-
1248- // todo: fix dummy values in CellHelper when it is clear what is filled for trigger information
1249- if (CellHelper::isTRU (cell)) { // Write only trigger cells into this table
1250- caloCellTRGTableCursor (0 ,
1251- bcID,
1252- CellHelper::getFastOrAbsID (cell),
1253- CellHelper::getLnAmplitude (cell),
1254- CellHelper::getTriggerBits (cell),
1255- caloType);
1256- }
1302+ if (caloType == 0 ) { // phs
1303+ addToCaloTable (phsEventHandler, caloCellCursor, caloTRGCursor, eventID, bcID, caloType);
1304+ }
1305+ if (caloType == 1 ) { // emc
1306+ addToCaloTable (emcEventHandler, caloCellCursor, caloTRGCursor, eventID, bcID, caloType);
12571307 }
12581308 }
1309+
1310+ caloEvents.clear ();
12591311}
12601312
12611313void AODProducerWorkflowDPL::init (InitContext& ic)
@@ -1361,13 +1413,6 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
13611413 auto zdcBCRecData = recoData.getZDCBCRecData ();
13621414 auto zdcTDCData = recoData.getZDCTDCData ();
13631415
1364- // get calo information
1365- auto caloEMCCells = recoData.getEMCALCells ();
1366- auto caloEMCCellsTRGR = recoData.getEMCALTriggers ();
1367-
1368- auto caloPHOSCells = recoData.getPHOSCells ();
1369- auto caloPHOSCellsTRGR = recoData.getPHOSTriggers ();
1370-
13711416 auto cpvClusters = recoData.getCPVClusters ();
13721417 auto cpvTrigRecs = recoData.getCPVTriggers ();
13731418
@@ -1384,8 +1429,6 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
13841429 LOG (debug) << " FOUND " << ft0RecPoints.size () << " FT0 rec. points" ;
13851430 LOG (debug) << " FOUND " << fv0RecPoints.size () << " FV0 rec. points" ;
13861431 LOG (debug) << " FOUND " << fddRecPoints.size () << " FDD rec. points" ;
1387- LOG (debug) << " FOUND " << caloEMCCells.size () << " EMC cells" ;
1388- LOG (debug) << " FOUND " << caloEMCCellsTRGR.size () << " EMC Trigger Records" ;
13891432 LOG (debug) << " FOUND " << cpvClusters.size () << " CPV clusters" ;
13901433 LOG (debug) << " FOUND " << cpvTrigRecs.size () << " CPV trigger records" ;
13911434
@@ -1809,16 +1852,8 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
18091852
18101853 bcToClassMask.clear ();
18111854
1812- if (mInputSources [GIndex::EMC]) {
1813- // fill EMC cells to tables
1814- // TODO handle MC info
1815- o2::emcal::EventHandler<o2::emcal::Cell> caloEventHandler;
1816- fillCaloTable (&caloEventHandler, caloEMCCells, caloEMCCellsTRGR, caloCellsCursor, caloCellsTRGTableCursor, bcsMap, 1 );
1817- }
1818-
1819- if (mInputSources [GIndex::PHS]) {
1820- o2::phos::EventHandler<o2::phos::Cell> caloEventHandler;
1821- fillCaloTable (&caloEventHandler, caloPHOSCells, caloPHOSCellsTRGR, caloCellsCursor, caloCellsTRGTableCursor, bcsMap, 0 );
1855+ if (mInputSources [GIndex::PHS] || mInputSources [GIndex::EMC]) {
1856+ fillCaloTable (caloCellsCursor, caloCellsTRGTableCursor, bcsMap, recoData);
18221857 }
18231858
18241859 // fill cpvcluster table
0 commit comments