void CVolumeOutMaster::OnControlChanged( DWORD dwControlID ) { if ( m_dwVolumeControlID == dwControlID ) { DWORD dwVolume = GetCurrentVolume(); if ( (dwVolume!=BAD_DWORD) && (m_pfUserSink) ) { (*m_pfUserSink)( dwVolume, m_dwUserValue ); } } }
TGeoVolume* KVGeoNavigator::GetCurrentDetectorNameAndVolume(KVString& detector_name, Bool_t& multilayer) { // Returns the name of the current detector (if we are inside a detector) // and whether it is a multilayer or simple detector. // Returns 0x0 if we are not inside a detector volume. // // N.B. the returned volume corresponds to the *whole* detector (even if it has several layers). // For a multilayer detector, GetCurrentVolume() returns the volume for the current layer. // // See ExtractDetectorNameFromPath(KVString&) for details on detector name formatting. // Info("GetCurrentDetectorNameAndVolume","now i am in %s on node %s with path %s and matrix:", // fCurrentVolume->GetName(),fCurrentNode->GetName(),fCurrentPath.Data()); // fCurrentMatrix.Print(); multilayer = kFALSE; fCurrentDetectorNode = 0; TString volNom = GetCurrentVolume()->GetName(); TGeoVolume* detector_volume = 0; if (volNom.BeginsWith("DET_")) { // simple detector fCurrentDetectorNode = GetCurrentNode(); detector_volume = GetCurrentVolume(); } else { // have we hit 1 layer of a multilayer detector? TGeoVolume* mother_vol = GetCurrentNode()->GetMotherVolume(); if (mother_vol) { TString mom = mother_vol->GetName(); if (mom.BeginsWith("DET_")) { // it *is* a multilayer detector (youpi! :-) if (fMotherNode) { // this is the node corresponding to the whole detector, fCurrentDetectorNode = fMotherNode; detector_volume = mother_vol; multilayer = kTRUE; } } } } if (detector_volume) ExtractDetectorNameFromPath(detector_name); return detector_volume; }
void CVolumeOutMaster::timerEvent(QTimerEvent *evt) { Q_UNUSED(evt); int newVolume = (int)(GetCurrentVolume() * 100 /65535); if(m_currVolume != newVolume) { m_currVolume = newVolume; emit volumeChangedExternaly(newVolume); } bool newMuteState = isMute(); if(m_isMute != newMuteState) { m_isMute = newMuteState; emit muteStateChangedExternaly(newMuteState); } //qDebug() << "Timer ID:" << evt->timerId(); }
void KVGeoNavigator::PropagateParticle(KVNucleus* part, TVector3* TheOrigin) { // Propagate a particle through the geometry in the direction of its momentum, // until we reach the boundary of the geometry, or until fStopPropagation is set to kFALSE. // Propagation will also stop if we encounter a volume whose name begins with "DEADZONE" // Define point of origin of particles if (TheOrigin) fGeometry->SetCurrentPoint(TheOrigin->X(), TheOrigin->Y(), TheOrigin->Z()); else fGeometry->SetCurrentPoint(0., 0., 0.); // unit vector in direction of particle's momentum TVector3 v = part->GetMomentum().Unit(); // use particle's momentum direction fGeometry->SetCurrentDirection(v.x(), v.y(), v.z()); fGeometry->FindNode(); fCurrentVolume = fGeometry->GetCurrentVolume(); fCurrentNode = fGeometry->GetCurrentNode(); fMotherNode = fGeometry->GetMother(); fCurrentMatrix = *(fGeometry->GetCurrentMatrix()); fCurrentPath = fGeometry->GetPath(); // move along trajectory until we hit a new volume fGeometry->FindNextBoundaryAndStep(); fStepSize = fGeometry->GetStep(); TGeoVolume* newVol = fGeometry->GetCurrentVolume(); TGeoNode* newNod = fGeometry->GetCurrentNode(); TGeoNode* newMom = fGeometry->GetMother(); TGeoHMatrix* newMatx = fGeometry->GetCurrentMatrix(); TString newPath = fGeometry->GetPath(); Double_t XX, YY, ZZ; XX = YY = ZZ = 0.; // reset user flag for stopping propagation of particle SetStopPropagation(kFALSE); // Info("PropagateParticle","Beginning: i am in %s on node %s with path %s, and matrix:", // fCurrentVolume->GetName(),fCurrentNode->GetName(),fCurrentPath.Data()); // fCurrentMatrix.Print(); // track particle until we leave the geometry or until fStopPropagation // becomes kTRUE while (!fGeometry->IsOutside()) { const Double_t* posi = fGeometry->GetCurrentPoint(); fEntryPoint.SetXYZ(XX, YY, ZZ); XX = posi[0]; YY = posi[1]; ZZ = posi[2]; fExitPoint.SetXYZ(XX, YY, ZZ); TString vn = GetCurrentVolume()->GetName(); if (vn.BeginsWith("DEADZONE")) { part->GetParameters()->SetValue("DEADZONE", Form("%s/%s", GetCurrentVolume()->GetName(), GetCurrentNode()->GetName())); break; } // Info("PropagateParticle","just before ParticleEntersNewVolume\nnow i am in %s on node %s with path %s and matrix:", // fCurrentVolume->GetName(),fCurrentNode->GetName(),fCurrentPath.Data()); // fCurrentMatrix.Print(); ParticleEntersNewVolume(part); if (StopPropagation()) break; fCurrentVolume = newVol; fCurrentNode = newNod; fMotherNode = newMom; fCurrentMatrix = *newMatx; fCurrentPath = newPath; // Info("PropagateParticle","after ParticleEntersNewVolume\nnow i am in %s on node %s with path %s and matrix:", // fCurrentVolume->GetName(),fCurrentNode->GetName(),fCurrentPath.Data()); // fCurrentMatrix.Print(); // move on to next volume crossed by trajectory fGeometry->FindNextBoundaryAndStep(); fStepSize = fGeometry->GetStep(); newVol = fGeometry->GetCurrentVolume(); newNod = fGeometry->GetCurrentNode(); newMom = fGeometry->GetMother(); newMatx = fGeometry->GetCurrentMatrix(); newPath = fGeometry->GetPath(); } }
/// <summary> /// Authenticates cartridge by verifying its certificate and its signature of a random token. /// </summary> /// <param name="ucCartridgeNum">The cartridge number.</param> /// <param name="aucPubKS">Stratasys public key.</param> /// <param name="aucIdd">The tag identification data (output parameter).</param> /// <param name="usIddLength">The tag identification data length (output parameter).</param> /// <param name="uiCurrentVolume">The tag current volume (output parameter).</param> /// <returns>0 on success, non-zero for failures.</returns> int MaterialMonitor::AuthenticateCartridge(unsigned char ucCartridgeNum, const unsigned char *aucPubKS, unsigned char *aucIdd, unsigned short *usIddLength, unsigned int *uiCurrentVolume) { UniqueLock uniqueLock(m_mtx); int returnValue = IDTLIB_SUCCESS; if (aucPubKS == NULL && m_pubKS == NULL) { returnValue = INVALID_HOST_KEY; LOG_EXT(LEVEL_ERROR, "Invalid host key (error code 0x" << hex << (short)returnValue << ")."); return returnValue; } if (aucIdd == NULL || usIddLength == NULL || uiCurrentVolume == NULL) { returnValue = AUTHENTICATE_NULL_PARAMS; LOG_EXT(LEVEL_ERROR, "Invalid parameters (error code 0x" << hex << (short)returnValue << ")."); return returnValue; } if (!m_bInitialized) { returnValue = HW_NOT_INITIALIZED; LOG_EXT(LEVEL_ERROR, "Hardware not initialized (error code 0x" << hex << (short)returnValue << ")."); return returnValue; } try { LOG_EXT(LEVEL_INFO, "Cartridge #" << (unsigned short)ucCartridgeNum << " authentication started:"); LOG_EXT(LEVEL_INFO, "Reset cartridge #"<< (unsigned short)ucCartridgeNum << " info..."); int returnValue = ResetCartridgeInfo(ucCartridgeNum); if (returnValue != IDTLIB_SUCCESS) { LOG_EXT(LEVEL_ERROR, "Error resetting cartridge #"<< (unsigned short)ucCartridgeNum << " info (number of cartridges: " << (unsigned short)m_ucCartridgesCount << ", error code 0x" << hex << (short)returnValue << ")."); return returnValue; } LOG_EXT(LEVEL_INFO, "Switching to cartridge #"<< (unsigned short)ucCartridgeNum << "..."); returnValue = m_tagAdapter->SwitchToCartridge(ucCartridgeNum); if (returnValue != IDTLIB_SUCCESS) { LOG_EXT(LEVEL_ERROR, "Error switching to cartridge #"<< (unsigned short)ucCartridgeNum << " (number of cartridges: " << (unsigned short)m_ucCartridgesCount << ", error code 0x" << hex << (short)returnValue << ")."); return returnValue; } LOG_EXT(LEVEL_INFO, "Reading ID certificate..."); unsigned char aucBuffer[CERTIFICATE_SIZE]; memset(aucBuffer, 0, sizeof(aucBuffer)); returnValue = ReadIDCertificate(aucBuffer); if (returnValue != IDTLIB_SUCCESS) { LOG_EXT(LEVEL_ERROR, "Error reading ID certificate (error code 0x" << hex << (short)returnValue << ")."); return returnValue; } bool isEmpty = m_tagAdapter->IsCertificateEmpty(aucBuffer); if (isEmpty) { returnValue = EMPTY_CERTIFICATE_FILE; LOG_EXT(LEVEL_ERROR, "Tag is blank (error code 0x" << hex << (short)returnValue << ")."); return returnValue; } LOG_EXT(LEVEL_DEBUG, "Extracting cartridge #" << (unsigned short)ucCartridgeNum << " public key..."); IDCertificate *certificate = new IDCertificate(); unsigned short certificateSize; try { certificateSize = (unsigned short)certificate->Decode(aucBuffer); } catch (exception& e) { delete certificate; returnValue = INVALID_CERTIFICATE_FILE; LOG_EXT(LEVEL_ERROR, "Invalid certificate (error code 0x" << hex << (short)returnValue << "): " << e.what() << "."); return returnValue; } *usIddLength = certificateSize - SIGNATURE_SIZE - PUBLIC_KEY_SIZE; memcpy(aucIdd, aucBuffer, *usIddLength); ECDSA<EC2N, SHA256>::PublicKey* pubKS; if (aucPubKS != NULL) { pubKS = LoadPublicKey(aucPubKS); if (pubKS == NULL) { delete certificate; return INVALID_HOST_KEY; } } else { pubKS = m_pubKS; } LOG_EXT(LEVEL_INFO, "Verifying ID certificate..."); SetVerifier(pubKS); pthread_t verifierThread; VerifyParameters* verifyParameters = CreateVerifyParameters( m_veriferS, aucBuffer, certificateSize - SIGNATURE_SIZE, aucBuffer + (certificateSize - SIGNATURE_SIZE), SIGNATURE_SIZE); CreateVerifierThread(&verifierThread, verifyParameters); LOG_EXT(LEVEL_INFO, "Sending random token for IDT to sign..."); byte aucHostChallenge[TOKEN_SIZE]; GenerateToken(aucHostChallenge, TOKEN_SIZE); byte aucDeviceChallenge[64]; // expected device challenge length byte aucSignedDeviceChallenge[SIGNATURE_SIZE]; unsigned short usDeviceChallengeLength = sizeof(aucDeviceChallenge); unsigned short usSignedDeviceChallengeLength = sizeof(aucSignedDeviceChallenge); returnValue = ChallengeHostDevice(ucCartridgeNum, aucHostChallenge, TOKEN_SIZE, aucDeviceChallenge, &usDeviceChallengeLength, aucSignedDeviceChallenge, &usSignedDeviceChallengeLength); void* status; pthread_join(verifierThread, &status); delete verifyParameters; if (!m_bVerified) { returnValue = INVALID_CERTIFICATE_SIGNATURE; LOG_EXT(LEVEL_ERROR, "Error verifying ID certificate (error code 0x" << hex << (short)returnValue << ")."); delete certificate; return returnValue; } if (returnValue != IDTLIB_SUCCESS) { LOG_EXT(LEVEL_ERROR, "Error sending random token to IDT (error code 0x" << hex << (short)returnValue << ")."); delete certificate; return returnValue; } LOG_EXT(LEVEL_INFO, "Verifying IDT signature..."); verifyParameters = CreateVerifyParameters( certificate->IDD.GetVerifier(), aucDeviceChallenge, usDeviceChallengeLength, aucSignedDeviceChallenge, usSignedDeviceChallengeLength); CreateVerifierThread(&verifierThread, verifyParameters); LOG_EXT(LEVEL_INFO, "Getting current volume..."); returnValue = GetCurrentVolume(ucCartridgeNum, uiCurrentVolume); pthread_join(verifierThread, &status); delete verifyParameters; if (!m_bVerified) { returnValue = INVALID_TOKEN_SIGNATURE; LOG_EXT(LEVEL_ERROR, "Invalid signature (error code 0x" << hex << (short)returnValue << ")."); delete certificate; return returnValue; } if (returnValue != IDTLIB_SUCCESS) { LOG_EXT(LEVEL_ERROR, "Error getting current volume (error code 0x" << hex << (short)returnValue << ")."); delete certificate; return returnValue; } m_certificates[ucCartridgeNum] = certificate; LOG_EXT(LEVEL_INFO, "Cartridge #" << (unsigned short)ucCartridgeNum << " authentication ended successfully. Current weight: " << *uiCurrentVolume << " milligrams."); return returnValue; } catch (exception& e) { LOG_EXT(LEVEL_ERROR, "Exception caught: " << e.what() << "."); return EXCEPTION_CAUGHT; } }
void KVVAMOSReconGeoNavigator::ParticleEntersNewVolume(KVNucleus* nuc) { // Overrides method in KVGeoNavigator base class. // Every time a particle enters a new volume, we check the material to see // if it is known (i.e. contained in the range table fRangeTable). // If so, then we calculate the step through the material (STEP) of the nucleus // and the distance (DPATH in cm) between the intersection point at the focal plane // and the point at the entrance of the volume if it is the first active volume of a detector. // DPATH has the sign + if the volume is behind the focal plane or - if it // is at the front of it. // KVVAMOSReconNuc* rnuc = (KVVAMOSReconNuc*)nuc; // stop the propagation if the current volume is the stopping detector // of the nucleus but after the process of this volume if (rnuc->GetStoppingDetector()) { TGeoVolume* stopVol = (TGeoVolume*)((KVVAMOSDetector*)rnuc->GetStoppingDetector())->GetActiveVolumes()->Last(); if (GetCurrentVolume() == stopVol) SetStopPropagation(); } if (fDoNothing) return; TGeoMaterial* material = GetCurrentVolume()->GetMaterial(); KVIonRangeTableMaterial* irmat = 0; // skip the process if the current material is unkown if ((irmat = fRangeTable->GetMaterial(material))) { KVString dname; Bool_t multi; TString absorber_name; Bool_t is_active = kFALSE; if (GetCurrentDetectorNameAndVolume(dname, multi)) { is_active = kTRUE; if (multi) { absorber_name.Form("%s/%s", dname.Data(), GetCurrentNode()->GetName()); is_active = absorber_name.Contains("ACTIVE_"); } else absorber_name = dname; } else absorber_name = irmat->GetName(); // Coordinates of the vector between the intersection point at the // focal plane and the point at the entrance of the current detector Double_t X = GetEntryPoint().X() - fOrigine.X(); Double_t Y = GetEntryPoint().Y() - fOrigine.Y(); Double_t Z = GetEntryPoint().Z() - fOrigine.Z(); // Norm of this vector. The signe gives an infomation about the detector position // (1: behind; -1: in front of) with respect to the focal plane. Double_t Delta = TMath::Sign(1., Z) * TMath::Sqrt(X * X + Y * Y + Z * Z); if ((fCalib & kECalib) || (fCalib & kTCalib)) { if (fE > 1e-3) { // velocity before material Double_t Vi = nuc->GetVelocity().Mag(); // energy lost in the material Double_t DE = irmat->GetLinearDeltaEOfIon( nuc->GetZ(), nuc->GetA(), fE, GetStepSize(), 0., material->GetTemperature(), material->GetPressure()); fE -= DE; nuc->SetEnergy(fE); //set flag to say that particle has been slowed down nuc->SetIsDetected(); // velocity after material Double_t Vf = nuc->GetVelocity().Mag(); if (fCalib & kTCalib) { //from current start point to the entrance point fTOF += (Delta - fStartPath) / Vi; fStartPath = Delta; //nuc->GetParameters()->SetValue(Form("TOF:%s",absorber_name.Data()), fTOF); if (is_active) nuc->GetParameters()->SetValue(Form("TOF:%s", dname.Data()), fTOF); else if ((fCalib & kFullTCalib) == kFullTCalib) nuc->GetParameters()->SetValue(Form("TOF:%s", absorber_name.Data()), fTOF); // from the entrance to the exit of the material Double_t step = GetStepSize(); fTOF += CalculateLinearDeltaT(Vi, Vf, step); fStartPath += step; } if (fCalib & kECalib) { if (is_active) nuc->GetParameters()->SetValue(Form("DE:%s", dname.Data()), DE); else if ((fCalib & kFullECalib) == kFullECalib) nuc->GetParameters()->SetValue(Form("DE:%s", absorber_name.Data()), DE); } } } if (is_active) nuc->GetParameters()->SetValue(Form("DPATH:%s", dname.Data()), Delta); else if ((fCalib & kFullTCalib) == kFullTCalib) nuc->GetParameters()->SetValue(Form("DPATH:%s", absorber_name.Data()), Delta); nuc->GetParameters()->SetValue(Form("STEP:%s", absorber_name.Data()), GetStepSize()); } }
KVDetector* KVGeoImport::GetCurrentDetector() { // Returns pointer to KVDetector corresponding to current location // in geometry. Detector is created and added to array if needed. // We also set up any geometry structure elements (from nodes beginning with "STRUCT_") KVString detector_name; Bool_t multilay; TGeoVolume* detector_volume = GetCurrentDetectorNameAndVolume(detector_name,multilay); // failed to identify current volume as part of a detector if(!detector_volume) return 0; // has detector already been built ? if not, do it now KVDetector* det = fArray->GetDetector(detector_name); if(!fCreateArray){ if(det){ // set matrix & shape for entrance window if not done yet if(!det->GetEntranceWindowMatrix()){ det->SetEntranceWindowMatrix(GetCurrentMatrix()); det->SetEntranceWindowShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } TString vol_name(GetCurrentVolume()->GetName()); if(!multilay || vol_name.BeginsWith("ACTIVE_")){ // set matrix & shape for active layer det->SetActiveLayerMatrix(GetCurrentMatrix()); det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } } } else { if(!det) { det = BuildDetector(detector_name, detector_volume); if(det) { // Setting the entrance window shape and matrix // ============================================ // for consistency, the matrix and shape MUST correspond // i.e. we cannot have the matrix corresponding to the entrance window // of a multilayer detector and the shape corresponding to the // whole detector (all layers) - otherwise, calculation of points // on detector entrance window will be false! // Info("GetCurrentDetector","Setting EW matrix to current matrix:"); // GetCurrentMatrix()->Print(); det->SetEntranceWindowMatrix(GetCurrentMatrix()); det->SetEntranceWindowShape((TGeoBBox*)GetCurrentVolume()->GetShape()); TString vol_name(GetCurrentVolume()->GetName()); if(!multilay || vol_name.BeginsWith("ACTIVE_")){ // first layer of detector (or only layer) is also active layer // Info("GetCurrentDetector","and also setting active layer matrix to current matrix:"); // GetCurrentMatrix()->Print(); det->SetActiveLayerMatrix(GetCurrentMatrix()); det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } fArray->Add(det); Int_t nstruc = CurrentStructures().GetEntries(); if(nstruc){ // Build and add geometry structure elements KVGeoStrucElement* ELEM = fArray; for(register int i=0;i<nstruc;i++){ KVGeoStrucElement* elem = (KVGeoStrucElement*)CurrentStructures()[i]; KVGeoStrucElement* nextELEM = ELEM->GetStructure(elem->GetName()); if(!nextELEM){ // make new structure nextELEM = new KVGeoStrucElement(elem->GetName(), elem->GetType()); nextELEM->SetNumber(elem->GetNumber()); ELEM->Add(nextELEM); } ELEM=nextELEM; } // add detector to last structure ELEM->Add(det); } } } else { // Detector already built, are we now in its active layer ? TString vol_name(GetCurrentVolume()->GetName()); if(!multilay || vol_name.BeginsWith("ACTIVE_")){ // Info("GetCurrentDetector","Setting active layer matrix to current matrix:"); // GetCurrentMatrix()->Print(); det->SetActiveLayerMatrix(GetCurrentMatrix()); det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } } } return det; }