#include "IFieldMapLoader.hxx" #include "IFieldManager.hxx" #include "IFieldMapList.hxx" #include #include #include "TMath.h" // Map not found exception OA_EXCEPTION(EFieldMapNotFound, COMET::EoaCore); COMET::IFieldMapLoader::IFieldMapLoader(){} int COMET::IFieldMapLoader::ProcessArgument(const char& argument, const char* optArgument, COMET::IFieldMapList* fieldList){ // Load a dummy stream std::stringstream tempStream; if (optArgument) tempStream.str(optArgument); // Load in the fieldmap from the arguments IFieldMapDescription* desc = NULL; switch (argument) { case 'R': if(!COMET::IFieldManager::Import(optarg)) return 1; else return 0; case 'f': desc = fieldList->AddFieldmap(optarg); if (!desc->CheckSum()) { COMETError("Field map " << desc->Filename() << " was not found!"); throw EFieldMapNotFound(); } return 0; case 't': { if(!fieldList->CheckHaveAFile()) return 2; double vect[3]; tempStream>>vect[0]>>vect[1]>>vect[2]; TVector3 translation(vect[0],vect[1],vect[2]); fieldList->GetLastFieldmap()->SetTranslation(translation); break; } case 'r': { if(!fieldList->CheckHaveAFile()) return 2; TRotation newRot = TRotation(); const TRotation* oldRot = fieldList->GetLastFieldmap()->Rotation(); if (oldRot) newRot = TRotation(*oldRot); bool all_good = StringToRotation(newRot,tempStream); if(!all_good) tempStream.setstate(std::ios_base::failbit); else fieldList->GetLastFieldmap()->SetRotation(newRot); break; } case 's': { if(! fieldList->CheckHaveAFile()) return 2; double scale; tempStream>>scale; fieldList->GetLastFieldmap()->SetScaling(scale); break; } default: return 3; } if(tempStream.fail() || !tempStream.eof()){ std::cout << tempStream.str() << std::endl; return 4; } else return 0; } std::string COMET::IFieldMapLoader::UsageMessage(){ return "Input file Options: \n" " -f Add a file to the list of fieldmaps. Should be a path \n" " relative to the current working directory or an absolute path\n" " -t Set the translation of the last fieldmap added to the list of inputs. \n" " NOTE: uses mm\n" " -r Set the rotation of the last fieldmap added to the list of inputs. \n" " The format is (rotX, rotY, rotZ), where the rotations act \n" " left-to-right, i.e. first around X, then Y, then Z. \n" " NOTE: uses rads\n" " -s Set the scale factor of the last fieldmap added to the list of inputs. \n" " -R Recreate a fieldmap from an existing root file \n"; } bool COMET::IFieldMapLoader::StringToRotation(TRotation& rotation, std::stringstream& input){ // We apply successive rotations OF THE OBJECT around the FIXED // axes of the parent's local coordinates; rotations are applied // left-to-right (rotation="r1,r2,r3" => r1 then r2 then r3). char axis='0'; double angle=0.0; while (input>> axis >>angle){ switch(axis){ case 'X':case 'x': rotation.RotateX(angle); break; case 'Y':case 'y': rotation.RotateY(angle); COMETLog("inside y rotation"); break; case 'Z':case 'z': rotation.RotateZ(angle); break; default: COMETError("Bad input axis: "<ls(); fieldList->InitialiseField(); return true; } bool COMET::IFieldMapLoader::WriteAllFields(IFieldMapList* fieldList){ fieldList->ls(); fieldList->Write(); COMET::IFieldManager* mgr=COMET::IFieldManager::GetObject(); COMET::IHandle description=mgr->MakeDescription(); description->Write(); description->ls(); return true; }