RawTofConverter Class Reference

#include <RawTofConverter.h>

List of all members.

Public Member Functions

 RawTofConverter (RawRecord *rr)
 ~RawTofConverter ()
void Dump (std::ostream &)
const RawRopTdcRawDataBlockGetRawRopTdcDataBlock () const
int GetNumberOfRawTOFBlocks () const
RawTOFBlockAbandonRawTOFBlock (int n, const RawDigit &rd)
RawTOFBlockAbandonRawTOFBlock (int n, long *p)
int * GetPackedRawTOFBlock (int n, long *p)

Private Member Functions

int ConstructTofBlocks ()
void ReadDataWord (int input, int &v, int &un, int &ov, int &tdc)
bool ParityOK (int i) const

Private Attributes

const RawRecordfRR
const RawRopTdcRawDataBlockfTDC
int fNBlocks
std::vector< int * > fPackedRawTOFBlocks

Detailed Description

Definition at line 20 of file RawTofConverter.h.


Constructor & Destructor Documentation

RawTofConverter::RawTofConverter ( RawRecord rr  ) 

Definition at line 9 of file RawTofConverter.cxx.

References ConstructTofBlocks(), RawRecord::FindRawBlock(), fRR, and fTDC.

00010   :
00011   fRR(rr), fTDC(0), fNBlocks(0)
00012 {
00013   if(fRR!=0){
00014     fTDC = static_cast<const RawRopTdcRawDataBlock*>
00015       (fRR->FindRawBlock("RawRopTdcRawDataBlock"));    
00016   }
00017   if(fTDC) ConstructTofBlocks();
00018 }

RawTofConverter::~RawTofConverter (  ) 

Definition at line 20 of file RawTofConverter.cxx.

References fPackedRawTOFBlocks.

00021 {
00022   for(unsigned int blk=0; blk<fPackedRawTOFBlocks.size(); blk++)
00023     {
00024         delete [] fPackedRawTOFBlocks[blk];
00025     }
00026 }


Member Function Documentation

RawTOFBlock * RawTofConverter::AbandonRawTOFBlock ( int  n,
long *  p 
)

Definition at line 27 of file RawTofConverter.cxx.

References fNBlocks, fPackedRawTOFBlocks, and rdxsum_fill().

00028 {
00029 
00030   // if you have the original hit data, use this one
00031 
00032   RawTOFBlock* result = 0;
00033   if(n>=fNBlocks) return result;
00034 
00035   int* p = fPackedRawTOFBlocks[n];
00036   p[7] = *varcp;
00037   p[8] = *(varcp+1);
00038 
00039   // compute the checksum
00040   rdxsum_fill(reinterpret_cast<int32_t*>(p), 0);
00041 
00042   // its ready
00043   result = new RawTOFBlock(fPackedRawTOFBlocks[n]);
00044   return result;
00045 }

RawTOFBlock * RawTofConverter::AbandonRawTOFBlock ( int  n,
const RawDigit rd 
)

Definition at line 65 of file RawTofConverter.cxx.

References fNBlocks, fPackedRawTOFBlocks, RawDigit::GetADC(), RawDigit::GetChannel(), RawChannelId::GetEncoded(), RawDigit::GetTDC(), ParityOK(), and rdxsum_fill().

00066 {
00067   RawTOFBlock* result = 0;
00068   if(n>=fNBlocks) return result;
00069 
00070    int rcid_encoded= rd.GetChannel().GetEncoded();
00071    int adc = rd.GetADC();
00072    int tdc = rd.GetTDC();
00073   
00074 
00075   // fix up the raw digit part of the tdc readout
00076   // first to the channel+adc word
00077   // set initial bit
00078    int varc1 = 0x80000000;
00079   // assume fifo|calinject ok
00080   varc1|=0x20000000;
00081   // shift back rcid
00082   varc1|=(((rcid_encoded&0x00001fff)<<16)&0x1fff0000);
00083   // set mode to normal data taking
00084   varc1|=0x00008000;
00085   // pack in adc
00086   varc1|=(adc&0x00007fff);
00087   
00088   // now do the tdc part
00089    int varc2=0x0;
00090   varc2|=(tdc&0x3fffffff);
00091 
00092   // now recompute parities
00093   // assume they were originally correct
00094   // varc 1
00095   if(!ParityOK(varc1)) varc1|=0x40000000;
00096   // varc 2
00097   if(!ParityOK(varc2)) varc2|=0x40000000;
00098   
00099 
00100   // now add the varc stuff to the packed raw tof block
00101   int* p = fPackedRawTOFBlocks[n];
00102   p[7]=varc1;
00103   p[8]=varc2;
00104 
00105   // compute the checksum
00106   rdxsum_fill(reinterpret_cast<int32_t*>(p), 0);
00107 
00108   // its ready
00109   result = new RawTOFBlock(fPackedRawTOFBlocks[n]);
00110   return result;
00111   
00112 }

int RawTofConverter::ConstructTofBlocks (  )  [private]

pack the raw_tof_blk up ///

Definition at line 141 of file RawTofConverter.cxx.

References fNBlocks, fPackedRawTOFBlocks, fTDC, RawDataBlock::GetBlockId(), RawRopTdcRawDataBlock::GetCrateId(), RawBlockId::GetEncoded(), VldTimeStamp::GetNanoSec(), RawRopTdcRawDataBlock::GetNumberOfTdcReadoutBytes(), VldTimeStamp::GetSec(), RawRopTdcRawDataBlock::GetTdcData(), RawRopTdcRawDataBlock::GetTimeStamp(), and kMdBlockTofReadout.

Referenced by RawTofConverter().

00142 {
00143   
00144   // the strategy here is to decompose the Rop blocks
00145   // which contain tdc data from many events
00146   // into a collection of integer arrays (one for each tof event)
00147   // in the format that RawTofBlock(int*) expects
00148   // I do not immediately create RawTofBlocks because
00149   // they require knowledge of the fake hit generated in the
00150   // detector when we have a tof coincidence
00151   
00152   
00153   if(fTDC==0) return 0;
00154 
00155   //unused: const int orig_cksum = fTDC->GetChecksum();
00156   const int orig_blkid = fTDC->GetBlockId().GetEncoded();
00157   const int orig_crid = fTDC->GetCrateId();
00158   //unused: const int orig_tf = fTDC->GetTimeFrame();
00159   //unused: const int orig_run = fTDC->GetRun();
00160   //unused: const int orig_subrum = fTDC->GetSubRun();
00161   //unused: const int orig_runtype = fTDC->GetRunType();
00162   const VldTimeStamp orig_ts = fTDC->GetTimeStamp();
00163   const int orig_t0_0 = orig_ts.GetSec();
00164   const int orig_t0_1 = orig_ts.GetNanoSec();
00165   //  cout<<"orig_blkid="<<hex<<orig_blkid<<dec<<endl;
00166   // below I get the packed up tdc data
00167   // format:
00168   //
00169   // header
00170   // data words
00171   // trailer
00172   //
00173   // header
00174   // etc..
00175   const int orig_bytes = fTDC->GetNumberOfTdcReadoutBytes();
00176   const char* orig_cdata = fTDC->GetTdcData();
00177   const int orig_nints = orig_bytes/sizeof(unsigned long);
00178   //  const int* orig_idata = static_cast<int*>(orig_cdata);
00179   //  const unsigned long* orig_idata = reinterpret_cast<const unsigned long*>(orig_cdata);
00180   const int* orig_idata = reinterpret_cast<const int*>(orig_cdata);
00181 
00182   // loop through raw tdc data
00183   //  const unsigned long* iptr = orig_idata;
00184   const int* iptr = orig_idata;
00185   
00186   //  unsigned long* raw_tof_blk = 0;
00187   int* raw_tof_blk = 0;
00188   while (iptr<(orig_idata+orig_nints))
00189     {
00190       // on header word
00191       //      const unsigned long* const  hptr = iptr;
00192       const int* const  hptr = iptr;
00193       
00194       // see CAEN v775 manual, p 36-37
00195       //      const unsigned long nchanmask = 0x3f00;
00196       const int nchanmask = 0x3f00;
00197       const int nchan = ((*iptr)&nchanmask)>>8;
00198       //      const unsigned long* const dptr = hptr+1;
00199       const int* const dptr = hptr+1;
00200       //      const unsigned long* const tptr = dptr+nchan;
00201       const int* const tptr = dptr+nchan;
00202       //  cout<<"nchan="<<nchan<<endl;
00203       // create the TofBlock data array
00204 
00205       // tof_blk_hdr_words: 7 words
00206       // one word each for:
00207       // nbytes in block
00208       // chksum
00209       // block id
00210       // crate id
00211       // # tof hits
00212       // t0 first word
00213       // t0 second word
00214       const int tof_blk_hdr_words = 9;
00215 
00216       // tof_blk_tdc_words:
00217       // one word each for:
00218       // header
00219       // trailer
00220       // number of channels read out
00221       const int tof_blk_tdc_words = 2 + nchan;
00222 
00223       // tof_blk_trl_words:
00224       // one word each for:
00225       // tof block trailer
00226       const int tof_blk_trl_words = 1;
00227 
00228       const int tof_blk_words = tof_blk_hdr_words
00229         + tof_blk_tdc_words
00230         + tof_blk_trl_words;
00231       //cout<<"tof_blk_words="<<tof_blk_words<<endl;
00232       //      raw_tof_blk = new unsigned long[tof_blk_words];
00233       //      if(raw_tof_blk==0){
00234         raw_tof_blk = new int[tof_blk_words];
00235 
00236         //      }
00237 
00238       // increment the number of tof blocks counter
00239 
00240       fNBlocks++;
00241       
00242       
00244 
00245       // set number of words
00246       //      raw_tof_blk[0] = tof_blk_words*sizeof(unsigned long);
00247       // isn't the first word in the block?
00248       // i guess not
00249       raw_tof_blk[0] = tof_blk_words-1;
00250       // do not compute checksum yet
00251       // this has to wait for the association with
00252       // the fake hit that the tof system generates
00253       raw_tof_blk[1] = 0;
00254       // set block id to TofReadout block id
00255       // from mdBlockDefinitions.h
00256       int newblkid = orig_blkid;
00257       newblkid&=0xfff000ff;
00258       //      newblkid|=0x00010400;
00259       newblkid|=((kMdBlockTofReadout<<8)&0x000fff00);
00260       raw_tof_blk[2] = newblkid;
00261 
00262       // set the crate id
00263 
00264       raw_tof_blk[3] = orig_crid;
00265       
00266       //      cout<<hex<<orig_crid<<endl;
00267       // set the number of tof hits
00268       // i assume a maximum of 1 tof hit per event
00269       // i may need to revisit this assumption
00270       raw_tof_blk[4] = 1;
00271       // set t0
00272       // for now copy from the RawRopTdcRawDataBlock
00273       // perhaps when I associate this tdc data with an event
00274       // this should change to reflect t0 from that event
00275       raw_tof_blk[5] = orig_t0_0;
00276       raw_tof_blk[6] = orig_t0_1;
00277       // set the varc readout
00278       // this must wait for the association of
00279       // this tdc data with the fake hit produced
00280       // by the tof system
00281       raw_tof_blk[7] = 0;
00282       raw_tof_blk[8] = 0;
00283 
00284       // set the tdc data
00285       // set the header
00286       raw_tof_blk[9] = *hptr;
00287       // if we have data then nchan>0 and we enter this loop
00288       // otherwise we just got a header and a trailer
00289       //cout<<"one event: "<<endl;
00290 
00291       for(int tdc_data_idx = 0; tdc_data_idx<nchan; tdc_data_idx++)
00292         {         
00293           //int v=0; int un=0; int ov=0; int tdc = 0;
00294           //ReadDataWord(*(dptr+tdc_data_idx), v, un, ov, tdc);
00295           //cout<<"v="<<v<<", un="<<un<<", ov="<<ov<<", tdc="<<tdc<<endl;
00296           raw_tof_blk[10+tdc_data_idx]=*(dptr+tdc_data_idx);
00297         }
00298 
00299       // on trailer word
00300 
00301       raw_tof_blk[10+nchan] = *tptr;
00302       //      int* testarray = new int[13];
00303       // increment iptr
00304       // header+trailer+nchannels
00305 
00306       iptr+=(2+nchan);
00307 
00308       // add raw_tof_blk to the vector
00309             fPackedRawTOFBlocks.push_back(raw_tof_blk);
00310 
00311     }
00312   return fNBlocks;
00313 }

void RawTofConverter::Dump ( std::ostream &  os  ) 

Definition at line 316 of file RawTofConverter.cxx.

References RawTOFBlock::FormatToOStream(), and fPackedRawTOFBlocks.

00317 {
00318 
00319   os<<"Dumping the contents of RawTofConverter:"<<std::endl;
00320   for(unsigned int blk = 0; blk<fPackedRawTOFBlocks.size(); blk++)
00321     {
00322       RawTOFBlock rtb(fPackedRawTOFBlocks[blk]);
00323       rtb.FormatToOStream(os,"");
00324     }
00325 }

int RawTofConverter::GetNumberOfRawTOFBlocks (  )  const [inline]

Definition at line 27 of file RawTofConverter.h.

References fNBlocks.

Referenced by OltNewModule::SuckVaCrate().

00027 {return fNBlocks;}

int * RawTofConverter::GetPackedRawTOFBlock ( int  n,
long *  p 
)

Definition at line 47 of file RawTofConverter.cxx.

References fNBlocks, fPackedRawTOFBlocks, and rdxsum_fill().

Referenced by OltNewModule::SuckVaCrate().

00048 {
00049 
00050   int* result = 0;
00051   if(n>=fNBlocks) return result;
00052 
00053   int* p = fPackedRawTOFBlocks[n];
00054   p[7] = *varcp;
00055   p[8] = *(varcp+1);
00056 
00057   // compute the checksum
00058   rdxsum_fill(reinterpret_cast<int32_t*>(p), 0);
00059 
00060   result = p;
00061   // its ready
00062   return result;
00063 }

const RawRopTdcRawDataBlock* RawTofConverter::GetRawRopTdcDataBlock (  )  const [inline]

Definition at line 26 of file RawTofConverter.h.

References fTDC.

00026 {return fTDC;}

bool RawTofConverter::ParityOK ( int  i  )  const [private]

Definition at line 114 of file RawTofConverter.cxx.

Referenced by AbandonRawTOFBlock().

00115 {
00116    int sum = 0;
00117   for(int j=0; j<32; j++){
00118     sum+=(i&1);
00119     i=i>>1;
00120   }
00121   if(sum%2==0) return true;
00122   else return false;
00123 }

void RawTofConverter::ReadDataWord ( int  input,
int &  v,
int &  un,
int &  ov,
int &  tdc 
) [private]

Definition at line 125 of file RawTofConverter.cxx.

00126 {
00127 
00128   // see CAEN V775 manual, page 36
00129   const int vmask = 0x4000;
00130   const int unmask = 0x2000;
00131   const int ovmask = 0x1000;
00132   const int tdcmask = 0xfff;
00133   v = (input&vmask)>>14;
00134   un = (input&unmask)>>13;
00135   ov = (input&ovmask)>>12;
00136   tdc = input&tdcmask;
00137 
00138 }


Member Data Documentation

std::vector<int*> RawTofConverter::fPackedRawTOFBlocks [private]
const RawRecord* RawTofConverter::fRR [private]

Definition at line 35 of file RawTofConverter.h.

Referenced by RawTofConverter().

Definition at line 36 of file RawTofConverter.h.

Referenced by ConstructTofBlocks(), GetRawRopTdcDataBlock(), and RawTofConverter().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1