23#include "GaudiKernel/SystemOfUnits.h"
43 header.m_version = version;
62 header.m_qualy_mask = 0x8000;
63 header.m_egain_mask = 0x6000;
64 header.m_esign_mask = 0x1000;
70 header.m_crtae_mask = 0x0fff;
71 header.m_egain_tile_mask = 0x4000;
72 header.m_esign_tile_mask = 0x2000;
76 header.m_crtae_tile_mask = 0x1fff;
77 header.m_tsign_mask = 0x8000;
78 header.m_logat_mask = 0x7fff;
88 header.m_e1_norm_res = 3.2*Gaudi::Units::TeV;
89 header.m_e1_high_res = 50*Gaudi::Units::GeV;
90 header.m_high_tile = 50*Gaudi::Units::GeV;
91 header.m_low_tile = 3.2*Gaudi::Units::TeV;
92 header.m_t0 = 0.001*Gaudi::Units::ns;
93 header.m_t1 = 1250.0*Gaudi::Units::ns;
105 header.m_ncells_larem = 0;
106 header.m_ncells_larhec = 0;
107 header.m_ncells_larfcal = 0;
113 header.m_lengthProvenance = 0;
219 ltime = log(fabs(time));
228 if ( time < 0 && data != 0 )
251 double energy = cell->energy();
252 double time = cell->time();
254 if( (cell->provenance() & 0x2000) == 0x2000 )
259 int gain = cell->gain();
296 if (gainflag == -999) {
301 double crtae = cbrt(fabs(energy));
310 if (energy < 0 && data != 0)
323 if ( qualflag != pars.
m_qabad){
326 it.set(cell->quality());
346 double ene[2] = {cell->ene1(), cell->ene2()};
347 double time[2] = {cell->time1(), cell->time2()};
348 int qbit[2] = {cell->qbit1(), cell->qbit2()};
349 int gain[2] = {cell->gain1(), cell->gain2()};
354 bool write_qual =
false;
355 for (
int ipmt=0; ipmt<2; ++ipmt) {
357 bool write_time =
false;
378 double crtae = cbrt(fabs(ene[ipmt]));
379 if (gain[ipmt] != pars.
m_glow)
388 if (ene[ipmt] < 0 && data != 0)
408 if (pars.
m_version >= 502 && write_qual) {
409 it.set (cell->quality());
435 it.set ((data>>16) & 0xffff);
436 it.set (data & 0xffff);
479 std::vector<short unsigned int> vProvenance;
487 unsigned int maxsize =
489 packed.resize (maxsize);
495 (packed.compact_begin_output (pars.
m_length));
500 (packed.compact_begin_output (pars.
m_length));
503 unsigned int seqhash =
static_cast<unsigned int> (-1);
507 unsigned int nseq = 0;
513 short unsigned int prevCellProvenance=0;
529 for (
size_t icell = 0;
const CaloCell* cell : cells)
532 if (dec && dec->
thinned (icell++)) {
547 seqhash + nseq != hash ||
558 finish_seq (seqhash, nseq, seqit, prevcalo, pars);
575 if (version >= 502 &&
582 vProvenance.push_back ((data>>16) & 0xffff);
583 vProvenance.push_back (data & 0xffff);
587 pack_lar (cell, subcalo, outit, pars);
590 if (version >= 500 &&
591 (cell->provenance() & pars.
m_prov_max) != prevCellProvenance)
593 prevCellProvenance = cell->provenance() & pars.
m_prov_max;
597 vProvenance.push_back ((data>>16) & 0xffff);
598 vProvenance.push_back (data & 0xffff);
606 finish_seq (seqhash, nseq, seqit, prevcalo, pars);
610 assert (outit.
used() + pars.
m_length + vProvenance.size()/2 + 1 <= maxsize);
620 if (
x!=
y) outit.
set(0);
624 for (
unsigned short & iter : vProvenance)
647 const int * phead = &(
header.m_length);
648 std::vector<CaloCompactCellContainer::value_type>
649 vhead (phead, phead +
header.m_length);
650 packed.setHeader(vhead);
684 double ee = std::exp (time);
710 uint16_t provenance)
const
731 if ( gainflag == pars.
m_ehhig ) {
739 if ( gainflag == pars.
m_enhig ) {
742 else if ( gainflag == pars.
m_enmed ) {
745 else if ( gainflag == pars.
m_enlow) {
752 energy = energy*energy*energy;
759 if ( qualflag != pars.
m_qabad ) {
763 provenance = provenance | 0x2000;
767 cell->set (energy, time, quality, provenance, gain);
786 uint16_t provenance)
const
794 bool read_qual =
false;
796 for (
int ipmt = 0; ipmt < 2; ++ipmt) {
808 time[ipmt] = time[0];
818 gain[ipmt] = gainflag;
822 if (gainflag != pars.
m_glow)
828 ene[ipmt] = -ene[ipmt];
831 if (qualflag != pars.
m_qabad) {
847 uint16_t qualp = it.next();
856 qual[0] = qual[1] = 0;
860 return TileCell (dde, ene[0], ene[1], time[0], time[1],
861 qual[0], qual[1], qbit[0], qbit[1], gain[0], gain[1]);
879 const std::vector<int>& vheader,
898 const int* headerbeg = &*vheader.begin();
899 const int* headerend = headerbeg + vheader.size();
900 size_t nheader = headerend - headerbeg;
901 size_t parsize =
sizeof(
header) /
sizeof(
int);
902 size_t ncopy = std::min (nheader, parsize);
903 int* parsbeg =
reinterpret_cast<int*
>(&pars);
904 std::copy (headerbeg, headerbeg+ncopy, parsbeg);
905 if (nheader > parsize) {
909 "CaloCellPacker_400_500 ")
910 <<
"Corrupted data: Compact cell header is "
911 << nheader <<
" words long, longer than the largest expected value of "
914 else if (ncopy < parsize) {
919 std::fill (parsbeg + ncopy, parsbeg + parsize, 0);
928 if (nprov + vheader.size() > packed.getData().size()) {
930 "CaloCellPacker_400_500 ")
931 <<
"Corrupted data: Provenance count too large "
943 short unsigned int currProvValue=0;
945 short unsigned int nextProvValue=0;
947 unsigned int provhash = provIt.
next();
948 provhash = (provhash<<16) | provIt.
next();
962 throw std::runtime_error(
"Failed to initialize ReadCondHandleKey for CaloSuperCellDetDescrManager");
965 ddmgr = *caloSuperCellMgrHandle;
971 throw std::runtime_error(
"Failed to initialize ReadCondHandleKey for CaloDetDescrManager");
974 ddmgr = *caloMgrHandle;
985 "CaloCellPacker_400_500 ")
986 <<
"Corrupted data: Too many cells " << totcells <<
".";
989 cells.reserve (totcells);
993 packed.compact_begin_input();
996 std::vector<CaloCompactCellContainer::value_type>::const_iterator pend =
1000 unsigned int ncells =
1005 unsigned int nseqs =
1018 if (ncells > hashmax || nseqs > hashmax || nseqs > ncells) {
1020 "CaloCellPacker_400_500 ")
1021 <<
"Corrupted data: Bad counts"
1022 <<
": ncells " << ncells <<
" nseqs " << nseqs <<
" hashmax " << hashmax;
1028 for (; nseqs > 0; --nseqs) {
1031 if (it.base() >= pend) {
1033 "CaloCellPacker_400_500 ")
1034 <<
"Corrupted data: cell vector overrun.";
1040 unsigned int hashlength = data << 16;
1041 hashlength |= it.next();
1046 if (nseq > ncells || hash+nseq > hashmax)
1049 "CaloCellPacker_400_500 ")
1050 <<
"Corrupted data: bad sequence. "
1051 <<
"nseq " << nseq <<
" hash " << hash <<
" ncells " << ncells
1052 <<
" hashmax " << hashmax;
1061 if (subcalo != prevcalo) {
1064 cells.updateCaloEndIterators (prevcalo, cells.size());
1065 if (subcalo < prevcalo) {
1067 "CaloCellPacker_400_500 ")
1068 <<
"Cells not in subcalo order; iterators will be wrong.";
1071 cells.updateCaloBeginIterators (subcalo, cells.size());
1073 cells.setHasCalo (subcalo);
1082 if (dde ==
nullptr) {
1084 "CaloCellPacker_400_500 ")
1085 <<
"Corrupted data: can't find DDE for cell with hash " << hash;
1129 if (hash==
static_cast<unsigned int>(nextProvHash)){
1130 currProvValue = nextProvValue;
1132 unsigned int provhash = provIt.
next();
1133 provhash = (provhash<<16) | provIt.
next();
1147 pars, currProvValue));
1154 cell->set (dde, calo_id->
cell_id(hash));
1159 cells.push_back (cell);
1168 cells.updateCaloEndIterators (prevcalo, cells.size());
1172 if (it.base() < pend-2) {
1174 "CaloCellPacker_400_500 ")
1175 <<
"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