22#include "GaudiKernel/SystemOfUnits.h"
42 header.m_version = version;
61 header.m_qualy_mask = 0x8000;
62 header.m_egain_mask = 0x6000;
63 header.m_esign_mask = 0x1000;
69 header.m_crtae_mask = 0x0fff;
70 header.m_egain_tile_mask = 0x4000;
71 header.m_esign_tile_mask = 0x2000;
75 header.m_crtae_tile_mask = 0x1fff;
76 header.m_tsign_mask = 0x8000;
77 header.m_logat_mask = 0x7fff;
87 header.m_e1_norm_res = 3.2*Gaudi::Units::TeV;
88 header.m_e1_high_res = 50*Gaudi::Units::GeV;
89 header.m_high_tile = 50*Gaudi::Units::GeV;
90 header.m_low_tile = 3.2*Gaudi::Units::TeV;
91 header.m_t0 = 0.001*Gaudi::Units::ns;
92 header.m_t1 = 1250.0*Gaudi::Units::ns;
104 header.m_ncells_larem = 0;
105 header.m_ncells_larhec = 0;
106 header.m_ncells_larfcal = 0;
112 header.m_lengthProvenance = 0;
218 ltime = log(fabs(time));
227 if ( time < 0 && data != 0 )
250 double energy = cell->energy();
251 double time = cell->time();
253 if( (cell->provenance() & 0x2000) == 0x2000 )
258 int gain = cell->gain();
295 if (gainflag == -999) {
300 double crtae = cbrt(fabs(energy));
309 if (energy < 0 && data != 0)
322 if ( qualflag != pars.
m_qabad){
325 it.set(cell->quality());
345 double ene[2] = {cell->ene1(), cell->ene2()};
346 double time[2] = {cell->time1(), cell->time2()};
347 int qbit[2] = {cell->qbit1(), cell->qbit2()};
348 int gain[2] = {cell->gain1(), cell->gain2()};
353 bool write_qual =
false;
354 for (
int ipmt=0; ipmt<2; ++ipmt) {
356 bool write_time =
false;
377 double crtae = cbrt(fabs(ene[ipmt]));
378 if (gain[ipmt] != pars.
m_glow)
387 if (ene[ipmt] < 0 && data != 0)
407 if (pars.
m_version >= 502 && write_qual) {
408 it.set (cell->quality());
434 it.set ((data>>16) & 0xffff);
435 it.set (data & 0xffff);
478 std::vector<short unsigned int> vProvenance;
486 unsigned int maxsize =
488 packed.resize (maxsize);
494 (packed.compact_begin_output (pars.
m_length));
499 (packed.compact_begin_output (pars.
m_length));
502 unsigned int seqhash =
static_cast<unsigned int> (-1);
506 unsigned int nseq = 0;
512 short unsigned int prevCellProvenance=0;
528 for (
size_t icell = 0;
const CaloCell* cell : cells)
531 if (dec && dec->
thinned (icell++)) {
546 seqhash + nseq != hash ||
557 finish_seq (seqhash, nseq, seqit, prevcalo, pars);
574 if (version >= 502 &&
581 vProvenance.push_back ((data>>16) & 0xffff);
582 vProvenance.push_back (data & 0xffff);
586 pack_lar (cell, subcalo, outit, pars);
589 if (version >= 500 &&
590 (cell->provenance() & pars.
m_prov_max) != prevCellProvenance)
592 prevCellProvenance = cell->provenance() & pars.
m_prov_max;
596 vProvenance.push_back ((data>>16) & 0xffff);
597 vProvenance.push_back (data & 0xffff);
605 finish_seq (seqhash, nseq, seqit, prevcalo, pars);
609 assert (outit.
used() + pars.
m_length + vProvenance.size()/2 + 1 <= maxsize);
619 if (
x!=
y) outit.
set(0);
623 for (
unsigned short & iter : vProvenance)
646 const int * phead = &(
header.m_length);
647 std::vector<CaloCompactCellContainer::value_type>
648 vhead (phead, phead +
header.m_length);
649 packed.setHeader(vhead);
683 double ee = std::exp (time);
709 uint16_t provenance)
const
730 if ( gainflag == pars.
m_ehhig ) {
738 if ( gainflag == pars.
m_enhig ) {
741 else if ( gainflag == pars.
m_enmed ) {
744 else if ( gainflag == pars.
m_enlow) {
751 energy = energy*energy*energy;
758 if ( qualflag != pars.
m_qabad ) {
762 provenance = provenance | 0x2000;
766 cell->set (energy, time, quality, provenance, gain);
785 uint16_t provenance)
const
793 bool read_qual =
false;
795 for (
int ipmt = 0; ipmt < 2; ++ipmt) {
807 time[ipmt] = time[0];
817 gain[ipmt] = gainflag;
821 if (gainflag != pars.
m_glow)
827 ene[ipmt] = -ene[ipmt];
830 if (qualflag != pars.
m_qabad) {
846 uint16_t qualp = it.next();
855 qual[0] = qual[1] = 0;
859 return TileCell (dde, ene[0], ene[1], time[0], time[1],
860 qual[0], qual[1], qbit[0], qbit[1], gain[0], gain[1]);
878 const std::vector<int>& vheader,
897 const int* headerbeg = &*vheader.begin();
898 const int* headerend = headerbeg + vheader.size();
899 size_t nheader = headerend - headerbeg;
900 size_t parsize =
sizeof(
header) /
sizeof(
int);
901 size_t ncopy = std::min (nheader, parsize);
902 int* parsbeg =
reinterpret_cast<int*
>(&pars);
903 std::copy (headerbeg, headerbeg+ncopy, parsbeg);
904 if (nheader > parsize) {
908 "CaloCellPacker_400_500 ")
909 <<
"Corrupted data: Compact cell header is "
910 << nheader <<
" words long, longer than the largest expected value of "
913 else if (ncopy < parsize) {
918 std::fill (parsbeg + ncopy, parsbeg + parsize, 0);
927 if (nprov + vheader.size() > packed.getData().size()) {
929 "CaloCellPacker_400_500 ")
930 <<
"Corrupted data: Provenance count too large "
942 short unsigned int currProvValue=0;
944 short unsigned int nextProvValue=0;
946 unsigned int provhash = provIt.
next();
947 provhash = (provhash<<16) | provIt.
next();
961 throw std::runtime_error(
"Failed to initialize ReadCondHandleKey for CaloSuperCellDetDescrManager");
964 ddmgr = *caloSuperCellMgrHandle;
970 throw std::runtime_error(
"Failed to initialize ReadCondHandleKey for CaloDetDescrManager");
973 ddmgr = *caloMgrHandle;
984 "CaloCellPacker_400_500 ")
985 <<
"Corrupted data: Too many cells " << totcells <<
".";
988 cells.reserve (totcells);
992 packed.compact_begin_input();
995 std::vector<CaloCompactCellContainer::value_type>::const_iterator pend =
999 unsigned int ncells =
1004 unsigned int nseqs =
1017 if (ncells > hashmax || nseqs > hashmax || nseqs > ncells) {
1019 "CaloCellPacker_400_500 ")
1020 <<
"Corrupted data: Bad counts"
1021 <<
": ncells " << ncells <<
" nseqs " << nseqs <<
" hashmax " << hashmax;
1027 for (; nseqs > 0; --nseqs) {
1030 if (it.base() >= pend) {
1032 "CaloCellPacker_400_500 ")
1033 <<
"Corrupted data: cell vector overrun.";
1039 unsigned int hashlength = data << 16;
1040 hashlength |= it.next();
1045 if (nseq > ncells || hash+nseq > hashmax)
1048 "CaloCellPacker_400_500 ")
1049 <<
"Corrupted data: bad sequence. "
1050 <<
"nseq " << nseq <<
" hash " << hash <<
" ncells " << ncells
1051 <<
" hashmax " << hashmax;
1060 if (subcalo != prevcalo) {
1063 cells.updateCaloEndIterators (prevcalo, cells.size());
1064 if (subcalo < prevcalo) {
1066 "CaloCellPacker_400_500 ")
1067 <<
"Cells not in subcalo order; iterators will be wrong.";
1070 cells.updateCaloBeginIterators (subcalo, cells.size());
1072 cells.setHasCalo (subcalo);
1081 if (dde ==
nullptr) {
1083 "CaloCellPacker_400_500 ")
1084 <<
"Corrupted data: can't find DDE for cell with hash " << hash;
1128 if (hash==
static_cast<unsigned int>(nextProvHash)){
1129 currProvValue = nextProvValue;
1131 unsigned int provhash = provIt.
next();
1132 provhash = (provhash<<16) | provIt.
next();
1146 pars, currProvValue));
1153 cell->set (dde, calo_id->
cell_id(hash));
1158 cells.push_back (cell);
1167 cells.updateCaloEndIterators (prevcalo, cells.size());
1171 if (it.base() < pend-2) {
1173 "CaloCellPacker_400_500 ")
1174 <<
"Corrupted data: didn't consume all packed data.";
Calo cell packer/unpacker v400/500.
Definition of CaloDetDescrManager.
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Hold thinning decisions for one container.
Container class for CaloCell.
Helper for packing into/out of a bit field.
unsigned int out(unsigned int x) const
Extract a value from the bitfield.
unsigned int in(unsigned int x) const
Shift and mask a value into the bitfield.
Helper for packing a float into/out of a bit field, with a minimum of 0.
unsigned int in(double x) const
Shift and mask a value into the bitfield.
double out(unsigned int x) const
Extract a value from the bitfield.
Helper for packing a float into/out of a bit field.
unsigned int in(double x) const
Shift and mask a value into the bitfield.
double out(unsigned int x, int &underflow) const
Extract a value from the bitfield.
CaloCell * unpack_lar(CaloCompactCellContainer::compact_input_iterator &it, CaloCell_ID::SUBCALO subcalo, LArCell *cell, const pars500 &pars, uint16_t provenance) const
Unpack a LAr cell.
void finish_seq(unsigned int hash, unsigned int nseq, CaloCompactCellContainer::compact_output_iterator &it, CaloCell_ID::SUBCALO subcalo, pars500 &pars) const
Finish up one cell sequence.
void write_header(const header &header, CaloCompactCellContainer &packed) const
Write the header to the output container.
void pack_tile(const TileCell *cell, CaloCompactCellContainer::compact_output_iterator &it, const pars500 &pars) const
Pack one tile cell.
header501 header
The most recent header version.
void unpack(const CaloCompactCellContainer &packed, const std::vector< CaloCompactCellContainer::value_type > &vheader, CaloCellContainer &cells, DataPool< LArCell > &larpool, DataPool< TileCell > &tilepool) const
Unpack cells.
double unpack_time(CaloCompactCellContainer::compact_input_iterator &it, const pars500 &pars) const
Unpack the time word.
void pack_time(float time, CaloCompactCellContainer::compact_output_iterator &it, const pars500 &pars) const
Pack a time value.
void pack_lar(const CaloCell *cell, CaloCell_ID::SUBCALO subcalo, CaloCompactCellContainer::compact_output_iterator &it, const pars500 &pars) const
Pack one LAr cell.
void init_derived(pars500 &pars) const
Initialize the derived packing parameters from the constants in the header.
TileCell unpack_tile(CaloCompactCellContainer::compact_input_iterator &it, const CaloDetDescrElement *dde, const pars500 &pars, uint16_t provenance) const
Unpack a tile cell.
void init_header(header &header, int version) const
Initialize header with the current version of the packing parameters.
void pack(const CaloCellContainer &cells, CaloCompactCellContainer &packed, const SG::ThinningDecisionBase *dec, int version) const
Pack cells.
void clear_header(header &header) const
Clear the counters in the event header.
Helper base class for offline cell identifiers.
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
size_type calo_cell_hash_max() const
cell 'global' hash table max size
bool is_supercell(const Identifier id) const
Test if the identifier represents a supercell.
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
CaloCell_Base_ID::size_type size_type
CaloCell_Base_ID::SUBCALO SUBCALO
Data object for each calorimeter readout cell.
Simple iterator-like object for writing to the container.
int used() const
Return the number of underlying value_type words used.
void set(CaloCompactCell::value_type x)
Set the next value, and advance the iterator.
container class for CaloCompactCell objects
int value_type
value type for the internal data
unsigned short value_type
value type for the compact CaloCell data
This class groups all DetDescr information related to a CaloCell.
IdentifierHash calo_hash() const
cell calo hash
CaloCell_ID::SUBCALO getSubCalo() const
cell subcalo
const CaloDetDescriptor * descriptor() const
cell descriptor
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
const CaloCell_Base_ID * getCaloCell_ID() const
get calo cell ID helper
const CaloCell_Base_ID * get_calo_helper() const
get Calo Cell ID helper
a typed memory pool that saves time spent allocation small object.
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
This is a "hash" representation of an Identifier.
Data object for LAr calorimeter readout cell.
StatusCode initialize(bool used=true)
Hold thinning decisions for one container.
bool thinned(size_t ndx) const
Return true if element ndx should be thinned.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Derived packing parmeters.
double m_cbrt_e1_norm_res
Transformed packing ranges for floats.
CaloCellPackerUtils::Floatfield2 m_crtae_norm_field
CaloCellPackerUtils::Floatfield2 m_crtae_high_field
CaloCompactCell::value_type m_tile_dummy
CaloCompactCell::value_type m_lar_dummy
CaloCompactCell::value_type m_lar_dummy_subst
CaloCellPackerUtils::Bitfield m_egain_tile_field
CaloCellPackerUtils::Bitfield m_egain_field
unsigned int m_nseq_max
Maximum number of cells in a sequence.
unsigned int m_prov_max_tile
CaloCellPackerUtils::Bitfield m_prov_field
CaloCellPackerUtils::Floatfield2 m_crtae_tile_high_field
CaloCellPackerUtils::Floatfield2 m_crtae_tile_low_field
CaloCellPackerUtils::Bitfield m_qualy_field
int m_qgood
Good quality flag.
double m_cbrt_e1_high_res
CaloCellPackerUtils::Bitfield m_tile_qual1_field
CaloCompactCell::value_type m_tile_dummy_subst
CaloCellPackerUtils::Bitfield m_hash_field
Bitfields for various quantities.
CaloCellPackerUtils::Bitfield m_tile_qual2_field
CaloCellPackerUtils::Bitfield m_nseq_field
CaloCellPackerUtils::Floatfield m_logat_field