14#include "GaudiKernel/Bootstrap.h"
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/IToolSvc.h"
22#define LARBSDBG(text) m_logstr<<MSG::DEBUG<<text<<endmsg
41 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service(
"DetectorStore")};
43 m_logstr << MSG::ERROR <<
"Unable to locate DetectorStore" <<
endmsg;
46 StatusCode
sc = detStore->retrieve(online_id,
"LArOnlineID");
48 m_logstr << MSG::FATAL <<
"Could not get LArOnlineID helper !" << endmsg;
52 m_onlineHelper=online_id;
53 m_logstr << MSG::DEBUG <<
" Found the LArOnlineID helper. " << endmsg;
156 m_logstr <<
MYLEVEL <<
"***********************************************************************"<<
endmsg;
158 m_logstr <<
MYLEVEL <<
"************************************************************************"<<
endmsg;
165 m_logstr <<
MYLEVEL <<
"************************************************************************"<<
endmsg;
167 m_logstr <<
MYLEVEL <<
"********************* SumBlck ************************************"<<
endmsg;
168 for(
int toto=0;toto<4;toto++)
170 m_logstr <<
MYLEVEL <<
"************************************************************************"<<
endmsg;
172 m_logstr <<
MYLEVEL <<
"********************* CounterBlck ************************************"<<
endmsg;
174 m_logstr <<
MYLEVEL <<
"************************************************************************"<<
endmsg;
176 m_logstr <<
MYLEVEL <<
"********************* FebInfoBlck ************************************"<<
endmsg;
178 m_logstr <<
MYLEVEL <<
"************************************************************************"<<
endmsg;
181 m_logstr <<
MYLEVEL <<
"********************* Energies ************************************"<<
endmsg;
182 for(
int toto=0;toto<128;toto++)
184 m_logstr <<
MYLEVEL <<
"************************************************************************"<<
endmsg;
186 m_logstr <<
MYLEVEL <<
"********************* Time & Quality ************************************"<<
endmsg;
187 for(
int toto=0;toto<10;toto++)
189 m_logstr <<
MYLEVEL <<
"************************************************************************"<<
endmsg;
221 const int32_t time,
const int32_t quality,
const uint32_t gain)
223 m_logstr <<
MYLEVEL <<
"setNextEnergy-------------------->>>>>********************** new format V3 ***********" <<
endmsg;
229 m_logstr << MSG::ERROR <<
"LArRODBlockStructure Error: Internal error. Channels not ordered correctly. rcNb=" << rcNb
236 setNextEnergy((int16_t)0,(int16_t)32767,(int16_t)-32767,(uint32_t)0);
249 uint32_t abse,EncodedE;
250 int16_t thetime,thequality;
253 thetime = (int16_t) time >> 4;
254 thequality = (int16_t) quality;
256 sign=(energy>=0?1:-1);
257 abse=(uint32_t)abs(energy);
261 if ((abse>8192)&&(abse<65536))
263 EncodedE=((abse>>3)|0x2000);
265 else if ((abse>65535)&&(abse<524288))
267 EncodedE=((abse>>6)|0x4000);
269 else if ((abse>524288))
271 EncodedE=((abse>>9)|0x6000);
276 if (
sign<0) EncodedE |= 0x8000;
277 theenergy = (uint16_t) EncodedE;
282 m_logstr <<
MYLEVEL <<
"setNextEnergy-------------------->>>>> Energy = "<< energy <<
" Encoded Energy =" << theenergy <<
endmsg;
290 setNextEnergy(theenergy,(int16_t)32767,(int16_t)-32767,gain);
300 {
m_logstr << MSG::ERROR <<
"LArRodBlockStructure Error: Attempt to write Energy for channel "
306 m_logstr <<
MYLEVEL <<
"In setNextEnergy-------------------->>>>> time = " << time <<
" quality=" << quality <<
endmsg;
314 ShortLong twoValues{};
317 twoValues.s[0]= energy;
324 uint16_t* valptr=
reinterpret_cast<uint16_t*
>(&oneValue);
325 twoValues.s[0]=valptr[0];
326 twoValues.s[1]=(uint16_t)energy;
329 LARBSDBG(
"Writing words: val0= " << twoValues.s[0] <<
" val1= " << twoValues.s[1]);
331 LARBSDBG(
"Writing Raw data to E block. E=" << energy);
337 if (mylocalBitwiseIndex==0)
340 SB = (quality==-32767?0x00000000:0x00000001);
347 SB=(SB<<1)|(quality==-32767?0x00000000:0x00000001);
354 if (mylocalBitwiseIndex==0)
362 encodedgains=(encodedgains<<2)|(gain&0x00000003);
376 ShortLong twoValues{};
377 if (mylocalBitwiseIndex==0)
381 twoValues.s[0]=(int16_t)(time)|((quality>>10)&0x003F);
387 int16_t* valptr=
reinterpret_cast<int16_t*
>(&oneValue);
388 twoValues.s[0]=valptr[0];
389 twoValues.s[1]=(int16_t)(time)|((quality>>12)&0x003F);
400 {
m_logstr << MSG::ERROR <<
"Attempt to write Energy for channel " << rcNb <<
" channels into a FEB!" <<
endmsg;
404 if(samples.size() != nsamples) {
405 m_logstr << MSG::ERROR <<
"Number of samples mismatch!\n";
406 m_logstr <<
" nsamples =" << nsamples;
414 if((nsamples/2)*2!=nsamples) {
416 for (
unsigned int i=1;i<nsamples;i+=2)
420 m_RawDataBlock.push_back((gain<<30) | (samples[1]<<18) | samples[0]<<2);
421 for (
unsigned int i=2;i<nsamples;i+=2)
432 unsigned int sizeRead=0;
434 while (sizeRead<fragment.size()) {
435 std::vector<uint32_t>::iterator FebIter;
436 FebIter=fragment.begin()+sizeRead;
440 if (FebIter+currFebSize>fragment.end()) {
442 m_logstr << MSG::ERROR <<
"Got inconsistent ROD-Fragment!" <<
endmsg;
445 m_mFebBlocks[currFEBid].assign(FebIter,FebIter+currFebSize);
447 LARBSDBG(
"Found FEB-id " << currFEBid <<
" in existing ROD-Fragment");
479 setNextEnergy((uint16_t)0,(int16_t)32767,(int32_t)-32767,(uint32_t)0);
482 uint16_t BlockOffset;
488 LARBSDBG(
"Checking for Summary Block n=" << n <<
"BlockOffset=" << BlockOffset);
489 if (n && !BlockOffset)
493 m_logstr << MSG::DEBUG <<
"In finalizeFEB-------------------->>>>> " <<
"Checking for Summary Block : length= " << n <<
" BlockOffset=" << BlockOffset <<
endmsg;
494 for (
unsigned i=0;i<n;i++)
501 ShortLong twoValues{};
516 uint32_t* aux = (uint32_t*)&
m_Ex;
518 aux = (uint32_t*)&
m_Ey;
527 aux = (uint32_t*)&
m_Ez;
533 LARBSDBG(
"Checking for Counter Block n=" << n <<
"BlockOffset=" << BlockOffset);
534 if (n && !BlockOffset)
538 m_logstr << MSG::INFO <<
"In finalyseFEB-------------------->>>>> " <<
"Checking for Counter Block : length= " << n <<
" BlockOffset=" << BlockOffset <<
endmsg;
539 for (
unsigned i=0;i<n;i++)
546 LARBSDBG(
"Checking Energy Block n=" << n <<
"BlockOffset=" << BlockOffset);
548 if (n && !BlockOffset)
552 m_logstr << MSG::DEBUG <<
"In finalyseFEB-------------------->>>>> " <<
"Checking for Energy Block : length= " << n <<
" BlockOffset=" << BlockOffset <<
endmsg;
553 for(
unsigned int i=0;i<n;i++)
560 LARBSDBG(
"Checking Gain Block n=" << n <<
"BlockOffset=" << BlockOffset);
562 if (n && !BlockOffset)
566 for(
unsigned int i=0;i<n;i++)
577 LARBSDBG(
"Checking FebInfo Block n=" << n <<
"BlockOffset=" << BlockOffset);
579 if (n && !BlockOffset)
583 for(
unsigned int i=0;i<n;i++)
590 LARBSDBG(
"Checking Time and Quality Block n=" << n <<
"BlockOffset=" << BlockOffset);
592 if (n && !BlockOffset)
596 m_logstr << MSG::DEBUG <<
"In finalyseFEB-------------------->>>>> " <<
"Checking for Time and Quality Block : length= " << n <<
" BlockOffset=" << BlockOffset <<
endmsg;
597 for(
unsigned int i=0;i<n;i++)
602 LARBSDBG(
"Checking Raw Data Block");
605 LARBSDBG(
"Checking Raw Data Block. n=" << n <<
"BlockOffset=" << BlockOffset);
610 for(
unsigned int i=0;i<n;i++)
615 m_logstr <<
MYLEVEL <<
"***********************************************************************"<<
endmsg;
618 m_logstr <<
MYLEVEL <<
"***********************************************************************"<<
endmsg;
621 m_logstr <<
MYLEVEL <<
"***********************************************************************"<<
endmsg;
631 FEBMAPTYPE::const_iterator feb_it_b=
m_mFebBlocks.begin();
633 FEBMAPTYPE::const_iterator feb_it;
634 for (feb_it=feb_it_b;feb_it!=feb_it_e;++feb_it) {
635 if (feb_it!=feb_it_b)
640 feb_it->second.begin(), feb_it->second.end());
649 LARBSDBG(
"in LArRodBlockPhysicsV3::getNextRawData.");
673 LARBSDBG(
"This run has " << nsamples <<
" samples");
678 gain=3-((
m_GainPtr[channelNumber/16] >> (channelNumber%16)*2) & 0x3);
680 for(
unsigned int i=0;i<nsamples;i++) {
686 samples.push_back((
short) (
x & 0xfff));
692 short movedSample=samples[0];
694 samples[i-1]=samples[i];
705template<
class RAWDATA>
706bool LArRodBlockPhysicsV3::operator ()
707 (
const RAWDATA* ch1,
const RAWDATA* ch2)
const
715 if(febId1 == febId2 ){
721 return febId1 < febId2 ;
728{
std::sort(vDigit.begin(),vDigit.end(),*
this);
#define LARBSDBG(text)
This class provides decoding/encoding from/to ROD format.
virtual void resetPointers()
virtual uint16_t getCtrl3(uint32_t adc) const
virtual void setOffTimeCut(uint16_t TimeCut)
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
uint16_t m_HottestCellIndex
const uint32_t * m_SumBlkPtr
const int16_t * m_RawDataPtr
virtual void concatinateFEBs()
const uint32_t * m_GainPtr
virtual uint32_t getNumberOfSamples() const
std::vector< uint32_t > m_EnergyBlock
virtual void setEz(double Ez)
static const uint32_t m_DummyBitMap[4]
std::vector< uint32_t > m_RawDataBlock
std::vector< uint32_t > m_CounterBlkBlock
std::vector< uint32_t > m_SumBlkBlock
virtual void setNextEnergy(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain)
virtual void setNumberOfSamples(const uint8_t n)
LArRodBlockPhysicsV3(IMessageSvc *msgSvc)
std::vector< uint32_t > m_TimeQualityBlock
virtual void initializeFragment(std::vector< uint32_t > &fragment)
virtual void setEy(double Ey)
virtual void initializeFEB(const uint32_t id)
std::vector< uint32_t > m_GainBlock
uint16_t m_EnergyThreshold
const int16_t * m_TimeQualityPtr
virtual void sortDataVector(std::vector< const LArRawChannel * > &)
const LArOnlineID * m_onlineHelper
virtual uint16_t getCtrl1(uint32_t adc) const
const uint16_t * m_CounterPtr
virtual uint32_t getNumberOfGains() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
const int16_t * m_FebInfoDataPtr
int FebToRodChannel(int ch) const
virtual uint16_t getCtrl2(uint32_t adc) const
const uint32_t * m_RawDataFlagsPtr
uint16_t m_numberHotCellOffTime
std::vector< uint32_t > m_FebInfoBlock
virtual bool setPointers()
virtual void setEThreshold(uint16_t thres)
virtual uint32_t getStatus() const
const uint16_t * m_EnergyPtr
uint32_t m_HottestCellEnergy
virtual void finalizeFEB()
virtual void setEx(double Ex)
virtual void setRawData(const int channel, const std::vector< short > &samples, const uint32_t gain)
virtual void setNumberOfGains(const uint8_t n)
unsigned int m_rearrangeFirstSample
int getBit(const uint32_t *const p, const unsigned chan) const
void setHeader32(const unsigned n, const uint32_t w)
uint16_t LE_getVectorHeader16(const unsigned n) const
void LE_setHeader16(const unsigned n, const uint16_t w)
uint32_t getHeader32(const unsigned n) const
const uint32_t * m_FebBlock
void setBit(uint32_t *const p, const unsigned chan)
std::vector< uint32_t > * m_pRODblock
unsigned short m_iHeadBlockSize
LArRodBlockStructure(IMessageSvc *msgSvc, const std::string &blockType)
std::vector< uint32_t > * m_vFragment
int32_t m_MiddleHeaderSize
uint16_t LE_getHeader16(const unsigned n) const
uint32_t getNumberOfWords() const
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.