CMS 3D CMS Logo

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

#include <CastorCtdcPacker.h>

Public Member Functions

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

Private Member Functions

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 
)
private

Definition at line 28 of file CastorCtdcPacker.cc.

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

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

pack into CastorCORData

Definition at line 40 of file CastorCtdcPacker.cc.

References CastorCORData::allocate(), CastorCORData::CHANNELS_PER_SPIGOT, CastorCTDCHeader::clear(), evf::compute_crc(), 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().

44  {
47  std::vector<unsigned char> preclen(CastorCORData::CHANNELS_PER_SPIGOT);
48  std::vector<unsigned char> triglen(CastorCORData::CHANNELS_PER_SPIGOT);
49  static const int CORFormatVersion=1;
50 
51 // CastorCORData spigots[CastorCTDCHeader::SPIGOT_COUNT];
52  CastorCORData spigots[2];
53  // loop over all valid channels in the given ctdc, spigot by spigot.
54  for (int spigot=0; spigot<CastorCTDCHeader::SPIGOT_COUNT; spigot++) {
55  spigots[spigot].allocate(CORFormatVersion);
56  CastorElectronicsId exampleEId;
57  int npresent=0;
58  int presamples=-1, samples=-1;
59  for (int fiber=1; fiber<=12; fiber++)
60  for (int fiberchan=0; fiberchan<3; fiberchan++) {
61  int linear=(fiber-1)*3+fiberchan;
62 // HcalQIESample chanSample(0,0,fiber,fiberchan,false,false);
63 // unsigned short chanid=chanSample.raw()&0xF800;
64  preclen[linear]=0;
65  CastorElectronicsId partialEid(fiberchan,fiber,spigot,dccnumber);
66  // does this partial id exist?
67  CastorElectronicsId fullEid;
68  HcalGenericDetId genId;
69  if (!emap.lookup(partialEid,fullEid,genId)) continue;
70 
71  // next, see if there is a digi with this id
72  unsigned short* database=&(precdata[linear*CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL]);
73  int mypresamples;
74  int mysamples=findSamples(genId,inputs,database,mypresamples);
75  if (mysamples>0) {
76  if (samples<0) samples=mysamples;
77  else if (samples!=mysamples) {
78  edm::LogError("CASTOR") << "Mismatch of samples in a single COR (unsupported) " << mysamples << " != " << samples;
79  continue;
80  }
81  if (presamples<0) {
82  presamples=mypresamples;
83  exampleEId=fullEid;
84  } else if (mypresamples!=presamples) {
85  edm::LogError("CASTOR") << "Mismatch of presamples in a single COR (unsupported) " << mypresamples << " != " << presamples;
86  continue;
87  }
88  preclen[linear]=(unsigned char)(samples);
89  npresent++;
90 
91  }
92  }
94  if (npresent>0) {
95  spigots[spigot].pack(&(preclen[0]),&(precdata[0]),
96  &(triglen[0]),&(trigdata[0]),
97  true);
98  static const int pipeline=0x22;
99  static const int firmwareRev=0;
100  int submodule=exampleEId.htrTopBottom()&0x1;
101  submodule|=(exampleEId.htrSlot()&0x1F)<<1;
102  submodule|=(exampleEId.readoutVMECrateId()&0x1f)<<6;
103  spigots[spigot].packHeaderTrailer(nl1a,
104  bcn,
105  submodule,
106  orbitn,
107  pipeline,
108  samples,
109  presamples,
110  firmwareRev);
111 
112  }
113  }
114  // calculate the total length, and resize the FEDRawData
115  int theSize=0;
116  for (int spigot=0; spigot<2; spigot++) {
117  theSize+=spigots[spigot].getRawLength()*sizeof(unsigned short);
118  }
119  // the merger payload - not yet defined
120  CastorMergerData mergerdata;
121  // would need to fill mergdata here
122  theSize+=mergerdata.getRawLength()*sizeof(unsigned short);
123 
124  theSize+=sizeof(CastorCTDCHeader)+8; // 8 for trailer
125  theSize+=(8-(theSize%8))%8; // even number of 64-bit words.
126  output.resize(theSize);
127 
128  // construct the bare CTDC Header
129  CastorCTDCHeader* dcc=(CastorCTDCHeader*)(output.data());
130  dcc->clear();
131  dcc->setHeader(fedid,bcn,nl1a,orbitn);
132 
133  // pack the HTR data into the FEDRawData block using CastorCTDCHeader
134  for (int spigot=0; spigot<2; spigot++) {
135  if (spigots[spigot].getRawLength()>0)
136  dcc->copySpigotData(spigot,spigots[spigot],true,0);
137  }
138  if ( mergerdata.getRawLength()>0)
139  dcc->copyMergerData(mergerdata,true);
140  // trailer
141  FEDTrailer fedTrailer(output.data()+(output.size()-8));
142  fedTrailer.set(output.data()+(output.size()-8),
143  output.size()/8,
144  evf::compute_crc(output.data(),output.size()), 0, 0);
145 
146 }
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:67
void allocate(int version_to_create=0)
const int getRawLength() const
Get the length of the raw data.
Definition: CastorCORData.h:36
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)