How to use Quaternion from IMU to get the transformation to inertial reference frame?

Im trying to get the Linear Velocity integrating the acceleration from IMu. I know there will be accumulated error due to integration bit before the integration I have to do couple of other steps. First step would be transformation to the inertial reference frame. So basically using Quaternion transformation . Second, using that transformation to get the acceleration on the IMU regarding that inertial reference frame. And third final will be to integrate that transformed acceleration.

So here the steps before the integration part Quaternion-> T(r); a(inertial-reference-frame) = T(r)*a(imu);

So how would be ROS node (C++) that handle these two steps before the integration?

I have part of the code that think can do that but Im not sure

geometry_msgs::QuaternionStamped imu_quat = geometry_msgs::QuaternionStamped();
tf::StampedTransform transform;
tf::TransformListener listener;
ros::Duration(3.0));

transform);

imu_quat.quaternion = msg->orientation;
geometry_msgs::QuaternionStamped q_robot;

tf::Quaternion quatquat;
tf::quaternionMsgToTF(q_robot.quaternion,quatquat);
tf::Matrix3x3(quatquat).getEulerYPR(new_yaw,new_pitch,new_roll);
acceleration_x = (msg->linear_acceleration.x);
acceleration_x = transform.getOrigin().x();

if (count2 == 0){
time_prev = ros::Time::now().toSec();
count2=1;
}

float time_now = ros::Time::now().toSec();
float time_dif = time_now - time_prev;
time_prev = time_now;
acceleration_x = (msg->linear_acceleration.x );
m_velocity += acceleration_x*time_dif;
send_velocity();


Is this the correct way?Thanks