| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

RawReadoutHeaderCnv Class Reference

#include <RawReadoutHeaderCnv.h>

Inheritance diagram for RawReadoutHeaderCnv:

[legend]
Collaboration diagram for RawReadoutHeaderCnv:
[legend]
List of all members.

Public Types

 INVALID_ADDRESS
 INVALID_OBJECT
 NO_MEMORY
 BAD_STORAGE_TYPE
 NO_SOURCE_OBJECT
 ICONVERSIONSVC_LAST_ERROR
 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
enum  Status

Public Member Functions

 RawReadoutHeaderCnv (long storageType, const CLID &clid, ISvcLocator *svc)
 RawReadoutHeaderCnv (ISvcLocator *&)
virtual ~RawReadoutHeaderCnv ()
virtual long repSvcType () const
virtual StatusCode initialize ()
virtual StatusCode finalize ()
void declareObject (const std::string &fullPath, const CLID &clid, const std::string &bank, long par=0)
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddr)
virtual StatusCode updateObj (IOpaqueAddress *, DataObject *)
virtual StatusCode createObj (IOpaqueAddress *, DataObject *&)
virtual StatusCode fillRepRefs (IOpaqueAddress *, DataObject *)
virtual StatusCode updateRep (IOpaqueAddress *, DataObject *)
virtual StatusCode updateRepRefs (IOpaqueAddress *, DataObject *)
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
virtual unsigned long addRef ()
virtual unsigned long release ()
virtual StatusCode setDataProvider (IDataProviderSvc *svc)
virtual IDataProviderSvcdataProvider () const
virtual StatusCode setConversionSvc (IConversionSvc *svc)
virtual IConversionSvcconversionSvc () const
virtual StatusCode setAddressCreator (IAddressCreator *creator)
virtual IAddressCreatoraddressCreator () const
virtual const CLIDobjType () const
virtual long i_repSvcType () const
virtual StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
StatusCode service (const std::string &name, T *&psvc, bool createIf=false) const
StatusCode service (const std::string &type, const std::string &name, T *&psvc) const

Static Public Member Functions

static const long storageType ()
static const CLIDclassID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 INVALID_ADDRESS
 INVALID_OBJECT
 NO_MEMORY
 BAD_STORAGE_TYPE
 NO_SOURCE_OBJECT
 ICONVERSIONSVC_LAST_ERROR

Protected Member Functions

ISvcLocatorserviceLocator () const
IMessageSvcmsgSvc () const
IMessageSvcmessageService () const
IDataManagerSvcdataManager () const

Private Member Functions

StatusCode findTriggerTime (DayaBay::RawEvent *event, TimeStamp &triggerTime)
Site::Site_t convertSite (unsigned int daqSiteId)
DetectorId::DetectorId_t convertDetector (unsigned int daqDetectorId)
int convertConnector (unsigned int daqChannelId)
int convertBoard (unsigned int daqSlotId)
DayaBay::Trigger::TriggerType_t convertTriggerType (DayaBay::LocalTriggerData *ltbData, const DayaBay::Detector *detector)
TimeStamp convertTriggerTime (DayaBay::LocalTriggerData *ltbData)
DayaBay::FeeGain::FeeGain_t convertAdcRange (unsigned int daqAdcRange)
StatusCode unpackEvent (DayaBay::RawEvent *event, DayaBay::Readout *readout)
StatusCode unpackLtbModule (DayaBay::RawModule *module, DayaBay::Readout *readout)
StatusCode unpackFeeModule (DayaBay::RawModule *module, DayaBay::ReadoutPmtCrate *readout)

Private Attributes

MsgStream m_log
IRawDataInputSvcm_inputSvc

Detailed Description

Definition at line 27 of file RawReadoutHeaderCnv.h.


Constructor & Destructor Documentation

RawReadoutHeaderCnv::RawReadoutHeaderCnv ( long  storageType,
const CLID clid,
ISvcLocator svc 
)

Definition at line 23 of file RawReadoutHeaderCnv.cc.

00024 : Converter(RAWDATA_StorageType, classID(), svc)
00025   , m_log(msgSvc(), "RawReadoutHeaderCnv")
00026 {
00027   m_log << MSG::DEBUG << "RawReadoutHeaderCnv(long, const CLID&, ISvcLocator*)" << endreq;
00028 }

RawReadoutHeaderCnv::RawReadoutHeaderCnv ( ISvcLocator *&   ) 

Definition at line 31 of file RawReadoutHeaderCnv.cc.

00032 : Converter(RAWDATA_StorageType, classID(), svc)
00033   , m_log(msgSvc(), "RawReadoutHeaderCnv")
00034 {
00035   m_log << MSG::DEBUG << "RawReadoutHeaderCnv(ISvcLocator*&)" << endreq;
00036 }

RawReadoutHeaderCnv::~RawReadoutHeaderCnv (  )  [virtual]

Definition at line 39 of file RawReadoutHeaderCnv.cc.

00040 {
00041   m_log << MSG::DEBUG << "~RawReadoutHeaderCnv()" << endreq;
00042 }


Member Function Documentation

virtual long RawReadoutHeaderCnv::repSvcType (  )  const [inline, virtual]

Implements Converter.

Definition at line 36 of file RawReadoutHeaderCnv.h.

00036                                    {
00037       return RAWDATA_StorageType;
00038    }

static const long RawReadoutHeaderCnv::storageType (  )  [inline, static]

Definition at line 40 of file RawReadoutHeaderCnv.h.

00040                                    {
00041       return RAWDATA_StorageType;
00042    }

static const CLID& RawReadoutHeaderCnv::classID (  )  [inline, static]

Definition at line 44 of file RawReadoutHeaderCnv.h.

00044                                    {
00045       return DayaBay::CLID_ReadoutHeader;
00046    }

StatusCode RawReadoutHeaderCnv::initialize (  )  [virtual]

Reimplemented from Converter.

Definition at line 46 of file RawReadoutHeaderCnv.cc.

00047 {
00048   m_log << MSG::DEBUG << "initialize()" << endreq;
00049 
00050   m_log << MSG::DEBUG << "  query the service RawDataInputSvc." << endreq;
00051   IService* svc = 0;
00052   StatusCode sc = serviceLocator()->getService("RawDataInputSvc", svc, true);
00053   if (sc.isFailure()) {
00054     m_log << MSG::ERROR << "RawDataInputSvc could not be retrieved" << endreq;
00055     return sc;
00056   }
00057   svc->addRef();
00058 
00059   sc = svc->queryInterface(IID_IRawDataInputSvc, (void**) & m_inputSvc);
00060   if (sc.isFailure()) {
00061     m_log << MSG::ERROR << "queryInterface(IID_IRawDataInputSvc) failed" << endreq;
00062     return StatusCode::FAILURE;
00063   }
00064 
00065   return StatusCode::SUCCESS;
00066 }

StatusCode RawReadoutHeaderCnv::finalize (  )  [virtual]

Reimplemented from Converter.

Definition at line 268 of file RawReadoutHeaderCnv.cc.

00269 {
00270   m_log << MSG::DEBUG << "finalize()" << endreq;
00271   return StatusCode::SUCCESS;
00272 }

void RawReadoutHeaderCnv::declareObject ( const std::string &  fullPath,
const CLID clid,
const std::string &  bank,
long  par = 0 
)

StatusCode RawReadoutHeaderCnv::createRep ( DataObject pObject,
IOpaqueAddress *&  refpAddr 
) [virtual]

Reimplemented from Converter.

Definition at line 250 of file RawReadoutHeaderCnv.cc.

00251 {
00252   m_log << MSG::DEBUG << "createRep()" << endreq;
00253 
00254   ReadoutHeader* rdth = dynamic_cast<ReadoutHeader*>(pObj);
00255   if (!rdth) {
00256     m_log << MSG::ERROR << "Could not downcast Event" << endreq;
00257     return StatusCode::FAILURE;
00258   }
00259 
00260   string nm = pObj->registry()->name();
00261   RawDataAddress* addr = new RawDataAddress(classID(), nm, "");
00262   pAddr = addr;
00263 
00264   return StatusCode::SUCCESS;
00265 }

StatusCode RawReadoutHeaderCnv::updateObj ( IOpaqueAddress ,
DataObject  
) [virtual]

Reimplemented from Converter.

Definition at line 70 of file RawReadoutHeaderCnv.cc.

00071 {
00072   m_log << MSG::DEBUG << "updateObj()" << endreq;
00073   return Converter::updateObj(pAddr, pObj);
00074 }

StatusCode RawReadoutHeaderCnv::createObj ( IOpaqueAddress ,
DataObject *&   
) [virtual]

Reimplemented from Converter.

Definition at line 78 of file RawReadoutHeaderCnv.cc.

00079 {
00080   m_log << MSG::DEBUG << "createObj(IOpaqueAddress*, DataObject*&)" << endreq;
00081 
00082   ReadoutHeader* readoutHeader = new ReadoutHeader();
00083   pObj = readoutHeader;
00084 
00085   DayaBay::Readout* readout = 0;
00086 
00087   if(m_inputSvc->m_inputSvcVersion==2) {
00088     DayaBay::RawEvent *event = m_inputSvc->currentRawEvent();
00089     if (event == NULL) {
00090       m_log << MSG::INFO << "The RawEvent returned is not valid." << endreq;
00091       return StatusCode::FAILURE;
00092     }
00093 
00094     // Find the trigger time
00095     TimeStamp triggerTime;
00096     StatusCode sc = this->findTriggerTime(event,triggerTime);
00097     if(!sc.isSuccess()){
00098       m_log << MSG::WARNING << "Failed to find trigger time for event: " << event->eventId()
00099         << endreq;
00100     }
00101 
00102     // Set the context
00103     Site::Site_t site = this->convertSite( event->siteId() );
00104     Context context(site,
00105         SimFlag::kData,
00106         triggerTime,
00107         (DetectorId::DetectorId_t)(event->detectorId()));
00108 
00109     readoutHeader->setContext(context);
00110     readoutHeader->setEarliest(triggerTime);
00111     readoutHeader->setLatest(triggerTime);
00112 
00113     // Construct the readout
00114     DayaBay::Detector detector(this->convertSite(event->siteId()),
00115         this->convertDetector(event->detectorId()));
00116 
00117     if( detector.isAD() || detector.isWaterShield() ){
00118       readout = new DayaBay::ReadoutPmtCrate();
00119     }else if( detector.detectorId() == DetectorId::kRPC){
00120       readout = new DayaBay::ReadoutRpcCrate();
00121     }else{
00122       m_log << MSG::ERROR << "Unknown detector: \"" << detector.detName() << "\","
00123         << " cannot make readout." << endreq;
00124       return StatusCode::FAILURE;
00125     }
00126 
00127     // Need to set detector for proper persistency
00128     readout->setDetector(detector);
00129 
00130     // Fill readout
00131     if(m_inputSvc->m_usePacked){
00132       // Packed data
00133       readout->setRawEvent( event->clone() );
00134     }
00135 
00136     if(m_inputSvc->m_useUnpacked){
00137       // Unpacked data
00138       sc = this->unpackEvent(event, readout);
00139       if( !sc.isSuccess() ){
00140         delete readout;
00141         return sc;
00142       }
00143     }
00144 
00145   }
00146 
00147   else {
00148     RawDataEvent* rawEvt = m_inputSvc->currentEvent();
00149     if (rawEvt == NULL) {
00150       m_log << MSG::INFO << "The RawDataEvent returned is not valid." << endreq;
00151       return StatusCode::FAILURE;
00152     }
00153 
00154     readoutHeader->setExecNumber(rawEvt->m_evtNum);
00155 
00156     readout = new DayaBay::ReadoutPmtCrate();
00157     ReadoutPmtCrate* readoutCrate = dynamic_cast<ReadoutPmtCrate*>(readout);
00159     readoutCrate->setDetector(Detector(rawEvt->siteId(), rawEvt->detectorId()));
00160     readoutCrate->setTriggerType(rawEvt->triggerType());
00161 
00162     //the following code is temporarily commented because readoutCrate doesn't have setRawEvent function
00163     //if( rawEvt->m_rawBuffer.size() > 0){
00164     //  readoutCrate->setRawEvent(
00165     //                     DayaBay::RawEvent( &rawEvt->m_rawBuffer[0] ).clone() );
00166     //}
00167 
00169     ReadoutPmtCrate::FadcReadouts fadcReadouts;
00170     for (unsigned int i = 0; i < rawEvt->m_modules.size(); i++) {
00171       switch (rawEvt->m_modules[i]->m_type) {
00172         case kRomLtb:
00173           RawDataEvent::RomLtb* romLtb;
00174           romLtb = dynamic_cast<RawDataEvent::RomLtb*>(rawEvt->m_modules[i]);
00176           for (unsigned int j = 0; j < romLtb->m_frames.size(); j++) {
00177             RawDataEvent::LtbFrame *ltbFrame = romLtb->m_frames[j];
00178             readoutCrate->setTriggerTime(ltbFrame->timeStamp());
00179             break;
00180           }
00181           break;
00182         case kRomFadc:
00183           RawDataEvent::RomFadc* romFadc;
00184           romFadc = dynamic_cast<RawDataEvent::RomFadc*>(rawEvt->m_modules[i]);
00186           for (unsigned int j = 0; j < romFadc->m_channels.size(); j++) {
00187             RawDataEvent::FadcChannel &channel = romFadc->m_channels[j];
00188             FadcChannelId channelId(channel.m_channel+1, rawEvt->siteId(), rawEvt->detectorId());
00189             DigitalSignal channelData=channel.m_adcData;
00190             fadcReadouts[channelId]=channelData;
00191           }
00192           break;
00193         case kRomFee:
00194           RawDataEvent::RomFee* romFee;
00195           romFee = dynamic_cast<RawDataEvent::RomFee*>(rawEvt->m_modules[i]);
00196           readoutCrate->setTriggerNumber(romFee->m_triggerNum);
00198           for (unsigned int j = 0; j < romFee->m_channels.size(); j++) {
00199             RawDataEvent::PmtChannel &channel = romFee->m_channels[j];
00200             // FeeChannelId(board, connector, site, det)
00201             // FEE board number in the DAQ counts from '1 to n', but the connector counts from '0 to n-1'
00202             FeeChannelId channelId(romFee->m_slot, channel.m_channel+1, rawEvt->siteId(), rawEvt->detectorId());
00203             ReadoutPmtChannel &channelData = readoutCrate->channel(channelId);
00204 
00205             channelData.setReadout(readoutCrate);
00206             channelData.setMode(0x1);  //peak finding
00207             channelData.setChannelId(channelId);
00208             channelData.setAdc(channel.m_adc);
00209             channelData.setAdcCycle(channel.m_adcPeakingCycle);
00211             vector<int> tmpGain;
00212             for ( unsigned int ci = 0; ci!=channel.m_adcRange.size(); ci++) {
00213               if ( channel.m_adcRange[ci] == dyb::kAdcHighRange ) {
00214                 tmpGain.push_back(  FeeGain::kLow );
00215               } else if ( channel.m_adcRange[ci] == dyb::kAdcLowRange ) {
00216                 tmpGain.push_back(  FeeGain::kHigh );
00217               }
00218             }
00219             channelData.setAdcRange( tmpGain );
00220             channelData.setTdc(channel.m_tdc);
00221             channelData.setTdcHitCount(channel.m_tdcHitCount);
00222             channelData.setPedestal(channel.m_pedestal);
00223 
00224             // insert into readout map
00225             //readoutChannels[channelId] = channelData;
00226           }
00227           break;
00228       }
00229     }
00230 
00231     //readoutCrate->setChannelReadout(readoutChannels);
00232     readoutCrate->setFadcReadout(fadcReadouts);
00233     Site::Site_t site = rawEvt->siteId();
00234     SimFlag::SimFlag_t flag = SimFlag::kData;
00235     DetectorId::DetectorId_t det = rawEvt->detectorId();
00236     const TimeStamp& time = readoutCrate->triggerTime();
00237 
00238     Context context = Context(site, flag, time, det);
00239     readoutHeader->setContext(context);
00240   }
00241 
00242   readout->setHeader(readoutHeader);
00243   readoutHeader->setReadout(readout);
00244  
00245   return StatusCode::SUCCESS;
00246 }

virtual StatusCode RawReadoutHeaderCnv::fillRepRefs ( IOpaqueAddress ,
DataObject  
) [inline, virtual]

Reimplemented from Converter.

Definition at line 61 of file RawReadoutHeaderCnv.h.

00061                                                                                          {
00062       return StatusCode::SUCCESS;
00063    }

virtual StatusCode RawReadoutHeaderCnv::updateRep ( IOpaqueAddress ,
DataObject  
) [inline, virtual]

Reimplemented from Converter.

Definition at line 64 of file RawReadoutHeaderCnv.h.

00064                                                                                            {
00065       return StatusCode::SUCCESS;
00066    }

virtual StatusCode RawReadoutHeaderCnv::updateRepRefs ( IOpaqueAddress ,
DataObject  
) [inline, virtual]

Reimplemented from Converter.

Definition at line 67 of file RawReadoutHeaderCnv.h.

00067                                                                                                {
00068       return StatusCode::SUCCESS;
00069    }

StatusCode RawReadoutHeaderCnv::findTriggerTime ( DayaBay::RawEvent event,
TimeStamp triggerTime 
) [private]

Definition at line 275 of file RawReadoutHeaderCnv.cc.

00277 {
00278   // Find the trigger time for this event
00279   if(!event){
00280     m_log << MSG::ERROR << "Cannot find time of invalid event" << endreq;
00281     return StatusCode::FAILURE;
00282   }
00283   // Search raw data block for trigger time
00284   bool foundTriggerTime = false;
00285   while( DayaBay::RawModule* module = event->nextModule() ){
00286     if( module->isLocalTriggerModule() ){
00287       while( DayaBay::DataFragment* fragment = module->nextDataFragment() ){
00288         if( fragment->isLocalTriggerData() ){
00289           DayaBay::LocalTriggerData* ltbData = 
00290             dynamic_cast<DayaBay::LocalTriggerData*>(fragment);
00291           if(!ltbData){
00292             m_log << MSG::ERROR << "Failed to access local trigger data fragment" << endreq;
00293             return StatusCode::FAILURE;
00294           }
00295           triggerTime = this->convertTriggerTime(ltbData);
00296           foundTriggerTime = true;
00297           break;
00298         }
00299         delete fragment;
00300       }
00301       if( foundTriggerTime ) break;
00302     }
00303     delete module;
00304   }
00305   event->resetModule();
00306   if(!foundTriggerTime)   return StatusCode::FAILURE;
00307   return StatusCode::SUCCESS;
00308 }

Site::Site_t RawReadoutHeaderCnv::convertSite ( unsigned int  daqSiteId  )  [private]

Definition at line 359 of file RawReadoutHeaderCnv.cc.

00360 {
00361   // Convert site definition from DAQ to Offline convention 
00362   switch(daqSiteId){
00363     case 1:
00364       return Site::kDayaBay;
00365     case 2:
00366       return Site::kLingAo;
00367     case 3:
00368       return Site::kFar;
00369     case 4:
00370       return Site::kMid;
00371     case 6:
00372       return Site::kSAB;
00373     default:
00374       break;
00375   }
00376   return Site::kUnknown;
00377 }

DetectorId::DetectorId_t RawReadoutHeaderCnv::convertDetector ( unsigned int  daqDetectorId  )  [private]

Definition at line 379 of file RawReadoutHeaderCnv.cc.

00381 {
00382   // Convert detector definition from DAQ to Offline convention 
00383   switch(daqDetectorId){
00384     case 1:
00385       return DetectorId::kAD1;
00386     case 2:
00387       return DetectorId::kAD2;
00388     case 3:
00389       return DetectorId::kAD3;
00390     case 4:
00391       return DetectorId::kAD4;
00392     case 5:
00393       return DetectorId::kIWS;
00394     case 6:
00395       return DetectorId::kOWS;
00396     case 7:
00397       return DetectorId::kRPC;
00398     default:
00399       break;
00400   }
00401   return DetectorId::kUnknown;
00402 }

int RawReadoutHeaderCnv::convertConnector ( unsigned int  daqChannelId  )  [private]

Definition at line 409 of file RawReadoutHeaderCnv.cc.

00410 {
00411   return daqChannelId+1;
00412 }

int RawReadoutHeaderCnv::convertBoard ( unsigned int  daqSlotId  )  [private]

Definition at line 404 of file RawReadoutHeaderCnv.cc.

00405 {
00406   return daqSlotId;
00407 }

DayaBay::Trigger::TriggerType_t RawReadoutHeaderCnv::convertTriggerType ( DayaBay::LocalTriggerData ltbData,
const DayaBay::Detector detector 
) [private]

Definition at line 414 of file RawReadoutHeaderCnv.cc.

00417 {
00418   // Convert Online trigger type to Offline convention
00419   unsigned int triggerType = DayaBay::Trigger::kUnknown;
00420   if(ltbData->isManualTrigger())
00421     triggerType |= DayaBay::Trigger::kManual;
00422   if(ltbData->isCrossTrigger())
00423     triggerType |= DayaBay::Trigger::kCross;
00424   if(ltbData->isPeriodicTrigger())
00425     triggerType |= DayaBay::Trigger::kPeriodic;
00426   if(ltbData->isMultiplicityTrigger())
00427     triggerType |= DayaBay::Trigger::kMult;
00428   // FIXME: Need to add all Esum trigger types to offline convention
00429   if(ltbData->isEsumAdcTrigger())
00430     triggerType |= DayaBay::Trigger::kESum;
00431   if(ltbData->isEsumCompHighTrigger())
00432     triggerType |= DayaBay::Trigger::kESum;
00433   if(ltbData->isEsumCompLowTrigger())
00434     triggerType |= DayaBay::Trigger::kESum;
00435   if(ltbData->isEsumCompAllTrigger())
00436     triggerType |= DayaBay::Trigger::kESum;
00437 
00438   switch(detector->detectorId()){
00439     case DetectorId::kAD1:
00440       triggerType |= DayaBay::Trigger::kAD1;
00441       break;
00442     case DetectorId::kAD2:
00443       triggerType |= DayaBay::Trigger::kAD2;
00444       break;
00445     case DetectorId::kAD3:
00446       triggerType |= DayaBay::Trigger::kAD3;
00447       break;
00448     case DetectorId::kAD4:
00449       triggerType |= DayaBay::Trigger::kAD4;
00450       break;
00451     case DetectorId::kIWS:
00452       triggerType |= DayaBay::Trigger::kIWS;
00453       break;
00454     case DetectorId::kOWS:
00455       triggerType |= DayaBay::Trigger::kOWS;
00456       break;
00457     default:
00458       break;
00459   }
00460 
00461   return static_cast<DayaBay::Trigger::TriggerType_t>(triggerType);
00462 }

TimeStamp RawReadoutHeaderCnv::convertTriggerTime ( DayaBay::LocalTriggerData ltbData  )  [private]

Definition at line 311 of file RawReadoutHeaderCnv.cc.

00312 {
00313   //Unpack Trigger time from raw LTB data block
00314   TimeStamp triggerTime;
00315   if(ltbData->isUnixTime()){
00316     triggerTime = TimeStamp(ltbData->unixtime(),
00317         ltbData->nanosecond()+ltbData->accumulation());
00318   }else if(ltbData->isUtcTime()){
00319     // This data format provides no 'year'
00320     // Estimate the year from the file start time
00321     if(  ltbData->days()  <  m_inputSvc->m_utcDay ){
00322       // Catch case where file spans new year
00323       m_inputSvc->m_fileYear++;
00324     }
00325     triggerTime = TimeStamp(m_inputSvc->m_fileYear,
00326         1 /*month*/,
00327         ltbData->days()+1 /*day in year*/,
00328         ltbData->hour(),
00329         ltbData->minute(),
00330         ltbData->second(),
00331         ltbData->nanosecond()+ltbData->accumulation(),
00332         true /*UTC*/);
00333     m_inputSvc->m_utcDay = ltbData->days();
00334   }else{
00335     // Date format from LTB Data version 0
00336     // The trigger times in m_inputSvc format have many issues; see DocDB-4635
00337     // Override using the file start time
00338     // Fix bug caused by 61s in a minute and 61m in an hour
00339     unsigned int seconds = ltbData->hour()*61*61 
00340       + ltbData->minute()*61 
00341       + ltbData->second();
00342     unsigned int hour = seconds / 3600;
00343     unsigned int minute = (seconds - hour*3600) / 60;
00344     unsigned int second = (seconds - (hour*3600 + minute*60));
00345     int timezoneOffset = -8*60*60; /* 8hr offset of PRC from UTC */
00346     triggerTime = TimeStamp(m_inputSvc->m_fileYear,  //ltbData->year(),
00347         m_inputSvc->m_fileMonth, //ltbData->month(),
00348         m_inputSvc->m_fileDay,   //ltbData->day(),
00349         hour,
00350         minute,
00351         second,
00352         (int)(ltbData->clock()*12.5) /* 80MHz clock */,
00353         true /*use UTC with timezone offset*/,
00354         timezoneOffset);
00355   }
00356   return triggerTime;
00357 }

DayaBay::FeeGain::FeeGain_t RawReadoutHeaderCnv::convertAdcRange ( unsigned int  daqAdcRange  )  [private]

Definition at line 464 of file RawReadoutHeaderCnv.cc.

00466 {
00467   // Convert ADC Range definition from DAQ to Offline convention 
00468   switch(daqAdcRange){
00469     case 0:
00470       return DayaBay::FeeGain::kHigh;
00471     case 1:
00472       return DayaBay::FeeGain::kLow;
00473     default:
00474       break;
00475   }
00476   return DayaBay::FeeGain::kUnknown;
00477 }

StatusCode RawReadoutHeaderCnv::unpackEvent ( DayaBay::RawEvent event,
DayaBay::Readout readout 
) [private]

Definition at line 480 of file RawReadoutHeaderCnv.cc.

00482 {
00483   // Unpack raw data into readout object
00484 
00485   // Loop over modules
00486   while( DayaBay::RawModule* module = event->nextModule() ){
00487     StatusCode sc;
00488     if( module->isLocalTriggerModule() ){
00489       sc = this->unpackLtbModule(module, readout);
00490     }else if( module->isPmtFeeModule() ){
00491       sc = this->unpackFeeModule(module, 
00492           dynamic_cast<DayaBay::ReadoutPmtCrate*>(readout));
00493     }else if( module->isFlashAdcModule() ){
00494       //sc = this->unpackFlashAdcModule(module, readout);
00495     }else if( module->isRpcRomModule() ){
00496       //sc = this->unpackRpcRomModule(module, readout);
00497     }else if( module->isRpcRtmModule() ){
00498       //sc = this->unpackRpcRomModule(module, readout);
00499     }else{
00500       m_log << MSG::WARNING << "Cannot unpack unknown module type: " 
00501         << module->moduleType()<< endreq;
00502       sc = StatusCode::FAILURE;
00503     }
00504     if( !sc.isSuccess() ){
00505       // Gracefully continue even if there is trouble reading a module
00506       continue;
00507     }
00508     delete module;
00509   }
00510 
00511   return StatusCode::SUCCESS;
00512 }

StatusCode RawReadoutHeaderCnv::unpackLtbModule ( DayaBay::RawModule module,
DayaBay::Readout readout 
) [private]

Definition at line 514 of file RawReadoutHeaderCnv.cc.

00516 {
00517   // Unpack the trigger data module
00518   bool firstTriggerFragment = true;
00519   TimeStamp triggerTime;
00520 
00521   while( DayaBay::DataFragment* fragment = module->nextDataFragment() ){
00522     if( fragment->isLocalTriggerData() ){
00523       // Process the trigger data fragment
00524       DayaBay::LocalTriggerData* ltbData = 
00525         dynamic_cast<DayaBay::LocalTriggerData*>(fragment);
00526       if(!ltbData){
00527         m_log << MSG::WARNING << "Bad Local Trigger Data fragment" << endreq;
00528         continue;
00529       }
00530       triggerTime = this->convertTriggerTime(ltbData);
00531       if(firstTriggerFragment){
00532         // Set trigger time, type, number according to first trigger data block
00533         readout->setTriggerTime( triggerTime );
00534         readout->setTriggerType(this->convertTriggerType(ltbData, 
00535               &(readout->detector())));
00536         // Get Trigger Number from head fragment
00537         DayaBay::HeadFragment* headFragment = module->headFragment();
00538         if( headFragment ){
00539           readout->setTriggerNumber( headFragment->triggerNumber() );
00540           delete headFragment;
00541         }else{
00542           m_log << MSG::WARNING << "Missing head fragment!" << endreq;
00543         }
00544         firstTriggerFragment = false;
00545       }else{
00546         if(triggerTime != readout->triggerTime()){
00547           TimeStamp dtTrigger( triggerTime );
00548           dtTrigger.Subtract( readout->triggerTime() );
00549           m_log << MSG::DEBUG << "Additional trigger at dT = " <<  dtTrigger.GetSeconds()
00550             << " [s]" << endreq;
00551         }
00552       }
00553     }else{
00554       m_log << MSG::WARNING << "Unknown LTB data fragment type: " << fragment->dataType() 
00555         << endreq;
00556     }
00557     delete fragment;
00558   }
00559   return StatusCode::SUCCESS;
00560 }

StatusCode RawReadoutHeaderCnv::unpackFeeModule ( DayaBay::RawModule module,
DayaBay::ReadoutPmtCrate readout 
) [private]

Definition at line 562 of file RawReadoutHeaderCnv.cc.

00564 {
00565   // Unpack the front-end electronics data module
00566   if(!readout){
00567     m_log << MSG::WARNING << "Trying to add FEE data to a non-PMT readout"
00568       << endreq;
00569     return StatusCode::FAILURE;
00570   }
00571 
00572   while( DayaBay::DataFragment* fragment = module->nextDataFragment() ){
00573     if( fragment->isFeePeakData() ){
00574       // Process the FEE peak-finding data fragment
00575       DayaBay::FeePeakData* feePeakData = 
00576         dynamic_cast<DayaBay::FeePeakData*>(fragment);
00577       if(!feePeakData){
00578         m_log << MSG::WARNING << "Bad FEE Peak-finding Data fragment" << endreq;
00579         continue;
00580       }
00581       // Add channel data to readout
00582       DayaBay::FeeChannelId channelId(
00583           this->convertBoard(module->slot()),
00584           this->convertConnector(feePeakData->channel()),
00585           readout->detector().site(),
00586           readout->detector().detectorId()); 
00587 
00588       DayaBay::ReadoutPmtChannel& feeChannel = readout->channel(channelId);
00589       if(feeChannel.channelId() != channelId){
00590         // New channel, initialize
00591         feeChannel.setChannelId(channelId);
00592         feeChannel.setMode(0x1); // Peak-finding
00593         feeChannel.setReadout(readout);
00594       }
00595       // Add hit data
00596       feeChannel.tdc().push_back( feePeakData->tdc() );
00597       feeChannel.tdcHitCount().push_back( feePeakData->tdcHitCount() );
00598       feeChannel.adc().push_back( feePeakData->adc() );
00599       feeChannel.adcRange().push_back( 
00600           this->convertAdcRange(feePeakData->adcRange()) );
00601       feeChannel.adcCycle().push_back( feePeakData->peakCycle() );
00602       if( feePeakData->hasAdcPedestal() )
00603         feeChannel.pedestal().push_back( feePeakData->adcPedestal() ); 
00604     }else{
00605       m_log << MSG::WARNING << "Unknown FEE data fragment type: " << fragment->dataType() 
00606         << endreq;
00607     }
00608     delete fragment;
00609   }
00610   return StatusCode::SUCCESS;
00611 }


Member Data Documentation

MsgStream RawReadoutHeaderCnv::m_log [mutable, private]

Definition at line 72 of file RawReadoutHeaderCnv.h.

IRawDataInputSvc* RawReadoutHeaderCnv::m_inputSvc [private]

Definition at line 74 of file RawReadoutHeaderCnv.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:27:05 2011 for RawDataIO by doxygen 1.4.7