CMS 3D CMS Logo

List of all members | Static Public Member Functions | Static Private Member Functions
CastorCtdcPacker Class Reference

#include <CastorCtdcPacker.h>

Static Public Member Functions

static void pack (int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const CastorCollections &inputs, const CastorElectronicsMap &emap, FEDRawData &output)
 

Static Private Member Functions

static int findSamples (const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
 

Detailed Description

Author
A. Campbell - DESY

Definition at line 13 of file CastorCtdcPacker.h.

Member Function Documentation

int CastorCtdcPacker::findSamples ( const DetId did,
const CastorCollections inputs,
unsigned short *  buffer,
int &  presamples 
)
staticprivate

Definition at line 30 of file CastorCtdcPacker.cc.

References edmScanValgrind::buffer, DetId::Calo, CastorCollections::castorCont, DetId::det(), hcalTTPDigis_cfi::presamples, and findQualityFiles::size.

31  {
32 
33  if (did.det()!=DetId::Calo) return 0;
34  int size=0;
35  HcalCastorDetId genId(did);
36 
37  size=process<CastorDigiCollection,HcalCastorDetId>(inputs.castorCont,did,buffer,presamples);
38 
39  return size;
40 }
size
Write out results.
const CastorDigiCollection * castorCont
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
void CastorCtdcPacker::pack ( int  fedid,
int  dccnumber,
int  nl1a,
int  orbitn,
int  bcn,
const CastorCollections inputs,
const CastorElectronicsMap emap,
FEDRawData output 
)
static

pack into CastorCORData

Definition at line 42 of file CastorCtdcPacker.cc.

References CastorCORData::allocate(), CastorCORData::CHANNELS_PER_SPIGOT, CastorCTDCHeader::clear(), evf::compute_crc(), constexpr, CastorCTDCHeader::copyMergerData(), CastorCTDCHeader::copySpigotData(), FEDRawData::data(), CastorCORData::getRawLength(), CastorMergerData::getRawLength(), CastorElectronicsId::htrSlot(), CastorElectronicsId::htrTopBottom(), linear(), CastorElectronicsMap::lookup(), CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL, CastorCORData::pack(), CastorCORData::packHeaderTrailer(), hcalTTPDigis_cfi::presamples, CastorElectronicsId::readoutVMECrateId(), FEDRawData::resize(), hcalTTPDigis_cfi::samples, FEDTrailer::set(), CastorCTDCHeader::setHeader(), FEDRawData::size(), and CastorCTDCHeader::SPIGOT_COUNT.

Referenced by pyrootRender.interactiveRender::draw(), and CastorDigiToRaw::produce().

46  {
49  std::vector<unsigned char> preclen(CastorCORData::CHANNELS_PER_SPIGOT);
50  std::vector<unsigned char> triglen(CastorCORData::CHANNELS_PER_SPIGOT);
51  constexpr int CORFormatVersion=1;
52 
53 // CastorCORData spigots[CastorCTDCHeader::SPIGOT_COUNT];
54  CastorCORData spigots[2];
55  // loop over all valid channels in the given ctdc, spigot by spigot.
56  for (int spigot=0; spigot<CastorCTDCHeader::SPIGOT_COUNT; spigot++) {
57  spigots[spigot].allocate(CORFormatVersion);
58  CastorElectronicsId exampleEId;
59  int npresent=0;
60  int presamples=-1, samples=-1;
61  for (int fiber=1; fiber<=12; fiber++)
62  for (int fiberchan=0; fiberchan<3; fiberchan++) {
63  int linear=(fiber-1)*3+fiberchan;
64 // HcalQIESample chanSample(0,0,fiber,fiberchan,false,false);
65 // unsigned short chanid=chanSample.raw()&0xF800;
66  preclen[linear]=0;
67  CastorElectronicsId partialEid(fiberchan,fiber,spigot,dccnumber);
68  // does this partial id exist?
69  CastorElectronicsId fullEid;
70  HcalGenericDetId genId;
71  if (!emap.lookup(partialEid,fullEid,genId)) continue;
72 
73  // next, see if there is a digi with this id
74  unsigned short* database=&(precdata[linear*CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL]);
75  int mypresamples;
76  int mysamples=findSamples(genId,inputs,database,mypresamples);
77  if (mysamples>0) {
78  if (samples<0) samples=mysamples;
79  else if (samples!=mysamples) {
80  edm::LogError("CASTOR") << "Mismatch of samples in a single COR (unsupported) " << mysamples << " != " << samples;
81  continue;
82  }
83  if (presamples<0) {
84  presamples=mypresamples;
85  exampleEId=fullEid;
86  } else if (mypresamples!=presamples) {
87  edm::LogError("CASTOR") << "Mismatch of presamples in a single COR (unsupported) " << mypresamples << " != " << presamples;
88  continue;
89  }
90  preclen[linear]=(unsigned char)(samples);
91  npresent++;
92 
93  }
94  }
96  if (npresent>0) {
97  spigots[spigot].pack(&(preclen[0]),&(precdata[0]),
98  &(triglen[0]),&(trigdata[0]),
99  true);
100  constexpr int pipeline=0x22;
101  constexpr int firmwareRev=0;
102  int submodule=exampleEId.htrTopBottom()&0x1;
103  submodule|=(exampleEId.htrSlot()&0x1F)<<1;
104  submodule|=(exampleEId.readoutVMECrateId()&0x1f)<<6;
105  spigots[spigot].packHeaderTrailer(nl1a,
106  bcn,
107  submodule,
108  orbitn,
109  pipeline,
110  samples,
111  presamples,
112  firmwareRev);
113 
114  }
115  }
116  // calculate the total length, and resize the FEDRawData
117  int theSize=0;
118  for (int spigot=0; spigot<2; spigot++) {
119  theSize+=spigots[spigot].getRawLength()*sizeof(unsigned short);
120  }
121  // the merger payload - not yet defined
122  CastorMergerData mergerdata;
123  // would need to fill mergdata here
124  theSize+=mergerdata.getRawLength()*sizeof(unsigned short);
125 
126  theSize+=sizeof(CastorCTDCHeader)+8; // 8 for trailer
127  theSize+=(8-(theSize%8))%8; // even number of 64-bit words.
128  output.resize(theSize);
129 
130  // construct the bare CTDC Header
131  CastorCTDCHeader* dcc=(CastorCTDCHeader*)(output.data());
132  dcc->clear();
133  dcc->setHeader(fedid,bcn,nl1a,orbitn);
134 
135  // pack the HTR data into the FEDRawData block using CastorCTDCHeader
136  for (int spigot=0; spigot<2; spigot++) {
137  if (spigots[spigot].getRawLength()>0)
138  dcc->copySpigotData(spigot,spigots[spigot],true,0);
139  }
140  if ( mergerdata.getRawLength()>0)
141  dcc->copyMergerData(mergerdata,true);
142  // trailer
143  FEDTrailer fedTrailer(output.data()+(output.size()-8));
144  fedTrailer.set(output.data()+(output.size()-8),
145  output.size()/8,
146  evf::compute_crc(output.data(),output.size()), 0, 0);
147 
148 }
static const int CHANNELS_PER_SPIGOT
Definition: CastorCORData.h:16
void pack(unsigned char *daq_lengths, unsigned short *daq_samples, unsigned char *tp_lengths, unsigned short *tp_samples, bool do_capid=false)
Unpack the HTR data into TP and DAQ data sorted by channel.
int readoutVMECrateId() const
const int getRawLength() const
Get the length of the raw data.
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
void packHeaderTrailer(int L1Anumber, int bcn, int submodule, int orbitn, int pipeline, int ndd, int nps, int firmwareRev=0)
pack header and trailer (call after pack)
static const int SPIGOT_COUNT
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void copySpigotData(unsigned int spigot_id, const CastorCORData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given CastorCORData as the given spigot&#39;s data. This should be done in increasing spigot orde...
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
void copyMergerData(const CastorMergerData &data, bool valid)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: CastorCORData.h:17
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
void allocate(int version_to_create=0)
const int getRawLength() const
Get the length of the raw data.
Definition: CastorCORData.h:36
static int findSamples(const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...
float linear(float x)
#define constexpr