The prosecutor will file misdemeanor charges against a person for being under the influence of a controlled substance if he used a controlled substance, such as methamphetamine, heroin, ecstasy, or cocaine, and at the time of his arrest his body was being affected by that substance (Health & Safety Code Section 11550(a)).
If convicted of this misdemeanor offense, California law requires a mandatory minimum jail sentence of 90 days on a first violation unless you are eligible for a drug diversion and treatment program. If so, you may be able to avoid custody altogether, and even be able to keep a conviction off of your record if you complete such a program successfully.