Motive

CERN ROOT의 스크립트를 보다보면 (혹은 내가 스크립트를 작성하다보면) 변수의 타입이 본래의 C언어와는 비슷하면서 다른 것들이 등장한다. 예를 들어 정수형 변수는 C에서는 int라는 타입을 쓰는데, ROOT 환경에서는 Int_t로 해도 작동한다. 사실 간단한 데이터 분석에서는 뭐로 해도 상관없긴 한데 ROOT로 프로그래밍할때는 첫글자를 대문자로 바꾸고 뒤에는 _t가 붙는 ROOT 자체의 변수형을 습관적으로 쓰곤 한다. 문제는 vim에서는 이러한 ROOT 자체 변수형을 강조해 주지 않는다. 이러한 변수형이 존재하는지 vim은 모르기 때문이다. 그래서 변수의 선언 부분이 눈에 잘 띄지 않아 불편한 점이 있고 vim 에디터도 간지도 잘 나지 않는다.

왜 쓸까?

나도 처음에 ROOT를 배우기 시작할 때는 그냥 남들 따라서 int 대신 Int_t를 사용했지 그 이유를 정확히 알지 못했고 알려고 하지도 않았다. 그 이유는 한참이나 후에 알수 있었는데, 거두절미 하자면 다음 링크에서 그 이유를 찾을 수 있다.

https://en.wikibooks.org/wiki/ROOT/Handling_Data/ROOT_Data_Types

요약하자면 다음과 같다. intdouble 등의 표준 변수형은 컴퓨터에 따라 2바이트를 쓰기도 하고 4바이트를 쓰기도 하는 등 사이즈가 통일되어 있지 않다. 거대한 양의 데이터를 처리할 때는 사용하는 메모리의 양 등을 민감하게 고려해야 한다. (메모리 터지면 계산 날아갈 수도 있으니까) 하지만 이 컴퓨터 저 컴퓨터에서 같은 변수임에도 메모리 사이즈가 다르거나 하면 필요로 하는 메모리 영역이 머신에 따라 달라져 예측이 어렵다. 그게 싫어서 ROOT에서는 어느 머신에서든 데이터형들이 동일한 메모리 사이즈를 점유하게끔 독자적인 타입을 만들어 쓰는 것이다. 요즘 컴퓨터들은 거의 다 64비트 운영체제라 이런 문제가 생기는 상황은 매우 드물겠으나 조심해서 나쁠 것은 없다. 위 링크의 마지막 문장은 다음과 같다.

“It is strongly recommended to use this types when programming ROOT.”

List of CERN ROOT’s Data Types

구글에 검색을 하면 다음과 같은 변수형의 목록을 얻을 수 있다. intdouble 등도 눈에 띄지만 절대다수는 ROOT에서만 쓰이는 타입이다.

https://root.cern/root/html534/ListOfTypes.html

근데 Reference가 ROOT5만 나오고 ROOT6용으로는 검색이 안된다. 뭐… 타입이 5나 6이나 달라진 게 없다고 치면 될듯.

vim Syntax 수정

vim이 설치된 컴퓨터의 ~/.vim/syntax/c.vim 파일을 보면 C언어를 위한 구문강조 규칙이 정리되어 있다. 없으면 알아서 찾아서 다운받아 저 위치에 놓으면 됨. 저 파일의 뒤에 아래와 같은 내용을 추가하면 vim에서도 ROOT의 자료형을 강조해준다.

" Types from ROOT
syn keyword cType Atom_t Axis_t
syn keyword cType Bool_t Byte_t
syn keyword cType Char_t CheckSecCtx_t ClassStreamerFunc_t Color_t Colormap_t COMPAREMETHOD Cursor_t
syn keyword cType Display_t Double32_t Double_t Drawable_t
syn keyword cType Float16_t Float_t Font_t FontH_t FontStruct_t
syn keyword cTpye G__InterfaceMethod GContext_t GlobusAuth_t
syn keyword cType Handle_t
syn keyword cType Int_t ios_base::event_callback IsAGlobalFunc_t
syn keyword cTpye KeySym_t Krb5Auth_t
syn keyword cType Long64_t Long_t
syn keyword cTpye Marker_t Mask_t MemberStreamerFunc_t
syn keyword cType Option_t
syn keyword cType ParametricEquation_t Pixel_t Pixmap_t PrintProgress_t
syn keyword cType ReAllocCFun_t ReAllocCharFun_t ReAllocFun_t Reflex::OffsetFunction
syn keyword cType Reflex::StubFunction Region_t
syn keyword cType RooFit::CFUNCD1D RooFit::CFUNCD1I RooFit::CFUNCD2DD RooFit::CFUNCD2DI
syn keyword cType RooFit::CFUNCD2ID RooFit::CFUNCD2II RooFit::CFUNCD2UD RooFit::CFUNCD3DDB
syn keyword cType RooFit::CFUNCD3DDD RooFit::CFUNCD3DI RooFit::CFUNCD3UDD RooFit::CFUNCD3UDU
syn keyword cType RooFit::CFUNCD3UUD RooFit::CFUNCD4DDDB RooFit::CFUNCD4DDDD RooFit::CFUNCD4DDDI
syn keyword cType RooStats::SamplingSummaryLookup::AcceptanceCriteria
syn keyword cType RooStats::SamplingSummaryLookup::LookupTable
syn keyword cType ROOT::DelArrFunc_t ROOT::DelFunc_t ROOT::DesFunc_t ROOT::DirAutoAdd_t
syn keyword cType ROOT::Math::Derivator::GSLFuncPointer ROOT::Math::GSLFuncPointer
syn keyword cType ROOT::Math::GSLMCIntegrator::GSLMonteFuncPointer ROOT::Math::GSLRngRanLux1
syn keyword cType ROOT::Math::GSLRngRanLux2 ROOT::Math::GSLRngRanLux48
syn keyword cType ROOT::Math::GSLRootFinder::GSLFuncPointer
syn keyword cType ROOT::Math::GSLRootFinderDeriv::GSLFdFPointer
syn keyword cType ROOT::Math::GSLRootFinderDeriv::GSLFuncPointer ROOT::Math::IntegratorOneDim::Type
syn keyword cType ROOT::NewArrFunc_t ROOT::NewFunc_t ROOT::TArrayDouble32Proxy
syn keyword cType ROOT::TArrayFloat16Proxy ROOT::TArrayShortProxy ROOT::TBoolProxy ROOT::TCharProxy
syn keyword cType ROOT::TClaArrayDouble32Proxy ROOT::TClaArrayFloat16Proxy ROOT::TClaArrayShortProxy
syn keyword cType ROOT::TClaBoolProxy ROOT::TClaCharProxy ROOT::TClaDouble32Proxy
syn keyword cType ROOT::TClaDoubleProxy ROOT::TClaFloat16Proxy ROOT::TClaFloatProxy
syn keyword cType ROOT::TClaIntProxy ROOT::TClaLong64Proxy ROOT::TClaLongProxy ROOT::TClaShortProxy
syn keyword cType ROOT::TClaUCharProxy ROOT::TClaUIntProxy ROOT::TClaULong64Proxy
syn keyword cType ROOT::TClaULongProxy ROOT::TClaUShortProxy ROOT::TDouble32Proxy ROOT::TDoubleProxy
syn keyword cType ROOT::TFloat16Proxy ROOT::TFloatProxy ROOT::TIntProxy ROOT::TLong64Proxy
syn keyword cType ROOT::TLongProxy ROOT::TSchemaRule::ReadFuncPtr_t
syn keyword cType ROOT::TSchemaRule::ReadRawFuncPtr_t ROOT::TShortProxy ROOT::TStlArrayBoolProxy
syn keyword cType ROOT::TStlArrayCharProxy ROOT::TStlArrayDouble32Proxy ROOT::TStlArrayDoubleProxy
syn keyword cType ROOT::TStlArrayFloat16Proxy ROOT::TStlArrayFloatProxy ROOT::TStlArrayIntProxy
syn keyword cType ROOT::TStlArrayLong64Proxy ROOT::TStlArrayLongProxy ROOT::TStlArrayShortProxy
syn keyword cType ROOT::TStlArrayUCharProxy ROOT::TStlArrayUIntProxy ROOT::TStlArrayULong64Proxy
syn keyword cType ROOT::TStlArrayULongProxy ROOT::TStlArrayUShortProxy ROOT::TStlBoolProxy
syn keyword cType ROOT::TStlCharProxy ROOT::TStlDouble32Proxy ROOT::TStlDoubleProxy
syn keyword cType ROOT::TStlFloat16Proxy ROOT::TStlFloatProxy ROOT::TStlIntProxy
syn keyword cType ROOT::TStlLong64Proxy ROOT::TStlLongProxy ROOT::TStlShortProxy
syn keyword cType ROOT::TStlUCharProxy ROOT::TStlUIntProxy ROOT::TStlULong64Proxy
syn keyword cType ROOT::TStlULongProxy ROOT::TStlUShortProxy ROOT::TUCharProxy ROOT::TUIntProxy
syn keyword cType ROOT::TULong64Proxy ROOT::TULongProxy ROOT::TUShortProxy
syn keyword cType SCoord_t SEARCHMETHOD SecureAuth_t Short_t ShowMembersFunc_t Size_t Ssiz_t Stat_t
syn keyword cType Style_t
syn keyword cType TBranch::ReadLeaves_t TClass::StreamerImpl_t
syn keyword cType TEveCompositeFrame::IconBarCreator_foo TEveDigitSet::Callback_foo
syn keyword cType TEveDigitSet::TooltipCB_foo TEveElement::ImplySelect_foo TEveElement::Select_foo
syn keyword cType TEveGedEditor::NameFrameCreator_t Text_t TFormula::TFuncG
syn keyword cType TFormulaPrimitive::GenFunc0 TFormulaPrimitive::GenFunc10
syn keyword cType TFormulaPrimitive::GenFunc110 TFormulaPrimitive::GenFunc1110
syn keyword cType TFormulaPrimitive::GenFuncG TFormulaPrimitive::TFunc0 TFormulaPrimitive::TFunc10
syn keyword cType TFormulaPrimitive::TFunc110 TFormulaPrimitive::TFunc1110
syn keyword cType TGenCollectionProxy::ArrIterfunc_t TGenCollectionProxy::Feedfunc_t
syn keyword cType TGenCollectionProxy::Sizing_t TGenCollectionProxy::Staged_t
syn keyword cType TGLAxisPainter::Lab_t TGLAxisPainter::TM_t TGLAxisPainter::TMVec_t
syn keyword cType TGLViewerBase::SubRender_foo Time_t TMatrixFBase
syn keyword cType TPainter3dAlgorithms::DrawFaceFunc_t TPainter3dAlgorithms::LegoFunc_t
syn keyword cType TPainter3dAlgorithms::SurfaceFunc_t TProofMgr_t TSlave_t
syn keyword cType TStreamerInfoActions::TStreamerInfoAction_t
syn keyword cType TStreamerInfoActions::TStreamerInfoLoopAction_t
syn keyword cType TStreamerInfoActions::TStreamerInfoVecPtrLoopAction_t TThread::VoidFunc_t
syn keyword cType TThread::VoidRtnFunc_t TVirtualBranchBrowsable::MethodCreateListOfBrowsables_t
syn keyword cType TVirtualCollectionProxy::CopyIterator_t TVirtualCollectionProxy::CreateIterators_t
syn keyword cType TVirtualCollectionProxy::DeleteIterator_t 
syn keyword cType TVirtualCollectionProxy::DeleteTwoIterators_t TVirtualCollectionProxy::Next_t
syn keyword cType TVirtualFitter::FCNFunc_t
syn keyword cType UChar_t UInt_t ULong64_t ULong_t UShort_t
syn keyword cType Version_t Visual_t VoidFuncPtr_t
syn keyword cType Width_t Window_t

" ROOT constants
syn keyword cConstant kTRUE kFALSE
syn keyword cConstant kMaxUChar kMaxChar kMinChar
syn keyword cConstant kMaxUShort kMaxShort kMinShort
syn keyword cConstant kMaxUInt kMaxInt kMinInt
syn keyword cConstant kMaxULong kMaxLong kMinLong
syn keyword cConstant kMaxULong64 kMaxLong64 kMinLong64
syn keyword cConstant kBitsPerByte kNPOS
syn keyword cConstant kWhite kBlack kGray kRed kGreen kBlue kYellow kMagenta
syn keyword cConstant kCyan kOrange kSpring kTeal kAzure kViolet kPink

Type들은 내가 위 링크에서 리스트를 가져와 노가다로 정리했고, contant들은 내가 개인적으로 기억하고 있는 것들과 ROOT의 소스코드를 뒤져서 빠진 것을 추가해서 직접 작성했음.

카테고리: Computer Language

0개의 댓글

답글 남기기

Avatar placeholder