CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorPacker.cc
Go to the documentation of this file.
9 
10 template <class Coll, class DetIdClass>
11 int process(const Coll* pt, const DetId& did, unsigned short* buffer, int& presamples) {
12  if (pt==0) return 0;
13  int size=0;
14  typename Coll::const_iterator i=pt->find(DetIdClass(did));
15  if (i!=pt->end()) {
16  presamples=i->presamples();
17  size=i->size();
18  for (int j=0; j<size; j++)
19  buffer[j]=(*i)[j].raw();
20  }
21  return size;
22 }
23 
25  unsigned short* buffer, int &presamples) {
26 
27  if (did.det()!=DetId::Calo) return 0;
28  int size=0;
29  HcalCastorDetId genId(did);
30 
31  size=process<CastorDigiCollection,HcalCastorDetId>(inputs.castorCont,did,buffer,presamples);
32 
33  return size;
34 }
35 
36 void CastorPacker::pack(int fedid, int dccnumber,
37  int nl1a, int orbitn, int bcn,
38  const CastorCollections& inputs,
39  const CastorElectronicsMap& emap,
40  FEDRawData& output) {
42  std::vector<unsigned short> trigdata(HcalHTRData::CHANNELS_PER_SPIGOT*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL);
43  std::vector<unsigned char> preclen(HcalHTRData::CHANNELS_PER_SPIGOT);
44  std::vector<unsigned char> triglen(HcalHTRData::CHANNELS_PER_SPIGOT);
45  static const int HTRFormatVersion=3;
46 
47  HcalHTRData spigots[15];
48  // loop over all valid channels in the given dcc, spigot by spigot.
49  for (int spigot=0; spigot<15; spigot++) {
50  spigots[spigot].allocate(HTRFormatVersion);
51  CastorElectronicsId exampleEId;
52  int npresent=0;
53  int presamples=-1, samples=-1;
54  for (int fiber=1; fiber<=8; fiber++)
55  for (int fiberchan=0; fiberchan<3; fiberchan++) {
56  int linear=(fiber-1)*3+fiberchan;
57  HcalQIESample chanSample(0,0,fiber,fiberchan,false,false);
58  unsigned short chanid=chanSample.raw()&0xF800;
59  preclen[linear]=0;
60 
61  CastorElectronicsId partialEid(fiberchan,fiber,spigot,dccnumber);
62  // does this partial id exist?
63  CastorElectronicsId fullEid;
64  HcalGenericDetId genId;
65  if (!emap.lookup(partialEid,fullEid,genId)) continue;
66 
67  // next, see if there is a digi with this id
68  unsigned short* database=&(precdata[linear*HcalHTRData::MAXIMUM_SAMPLES_PER_CHANNEL]);
69  int mypresamples;
70  int mysamples=findSamples(genId,inputs,database,mypresamples);
71 
72  if (mysamples>0) {
73  if (samples<0) samples=mysamples;
74  else if (samples!=mysamples) {
75  edm::LogError("CASTOR") << "Mismatch of samples in a single HTR (unsupported) " << mysamples << " != " << samples;
76  continue;
77  }
78  if (presamples<0) {
79  presamples=mypresamples;
80  exampleEId=fullEid;
81  } else if (mypresamples!=presamples) {
82  edm::LogError("CASTOR") << "Mismatch of presamples in a single HTR (unsupported) " << mypresamples << " != " << presamples;
83  continue;
84  }
85  for (int ii=0; ii<samples; ii++)
86  database[ii]=(database[ii]&0x7FF)|chanid;
87  preclen[linear]=(unsigned char)(samples);
88  npresent++;
89  }
90  }
92  if (npresent>0) {
93  spigots[spigot].pack(&(preclen[0]),&(precdata[0]),
94  &(triglen[0]),&(trigdata[0]),
95  false);
96  static const int pipeline=0x22;
97  static const int firmwareRev=0;
98  int submodule=exampleEId.htrTopBottom()&0x1;
99  submodule|=(exampleEId.htrSlot()&0x1F)<<1;
100  submodule|=(exampleEId.readoutVMECrateId()&0x1f)<<6;
101  spigots[spigot].packHeaderTrailer(nl1a,
102  bcn,
103  submodule,
104  orbitn,
105  pipeline,
106  samples,
107  presamples,
108  firmwareRev);
109 
110  }
111  }
112  // calculate the total length, and resize the FEDRawData
113  int theSize=0;
114  for (int spigot=0; spigot<15; spigot++) {
115  theSize+=spigots[spigot].getRawLength()*sizeof(unsigned short);
116  }
117  theSize+=sizeof(HcalDCCHeader)+8; // 8 for trailer
118  theSize+=(8-(theSize%8))%8; // even number of 64-bit words.
119  output.resize(theSize);
120 
121  // construct the bare DCC Header
122  HcalDCCHeader* dcc=(HcalDCCHeader*)(output.data());
123  dcc->clear();
124  dcc->setHeader(fedid,bcn,nl1a,orbitn);
125 
126  // pack the HTR data into the FEDRawData block using HcalDCCHeader
127  for (int spigot=0; spigot<15; spigot++) {
128  if (spigots[spigot].getRawLength()>0)
129  dcc->copySpigotData(spigot,spigots[spigot],true,0);
130  }
131  // trailer
132  FEDTrailer fedTrailer(output.data()+(output.size()-8));
133  fedTrailer.set(output.data()+(output.size()-8),
134  output.size()/8,
135  evf::compute_crc(output.data(),output.size()), 0, 0);
136 
137 }
int i
Definition: DBlmapReader.cc:9
uint16_t raw() const
get the raw word
Definition: HcalQIESample.h:20
int readoutVMECrateId() const
int findSamples(const DetId &did, const CastorCollections &inputs, unsigned short *buffer, int &presamples)
Definition: CastorPacker.cc:24
static const int CHANNELS_PER_SPIGOT
Definition: HcalHTRData.h:18
const CastorDigiCollection * castorCont
int ii
Definition: cuy.py:588
static const int MAXIMUM_SAMPLES_PER_CHANNEL
Definition: HcalHTRData.h:19
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:42
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void allocate(int version_to_create=0)
Definition: HcalHTRData.cc:26
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
void copySpigotData(unsigned int spigot_id, const HcalHTRData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given HcalHTRData as the given spigot&#39;s data. This should be done in increasing spigot order!...
void resize(size_t newsize)
Definition: FEDRawData.cc:32
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:67
const int getRawLength() const
Get the length of the raw data.
Definition: HcalHTRData.h:39
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
int j
Definition: DBlmapReader.cc:9
Definition: DetId.h:18
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.
Definition: HcalHTRData.cc:224
void pack(int fedid, int dccnumber, int nl1a, int orbitn, int bcn, const CastorCollections &inputs, const CastorElectronicsMap &emap, FEDRawData &output)
Definition: CastorPacker.cc:36
void packHeaderTrailer(int L1Anumber, int bcn, int submodule, int orbitn, int pipeline, int ndd, int nps, int firmwareRev=0, int firmwareFlav=0)
pack header and trailer (call after pack)
Definition: HcalHTRData.cc:283
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)
tuple process
Definition: LaserDQM_cfg.py:3
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
tuple size
Write out results.