// File: atfrank[P]PCASA/lib/Analyze.cpp
// Function: AnalyzePcasso::runAnalysis()
void AnalyzePcasso::runAnalysis(){
  std::string line;
  std::vector<std::string> s;
  unsigned int natom;
  bool last;

  Analyze::pcasso(this->getMol(0), this->getFDataVec()); //PCASSO features get stored in the second argument (a 2-D vector double)

  natom=0;
  last=false;

  std::vector<std::vector<double> > &feat=this->getFDataVec();
  std::map<std::string, unsigned int> vote; 
  std::map<std::string, unsigned int>::iterator iter;
  std::string tmpClass;
  std::string maxClass;
  unsigned int maxVote;
  bool majority;
  unsigned int ntree;

  ntree=PCASSO::getNTree();

  if (this->getOutType() == PREDICT || this->getOutType() == PREDICTION){
    for (unsigned int i=0; i< feat.size(); i++){
      vote.clear();
      maxVote=0;
      majority=false;
      for (unsigned int j=0; j< ntree && majority == false; j++){
        tmpClass=t.at(j)->getDTreeClass(feat.at(i));
        if (vote.find(tmpClass) != vote.end()){
          vote.at(tmpClass)++;
          if (vote.at(tmpClass) > maxVote){
            //Find majority vote, method adapted from openCV
            //Is pseudo-random since it depends on the order of the trees
            maxVote=vote.at(tmpClass);
            maxClass=tmpClass;
            if (static_cast<float>(maxVote)/ntree > 0.5){ //Unsigned integer division!
              majority=true;
            }
          }
        }
        else{
          vote.insert(std::pair<std::string, unsigned int>(tmpClass,1));
        }
      }
      if (this->getVerbose() == true && this->getMol(0)->getNAtom() == feat.size()){
        std::cout << " " << this->getMol(0)->getAtom(i)->getSummary();
        std::cout << " " << maxClass ; //Print majority vote
      }
      else{
        std::cout << " " << maxClass; //Print majority vote
      }
    }
  }
  else{
    std::cerr << "Warning: Unrecognized PCASSO output type" << std::endl;
  }

}

// Assembly:
subq $0x248, %rsp            # imm = 0x248
movq %rdi, 0x240(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x220(%rsp), %rdi
callq 0x5600
leaq 0x208(%rsp), %rdi
callq 0x77e0
movq 0xc8(%rsp), %rdi
movl $0x0, 0x1fc(%rsp)
leaq 0x1fc(%rsp), %rsi
callq 0xece0
movq %rax, 0xd0(%rsp)
jmp 0x108a3
movq 0xc8(%rsp), %rdi
callq 0xed70
movq 0xd0(%rsp), %rdi
movq %rax, %rsi
callq 0x10f30
jmp 0x108c2
movq 0xc8(%rsp), %rdi
movl $0x0, 0x204(%rsp)
movb $0x0, 0x203(%rsp)
callq 0xed70
movq %rax, 0x1e0(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x16fd0
leaq 0x1a8(%rsp), %rdi
callq 0x16fe0
leaq 0x188(%rsp), %rdi
callq 0x5600
leaq 0x168(%rsp), %rdi
callq 0x5600
callq 0x7a8a0
movl %eax, 0xc4(%rsp)
jmp 0x1092c
movq 0xc8(%rsp), %rdi
movl 0xc4(%rsp), %eax
movl %eax, 0x15c(%rsp)
callq 0x13690
movl %eax, 0xc0(%rsp)
jmp 0x10950
movl 0xc0(%rsp), %eax
cmpl $0x2, %eax
je 0x10982
movq 0xc8(%rsp), %rdi
callq 0x13690
movl %eax, 0xbc(%rsp)
jmp 0x10972
movl 0xbc(%rsp), %eax
cmpl $0x3, %eax
jne 0x10e6a
movl $0x0, 0x158(%rsp)
movl 0x158(%rsp), %eax
movq %rax, 0xb0(%rsp)
movq 0x1e0(%rsp), %rdi
callq 0x17000
movq %rax, %rcx
movq 0xb0(%rsp), %rax
cmpq %rcx, %rax
jae 0x10e68
leaq 0x1b0(%rsp), %rdi
callq 0x17020
movl $0x0, 0x164(%rsp)
movb $0x0, 0x163(%rsp)
movl $0x0, 0x154(%rsp)
movl 0x154(%rsp), %ecx
xorl %eax, %eax
cmpl 0x15c(%rsp), %ecx
movb %al, 0xaf(%rsp)
jae 0x10a1a
movb 0x163(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
sete %al
movb %al, 0xaf(%rsp)
movb 0xaf(%rsp), %al
testb $0x1, %al
jne 0x10a2a
jmp 0x10ce9
movq 0xc8(%rsp), %rdi
addq $0xb8, %rdi
movl 0x154(%rsp), %eax
movl %eax, %esi
callq 0x16b50
movq %rax, 0xa0(%rsp)
jmp 0x10a51
movq 0xa0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x90(%rsp)
movq 0x1e0(%rsp), %rdi
movl 0x158(%rsp), %eax
movl %eax, %esi
callq 0x16f50
movq %rax, 0x98(%rsp)
jmp 0x10a84
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x3c560
jmp 0x10aa3
leaq 0x188(%rsp), %rdi
movq %rdi, 0x80(%rsp)
leaq 0x130(%rsp), %rsi
movq %rsi, 0x78(%rsp)
callq 0x5510
movq 0x78(%rsp), %rdi
callq 0x5250
movq 0x80(%rsp), %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x17050
movq %rax, 0x88(%rsp)
jmp 0x10aee
movq 0x88(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x17080
movq %rax, 0x120(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x17030
testb $0x1, %al
jne 0x10b31
jmp 0x10c3a
leaq 0x1b0(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x170b0
movq %rax, 0x70(%rsp)
jmp 0x10b4d
movq 0x70(%rsp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
leaq 0x1b0(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x170b0
movq %rax, 0x68(%rsp)
jmp 0x10b74
movq 0x68(%rsp), %rax
movl (%rax), %eax
cmpl 0x164(%rsp), %eax
jbe 0x10c35
leaq 0x1b0(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x170b0
movq %rax, 0x60(%rsp)
jmp 0x10ba4
movq 0x60(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x164(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x5060
jmp 0x10bc9
movl 0x164(%rsp), %eax
cvtsi2ss %rax, %xmm0
movl 0x15c(%rsp), %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x6a7af(%rip), %xmm1    # 0x7b3a0
ucomisd %xmm1, %xmm0
jbe 0x10c33
movb $0x1, 0x163(%rsp)
jmp 0x10c33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x10f07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x10ee0
jmp 0x10c35
jmp 0x10cd1
movl $0x1, 0xf4(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
leaq 0xf4(%rsp), %rdx
callq 0x171b0
jmp 0x10c64
leaq 0x1b0(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x17160
movb %dl, 0x57(%rsp)
movq %rax, 0x58(%rsp)
jmp 0x10c84
movb 0x57(%rsp), %al
movq 0x58(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
movb %al, 0xe8(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x171f0
jmp 0x10cd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x171f0
jmp 0x10ee0
jmp 0x10cd3
movl 0x154(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x154(%rsp)
jmp 0x109e8
movq 0xc8(%rsp), %rdi
callq 0xedb0
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, 0x56(%rsp)
jne 0x10d67
movq 0xc8(%rsp), %rdi
movl $0x0, 0xdc(%rsp)
leaq 0xdc(%rsp), %rsi
callq 0xece0
movq %rax, 0x48(%rsp)
jmp 0x10d2d
movq 0x48(%rsp), %rdi
callq 0x44a80
movl %eax, 0x44(%rsp)
jmp 0x10d3d
movl 0x44(%rsp), %eax
movl %eax, %eax
movq %rax, 0x38(%rsp)
movq 0x1e0(%rsp), %rdi
callq 0x17000
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
sete %al
movb %al, 0x56(%rsp)
movb 0x56(%rsp), %al
testb $0x1, %al
jne 0x10d74
jmp 0x10e20
movq 0x42a23d(%rip), %rdi    # 0x43afb8
leaq 0x6b816(%rip), %rsi     # 0x7c598
callq 0x53f0
movq %rax, 0x30(%rsp)
jmp 0x10d8e
movq 0xc8(%rsp), %rdi
movl $0x0, 0xd8(%rsp)
leaq 0xd8(%rsp), %rsi
callq 0xece0
movq %rax, 0x28(%rsp)
jmp 0x10db5
movq 0x28(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x43580
movq %rax, 0x20(%rsp)
jmp 0x10dce
movq 0x20(%rsp), %rdi
callq 0x1f7a0
movq %rax, 0x18(%rsp)
jmp 0x10ddf
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x5390
jmp 0x10df0
movq 0x42a1c1(%rip), %rdi    # 0x43afb8
leaq 0x6b79a(%rip), %rsi     # 0x7c598
callq 0x53f0
movq %rax, 0x10(%rsp)
jmp 0x10e0a
movq 0x10(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x5390
jmp 0x10e1e
jmp 0x10e50
movq 0x42a191(%rip), %rdi    # 0x43afb8
leaq 0x6b76a(%rip), %rsi     # 0x7c598
callq 0x53f0
movq %rax, 0x8(%rsp)
jmp 0x10e3a
movq 0x8(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x5390
jmp 0x10e4e
jmp 0x10e50
jmp 0x10e52
movl 0x158(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x158(%rsp)
jmp 0x1098d
jmp 0x10e97
movq 0x42a17f(%rip), %rdi    # 0x43aff0
leaq 0x6a592(%rip), %rsi     # 0x7b40a
callq 0x53f0
movq %rax, (%rsp)
jmp 0x10e83
movq (%rsp), %rdi
movq 0x42a11a(%rip), %rsi    # 0x43afa8
callq 0x5460
jmp 0x10e95
jmp 0x10e97
leaq 0x168(%rsp), %rdi
callq 0x5250
leaq 0x188(%rsp), %rdi
callq 0x5250
leaq 0x1b0(%rsp), %rdi
callq 0x17200
leaq 0x208(%rsp), %rdi
callq 0x7ab0
leaq 0x220(%rsp), %rdi
callq 0x5250
addq $0x248, %rsp            # imm = 0x248
retq
leaq 0x168(%rsp), %rdi
callq 0x5250
leaq 0x188(%rsp), %rdi
callq 0x5250
leaq 0x1b0(%rsp), %rdi
callq 0x17200
leaq 0x208(%rsp), %rdi
callq 0x7ab0
leaq 0x220(%rsp), %rdi
callq 0x5250
movq 0x1f0(%rsp), %rdi
callq 0x5720
nop